Skip to content

Commit 940b0a1

Browse files
authored
Support install_mode with pyntc. (#265)
1 parent c98765f commit 940b0a1

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pip install terminal
102102
* **ntc_reboot** - reboots a network device. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista.
103103
* **ntc_get_facts** - gathers facts from a network device. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista.
104104
* **ntc_rollback** - performs two major functions. (1) Creates a checkpoint file or backup running config on box. (2) Rolls back to the previously created checkpoint/backup config. Use case is to create the checkpoint/backup as the first task in a playbook and then rollback to it _if_ needed using block/rescue, i.e. try/except in Ansible. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista.
105-
* **ntc_install_os** - installs a new operating system or just sets boot options. Depends on platform. Does not issue a "reload" command, but the device may perform an automatic reboot. Common workflow is to use ntc_file_copy, ntc_install_os, and then ntc_reboot (if needed) for upgrades. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista.
105+
* **ntc_install_os** - installs a new operating system or just sets boot options. Depends on platform. Does not issue a "reload" command, but the device may perform an automatic reboot. Common workflow is to use ntc_file_copy, ntc_install_os, and then ntc_reboot (if needed) for upgrades. Uses SSH/netmiko for IOS, NX-API for Nexus, and eAPI for Arista. For Cisco stack switches pyntc leverages `install_mode` flag to install with the install command. This has an optional parameter of `install_mode` available on install_os (requires PyNTC > 0.16.0)
106106

107107
## Common Issues
108108

library/ntc_install_os.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,16 @@ def already_set(boot_options, system_image_file, kickstart_image_file, **kwargs)
221221

222222
def main():
223223
connection_argument_spec = dict(
224-
platform=dict(choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI,
225-
PLATFORM_F5, PLATFORM_ASA],
226-
required=False),
224+
platform=dict(
225+
choices=[PLATFORM_NXAPI, PLATFORM_IOS, PLATFORM_EAPI, PLATFORM_F5, PLATFORM_ASA],
226+
required=False,
227+
),
227228
host=dict(required=False),
228229
port=dict(required=False),
229-
username=dict(required=False, type='str'),
230-
password=dict(required=False, type='str', no_log=True),
231-
secret=dict(required=False, type='str', no_log=True),
232-
transport=dict(required=False, choices=['http', 'https']),
230+
username=dict(required=False, type="str"),
231+
password=dict(required=False, type="str", no_log=True),
232+
secret=dict(required=False, type="str", no_log=True),
233+
transport=dict(required=False, choices=["http", "https"]),
233234
ntc_host=dict(required=False),
234235
ntc_conf_file=dict(required=False),
235236
)
@@ -238,24 +239,26 @@ def main():
238239
kickstart_image_file=dict(required=False),
239240
volume=dict(required=False, type="str"),
240241
reboot=dict(required=False, type="bool", default=False),
242+
install_mode=dict(required=False, type="bool", default=None),
241243
)
242244
argument_spec = base_argument_spec
243245
argument_spec.update(connection_argument_spec)
244246
argument_spec["provider"] = dict(required=False, type="dict", options=connection_argument_spec)
245247

246248
module = AnsibleModule(
247249
argument_spec=argument_spec,
248-
mutually_exclusive=[['host', 'ntc_host'],
249-
['ntc_host', 'secret'],
250-
['ntc_host', 'transport'],
251-
['ntc_host', 'port'],
252-
['ntc_conf_file', 'secret'],
253-
['ntc_conf_file', 'transport'],
254-
['ntc_conf_file', 'port'],
255-
],
256-
required_one_of=[['host', 'ntc_host', 'provider']],
250+
mutually_exclusive=[
251+
["host", "ntc_host"],
252+
["ntc_host", "secret"],
253+
["ntc_host", "transport"],
254+
["ntc_host", "port"],
255+
["ntc_conf_file", "secret"],
256+
["ntc_conf_file", "transport"],
257+
["ntc_conf_file", "port"],
258+
],
259+
required_one_of=[["host", "ntc_host", "provider"]],
257260
required_if=[["platform", PLATFORM_F5, ["volume"]]],
258-
supports_check_mode=True
261+
supports_check_mode=True,
259262
)
260263

261264
if not HAS_PYNTC:
@@ -324,6 +327,15 @@ def main():
324327
kickstart_image_file = module.params["kickstart_image_file"]
325328
volume = module.params["volume"]
326329

330+
# Get the NTC Version split
331+
version_numbers = pyntc_version.split(".")
332+
install_mode = module.params.get("install_mode")
333+
334+
if install_mode and not ((int(version_numbers[0]) > 0) or (int(version_numbers[1]) >= 16)):
335+
module.fail_json(
336+
msg="Current version of PyNTC does not support install_mode. Please update PyNTC >= 0.16.0"
337+
)
338+
327339
if kickstart_image_file == "null":
328340
kickstart_image_file = None
329341

@@ -337,7 +349,10 @@ def main():
337349
# TODO: Remove conditional if we require reboot for non-F5 devices
338350
if reboot or device.device_type == "f5_tmos_icontrol":
339351
changed = device.install_os(
340-
image_name=system_image_file, kickstart=kickstart_image_file, volume=volume
352+
image_name=system_image_file,
353+
kickstart=kickstart_image_file,
354+
volume=volume,
355+
install_mode=install_mode,
341356
)
342357
else:
343358
# TODO: Remove support if we require reboot for non-F5 devices

0 commit comments

Comments
 (0)