def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] vlan = 'vlan {0}'.format(want.get('vlan_id')) # Get the diff b/w want n have want_dict = dict_to_set(want) have_dict = dict_to_set(have) diff = want_dict - have_dict if diff: name = dict(diff).get('name') state = dict(diff).get('state') shutdown = dict(diff).get('shutdown') mtu = dict(diff).get('mtu') remote_span = dict(diff).get('remote_span') if name: cmd = 'name {0}'.format(name) self.add_command_to_config_list(vlan, cmd, commands) if state: cmd = 'state {0}'.format(state) self.add_command_to_config_list(vlan, cmd, commands) if mtu: cmd = 'mtu {0}'.format(mtu) self.add_command_to_config_list(vlan, cmd, commands) if remote_span: self.add_command_to_config_list(vlan, 'remote-span', commands) if shutdown == 'enabled': self.add_command_to_config_list(vlan, 'shutdown', commands) elif shutdown == 'disabled': self.add_command_to_config_list(vlan, 'no shutdown', commands) return commands
def _set_config(self, want, have, module): # 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) want_trunk = dict(want_dict).get('trunk') have_trunk = dict(have_dict).get('trunk') if want_trunk and have_trunk: diff = set(tuple(dict(want_dict).get('trunk'))) - set( tuple(dict(have_dict).get('trunk'))) else: diff = want_dict - have_dict if diff: diff = dict(diff) if diff.get('access'): cmd = 'switchport access vlan {0}'.format( diff.get('access')[0][1]) add_command_to_config_list(interface, cmd, commands) if diff.get('voice'): cmd = 'switchport voice vlan {0}'.format( diff.get('voice')[0][1]) add_command_to_config_list(interface, cmd, commands) if want_trunk: if diff.get('trunk'): diff = dict(diff.get('trunk')) if diff.get('encapsulation'): cmd = self.trunk_cmds['encapsulation'] + ' {0}'.format( diff.get('encapsulation')) add_command_to_config_list(interface, cmd, commands) if diff.get('native_vlan'): cmd = self.trunk_cmds['native_vlan'] + ' {0}'.format( diff.get('native_vlan')) add_command_to_config_list(interface, cmd, commands) allowed_vlans = diff.get('allowed_vlans') pruning_vlans = diff.get('pruning_vlans') if allowed_vlans and self._check_for_correct_vlan_range( allowed_vlans, module): allowed_vlans = ','.join(allowed_vlans) cmd = self.trunk_cmds['allowed_vlans'] + ' {0}'.format( allowed_vlans) add_command_to_config_list(interface, cmd, commands) if pruning_vlans and self._check_for_correct_vlan_range( pruning_vlans, module): pruning_vlans = ','.join(pruning_vlans) cmd = self.trunk_cmds['pruning_vlans'] + ' {0}'.format( pruning_vlans) add_command_to_config_list(interface, cmd, commands) return commands
def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] want_dict = dict_to_set(want) have_dict = dict_to_set(have) diff = want_dict - have_dict if diff: cmd = 'lacp system-priority {0}'.format(want.get('system').get('priority')) self._add_command_to_config_list(cmd, commands) return commands
def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] interface = 'interface ' + have['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) receive = diff.get('receive') transmit = diff.get('transmit') med_tlv_select = diff.get('med_tlv_select') tlv_select = diff.get('tlv_select') if receive: cmd = 'lldp receive' add_command_to_config_list(interface, cmd, commands) elif receive is False: cmd = 'no lldp receive' add_command_to_config_list(interface, cmd, commands) if transmit: cmd = 'lldp transmit' add_command_to_config_list(interface, cmd, commands) elif transmit is False: cmd = 'no lldp transmit' add_command_to_config_list(interface, cmd, commands) if med_tlv_select: med_tlv_select = dict(med_tlv_select) if med_tlv_select.get('inventory_management'): add_command_to_config_list( interface, 'lldp med-tlv-select inventory-management', commands) if tlv_select: tlv_select = dict(tlv_select) if tlv_select.get('power_management'): add_command_to_config_list( interface, 'lldp tlv-select power-management', commands) return commands
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
def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] # 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) holdtime = diff.get('holdtime') enabled = diff.get('enabled') timer = diff.get('timer') reinit = diff.get('reinit') tlv_select = diff.get('tlv_select') if holdtime: cmd = 'lldp holdtime {0}'.format(holdtime) self.add_command_to_config_list(cmd, commands) if enabled: cmd = 'lldp run' self.add_command_to_config_list(cmd, commands) if timer: cmd = 'lldp timer {0}'.format(timer) self.add_command_to_config_list(cmd, commands) if reinit: cmd = 'lldp reinit {0}'.format(reinit) self.add_command_to_config_list(cmd, commands) if tlv_select: tlv_selec_dict = dict(tlv_select) for k, v in iteritems(self.tlv_select_params): if k in tlv_selec_dict and tlv_selec_dict[k]: cmd = 'lldp tlv-select {0}'.format(v) self.add_command_to_config_list(cmd, commands) return commands
def _set_config(self, want, have, module): # Set the interface config based on the want and have config commands = [] # To remove keys with None values from want dict want = utils.remove_empties(want) # 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 # To get the channel-id from lag port-channel name lag_config = dict(diff).get('members') channel_name = re.search(r'(\d+)', want.get('name')) if channel_name: channel_id = channel_name.group() else: module.fail_json(msg="Lag Interface Name is not correct!") if lag_config: for each in lag_config: each = dict(each) each_interface = 'interface {0}'.format(each.get('member')) if have.get('name') == want['members'][0][ 'member'] or have.get('name').lower().startswith('po'): if each.get('mode'): cmd = 'channel-group {0} mode {1}'.format( channel_id, each.get('mode')) self.add_command_to_config_list( each_interface, cmd, commands) elif each.get('link'): cmd = 'channel-group {0} link {1}'.format( channel_id, each.get('link')) self.add_command_to_config_list( each_interface, cmd, commands) return commands
def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] interface = 'interface ' + have['name'] want_dict = dict_to_set(want) have_dict = dict_to_set(have) diff = want_dict - have_dict if diff: port_priotity = dict(diff).get('port_priority') max_bundle = dict(diff).get('max_bundle') fast_switchover = dict(diff).get('fast_switchover') if port_priotity: cmd = 'lacp port-priority {0}'.format(port_priotity) add_command_to_config_list(interface, cmd, commands) if max_bundle: cmd = 'lacp max-bundle {0}'.format(max_bundle) add_command_to_config_list(interface, cmd, commands) if fast_switchover: cmd = 'lacp fast-switchover' add_command_to_config_list(interface, cmd, commands) return commands
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 # Convert the want and have dict to set want_dict = dict_to_set(want) have_dict = dict_to_set(have) # To handle L3 IPV4 configuration if want.get('ipv4'): # Get the diff b/w want and have IPV4 if have.get('ipv4'): ipv4 = tuple(set(dict(want_dict).get('ipv4')) - set(dict(have_dict).get('ipv4'))) if ipv4: ipv4 = ipv4 if self.verify_diff_again(dict(want_dict).get('ipv4'), dict(have_dict).get('ipv4')) else () else: diff = want_dict - have_dict ipv4 = dict(diff).get('ipv4') if ipv4: for each in ipv4: ipv4_dict = dict(each) if ipv4_dict.get('address') != 'dhcp': cmd = "ip address {0}".format(ipv4_dict['address']) if ipv4_dict.get("secondary"): cmd += " secondary" elif ipv4_dict.get('address') == 'dhcp': cmd = "ip address dhcp" if ipv4_dict.get('dhcp_client') is not None and ipv4_dict.get('dhcp_hostname'): cmd = "ip address dhcp client-id GigabitEthernet 0/{0} hostname {1}"\ .format(ipv4_dict.get('dhcp_client'), ipv4_dict.get('dhcp_hostname')) elif ipv4_dict.get('dhcp_client') and not ipv4_dict.get('dhcp_hostname'): cmd = "ip address dhcp client-id GigabitEthernet 0/{0}"\ .format(ipv4_dict.get('dhcp_client')) elif not ipv4_dict.get('dhcp_client') and ipv4_dict.get('dhcp_hostname'): cmd = "ip address dhcp hostname {0}".format(ipv4_dict.get('dhcp_client')) add_command_to_config_list(interface, cmd, commands) # To handle L3 IPV6 configuration if want.get('ipv6'): # Get the diff b/w want and have IPV6 if have.get('ipv6'): ipv6 = tuple(set(dict(want_dict).get('ipv6')) - set(dict(have_dict).get('ipv6'))) else: diff = want_dict - have_dict ipv6 = dict(diff).get('ipv6') if ipv6: for each in 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