def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] differ = DictDiffer(have, want, {'vlan_id': [1], 'name': [3]}) dict_diff = differ.deepdiff() for diff in dict_diff: vlan_id = diff.get('vlan_id') vlan_cmd = 'dot1q vlan {0}'.format(vlan_id) if len(diff) == 1: commands.append(vlan_cmd) continue name = diff.get('name') if name != None: commands.append('{0} name {1}'.format(vlan_cmd, name)) interface = diff.get('interface') if interface != None: for each in interface: each = dict(each) intf_name = each.get('name') intf_cmd = '{0} interface {1}'.format(vlan_cmd, intf_name) tagged = each.get('tagged') if tagged != None: intf_cmd += ' tagged' if tagged else ' untagged' commands.append(intf_cmd) return commands
def _delete_config(self, want, have): # Set the interface config based on the want and have config commands = [] if not want and have: return ['no switchport'] differ = DictDiffer(have, want, { 'interface_name': [1], 'traffic': [3] }) dict_intsec = differ.deepintersect() for diff in dict_intsec: interface_name = diff.get('interface_name') switchport_cmd = 'no switchport interface {0}'.format( interface_name) switchport_n_keys = diff.get('n_keys') if switchport_n_keys == 1: commands.append(switchport_cmd) continue native_vlan_id = diff.get('native_vlan_id') if native_vlan_id != None: commands.append('{0} native-vlan'.format(switchport_cmd)) qinq = diff.get('qinq') if qinq != None: commands.append('{0} qinq'.format(switchport_cmd)) storm_control = diff.get('storm_control') if storm_control != None: for each in storm_control: each = dict(each) traffic = each.get('traffic') storm_control_cmd = '{0} storm-control {1}'.format( switchport_cmd, traffic) commands.append(storm_control_cmd) tpid = diff.get('tpid') if tpid != None: commands.append('{0} tpid'.format(switchport_cmd)) return commands
def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] differ = DictDiffer(have, want) dict_diff = differ.deepdiff() severity = dict_diff.get('severity') if severity != None: commands.append('log severity {0}'.format(severity)) syslog = dict_diff.get('syslog') if syslog != None: for each in syslog: commands.append('log syslog {0}'.format(each)) return commands
def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] differ = DictDiffer(have, want, {'lag_id': [1], 'name': [3]}) dict_diff = differ.deepdiff() sys_prio = dict_diff.get('sys_prio') if sys_prio != None: commands.append( 'link-aggregation system-priority {0}'.format(sys_prio)) lag = dict_diff.get('lag') if lag != None: for each_lag in lag: commands.extend(self._get_lag_commands(each_lag)) return commands
def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] differ = DictDiffer(have, want, { 'interface_name': [1], 'traffic': [3] }) dict_diff = differ.deepdiff() for diff in dict_diff: interface_name = diff.get('interface_name') switchport_cmd = 'switchport interface {0}'.format(interface_name) if len(diff) == 1: commands.append(switchport_cmd) continue native_vlan_id = diff.get('native_vlan_id') if native_vlan_id != None: commands.append('{0} native-vlan vlan-id {1}'.format( switchport_cmd, native_vlan_id)) qinq = diff.get('qinq') if qinq != None: commands.append('{0} {1} qinq'.format('' if qinq else 'no', switchport_cmd).strip()) storm_control = diff.get('storm_control') if storm_control != None: for each in storm_control: each = dict(each) traffic = each.get('traffic') percent = each.get('percent') storm_control_cmd = '{0} storm-control {1} {2}'.format( switchport_cmd, traffic, percent) commands.append(storm_control_cmd) tpid = diff.get('tpid') if tpid != None: commands.append('{0} tpid {1}'.format(switchport_cmd, tpid)) return commands
def _delete_config(self, want, have): # Set the interface config based on the want and have config commands = [] if not want and have: return ['no link-aggregation'] differ = DictDiffer(have, want, {'lag_id': [1], 'name': [3]}) dict_intsec = differ.deepintersect() sys_prio = dict_intsec.get('sys_prio') if sys_prio != None: commands.append('no link-aggregation system-priority') lag = dict_intsec.get('lag') if lag != None: for each_lag in lag: commands.extend(self._delete_lag_commands(each_lag)) return commands
def _delete_config(self, want, have): # Set the interface config based on the want and have config commands = [] if not want and have: return ['no log'] differ = DictDiffer(have, want) dict_intsec = differ.deepintersect() severity = dict_intsec.get('severity') if severity != None: commands.append('no log severity') syslog = dict_intsec.get('syslog') if syslog != None: for each in syslog: commands.append('no log syslog {0}'.format(each)) return commands
def _delete_config(self, want, have): # Set the interface config based on the want and have config commands = [] if not want and have: return ['no dot1q'] differ = DictDiffer(have, want, {'vlan_id': [1], 'name': [3]}) dict_intsec = differ.deepintersect() for diff in dict_intsec: vlan_id = diff.get('vlan_id') vlan_cmd = 'no dot1q vlan {0}'.format(vlan_id) vlan_n_keys = diff.get('n_keys') if vlan_n_keys == 1: commands.append(vlan_cmd) continue name = diff.get('name') if name != None: commands.append('{0} name'.format(vlan_cmd)) interface = diff.get('interface') if interface != None: for each in interface: each = dict(each) intf_name = each.get('name') intf_cmd = '{0} interface {1}'.format(vlan_cmd, intf_name) intf_n_keys = each.get('n_keys') if intf_n_keys == 1: commands.append(intf_cmd) continue tagged = each.get('tagged') if tagged != None: intf_cmd += ' tagged' if tagged else ' untagged' commands.append(intf_cmd) return commands
def _delete_config(self, want, have): commands = [] if not want and have: return ['no user'] differ = DictDiffer(have, want, {'name': [0, 1]}) dict_intsec = differ.deepintersect() for user in dict_intsec: name = user.get('name') if name is None: continue no_user_cmd = 'no user {}'.format(name) if user.get('n_keys') == 1: commands.append(no_user_cmd) continue alias = user.get('alias') if alias is not None: for each in alias: alias_name = each.get('name') if alias_name is None: continue temp_cmd = '{} alias {}'.format(no_user_cmd, alias_name) commands.append(temp_cmd) description = user.get('description') if description is not None: commands.append('{} description'.format(no_user_cmd)) session = user.get('session') if session is not None: for key in session.keys(): if key == 'n_keys': continue commands.append('{} session {}'.format( no_user_cmd, key.replace('_', '-'))) return commands
def _set_config(self, want, have): commands = [] differ = DictDiffer(have, want, {'name': [0, 1]}) dict_diff = differ.deepdiff() for user_config in dict_diff: cmd = '' name = user_config.get('name') if name is not None: cmd = 'user {}'.format(name) alias = user_config.get('alias') if alias is not None: for each in alias: alias_name = each.get('name') expansion = each.get('expansion') if alias_name is None: continue temp_cmd = '{} alias {}'.format(cmd, alias_name) if expansion is not None: temp_cmd = '{} expansion {}'.format( temp_cmd, expansion) commands.append(temp_cmd) description = user_config.get('description') if description is not None: commands.append('{} description {}'.format(cmd, description)) session = user_config.get('session') if session is not None: for key, value in session.items(): if isinstance(value, bool): value = str(value).lower() commands.append('{} session {} {}'.format( cmd, key.replace('_', '-'), value)) return commands
def _delete_config(self, want, have): commands = [] if not want and have: return ['no lldp'] differ = DictDiffer(have, want, {'name': [1]}) dict_intsec = differ.deepintersect() interface = dict_intsec.get('interface') if interface != None: for each in interface: each = dict(each) intf_name = each.get('name') intf_cmd = 'no lldp interface {0}'.format(intf_name) intf_n_keys = each.get('n_keys') if intf_n_keys == 1: commands.append(intf_cmd) continue admin_status = each.get('admin_status') if admin_status != None: commands.append('{0} admin-status'.format(intf_cmd)) notification = each.get('notification') if notification != None: commands.append('{0} notification'.format(intf_cmd)) tlv_port_description = each.get('tlv_port_description') if tlv_port_description != None: commands.append( '{0} tlvs-tx port-description'.format(intf_cmd)) tlv_system_capabilities = each.get('tlv_system_capabilities') if tlv_system_capabilities != None: commands.append( '{0} tlvs-tx system-capabilities'.format(intf_cmd)) tlv_system_description = each.get('tlv_system_description') if tlv_system_description != None: commands.append( '{0} tlvs-tx system-description'.format(intf_cmd)) tlv_system_name = each.get('tlv_system_name') if tlv_system_name != None: commands.append('{0} tlvs-tx system-name'.format(intf_cmd)) msg_fast_tx = dict_intsec.get('msg_fast_tx') if msg_fast_tx != None: commands.append('no lldp message-fast-tx'.format(msg_fast_tx)) msg_tx_hold_multi = dict_intsec.get('msg_tx_hold_multi') if msg_tx_hold_multi != None: commands.append( 'no lldp message-tx-hold-multiplier'.format(msg_tx_hold_multi)) msg_tx_interval = dict_intsec.get('msg_tx_interval') if msg_tx_interval != None: commands.append( 'no lldp message-tx-interval'.format(msg_tx_interval)) notification_interval = dict_intsec.get('notification_interval') if notification_interval != None: commands.append( 'no lldp notification-interval'.format(notification_interval)) reinit_delay = dict_intsec.get('reinit_delay') if reinit_delay != None: commands.append('no lldp reinit-delay'.format(reinit_delay)) tx_credit_max = dict_intsec.get('tx_credit_max') if tx_credit_max != None: commands.append('no lldp tx-credit-max'.format(tx_credit_max)) tx_fast_init = dict_intsec.get('tx_fast_init') if tx_fast_init != None: commands.append('no lldp tx-fast-init'.format(tx_fast_init)) return commands
def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] differ = DictDiffer(have, want, {'name': [1]}) dict_diff = differ.deepdiff() interface = dict_diff.get('interface') if interface != None: for each in interface: each = dict(each) intf_name = each.get('name') intf_cmd = 'lldp interface {0}'.format(intf_name) if len(each) == 1: commands.append(intf_cmd) continue admin_status = each.get('admin_status') if admin_status != None: commands.append('{0} admin-status {1}'.format( intf_cmd, admin_status)) notification = each.get('notification') if notification != None: commands.append('{0} {1} notification'.format( '' if notification else 'no', intf_cmd).strip()) tlv_port_description = each.get('tlv_port_description') if tlv_port_description != None: commands.append('{0} {1} tlvs-tx port-description'.format( '' if tlv_port_description else 'no', intf_cmd).strip()) tlv_system_capabilities = each.get('tlv_system_capabilities') if tlv_system_capabilities != None: commands.append( '{0} {1} tlvs-tx system-capabilities'.format( '' if tlv_system_capabilities else 'no', intf_cmd).strip()) tlv_system_description = each.get('tlv_system_description') if tlv_system_description != None: commands.append( '{0} {1} tlvs-tx system-description'.format( '' if tlv_system_description else 'no', intf_cmd).strip()) tlv_system_name = each.get('tlv_system_name') if tlv_system_name != None: commands.append('{0} {1} tlvs-tx system-name'.format( '' if tlv_system_name else 'no', intf_cmd).strip()) msg_fast_tx = dict_diff.get('msg_fast_tx') if msg_fast_tx != None: commands.append('lldp message-fast-tx {0}'.format(msg_fast_tx)) msg_tx_hold_multi = dict_diff.get('msg_tx_hold_multi') if msg_tx_hold_multi != None: commands.append('lldp message-tx-hold-multiplier {0}'.format( msg_tx_hold_multi)) msg_tx_interval = dict_diff.get('msg_tx_interval') if msg_tx_interval != None: commands.append( 'lldp message-tx-interval {0}'.format(msg_tx_interval)) notification_interval = dict_diff.get('notification_interval') if notification_interval != None: commands.append( 'lldp notification-interval {0}'.format(notification_interval)) reinit_delay = dict_diff.get('reinit_delay') if reinit_delay != None: commands.append('lldp reinit-delay {0}'.format(reinit_delay)) tx_credit_max = dict_diff.get('tx_credit_max') if tx_credit_max != None: commands.append('lldp tx-credit-max {0}'.format(tx_credit_max)) tx_fast_init = dict_diff.get('tx_fast_init') if tx_fast_init != None: commands.append('lldp tx-fast-init {0}'.format(tx_fast_init)) return commands
def _delete_config(self, want, have): # Set the interface config based on the want and have config commands = [] if not want and have: return ['no oam twamp'] differ = DictDiffer(have, want, { 'address': [3], 'network': [3], 'id': [2, 4] }) dict_intsec = differ.deepintersect() reflector = dict_intsec.get('reflector') if reflector != None: reflector_cmd = 'no oam twamp reflector' admin_status = reflector.get('admin_status') if admin_status != None: commands.append( '{0} administrative-status'.format(reflector_cmd)) ipv4 = reflector.get('ipv4') if ipv4 != None: client_address = ipv4.get('client_address') if client_address != None: for each in client_address: address = each.get('address') client_address_cmd = '{0} ipv4 client-address {1}'.format( reflector_cmd, address) client_address_n_keys = each.get('n_keys') if client_address_n_keys == 1: commands.append(client_address_cmd) continue state = each.get('state') if state != None: commands.append('{0} {1}'.format( client_address_cmd, state)) client_network = ipv4.get('client_network') if client_network != None: for each in client_network: network = each.get('network') client_network_cmd = '{0} ipv4 client-network {1}'.format( reflector_cmd, network) client_network_n_keys = each.get('n_keys') if client_network_n_keys == 1: commands.append(client_network_cmd) continue state = each.get('state') if state != None: commands.append('{0} {1}'.format( client_network_cmd, state)) ipv6 = reflector.get('ipv6') if ipv6 != None: client_address = ipv6.get('client_address') if client_address != None: for each in client_address: address = each.get('address') client_address_cmd = '{0} ipv6 client-address {1}'.format( reflector_cmd, address) client_address_n_keys = each.get('n_keys') if client_address_n_keys == 1: commands.append(client_address_cmd) continue state = each.get('state') if state != None: commands.append('{0} {1}'.format( client_address_cmd, state)) client_network = ipv6.get('client_network') if client_network != None: for each in client_network: network = each.get('network') client_network_cmd = '{0} ipv6 client-network {1}'.format( reflector_cmd, network) client_network_n_keys = each.get('n_keys') if client_network_n_keys == 1: commands.append(client_network_cmd) continue state = each.get('state') if state != None: commands.append('{0} {1}'.format( client_network_cmd, state)) port = reflector.get('port') if port != None: commands.append('{0} port'.format(reflector_cmd)) sender = dict_intsec.get('sender') if sender != None: sender_cmd = 'no oam twamp sender' admin_status = sender.get('admin_status') if admin_status != None: commands.append('{0} administrative-status'.format(sender_cmd)) connection = sender.get('connection') if connection != None: for each in connection: conn_id = each.get('id') conn_cmd = '{0} connection {1}'.format(sender_cmd, conn_id) conn_n_keys = each.get('n_keys') if conn_n_keys == 1: commands.append(conn_cmd) continue admin_status = each.get('admin_status') if admin_status != None: commands.append( '{0} administrative-status'.format(conn_cmd)) ipv4 = each.get('ipv4') if ipv4 != None: source_address = ipv4.get('source_address') if source_address != None: commands.append( '{0} ipv4 source-address'.format(conn_cmd)) target_address = ipv4.get('target_address') if target_address != None: commands.append( '{0} ipv4 target-address'.format(conn_cmd)) ipv6 = each.get('ipv6') if ipv6 != None: source_address = ipv6.get('source_address') if source_address != None: commands.append( '{0} ipv6 source-address'.format(conn_cmd)) target_address = ipv6.get('target_address') if target_address != None: commands.append( '{0} ipv6 target-address'.format(conn_cmd)) number_of_packets = each.get('number_of_packets') if number_of_packets != None: commands.append( '{0} number-of-packets'.format(conn_cmd)) server_port = each.get('server_port') if server_port != None: commands.append('{0} server-port'.format(conn_cmd)) test_interval = each.get('test_interval') if test_interval != None: commands.append('{0} test-interval'.format(conn_cmd)) test_session = each.get('test_session') if test_session != None: for each_test_session in test_session: test_session_id = each_test_session.get('id') test_session_cmd = '{0} test-session {1}'.format( conn_cmd, test_session_id) test_session_n_keys = each_test_session.get( 'n_keys') if test_session_n_keys == 1: commands.append(test_session_cmd) continue test_session_ipv4 = each_test_session.get('ipv4') if test_session_ipv4 != None: source_address = test_session_ipv4.get( 'source_address') if source_address != None: commands.append( '{0} ipv4 source-address'.format( test_session_cmd)) target_address = test_session_ipv4.get( 'target_address') if target_address != None: commands.append( '{0} ipv4 target-address'.format( test_session_cmd)) test_session_ipv6 = each_test_session.get('ipv6') if test_session_ipv6 != None: source_address = test_session_ipv6.get( 'source_address') if source_address != None: commands.append( '{0} ipv6 source-address'.format( test_session_cmd)) target_address = test_session_ipv6.get( 'target_address') if target_address != None: commands.append( '{0} ipv6 target-address'.format( test_session_cmd)) dscp = each_test_session.get('dscp') if dscp != None: commands.append( '{0} dscp'.format(test_session_cmd)) max_port = each_test_session.get('max_port') if max_port != None: commands.append( '{0} max-port'.format(test_session_cmd)) min_port = each_test_session.get('min_port') if min_port != None: commands.append( '{0} min-port'.format(test_session_cmd)) packet_size = each_test_session.get('packet_size') if packet_size != None: commands.append( '{0} packet-size'.format(test_session_cmd)) return commands
def _delete_config(self, want, have): # Set the interface config based on the want and have config commands = [] if not want and have: return ['no interface l3'] differ = DictDiffer(have, want, {'name': [1], 'ip': [5]}) dict_intsec = differ.deepintersect() for diff in dict_intsec: intf_name = diff.get('name') intf_cmd = 'no interface l3 {0}'.format(intf_name) intf_n_keys = diff.get('n_keys') if intf_n_keys == 1: commands.append(intf_cmd) continue description = diff.get('description') if description != None: commands.append('{0} description'.format(intf_cmd)) ip_mtu = diff.get('ip_mtu') if ip_mtu != None: commands.append('{0} ip-mtu'.format(intf_cmd)) lower_layer_if = diff.get('lower_layer_if') if lower_layer_if != None: commands.append('{0} lower-layer-if vlan'.format(intf_cmd)) # Ignoring vlan link detect deletion since its not possible, always returns error # vlan_link_detect = diff.get('vlan_link_detect') # if vlan_link_detect != None: # commands.append('{0} vlan-link-detect'.format(intf_cmd)) vrf = diff.get('vrf') if vrf != None: commands.append('{0} vrf'.format(intf_cmd)) ipv4 = diff.get('ipv4') if ipv4 != None: address = ipv4.get('address') if address != None: commands.append('{0} ipv4 address {1}'.format( intf_cmd, address)) secondary = ipv4.get('secondary') if secondary != None: for each in secondary: commands.append( '{0} ipv4 address secondary {1}'.format( intf_cmd, each)) ipv6 = diff.get('ipv6') if ipv6 != None: address = ipv6.get('address') if address != None: for each in address: commands.append('{0} ipv6 address {1}'.format( intf_cmd, each)) nd_ra = ipv6.get('nd_ra') if nd_ra != None: nd_ra_cmd = '{0} ipv6 nd ra'.format(intf_cmd) lifetime = nd_ra.get('lifetime') if lifetime != None: commands.append('{0} lifetime'.format(nd_ra_cmd)) max_interval = nd_ra.get('max_interval') if max_interval != None: commands.append('{0} max-interval'.format(nd_ra_cmd)) min_interval = nd_ra.get('min_interval') if min_interval != None: commands.append('{0} min-interval'.format(nd_ra_cmd)) prefix = nd_ra.get('prefix') if prefix != None: for each in prefix: each = dict(each) prefix_ip = each.get('ip') prefix_cmd = '{0} prefix {1}'.format( nd_ra_cmd, prefix_ip) prefix_n_keys = each.get('n_keys') if prefix_n_keys == 1: commands.append(prefix_cmd) continue no_advertise = each.get('no_advertise') if no_advertise != None: commands.append( '{0} no-advertise'.format(prefix_cmd)) no_autoconfig = each.get('no_autoconfig') if no_autoconfig != None: commands.append( '{0} no-autoconfig'.format(prefix_cmd)) off_link = each.get('off_link') if off_link != None: commands.append( '{0} off-link'.format(prefix_cmd)) suppress = nd_ra.get('suppress') if suppress != None: commands.append('{0} suppress'.format(nd_ra_cmd)) mtu_suppress = nd_ra.get('mtu_suppress') if mtu_suppress != None: commands.append('{0} mtu suppress'.format(nd_ra_cmd)) enable = ipv6.get('enable') if enable != None: commands.append('{0} ipv6 enable'.format(intf_cmd)) return commands
def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] differ = DictDiffer(have, want, {'name': [1], 'ip': [5]}) dict_diff = differ.deepdiff() for diff in dict_diff: intf_name = diff.get('name') intf_cmd = 'interface l3 {0}'.format(intf_name) if len(diff) == 1: commands.append(intf_cmd) continue description = diff.get('description') if description != None: commands.append('{0} description "{1}"'.format( intf_cmd, description)) ip_mtu = diff.get('ip_mtu') if ip_mtu != None: commands.append('{0} ip-mtu {1}'.format(intf_cmd, ip_mtu)) lower_layer_if = diff.get('lower_layer_if') if lower_layer_if != None: commands.append('{0} lower-layer-if vlan {1}'.format( intf_cmd, lower_layer_if)) vlan_link_detect = diff.get('vlan_link_detect') if vlan_link_detect != None: commands.append('{0} vlan-link-detect {1}'.format( intf_cmd, 'enabled' if vlan_link_detect else 'disabled')) vrf = diff.get('vrf') if vrf != None: commands.append('{0} vrf {1}'.format(intf_cmd, vrf)) ipv4 = diff.get('ipv4') if ipv4 != None: address = ipv4.get('address') if address != None: commands.append('{0} ipv4 address {1}'.format( intf_cmd, address)) secondary = ipv4.get('secondary') if secondary != None: for each in secondary: commands.append( '{0} ipv4 address secondary {1}'.format( intf_cmd, each)) ipv6 = diff.get('ipv6') if ipv6 != None: enable = ipv6.get('enable') if enable != None: commands.append('{0} {1} ipv6 enable'.format( '' if enable else 'no', intf_cmd).strip()) address = ipv6.get('address') if address != None: for each in address: commands.append('{0} ipv6 address {1}'.format( intf_cmd, each)) nd_ra = ipv6.get('nd_ra') if nd_ra != None: nd_ra_cmd = '{0} ipv6 nd ra'.format(intf_cmd) lifetime = nd_ra.get('lifetime') if lifetime != None: commands.append('{0} lifetime {1}'.format( nd_ra_cmd, lifetime)) max_interval = nd_ra.get('max_interval') if max_interval != None: commands.append('{0} max-interval {1}'.format( nd_ra_cmd, max_interval)) min_interval = nd_ra.get('min_interval') if min_interval != None: commands.append('{0} min-interval {1}'.format( nd_ra_cmd, min_interval)) prefix = nd_ra.get('prefix') if prefix != None: for each in prefix: each = dict(each) prefix_ip = each.get('ip') prefix_cmd = '{0} prefix {1}'.format( nd_ra_cmd, prefix_ip) if len(each) == 1: commands.append(prefix_cmd) continue no_advertise = each.get('no_advertise') if no_advertise != None: commands.append('{0} {1} no-advertise'.format( '' if no_advertise else 'no', prefix_cmd).strip()) no_autoconfig = each.get('no_autoconfig') if no_autoconfig != None: commands.append('{0} {1} no-autoconfig'.format( '' if no_autoconfig else 'no', prefix_cmd).strip()) off_link = each.get('off_link') if off_link != None: commands.append('{0} {1} off-link'.format( '' if off_link else 'no', prefix_cmd).strip()) suppress = nd_ra.get('suppress') if suppress != None: commands.append('{0} {1} suppress'.format( '' if suppress else 'no', nd_ra_cmd).strip()) mtu_suppress = nd_ra.get('mtu_suppress') if mtu_suppress != None: commands.append('{0} {1} mtu suppress'.format( '' if mtu_suppress else 'no', nd_ra_cmd).strip()) return commands