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: interface['name'] = normalize_interface(interface['name']) for each in have: if each['name'] == interface['name']: break elif interface['name'] in each['name']: break else: continue interface = dict(name=interface['name']) commands.extend(self._clear_config(interface, each)) else: for each in have: want = dict() commands.extend(self._clear_config(want, each)) return commands
def set_config(self, existing_lag_interfaces_facts): """ Collect the configuration from the args passed to the module, collect the current configuration (as a dict from facts) :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ want = self._module.params['config'] if want: for item in want: item['name'] = normalize_interface(item['name']) if 'members' in want and want['members']: for item in want['members']: item.update({ 'member': normalize_interface(item['member']), 'mode': item['mode'] }) have = existing_lag_interfaces_facts resp = self.set_state(want, have) return to_list(resp)
def _state_merged(self, want, have, module): """ 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 each in have: if each['name'] == interface['name']: break else: commands.extend(self._set_config(interface, dict(), module)) continue commands.extend(self._set_config(interface, each, module)) return commands
def _state_overridden(self, want, have, module): """ The command generator when state is overridden :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ commands = [] not_in_have = set() in_have = set() for each in have: for interface in want: interface['name'] = normalize_interface(interface['name']) if each['name'] == interface['name']: in_have.add(interface['name']) break elif interface['name'] != each['name']: not_in_have.add(interface['name']) else: # We didn't find a matching desired state, which means we can # pretend we recieved an empty desired state. interface = dict(name=each['name']) kwargs = {'want': interface, 'have': each} commands.extend(self._clear_config(**kwargs)) continue have_dict = filter_dict_having_none_value(interface, each) commands.extend(self._clear_config(dict(), have_dict)) commands.extend(self._set_config(interface, each, module)) # Add the want interface that's not already configured in have interface for each in (not_in_have - in_have): for every in want: interface = 'interface {0}'.format(every['name']) if each and interface not in commands: commands.extend(self._set_config(every, {}, module)) # Remove the duplicate interface call commands = remove_duplicate_interface(commands) return commands
def _state_replaced(self, want, have, module): """ 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: interface['name'] = normalize_interface(interface['name']) for each in have: if each['name'] == interface['name']: break else: commands.extend(self._set_config(interface, dict(), module)) continue have_dict = filter_dict_having_none_value(interface, each) commands.extend(self._clear_config(dict(), have_dict)) commands.extend(self._set_config(interface, each, module)) # Remove the duplicate interface call commands = remove_duplicate_interface(commands) return commands