def _state_deleted(self, 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 = [] if want: for interface in want: intfs = get_interfaces(interface['name']) for intf in intfs: have_dict = get_have_dict(intf, have) if have_dict is None: self._module.fail_json(msg='Interface does not exist') if have_dict: interface = dict(name=intf) commands.extend( self._clear_config(interface, have_dict)) else: for each in have: commands.extend(self._clear_config(dict(), each)) return remove_duplicate_interface(commands)
def _state_replaced(self, 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 interface in want: intfs = get_interfaces(interface['name']) for intf in intfs: partial_want = deepcopy(interface) partial_want['name'] = intf have_dict = get_have_dict(intf, have) if have_dict is None: self._module.fail_json(msg='Interface does not exist') if have_dict: commands.extend(self._clear_config(partial_want, have_dict)) commands.extend(self._set_config(partial_want, have_dict)) else: commands.extend(self._set_config(partial_want, dict())) # Remove the duplicate interface call return remove_duplicate_interface(commands)
def _state_replaced(self, 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 name, value in iteritems(want): if name in have: to_clear = dict_diff(value, have[name]) commands.extend(_clear_config(name, to_clear)) to_set = dict_diff(have[name], value) commands.extend(_set_config(name, to_set)) return remove_duplicate_interface(commands)
def _state_replaced(self, 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, want_dict in want.items(): if key in have: have_dict = have[key] diff = dict_diff(want_dict, have_dict) commands.extend(_clear_config(key, want_dict, diff)) commands.extend(_set_config(key, want_dict, have_dict)) return remove_duplicate_interface(commands)
def _state_overridden(self, 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 each in have: for interface in want: if each['name'] in interface['name']: break else: # We didn't find a matching desired state, which means we can # pretend we received an empty desired state. interface = dict(name=each['name']) kwargs = {'want': interface, 'have': each} commands.extend(self._clear_config(**kwargs)) continue # Iterating through want list which now only have range interfaces to be # configured for interface in want: intfs = get_interfaces(interface['name']) for intf in intfs: partial_want = deepcopy(interface) partial_want['name'] = intf have_dict = get_have_dict(intf, have) if have_dict is None: self._module.fail_json(msg='Interface does not exist') if have_dict: commands.extend(self._set_config(partial_want, have_dict)) else: commands.extend(self._set_config(partial_want, dict())) # Remove the duplicate interface call return remove_duplicate_interface(commands)