def _set_config(self, want, have, module):
        # Set the interface config based on the want and have config
        commands = []
        interface = 'interface ' + want['name']

        # To handle L3 IPV4 configuration
        if want.get("ipv4"):
            for each in want.get("ipv4"):
                if each.get('address') != 'dhcp':
                    ip_addr_want = validate_n_expand_ipv4(module, each)
                    each['address'] = ip_addr_want

        # Get the diff b/w want and have
        want_dict = dict_to_set(want)
        have_dict = dict_to_set(have)

        # To handle L3 IPV4 configuration
        want_ipv4 = dict(want_dict).get('ipv4')
        have_ipv4 = dict(have_dict).get('ipv4')
        if want_ipv4:
            if have_ipv4:
                diff_ipv4 = set(want_ipv4) - set(dict(have_dict).get('ipv4'))
                if diff_ipv4:
                    diff_ipv4 = diff_ipv4 if self.verify_diff_again(
                        want_ipv4, have_ipv4) else ()
            else:
                diff_ipv4 = set(want_ipv4)
            for each in diff_ipv4:
                ipv4_dict = dict(each)
                if ipv4_dict.get('address') != 'dhcp':
                    cmd = "ipv4 address {0}".format(ipv4_dict['address'])
                    if ipv4_dict.get("secondary"):
                        cmd += " secondary"
                add_command_to_config_list(interface, cmd, commands)

        # To handle L3 IPV6 configuration
        want_ipv6 = dict(want_dict).get('ipv6')
        have_ipv6 = dict(have_dict).get('ipv6')
        if want_ipv6:
            if have_ipv6:
                diff_ipv6 = set(want_ipv6) - set(have_ipv6)
            else:
                diff_ipv6 = set(want_ipv6)
            for each in diff_ipv6:
                ipv6_dict = dict(each)
                validate_ipv6(ipv6_dict.get('address'), module)
                cmd = "ipv6 address {0}".format(ipv6_dict.get('address'))
                add_command_to_config_list(interface, cmd, commands)

        return commands
Пример #2
0
    def _set_config(self, want, have, module):
        # Set the interface config based on the want and have config
        commands = []
        interface = "interface " + want["name"]

        # To handle L3 IPV4 configuration
        if want.get("ipv4"):
            for each in want.get("ipv4"):
                if each.get("address") != "dhcp":
                    ip_addr_want = validate_n_expand_ipv4(module, each)
                    each["address"] = ip_addr_want

        # Get the diff b/w want and have
        want_dict = dict_to_set(want)
        have_dict = dict_to_set(have)

        # To handle L3 IPV4 configuration
        if dict(want_dict).get("ipv4"):
            if dict(have_dict).get("ipv4"):
                diff_ipv4 = set(dict(want_dict).get("ipv4")) - set(
                    dict(have_dict).get("ipv4"))
            else:
                diff_ipv4 = set(dict(want_dict).get("ipv4"))
            for each in diff_ipv4:
                ipv4_dict = dict(each)
                if ipv4_dict.get("address") != "dhcp":
                    cmd = "ipv4 address {0}".format(ipv4_dict["address"])
                    if ipv4_dict.get("secondary"):
                        cmd += " secondary"
                add_command_to_config_list(interface, cmd, commands)

        # To handle L3 IPV6 configuration
        if dict(want_dict).get("ipv6"):
            if dict(have_dict).get("ipv6"):
                diff_ipv6 = set(dict(want_dict).get("ipv6")) - set(
                    dict(have_dict).get("ipv6"))
            else:
                diff_ipv6 = set(dict(want_dict).get("ipv6"))
            for each in diff_ipv6:
                ipv6_dict = dict(each)
                validate_ipv6(ipv6_dict.get("address"), module)
                cmd = "ipv6 address {0}".format(ipv6_dict.get("address"))
                add_command_to_config_list(interface, cmd, commands)

        return commands
Пример #3
0
    def _set_config(self, want, have):
        # Set the interface config based on the want and have config
        commands = []
        interface = 'interface ' + want['name']

        # Get the diff b/w want and have
        want_dict = dict_to_set(want)
        have_dict = dict_to_set(have)
        diff = want_dict - have_dict

        if diff:
            diff = dict(diff)
            for item in self.params:
                if diff.get(item):
                    cmd = item + ' ' + str(want.get(item))
                    add_command_to_config_list(interface, cmd, commands)
            if diff.get('enabled'):
                add_command_to_config_list(interface, 'no shutdown', commands)
            elif diff.get('enabled') is False:
                add_command_to_config_list(interface, 'shutdown', commands)

        return commands
Пример #4
0
    def _set_config(self, want, have):
        # Set the interface config based on the want and have config
        commands = []
        interface = "interface " + want["name"]

        # Get the diff b/w want and have
        want_dict = dict_to_set(want)
        have_dict = dict_to_set(have)
        diff = want_dict - have_dict

        if diff:
            diff = dict(diff)
            for item in self.params:
                if diff.get(item):
                    cmd = item + " " + str(want.get(item))
                    add_command_to_config_list(interface, cmd, commands)
            if diff.get("enabled"):
                add_command_to_config_list(interface, "no shutdown", commands)
            elif diff.get("enabled") is False:
                add_command_to_config_list(interface, "shutdown", commands)

        return commands
Пример #5
0
    def _set_config(self, want, have, module):
        # Set the interface config based on the want and have config
        commands = []
        interface = 'interface ' + want['name']
        l2_protocol_bool = False

        # Get the diff b/w want and have
        want_dict = dict_to_set(want)
        have_dict = dict_to_set(have)
        diff = want_dict - have_dict

        if diff:
            # For merging with already configured l2protocol
            if have.get('l2protocol') and len(have.get('l2protocol')) > 1:
                l2_protocol_diff = []
                for each in want.get('l2protocol'):
                    for every in have.get('l2protocol'):
                        if every == each:
                            break
                    if each not in have.get('l2protocol'):
                        l2_protocol_diff.append(each)
                l2_protocol_bool = True
                l2protocol = tuple(l2_protocol_diff)
            else:
                l2protocol = {}

            diff = dict(diff)
            wants_native = diff.get('native_vlan')
            l2transport = diff.get('l2transport')
            q_vlan = diff.get('q_vlan')
            propagate = diff.get('propagate')
            if l2_protocol_bool is False:
                l2protocol = diff.get('l2protocol')

            if wants_native:
                cmd = 'dot1q native vlan {0}'.format(wants_native)
                add_command_to_config_list(interface, cmd, commands)

            if l2transport or l2protocol:
                for each in l2protocol:
                    each = dict(each)
                    if isinstance(each, dict):
                        cmd = 'l2transport l2protocol {0} {1}'.format(
                            list(each.keys())[0],
                            list(each.values())[0])
                    add_command_to_config_list(interface, cmd, commands)
                if propagate and not have.get('propagate'):
                    cmd = 'l2transport propagate remote-status'
                    add_command_to_config_list(interface, cmd, commands)
            elif want.get('l2transport') is False and (
                    want.get('l2protocol') or want.get('propagate')):
                module.fail_json(
                    msg=
                    'L2transport L2protocol or Propagate can only be configured when '
                    'L2transport set to True!')

            if q_vlan and '.' in interface:
                q_vlans = (" ".join(map(str, want.get('q_vlan'))))
                if q_vlans != have.get('q_vlan'):
                    cmd = 'dot1q vlan {0}'.format(q_vlans)
                    add_command_to_config_list(interface, cmd, commands)

        return commands