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
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
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) commands.extend(generate_commands(key, add_config, del_config)) 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() intf_commands = set_interface(desired, extant) if intf_commands: commands.append("interface {0}".format(interface_name)) commands.extend(intf_commands) return commands