diff options
23 files changed, 271 insertions, 86 deletions
| diff --git a/plugins/module_utils/network/vyos/argspec/facts/facts.py b/plugins/module_utils/network/vyos/argspec/facts/facts.py index e660ef26..fc9d438e 100644 --- a/plugins/module_utils/network/vyos/argspec/facts/facts.py +++ b/plugins/module_utils/network/vyos/argspec/facts/facts.py @@ -18,7 +18,13 @@ class FactsArgs(object):  # pylint: disable=R0903      def __init__(self, **kwargs):          pass -    choices = ["all", "interfaces", "!interfaces", "l3_interfaces", "!l3_interfaces"] +    choices = [ +        "all", +        "interfaces", +        "!interfaces", +        "l3_interfaces", +        "!l3_interfaces", +    ]      argument_spec = {          "gather_subset": dict(default=["!config"], type="list"), diff --git a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py index 1b6584b9..adf61d78 100644 --- a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py +++ b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py @@ -16,7 +16,11 @@ __metaclass__ = type  from copy import deepcopy  from ansible.module_utils.network.common.cfg.base import ConfigBase -from ansible.module_utils.network.common.utils import to_list, dict_diff, remove_empties +from ansible.module_utils.network.common.utils import ( +    to_list, +    dict_diff, +    remove_empties, +)  from ansible.module_utils.six import iteritems  from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (      Facts, @@ -117,7 +121,9 @@ class Interfaces(ConfigBase):          elif state == "deleted":              if not want:                  for intf in have: -                    commands.extend(self._state_deleted({"name": intf["name"]}, intf)) +                    commands.extend( +                        self._state_deleted({"name": intf["name"]}, intf) +                    )              else:                  for item in want:                      obj_in_have = search_obj_in_list(item["name"], have) @@ -165,7 +171,9 @@ class Interfaces(ConfigBase):          for intf in have:              intf_in_want = search_obj_in_list(intf["name"], want)              if not intf_in_want: -                commands.extend(self._state_deleted({"name": intf["name"]}, intf)) +                commands.extend( +                    self._state_deleted({"name": intf["name"]}, intf) +                )          for intf in want:              intf_in_have = search_obj_in_list(intf["name"], have) @@ -203,7 +211,10 @@ class Interfaces(ConfigBase):                      want_vif["vlan_id"], have_vifs, key="vlan_id"                  )                  if not have_vif: -                    have_vif = {"vlan_id": want_vif["vlan_id"], "enabled": True} +                    have_vif = { +                        "vlan_id": want_vif["vlan_id"], +                        "enabled": True, +                    }                  vif_updates = dict_diff(have_vif, want_vif)                  if vif_updates: @@ -255,7 +266,10 @@ class Interfaces(ConfigBase):                      have_vif["vlan_id"], want_vifs, key="vlan_id"                  )                  if not want_vif: -                    want_vif = {"vlan_id": have_vif["vlan_id"], "enabled": True} +                    want_vif = { +                        "vlan_id": have_vif["vlan_id"], +                        "enabled": True, +                    }                  for key in dict_delete(have_vif, want_vif).keys():                      if key == "enabled": @@ -280,7 +294,9 @@ class Interfaces(ConfigBase):          return commands -    def _compute_commands(self, interface, key, vif=None, value=None, remove=False): +    def _compute_commands( +        self, interface, key, vif=None, value=None, remove=False +    ):          intf_context = "interfaces {0} {1}".format(              get_interface_type(interface), interface          ) diff --git a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py index 4260f35f..a69db052 100644 --- a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py @@ -52,7 +52,9 @@ class L3_interfaces(ConfigBase):          facts, _warnings = Facts(self._module).get_facts(              self.gather_subset, self.gather_network_resources          ) -        l3_interfaces_facts = facts["ansible_network_resources"].get("l3_interfaces") +        l3_interfaces_facts = facts["ansible_network_resources"].get( +            "l3_interfaces" +        )          if not l3_interfaces_facts:              return []          return l3_interfaces_facts @@ -120,7 +122,9 @@ class L3_interfaces(ConfigBase):          elif state == "deleted":              if not want:                  for intf in have: -                    commands.extend(self._state_deleted({"name": intf["name"]}, intf)) +                    commands.extend( +                        self._state_deleted({"name": intf["name"]}, intf) +                    )              else:                  for item in want:                      obj_in_have = search_obj_in_list(item["name"], have) @@ -168,7 +172,9 @@ class L3_interfaces(ConfigBase):          for intf in have:              intf_in_want = search_obj_in_list(intf["name"], want)              if not intf_in_want: -                commands.extend(self._state_deleted({"name": intf["name"]}, intf)) +                commands.extend( +                    self._state_deleted({"name": intf["name"]}, intf) +                )          for intf in want:              intf_in_have = search_obj_in_list(intf["name"], have) @@ -237,7 +243,10 @@ class L3_interfaces(ConfigBase):              for key, value in iteritems(update):                  commands.append(                      self._compute_commands( -                        key=key, value=value, interface=want_copy["name"], remove=True +                        key=key, +                        value=value, +                        interface=want_copy["name"], +                        remove=True,                      )                  ) @@ -263,7 +272,9 @@ class L3_interfaces(ConfigBase):          return commands -    def _compute_commands(self, interface, key, vif=None, value=None, remove=False): +    def _compute_commands( +        self, interface, key, vif=None, value=None, remove=False +    ):          intf_context = "interfaces {0} {1}".format(              get_interface_type(interface), interface          ) @@ -284,7 +295,11 @@ class L3_interfaces(ConfigBase):      def _get_updates(self, want, have):          updates = [] -        updates = diff_list_of_dicts(want.get("ipv4", []), have.get("ipv4", [])) -        updates.extend(diff_list_of_dicts(want.get("ipv6", []), have.get("ipv6", []))) +        updates = diff_list_of_dicts( +            want.get("ipv4", []), have.get("ipv4", []) +        ) +        updates.extend( +            diff_list_of_dicts(want.get("ipv6", []), have.get("ipv6", [])) +        )          return updates diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py index f92c7617..fcb6bf0f 100644 --- a/plugins/module_utils/network/vyos/facts/facts.py +++ b/plugins/module_utils/network/vyos/facts/facts.py @@ -31,7 +31,10 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legac      Config,  ) -from ansible.module_utils.network.vyos.vyos import run_commands, get_capabilities +from ansible.module_utils.network.vyos.vyos import ( +    run_commands, +    get_capabilities, +)  FACT_LEGACY_SUBSETS = dict(default=Default, neighbors=Neighbors, config=Config) @@ -50,7 +53,9 @@ class Facts(FactsBase):      def __init__(self, module):          super(Facts, self).__init__(module) -    def get_facts(self, legacy_facts_type=None, resource_facts_type=None, data=None): +    def get_facts( +        self, legacy_facts_type=None, resource_facts_type=None, data=None +    ):          """ Collect the facts for vyos          :param legacy_facts_type: List of legacy facts types @@ -59,15 +64,20 @@ class Facts(FactsBase):          :rtype: dict          :return: the facts gathered          """ -        netres_choices = FactsArgs.argument_spec["gather_network_resources"].get( -            "choices", [] -        ) +        netres_choices = FactsArgs.argument_spec[ +            "gather_network_resources" +        ].get("choices", [])          if self.VALID_RESOURCE_SUBSETS:              self.get_network_resources_facts( -                netres_choices, FACT_RESOURCE_SUBSETS, resource_facts_type, data +                netres_choices, +                FACT_RESOURCE_SUBSETS, +                resource_facts_type, +                data,              )          if self.VALID_LEGACY_GATHER_SUBSETS: -            self.get_network_legacy_facts(FACT_LEGACY_SUBSETS, legacy_facts_type) +            self.get_network_legacy_facts( +                FACT_LEGACY_SUBSETS, legacy_facts_type +            )          return self.ansible_facts, self._warnings diff --git a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py index 9d8d0086..7b73b9bf 100644 --- a/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py +++ b/plugins/module_utils/network/vyos/facts/interfaces/interfaces.py @@ -69,7 +69,9 @@ class InterfacesFacts(object):          facts = {}          if objs:              facts["interfaces"] = [] -            params = utils.validate_config(self.argument_spec, {"config": objs}) +            params = utils.validate_config( +                self.argument_spec, {"config": objs} +            )              for cfg in params["config"]:                  facts["interfaces"].append(utils.remove_empties(cfg)) @@ -88,7 +90,9 @@ class InterfacesFacts(object):          """          vif_conf = "\n".join(filter(lambda x: ("vif" in x), conf))          eth_conf = "\n".join(filter(lambda x: ("vif" not in x), conf)) -        config = self.parse_attribs(["description", "speed", "mtu", "duplex"], eth_conf) +        config = self.parse_attribs( +            ["description", "speed", "mtu", "duplex"], eth_conf +        )          config["vifs"] = self.parse_vifs(vif_conf)          return utils.remove_empties(config) diff --git a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py index 306a73bb..05973ba3 100644 --- a/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py +++ b/plugins/module_utils/network/vyos/facts/l3_interfaces/l3_interfaces.py @@ -74,7 +74,9 @@ class L3_interfacesFacts(object):          facts = {}          if objs:              facts["l3_interfaces"] = [] -            params = utils.validate_config(self.argument_spec, {"config": objs}) +            params = utils.validate_config( +                self.argument_spec, {"config": objs} +            )              for cfg in params["config"]:                  facts["l3_interfaces"].append(utils.remove_empties(cfg)) diff --git a/plugins/module_utils/network/vyos/facts/legacy/base.py b/plugins/module_utils/network/vyos/facts/legacy/base.py index a05516df..34992b1b 100644 --- a/plugins/module_utils/network/vyos/facts/legacy/base.py +++ b/plugins/module_utils/network/vyos/facts/legacy/base.py @@ -16,7 +16,10 @@ __metaclass__ = type  import platform  import re -from ansible.module_utils.network.vyos.vyos import run_commands, get_capabilities +from ansible.module_utils.network.vyos.vyos import ( +    run_commands, +    get_capabilities, +)  class LegacyFactsBase(object): diff --git a/plugins/module_utils/network/vyos/vyos.py b/plugins/module_utils/network/vyos/vyos.py index 2d6a1a80..c578dd51 100644 --- a/plugins/module_utils/network/vyos/vyos.py +++ b/plugins/module_utils/network/vyos/vyos.py @@ -37,13 +37,17 @@ vyos_provider_spec = {      "host": dict(),      "port": dict(type="int"),      "username": dict(fallback=(env_fallback, ["ANSIBLE_NET_USERNAME"])), -    "password": dict(fallback=(env_fallback, ["ANSIBLE_NET_PASSWORD"]), no_log=True), +    "password": dict( +        fallback=(env_fallback, ["ANSIBLE_NET_PASSWORD"]), no_log=True +    ),      "ssh_keyfile": dict(          fallback=(env_fallback, ["ANSIBLE_NET_SSH_KEYFILE"]), type="path"      ),      "timeout": dict(type="int"),  } -vyos_argument_spec = {"provider": dict(type="dict", options=vyos_provider_spec)} +vyos_argument_spec = { +    "provider": dict(type="dict", options=vyos_provider_spec) +}  vyos_top_spec = {      "host": dict(removed_in_version=2.9),      "port": dict(removed_in_version=2.9, type="int"), @@ -106,7 +110,9 @@ def get_config(module, flags=None, format=None):  def run_commands(module, commands, check_rc=True):      connection = get_connection(module)      try: -        response = connection.run_commands(commands=commands, check_rc=check_rc) +        response = connection.run_commands( +            commands=commands, check_rc=check_rc +        )      except ConnectionError as exc:          module.fail_json(msg=to_text(exc, errors="surrogate_then_replace"))      return response diff --git a/plugins/modules/_vyos_interface.py b/plugins/modules/_vyos_interface.py index ee82107f..51285746 100644 --- a/plugins/modules/_vyos_interface.py +++ b/plugins/modules/_vyos_interface.py @@ -175,7 +175,10 @@ from time import sleep  from ansible.module_utils._text import to_text  from ansible.module_utils.basic import AnsibleModule  from ansible.module_utils.connection import exec_command -from ansible.module_utils.network.common.utils import conditional, remove_default_spec +from ansible.module_utils.network.common.utils import ( +    conditional, +    remove_default_spec, +)  from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (      load_config,      get_config, @@ -218,7 +221,9 @@ def map_obj_to_commands(updates):                      if value and value != obj_in_have.get(item):                          if item == "description":                              value = "'" + str(value) + "'" -                        commands.append(set_interface + " " + item + " " + str(value)) +                        commands.append( +                            set_interface + " " + item + " " + str(value) +                        )                  if disable and not obj_in_have.get("disable", False):                      commands.append(set_interface + " disable") @@ -231,7 +236,9 @@ def map_obj_to_commands(updates):                      if value:                          if item == "description":                              value = "'" + str(value) + "'" -                        commands.append(set_interface + " " + item + " " + str(value)) +                        commands.append( +                            set_interface + " " + item + " " + str(value) +                        )                  if disable:                      commands.append(set_interface + " disable") @@ -399,7 +406,9 @@ def main():          enabled=dict(default=True, type="bool"),          neighbors=dict(type="list", elements="dict", options=neighbors_spec),          delay=dict(default=10, type="int"), -        state=dict(default="present", choices=["present", "absent", "up", "down"]), +        state=dict( +            default="present", choices=["present", "absent", "up", "down"] +        ),      )      aggregate_spec = deepcopy(element_spec) diff --git a/plugins/modules/_vyos_l3_interface.py b/plugins/modules/_vyos_l3_interface.py index 430217c3..a504e7c8 100644 --- a/plugins/modules/_vyos_l3_interface.py +++ b/plugins/modules/_vyos_l3_interface.py @@ -101,7 +101,10 @@ import re  from copy import deepcopy  from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.network.common.utils import is_masklen, validate_ip_address +from ansible.module_utils.network.common.utils import ( +    is_masklen, +    validate_ip_address, +)  from ansible.module_utils.network.common.utils import remove_default_spec  from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (      load_config, @@ -154,30 +157,48 @@ def map_obj_to_commands(updates, module):          obj_in_have = search_obj_in_list(name, have)          if state == "absent" and obj_in_have: -            if not ipv4 and not ipv6 and (obj_in_have["ipv4"] or obj_in_have["ipv6"]): +            if ( +                not ipv4 +                and not ipv6 +                and (obj_in_have["ipv4"] or obj_in_have["ipv6"]) +            ):                  if name == "lo":                      commands.append("delete interfaces loopback lo address")                  else: -                    commands.append("delete interfaces ethernet " + name + " address") +                    commands.append( +                        "delete interfaces ethernet " + name + " address" +                    )              else:                  if ipv4 and ipv4 in obj_in_have["ipv4"]:                      if name == "lo": -                        commands.append("delete interfaces loopback lo address " + ipv4) +                        commands.append( +                            "delete interfaces loopback lo address " + ipv4 +                        )                      else:                          commands.append( -                            "delete interfaces ethernet " + name + " address " + ipv4 +                            "delete interfaces ethernet " +                            + name +                            + " address " +                            + ipv4                          )                  if ipv6 and ipv6 in obj_in_have["ipv6"]:                      if name == "lo": -                        commands.append("delete interfaces loopback lo address " + ipv6) +                        commands.append( +                            "delete interfaces loopback lo address " + ipv6 +                        )                      else:                          commands.append( -                            "delete interfaces ethernet " + name + " address " + ipv6 +                            "delete interfaces ethernet " +                            + name +                            + " address " +                            + ipv6                          )          elif state == "present" and obj_in_have:              if ipv4 and ipv4 not in obj_in_have["ipv4"]:                  if name == "lo": -                    commands.append("set interfaces loopback lo address " + ipv4) +                    commands.append( +                        "set interfaces loopback lo address " + ipv4 +                    )                  else:                      commands.append(                          "set interfaces ethernet " + name + " address " + ipv4 @@ -185,7 +206,9 @@ def map_obj_to_commands(updates, module):              if ipv6 and ipv6 not in obj_in_have["ipv6"]:                  if name == "lo": -                    commands.append("set interfaces loopback lo address " + ipv6) +                    commands.append( +                        "set interfaces loopback lo address " + ipv6 +                    )                  else:                      commands.append(                          "set interfaces ethernet " + name + " address " + ipv6 diff --git a/plugins/modules/vyos_banner.py b/plugins/modules/vyos_banner.py index 67386247..447c174b 100644 --- a/plugins/modules/vyos_banner.py +++ b/plugins/modules/vyos_banner.py @@ -105,15 +105,21 @@ def spec_to_commands(updates, module):      if state == "absent":          if have.get("state") != "absent" or ( -            have.get("state") != "absent" and "text" in have.keys() and have["text"] +            have.get("state") != "absent" +            and "text" in have.keys() +            and have["text"]          ): -            commands.append("delete system login banner %s" % module.params["banner"]) +            commands.append( +                "delete system login banner %s" % module.params["banner"] +            )      elif state == "present": -        if want["text"] and want["text"].encode().decode("unicode_escape") != have.get( -            "text" -        ): -            banner_cmd = "set system login banner %s " % module.params["banner"] +        if want["text"] and want["text"].encode().decode( +            "unicode_escape" +        ) != have.get("text"): +            banner_cmd = ( +                "set system login banner %s " % module.params["banner"] +            )              banner_cmd += want["text"].strip()              commands.append(banner_cmd) @@ -162,7 +168,9 @@ def main():      required_if = [("state", "present", ("text",))]      module = AnsibleModule( -        argument_spec=argument_spec, required_if=required_if, supports_check_mode=True +        argument_spec=argument_spec, +        required_if=required_if, +        supports_check_mode=True,      )      warnings = list() diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py index a3593bab..b812fae4 100644 --- a/plugins/modules/vyos_command.py +++ b/plugins/modules/vyos_command.py @@ -143,7 +143,10 @@ import time  from ansible.module_utils._text import to_text  from ansible.module_utils.basic import AnsibleModule  from ansible.module_utils.network.common.parsing import Conditional -from ansible.module_utils.network.common.utils import transform_commands, to_lines +from ansible.module_utils.network.common.utils import ( +    transform_commands, +    to_lines, +)  from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import (      run_commands,  ) @@ -215,7 +218,9 @@ def main():          msg = "One or more conditional statements have not been satisfied"          module.fail_json(msg=msg, failed_conditions=failed_conditions) -    result.update({"stdout": responses, "stdout_lines": list(to_lines(responses))}) +    result.update( +        {"stdout": responses, "stdout_lines": list(to_lines(responses))} +    )      module.exit_json(**result) diff --git a/plugins/modules/vyos_config.py b/plugins/modules/vyos_config.py index 530fdc39..29560632 100644 --- a/plugins/modules/vyos_config.py +++ b/plugins/modules/vyos_config.py @@ -275,7 +275,9 @@ def run(module, result):      connection = get_connection(module)      try:          response = connection.get_diff( -            candidate=candidate, running=config, diff_match=module.params["match"] +            candidate=candidate, +            running=config, +            diff_match=module.params["match"],          )      except ConnectionError as exc:          module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py index 1e63c5d8..1fa52146 100644 --- a/plugins/modules/vyos_facts.py +++ b/plugins/modules/vyos_facts.py @@ -160,7 +160,9 @@ def main():      argument_spec.update(vyos_argument_spec) -    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) +    module = AnsibleModule( +        argument_spec=argument_spec, supports_check_mode=True +    )      warnings = [          "default value for `gather_subset` " diff --git a/plugins/modules/vyos_linkagg.py b/plugins/modules/vyos_linkagg.py index 7793b6d2..2fc8d668 100644 --- a/plugins/modules/vyos_linkagg.py +++ b/plugins/modules/vyos_linkagg.py @@ -139,12 +139,16 @@ def map_obj_to_commands(updates, module):          if state == "absent":              if obj_in_have:                  for m in obj_in_have["members"]: -                    commands.append("delete interfaces ethernet " + m + " bond-group") +                    commands.append( +                        "delete interfaces ethernet " + m + " bond-group" +                    )                  commands.append("delete interfaces bonding " + name)          else:              if not obj_in_have: -                commands.append("set interfaces bonding " + name + " mode " + mode) +                commands.append( +                    "set interfaces bonding " + name + " mode " + mode +                )                  for m in members:                      commands.append( @@ -152,21 +156,31 @@ def map_obj_to_commands(updates, module):                      )                  if state == "down": -                    commands.append("set interfaces bonding " + name + " disable") +                    commands.append( +                        "set interfaces bonding " + name + " disable" +                    )              else:                  if mode != obj_in_have["mode"]: -                    commands.append("set interfaces bonding " + name + " mode " + mode) +                    commands.append( +                        "set interfaces bonding " + name + " mode " + mode +                    ) -                missing_members = list(set(members) - set(obj_in_have["members"])) +                missing_members = list( +                    set(members) - set(obj_in_have["members"]) +                )                  for m in missing_members:                      commands.append(                          "set interfaces ethernet " + m + " bond-group " + name                      )                  if state == "down" and obj_in_have["state"] == "up": -                    commands.append("set interfaces bonding " + name + " disable") +                    commands.append( +                        "set interfaces bonding " + name + " disable" +                    )                  elif state == "up" and obj_in_have["state"] == "down": -                    commands.append("delete interfaces bonding " + name + " disable") +                    commands.append( +                        "delete interfaces bonding " + name + " disable" +                    )      return commands @@ -189,7 +203,14 @@ def map_config_to_obj(module):              else:                  members = [] -            obj.append({"name": name, "mode": mode, "members": members, "state": state}) +            obj.append( +                { +                    "name": name, +                    "mode": mode, +                    "members": members, +                    "state": state, +                } +            )      return obj @@ -236,7 +257,9 @@ def main():              default="802.3ad",          ),          members=dict(type="list"), -        state=dict(default="present", choices=["present", "absent", "up", "down"]), +        state=dict( +            default="present", choices=["present", "absent", "up", "down"] +        ),      )      aggregate_spec = deepcopy(element_spec) diff --git a/plugins/modules/vyos_lldp.py b/plugins/modules/vyos_lldp.py index 69a62a31..18a013f3 100644 --- a/plugins/modules/vyos_lldp.py +++ b/plugins/modules/vyos_lldp.py @@ -90,13 +90,16 @@ def main():      argument_spec = dict(          interfaces=dict(type="list"),          state=dict( -            default="present", choices=["present", "absent", "enabled", "disabled"] +            default="present", +            choices=["present", "absent", "enabled", "disabled"],          ),      )      argument_spec.update(vyos_argument_spec) -    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) +    module = AnsibleModule( +        argument_spec=argument_spec, supports_check_mode=True +    )      warnings = list() diff --git a/plugins/modules/vyos_lldp_interface.py b/plugins/modules/vyos_lldp_interface.py index 23d1eab5..5d25ea3a 100644 --- a/plugins/modules/vyos_lldp_interface.py +++ b/plugins/modules/vyos_lldp_interface.py @@ -133,13 +133,19 @@ def map_obj_to_commands(updates, module):                  and obj_in_have["state"] == "disabled"                  and state == "enabled"              ): -                commands.append("delete service lldp interface " + name + " disable") +                commands.append( +                    "delete service lldp interface " + name + " disable" +                )          elif state == "disabled":              if not obj_in_have:                  commands.append("set service lldp interface " + name) -                commands.append("set service lldp interface " + name + " disable") +                commands.append( +                    "set service lldp interface " + name + " disable" +                )              elif obj_in_have and obj_in_have["state"] != "disabled": -                commands.append("set service lldp interface " + name + " disable") +                commands.append( +                    "set service lldp interface " + name + " disable" +                )      return commands @@ -179,7 +185,9 @@ def map_params_to_obj(module):              obj.append(item.copy())      else: -        obj.append({"name": module.params["name"], "state": module.params["state"]}) +        obj.append( +            {"name": module.params["name"], "state": module.params["state"]} +        )      return obj @@ -190,7 +198,8 @@ def main():      element_spec = dict(          name=dict(),          state=dict( -            default="present", choices=["present", "absent", "enabled", "disabled"] +            default="present", +            choices=["present", "absent", "enabled", "disabled"],          ),      ) diff --git a/plugins/modules/vyos_logging.py b/plugins/modules/vyos_logging.py index 1fd0ca21..fa0d1cf7 100644 --- a/plugins/modules/vyos_logging.py +++ b/plugins/modules/vyos_logging.py @@ -192,7 +192,12 @@ def config_to_dict(module):                  level = match.group(1).strip("'")                  obj.append( -                    {"dest": dest, "name": name, "facility": facility, "level": level} +                    { +                        "dest": dest, +                        "name": name, +                        "facility": facility, +                        "level": level, +                    }                  )      return obj @@ -232,7 +237,9 @@ def main():      """ main entry point for module execution      """      element_spec = dict( -        dest=dict(type="str", choices=["console", "file", "global", "host", "user"]), +        dest=dict( +            type="str", choices=["console", "file", "global", "host", "user"] +        ),          name=dict(type="str"),          facility=dict(type="str"),          level=dict(type="str"), @@ -260,7 +267,9 @@ def main():      ]      module = AnsibleModule( -        argument_spec=argument_spec, required_if=required_if, supports_check_mode=True +        argument_spec=argument_spec, +        required_if=required_if, +        supports_check_mode=True,      )      warnings = list() diff --git a/plugins/modules/vyos_ping.py b/plugins/modules/vyos_ping.py index 9e99d488..c770804d 100644 --- a/plugins/modules/vyos_ping.py +++ b/plugins/modules/vyos_ping.py @@ -154,7 +154,9 @@ def main():          ttl=dict(type="int"),          size=dict(type="int"),          interval=dict(type="int"), -        state=dict(type="str", choices=["absent", "present"], default="present"), +        state=dict( +            type="str", choices=["absent", "present"], default="present" +        ),      )      argument_spec.update(vyos_argument_spec) @@ -174,7 +176,9 @@ def main():      if warnings:          results["warnings"] = warnings -    results["commands"] = [build_ping(dest, count, size, interval, source, ttl)] +    results["commands"] = [ +        build_ping(dest, count, size, interval, source, ttl) +    ]      ping_results = run_commands(module, commands=results["commands"])      ping_results_list = ping_results[0].split("\n") diff --git a/plugins/modules/vyos_static_route.py b/plugins/modules/vyos_static_route.py index dfb1d21e..734a1b08 100644 --- a/plugins/modules/vyos_static_route.py +++ b/plugins/modules/vyos_static_route.py @@ -132,7 +132,9 @@ def spec_to_commands(updates, module):          del w["state"]          if state == "absent" and w in have: -            commands.append("delete protocols static route %s/%s" % (prefix, mask)) +            commands.append( +                "delete protocols static route %s/%s" % (prefix, mask) +            )          elif state == "present" and w not in have:              cmd = "set protocols static route %s/%s next-hop %s" % (                  prefix, diff --git a/plugins/modules/vyos_system.py b/plugins/modules/vyos_system.py index 99841542..4f0d5db7 100644 --- a/plugins/modules/vyos_system.py +++ b/plugins/modules/vyos_system.py @@ -158,9 +158,13 @@ def spec_to_commands(want, have):                  commands.append("delete system %s" % device_key)              for config in proposed:                  if state == "absent" and config in current: -                    commands.append("delete system %s '%s'" % (device_key, config)) +                    commands.append( +                        "delete system %s '%s'" % (device_key, config) +                    )                  elif state == "present" and config not in current: -                    commands.append("set system %s '%s'" % (device_key, config)) +                    commands.append( +                        "set system %s '%s'" % (device_key, config) +                    )          else:              if state == "absent" and current and proposed:                  commands.append("delete system %s" % device_key) @@ -186,7 +190,9 @@ def main():          domain_name=dict(type="str"),          domain_search=dict(type="list"),          name_server=dict(type="list", aliases=["name_servers"]), -        state=dict(type="str", default="present", choices=["present", "absent"]), +        state=dict( +            type="str", default="present", choices=["present", "absent"] +        ),      )      argument_spec.update(vyos_argument_spec) diff --git a/plugins/modules/vyos_user.py b/plugins/modules/vyos_user.py index 74ec7205..a309d2a5 100644 --- a/plugins/modules/vyos_user.py +++ b/plugins/modules/vyos_user.py @@ -152,7 +152,9 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import  def validate_level(value, module):      if value not in ("admin", "operator"): -        module.fail_json(msg="level must be either admin or operator, got %s" % value) +        module.fail_json( +            msg="level must be either admin or operator, got %s" % value +        )  def spec_to_commands(updates, module): @@ -292,7 +294,9 @@ def main():          full_name=dict(),          level=dict(aliases=["role"]),          configured_password=dict(no_log=True), -        update_password=dict(default="always", choices=["on_create", "always"]), +        update_password=dict( +            default="always", choices=["on_create", "always"] +        ),          state=dict(default="present", choices=["present", "absent"]),      ) diff --git a/plugins/modules/vyos_vlan.py b/plugins/modules/vyos_vlan.py index 983a50a4..7c3fa69d 100644 --- a/plugins/modules/vyos_vlan.py +++ b/plugins/modules/vyos_vlan.py @@ -162,18 +162,26 @@ def map_obj_to_commands(updates, module):                  for obj in obj_in_have:                      for i in obj["interfaces"]:                          commands.append( -                            "delete interfaces ethernet {0} vif {1}".format(i, vlan_id) +                            "delete interfaces ethernet {0} vif {1}".format( +                                i, vlan_id +                            )                          )          elif state == "present":              if not obj_in_have:                  if w["interfaces"] and w["vlan_id"]:                      for i in w["interfaces"]: -                        cmd = "set interfaces ethernet {0} vif {1}".format(i, vlan_id) +                        cmd = "set interfaces ethernet {0} vif {1}".format( +                            i, vlan_id +                        )                          if w["name"]: -                            commands.append(cmd + " description {0}".format(name)) +                            commands.append( +                                cmd + " description {0}".format(name) +                            )                          elif w["address"]: -                            commands.append(cmd + " address {0}".format(address)) +                            commands.append( +                                cmd + " address {0}".format(address) +                            )                          else:                              commands.append(cmd) @@ -183,7 +191,9 @@ def map_obj_to_commands(updates, module):              if not obj_in_want:                  for i in h["interfaces"]:                      commands.append( -                        "delete interfaces ethernet {0} vif {1}".format(i, h["vlan_id"]) +                        "delete interfaces ethernet {0} vif {1}".format( +                            i, h["vlan_id"] +                        )                      )      return commands @@ -215,7 +225,9 @@ def map_params_to_obj(module):                  "address": module.params["address"],                  "state": module.params["state"],                  "interfaces": module.params["interfaces"], -                "associated_interfaces": module.params["associated_interfaces"], +                "associated_interfaces": module.params[ +                    "associated_interfaces" +                ],              }          ) @@ -281,7 +293,9 @@ def check_declarative_intent_params(want, module, result):          if w.get("associated_interfaces") is None:              continue          for i in w["associated_interfaces"]: -            if (set(obj_interface) - set(w["associated_interfaces"])) != set([]): +            if (set(obj_interface) - set(w["associated_interfaces"])) != set( +                [] +            ):                  module.fail_json(                      msg="Interface {0} not configured on vlan {1}".format(                          i, w["vlan_id"] | 
