def _state_overridden(want, have):
        """ The command generator when state is overridden
        :rtype: A list
        :returns: the commands necessary to migrate the current configuration
                  to the desired configuration
        """
        commands = []
        for extant in have:
            for interface in want:
                if normalize_interface(interface["name"]) == extant["name"]:
                    break
            else:
                interface = dict(name=extant["name"])
            commands.extend(remove_config(interface, extant))

        for interface in want:
            interface_name = normalize_interface(interface["name"])
            for extant in have:
                if extant["name"] == interface_name:
                    break
            else:
                extant = dict(name=interface_name)
            commands.extend(set_config(interface, extant))

        return commands
示例#2
0
    def _state_overridden(want, have):
        """The command generator when state is overridden

        :rtype: A list
        :returns: the commands necessary to migrate the current configuration
                  to the desired configuration
        """
        commands = []
        for key, extant in have.items():
            interface_name = normalize_interface(key)
            if interface_name in want:
                desired = want[interface_name]
            else:
                desired = dict()
            if desired.get("ipv4"):
                for ipv4 in desired["ipv4"]:
                    for k in ["secondary", "virtual"]:
                        if ipv4[k] is None:
                            del ipv4[k]
            intf_commands = set_interface(desired, extant)
            intf_commands.extend(clear_interface(desired, extant))

            if intf_commands:
                commands.append("interface {0}".format(interface_name))
                commands.extend(intf_commands)

        return commands
示例#3
0
    def _state_replaced(want, have):
        """ The command generator when state is replaced

        :rtype: A list
        :returns: the commands necessary to migrate the current configuration
                  to the desired configuration
        """
        commands = []
        for key, desired in want.items():
            interface_name = normalize_interface(key)
            if interface_name in have:
                extant = have[interface_name]
            else:
                extant = dict()

            add_config = dict_diff(extant, desired)
            del_config = dict_diff(desired, extant)

            if (
                "speed" in add_config.keys()
                and "duplex" not in add_config.keys()
            ):
                add_config.update({"duplex": desired.get("duplex")})

            commands.extend(generate_commands(key, add_config, del_config))

        return commands
示例#4
0
def _tmplt_ntp_global_servers(config_data):
    el = config_data["servers"]
    command = "ntp server"
    if el.get("vrf"):
        command += " vrf {vrf}".format(**el)
    if el.get("server"):
        command += " {server}".format(**el)
    if el.get("burst"):
        command += " burst"
    if el.get("iburst"):
        command += " iburst"
    if el.get("key_id"):
        command += " key {key_id}".format(**el)
    if el.get("local_interface"):
        command += " local_interface {local_interface}".format(**el)
    if el.get("maxpoll"):
        command += " maxpoll {maxpoll}".format(**el)
    if el.get("minpoll"):
        command += " minpoll {minpoll}".format(**el)
    if el.get("prefer"):
        command += " prefer"
    if el.get("source"):
        interface_name = normalize_interface(el["source"])
        command += " source " + interface_name
    if el.get("version"):
        command += " version {version}".format(**el)
    return command
    def _state_overridden(want, have):
        """The command generator when state is overridden

        :rtype: A list
        :returns: the commands necessary to migrate the current configuration
                  to the desired configuration
        """
        commands = []
        for key, extant in have.items():
            interface_name = normalize_interface(key)
            desired = dict()
            if "Management" in interface_name:
                continue
            for k in want.keys():
                k_want = normalize_interface(k)
                if key == k_want:
                    desired = want[k]
                    break
            if desired.get("ipv4"):
                for ipv4 in desired["ipv4"]:
                    for k in ["secondary", "virtual"]:
                        if ipv4[k] is None:
                            del ipv4[k]
            intf_commands = set_interface(desired, extant)
            intf_commands.extend(clear_interface(desired, extant))

            if intf_commands:
                commands.append("interface {0}".format(interface_name))
                commands.extend(intf_commands)

        # new interfaces in want
        new_intf_commands = []
        for key, desired in want.items():
            interface_name = normalize_interface(key)
            if interface_name not in have:
                extant = dict()
                new_intf_commands = set_interface(desired, extant)

            if new_intf_commands:
                commands.append("interface {0}".format(interface_name))
                commands.extend(new_intf_commands)

        return commands
 def _servers_compare(self, want, have):
     w = want.pop("servers", {})
     h = have.pop("servers", {})
     for name, entry in iteritems(w):
         if entry.get("source"):
             entry["source"] = normalize_interface(entry["source"])
         h_key = {}
         if h.get(name):
             h_key = {"servers": h.pop(name)}
         self.compare(parsers="servers",
                      want={"servers": entry},
                      have=h_key)
     for name, entry in iteritems(h):
         self.compare(parsers="servers", want={}, have={"servers": entry})
    def _state_merged(want, have):
        """ The command generator when state is merged
        :rtype: A list
        :returns: the commands necessary to merge the provided into
                  the current configuration
        """
        commands = []
        for interface in want:
            interface_name = normalize_interface(interface["name"])
            for extant in have:
                if extant["name"] == interface_name:
                    break
            else:
                extant = dict(name=interface_name)

            commands.extend(set_config(interface, extant))

        return commands
    def _state_merged(want, have):
        """The command generator when state is merged

        :rtype: A list
        :returns: the commands necessary to merge the provided into
                  the current configuration
        """
        commands = []
        for key, desired in want.items():
            interface_name = normalize_interface(key)
            if interface_name in have:
                extant = have[interface_name]
            else:
                extant = dict(name=interface_name)

            add_config = dict_diff(extant, desired)

            commands.extend(generate_commands(interface_name, add_config, {}))

        return commands
    def _state_deleted(want, have):
        """ The command generator when state is deleted
        :rtype: A list
        :returns: the commands necessary to remove the current configuration
                  of the provided objects
        """
        commands = []
        for interface in want:
            interface_name = normalize_interface(interface["name"])
            for extant in have:
                if extant["name"] == interface_name:
                    break
            else:
                extant = dict(name=interface_name)

            # Clearing all args, send empty dictionary
            interface = dict(name=interface_name)
            commands.extend(remove_config(interface, extant))

        return commands
    def _state_deleted(want, have):
        """The command generator when state is deleted

        :rtype: A list
        :returns: the commands necessary to remove the current configuration
                  of the provided objects
        """
        commands = []
        for key in want.keys():
            interface_name = normalize_interface(key)
            desired = dict(name=interface_name)
            if interface_name in have:
                extant = have[interface_name]
            else:
                continue

            del_config = dict_diff(desired, extant)

            commands.extend(generate_commands(interface_name, {}, del_config))

        return commands
示例#11
0
    def _state_merged(want, have):
        """The command generator when state is merged

        :rtype: A list
        :returns: the commands necessary to merge the provided into
                  the current configuration
        """
        commands = []
        for key, desired in want.items():
            interface_name = normalize_interface(key)
            if interface_name in have:
                extant = have[interface_name]
            else:
                extant = dict()

            intf_commands = set_interface(desired, extant)
            if intf_commands:
                commands.append("interface {0}".format(interface_name))
                commands.extend(intf_commands)

        return commands
示例#12
0
    def _state_deleted(want, have):
        """The command generator when state is deleted

        :rtype: A list
        :returns: the commands necessary to remove the current configuration
                  of the provided objects
        """
        commands = []
        for key in want:
            interface_name = normalize_interface(key)
            desired = dict()
            if interface_name in have:
                extant = have[interface_name]
            else:
                continue

            intf_commands = clear_interface(desired, extant)

            if intf_commands:
                commands.append("interface {0}".format(interface_name))
                commands.extend(intf_commands)

        return commands