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_multiplier') enabled = diff.get('enabled') timer = diff.get('timer') reinit = diff.get('reinit') if enabled: cmd = 'lldp enable' self.add_command_to_config_list(cmd, commands) if holdtime: cmd = 'lldp message-transmission hold-multiplier {0}'.format(holdtime) self.add_command_to_config_list(cmd, commands) if timer: cmd = 'lldp message-transmission interval {0}'.format(timer) self.add_command_to_config_list(cmd, commands) if reinit: cmd = 'lldp restart-delay {0}'.format(reinit) 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 = [] if want.get('name'): interface = 'interface ' + want['name'] else: 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) enabled = diff.get('enabled') if enabled: cmd = 'lldp enable' add_command_to_config_list(interface, cmd, commands) elif eanbled is False: cmd = 'undo lldp receive' add_command_to_config_list(interface, cmd, commands) if commands: add_command_to_config_list(interface, 'quit', commands) return commands
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') if name: cmd = 'name {0}'.format(name) self.add_command_to_config_list(vlan, cmd, commands) cmd = 'description {0}'.format(name) self.add_command_to_config_list(vlan, cmd, commands) cmd = 'quit' 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) cmd = 'quit' self.add_command_to_config_list(vlan, cmd, 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'] interface_type = get_interface_type(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) if diff.get('description'): cmd = 'description {0}'.format(want.get('description')) add_command_to_config_list(interface, cmd, commands) if diff.get('mtu'): cmd = 'jumboframe enable {0}'.format(want.get('mtu')) add_command_to_config_list(interface, cmd, commands) if diff.get('enabled'): add_command_to_config_list(interface, 'undo shutdown', commands) elif diff.get('enabled') is False: add_command_to_config_list(interface, 'shutdown', commands) if diff.get('negotiation'): add_command_to_config_list(interface, 'negotiation auto', commands) if interface_type.lower( ) == 'gigabitethernet' and not diff.get('negotiation'): for item in diff.keys(): if item in ['speed', 'duplex']: cmd = 'undo negotiation auto' add_command_to_config_list(interface, cmd, commands) break if diff.get('speed') == '1000' and have.get( 'duplex') == 'half': cmd = 'duplex full' add_command_to_config_list(interface, cmd, commands) cmd = 'speed {0}'.format(want.get('speed')) add_command_to_config_list(interface, cmd, commands) elif diff.get('speed'): cmd = 'speed {0}'.format(want.get('speed')) add_command_to_config_list(interface, cmd, commands) if diff.get('duplex'): cmd = 'duplex {0}'.format(want.get('duplex')) add_command_to_config_list(interface, cmd, commands) add_command_to_config_list(interface, 'quit', commands) return commands
def _set_config(self, want, have, module): # Set the interface config based on the want and have config commands = [] #Sort values in want and have dict if want.get('members'): j = 0 for intr in want['members']: intr = dict(sorted(intr.items())) want['members'][j] = intr j += 1 if have.get('members'): j = 0 for intr in have['members']: intr = dict(sorted(intr.items())) have['members'][j] = intr j += 1 # 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 if diff: diff = dict(diff) interface = 'interface {0}'.format(want.get('name')) for each in diff['members']: each = dict(each) if each.get('mode') == 'active' or each.get( 'mode') == 'passive': cmd = 'mode lacp' self.add_command_to_config_list(interface, cmd, commands) if each.get('mode') == 'on': cmd = 'mode manual load-balance' self.add_command_to_config_list(interface, cmd, commands) cmd = 'trunkport {0}'.format(each.get('member')) self.add_command_to_config_list(interface, cmd, commands) if commands: self.add_command_to_config_list(interface, 'quit', 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') #if port_priotity: # cmd = 'lacp priority {0}'.format(port_priotity) # add_command_to_config_list(interface, cmd, commands) if max_bundle: cmd = 'max active-linknumber {0}'.format(max_bundle) add_command_to_config_list(interface, cmd, commands) if commands: add_command_to_config_list(interface, 'quit', 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: diff = dict(diff) diff = dict(diff['system']) lacp_priority = diff.get('priority') lacp_id = diff.get('id') if lacp_priority: cmd = 'lacp priority {0}'.format( want.get('system').get('priority')) self._add_command_to_config_list(cmd, commands) #too many switches do not support this command #if lacp_id: # cmd = 'lacp system-id {0}'.format(want.get('system').get('id')) # 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 = [] interface = 'interface ' + want['name'] primary_address_dhcp = False #check than primary address is not a dhcp address for each in have.get('ipv4'): if each.get('address') == 'dhcp' and not each.get('secondary'): primary_address_dhcp = True # 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' and not ipv4_dict.get( 'secondary'): cmd = "ip address {0}".format(ipv4_dict['address']) primary_address_dhcp = False if ipv4_dict.get('address') != 'dhcp' and ipv4_dict.get( "secondary") and not primary_address_dhcp: cmd = "ip address {0} sub".format(ipv4_dict['address']) elif ipv4_dict.get('address') != 'dhcp' and ipv4_dict.get( "secondary") and primary_address_dhcp: continue elif ipv4_dict.get('address') == 'dhcp': cmd = "ip address dhcp-alloc" 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 enable" add_command_to_config_list(interface, cmd, commands) cmd = "ipv6 address {0}".format(ipv6_dict.get('address')) add_command_to_config_list(interface, cmd, commands) if commands: add_command_to_config_list(interface, 'quit', 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') want_hybrid = dict(want_dict).get('hybrid') have_hybrid = dict(have_dict).get('hybrid') if want_trunk and have_trunk: diff = set(tuple(dict(want_dict).get('trunk'))) - set( tuple(dict(have_dict).get('trunk'))) elif want_hybrid and have_hybrid: diff = set(tuple(dict(want_dict).get('hybrid'))) - set( tuple(dict(have_dict).get('hybrid'))) else: diff = want_dict - have_dict if diff: diff = dict(diff) if diff.get('access'): cmd = 'port link-type access' add_command_to_config_list(interface, cmd, commands) cmd = 'port default vlan {0}'.format(diff.get('access')[0][1]) add_command_to_config_list(interface, cmd, commands) cmd = 'quit' add_command_to_config_list(interface, cmd, commands) if want_trunk: if diff.get('trunk'): diff = dict(diff.get('trunk')) cmd = 'port lint-type trunk' add_command_to_config_list(interface, cmd, commands) if diff.get('native_vlan'): cmd = 'port trunk pvid vlan {0}'.format( diff.get('native_vlan')) add_command_to_config_list(interface, cmd, commands) allowed_vlans = diff.get('allowed_vlans') if allowed_vlans and self._check_for_correct_vlan_range( allowed_vlans, module): allowed_vlans_parsed = [] for allowed_vlan in allowed_vlans: allowed_vlan = allowed_vlan.replace('-', ' to ') allowed_vlans_parsed.append(allowed_vlan) allowed_vlans_parsed = ' '.join(allowed_vlans_parsed) cmd = 'undo port trunk allow-pass vlan all' add_command_to_config_list(interface, cmd, commands) cmd = 'port trunk allow-pass vlan {0}'.format( allowed_vlans_parsed) add_command_to_config_list(interface, cmd, commands) cmd = 'quit' add_command_to_config_list(interface, cmd, commands) if want_hybrid: if diff.get('hybrid'): diff = dict(diff.get('hybrid')) cmd = 'port link-type hybrid' add_command_to_config_list(interface, cmd, commands) if diff.get('native_vlan'): cmd = 'port hybrid pvid vlan {0}'.format( diff.get('native_vlan')) add_command_to_config_list(interface, cmd, commands) cmd = 'port hybrid untagged vlan {0}'.format( diff.get('native_vlan')) add_command_to_config_list(interface, cmd, commands) allowed_vlans = diff.get('allowed_vlans') if allowed_vlans and self._check_for_correct_vlan_range( allowed_vlans, module): allowed_vlans_parsed = [] for allowed_vlan in allowed_vlans: allowed_vlan = allowed_vlan.replace('-', ' to ') allowed_vlans_parsed.append(allowed_vlan) allowed_vlans_parsed = ' '.join(allowed_vlans_parsed) cmd = 'undo port hybrid tagged vlan all' add_command_to_config_list(interface, cmd, commands) cmd = 'port hybrid tagged vlan {0}'.format( allowed_vlans_parsed) add_command_to_config_list(interface, cmd, commands) cmd = 'quit' add_command_to_config_list(interface, cmd, commands) return commands