Skip to content

Commit

Permalink
Fix for issue Juniper#613 (Juniper#617)
Browse files Browse the repository at this point in the history
* Fix for issue Juniper#613
Support for software installation on specific members "member_id" of EX-VC

* Fix for issue Juniper#613
Support for software installation on specific members "member_id" of EX-VC
  • Loading branch information
chidanandpujar authored Aug 2, 2023
1 parent d661321 commit e3f6fca
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
16 changes: 12 additions & 4 deletions ansible_collections/juniper/device/plugins/connection/pyez.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def commit_configuration(self, ignore_warning=None, comment=None,
raise AnsibleError('Failure committing the configuraton: %s' %
(str(ex)))

def system_api(self, action, in_min, at, all_re, vmhost, other_re, media):
def system_api(self, action, in_min, at, all_re, vmhost, other_re, media, member_id):
"""Triggers the system calls like reboot, shutdown, halt and zeroize to device.
"""
msg = None
Expand All @@ -767,7 +767,11 @@ def system_api(self, action, in_min, at, all_re, vmhost, other_re, media):
try:
self.sw = jnpr.junos.utils.sw.SW(self.dev)
if action == 'reboot':
got = self.sw.reboot(in_min, at, all_re, None, vmhost, other_re)
if member_id is not None:
for m_id in member_id:
got = self.sw.reboot(in_min, at, all_re, None, vmhost, other_re, member_id=m_id)
else:
got = self.sw.reboot(in_min, at, all_re, None, vmhost, other_re)
elif action == 'shutdown':
got = self.sw.poweroff(in_min, at, None, all_re, other_re)
elif action == 'halt':
Expand Down Expand Up @@ -815,7 +819,7 @@ def software_api(self, install_params):
self.pyez_exception.RpcError) as ex:
raise AnsibleError('Installation failed. Error: %s' % str(ex))

def reboot_api(self, all_re, vmhost):
def reboot_api(self, all_re, vmhost, member_id):
"""reboots the device.
"""
msg = None
Expand All @@ -824,7 +828,11 @@ def reboot_api(self, all_re, vmhost):
if self.dev.timeout > 5:
self.dev.timeout = 5
try:
got = self.sw.reboot(0, None, all_re, None, vmhost)
if member_id is not None:
for m_id in member_id:
got = self.sw.reboot(0, None, all_re, None, vmhost, member_id=m_id)
else:
got = self.sw.reboot(0, None, all_re, None, vmhost)
self.dev.timeout = restore_timeout
except Exception: # pylint: disable=broad-except
self.dev.timeout = restore_timeout
Expand Down
23 changes: 21 additions & 2 deletions ansible_collections/juniper/device/plugins/modules/software.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
required: false
default: true
type: bool
member_id:
description:
- install software on the specified members ids of VC.
required: false
default: none
type: list
checksum:
description:
- The pre-calculated checksum, using the I(checksum_algorithm) of the
Expand Down Expand Up @@ -492,6 +498,9 @@ def main():
all_re=dict(required=False,
type='bool',
default=True),
member_id=dict(required=False,
type='list',
default=None),
vmhost=dict(required=False,
type='bool',
default=False),
Expand Down Expand Up @@ -541,6 +550,7 @@ def main():
install_timeout = junos_module.params.pop('install_timeout')
cleanfs = junos_module.params.pop('cleanfs')
all_re = junos_module.params.pop('all_re')
member_id = junos_module.params.pop('member_id')
kwargs = junos_module.params.pop('kwargs')

url = None
Expand Down Expand Up @@ -684,6 +694,7 @@ def main():
install_params['no_copy'] = no_copy
install_params['timeout'] = install_timeout
install_params['all_re'] = all_re
install_params['member_id'] = member_id
for key in option_keys:
value = junos_module.params.get(key)
if value is not None:
Expand Down Expand Up @@ -715,7 +726,11 @@ def main():
if reboot is True:
junos_module.logger.debug('Initiating reboot.')
if junos_module.conn_type != "local":
results['msg'] += junos_module._pyez_conn.reboot_api(all_re, install_params.get('vmhost'))
if member_id is not None:
for m_id in member_id:
results['msg'] += junos_module._pyez_conn.reboot_api(all_re, install_params.get('vmhost'), member_id=m_id)
else:
results['msg'] += junos_module._pyez_conn.reboot_api(all_re, install_params.get('vmhost'))
else:
try:
# Try to deal with the fact that we might not get the closing
Expand All @@ -728,7 +743,11 @@ def main():
"to 5 seconds.")
junos_module.dev.timeout = 5
try:
got = junos_module.sw.reboot(0, None, all_re, None, install_params.get('vmhost'))
if member_id is not None:
for m_id in member_id:
got = junos_module.sw.reboot(0, None, all_re, None, install_params.get('vmhost'), member_id=m_id)
else:
got = junos_module.sw.reboot(0, None, all_re, None, install_params.get('vmhost'))
junos_module.dev.timeout = restore_timeout
except Exception: # pylint: disable=broad-except
junos_module.dev.timeout = restore_timeout
Expand Down
16 changes: 14 additions & 2 deletions ansible_collections/juniper/device/plugins/modules/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ def main():
all_re=dict(type='bool',
required=False,
default=True),
member_id=dict(type='list',
required=False,
default=None),
other_re=dict(type='bool',
required=False,
default=False),
Expand All @@ -297,6 +300,7 @@ def main():
other_re = params.get('other_re')
media = params.get('media')
vmhost = params.get('vmhost')
member_id = params.get('member_id')

# Synonymn for shutdown
if action == 'off' or action == 'power_off' or action == 'power-off':
Expand Down Expand Up @@ -331,7 +335,11 @@ def main():

if not junos_module.check_mode:
if junos_module.conn_type != "local":
results['msg'] = junos_module._pyez_conn.system_api(action, in_min, at, all_re, vmhost, other_re, media)
if member_id is not None:
for m_id in member_id:
results['msg'] = junos_module._pyez_conn.system_api(action, in_min, at, all_re, vmhost, other_re, media, member_id=m_id)
else:
results['msg'] = junos_module._pyez_conn.system_api(action, in_min, at, all_re, vmhost, other_re, media)
results['failed'] = False
else:
if action != 'zeroize':
Expand All @@ -351,7 +359,11 @@ def main():
junos_module.logger.debug("Executing RPC")
junos_module.add_sw()
if action == 'reboot':
got = junos_module.sw.reboot(in_min, at, all_re, None, vmhost, other_re)
if member_id is not None:
for m_id in member_id:
got = junos_module.sw.reboot(in_min, at, all_re, None, vmhost, other_re, member_id=m_id)
else:
got = junos_module.sw.reboot(in_min, at, all_re, None, vmhost, other_re)
elif action == 'shutdown':
got = junos_module.sw.poweroff(in_min, at, None, all_re, other_re)
elif action == 'halt':
Expand Down

0 comments on commit e3f6fca

Please sign in to comment.