Skip to content

Commit

Permalink
feat: epld upgrade with nxos
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre PETIT committed Sep 6, 2024
1 parent 72225be commit d64e201
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions plugins/modules/nxos_install_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def massage_install_data(data):
return result_data


def build_install_cmd_set(issu, image, kick, type, force=True):
def build_install_cmd_set(issu, image, kick, epld, type, force=True):
commands = ["terminal dont-ask"]

# Different NX-OS platforms behave differently for
Expand Down Expand Up @@ -389,7 +389,10 @@ def build_install_cmd_set(issu, image, kick, type, force=True):
else:
rootcmd = "install all"
if kick is None:
commands.append("%s nxos %s %s" % (rootcmd, image, issu_cmd))
if epld is None:
commands.append("%s nxos %s %s" % (rootcmd, image, issu_cmd))
else:
commands.append("%s nxos %s epld %s %s" % (rootcmd, image, epld, issu_cmd))
else:
commands.append(
"%s %s system %s kickstart %s" % (rootcmd, issu_cmd, image, kick),
Expand Down Expand Up @@ -454,16 +457,16 @@ def check_mode_legacy(module, issu, image, kick=None):
return data


def check_mode_nextgen(module, issu, image, kick=None):
def check_mode_nextgen(module, issu, image, kick=None, epld=None):
"""Use the 'install all impact' command for check_mode"""
opts = {"ignore_timeout": True}
commands = build_install_cmd_set(issu, image, kick, "impact")
commands = build_install_cmd_set(issu, image, kick, epld, "impact")
data = parse_show_install(load_config(module, commands, True, opts))
# If an error is encountered when issu is 'desired' then try again
# but set issu to 'no'
if data["error"] and issu == "desired":
issu = "no"
commands = build_install_cmd_set(issu, image, kick, "impact")
commands = build_install_cmd_set(issu, image, kick, epld, "impact")
# The system may be busy from the previous call to check_mode so loop
# until it's done.
data = check_install_in_progress(module, commands, opts)
Expand Down Expand Up @@ -499,7 +502,7 @@ def check_mode(module, issu, image, kick=None):
return data


def do_install_all(module, issu, image, kick=None):
def do_install_all(module, issu, image, kick=None, epld=None):
"""Perform the switch upgrade using the 'install all' command"""
impact_data = check_mode(module, issu, image, kick)
if module.check_mode:
Expand All @@ -526,15 +529,15 @@ def do_install_all(module, issu, image, kick=None):
else:
issu = "no"

commands = build_install_cmd_set(issu, image, kick, "install")
commands = build_install_cmd_set(issu, image, kick, epld, "install")
opts = {"ignore_timeout": True}
# The system may be busy from the call to check_mode so loop until
# it's done.
upgrade = check_install_in_progress(module, commands, opts)
if upgrade["invalid_command"] and "force" in commands[1]:
# Not all platforms support the 'force' keyword. Check for this
# condition and re-try without the 'force' keyword if needed.
commands = build_install_cmd_set(issu, image, kick, "install", False)
commands = build_install_cmd_set(issu, image, kick, epld, "install", False)
upgrade = check_install_in_progress(module, commands, opts)
upgrade["upgrade_cmd"] = commands

Expand Down Expand Up @@ -563,6 +566,7 @@ def main():
argument_spec = dict(
system_image_file=dict(required=True),
kickstart_image_file=dict(required=False),
epld_image_file=dict(required=False),
issu=dict(choices=["required", "desired", "no", "yes"], default="no"),
)

Expand All @@ -574,6 +578,7 @@ def main():
# issu settings from module params.
sif = module.params["system_image_file"]
kif = module.params["kickstart_image_file"]
eif = module.params["epld_image_file"]
issu = module.params["issu"]

if re.search(r"(yes|required)", issu):
Expand All @@ -582,7 +587,10 @@ def main():
if kif == "null" or kif == "":
kif = None

install_result = do_install_all(module, issu, sif, kick=kif)
if eif == "null" or eif == "":
eif = None

install_result = do_install_all(module, issu, sif, kick=kif, epld=eif)
if install_result["error"]:
cmd = install_result["upgrade_cmd"]
msg = "Failed to upgrade device using command: %s" % cmd
Expand Down

0 comments on commit d64e201

Please sign in to comment.