def generate_neighbor_entries(filename, all_available_macs): db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.APPL_DB, False) # Make one attempt only arp_output = [] neighbor_entries = [] keys = db.keys(db.APPL_DB, 'NEIGH_TABLE:*') keys = [] if keys is None else keys for key in keys: vlan_name = key.split(':')[1] entry = db.get_all(db.APPL_DB, key) mac = entry['neigh'].lower() if (vlan_name, mac) not in all_available_macs: # FIXME: print me to log continue obj = {key: entry, 'OP': 'SET'} arp_output.append(obj) ip_addr = key.split(':')[2] if ipaddress.ip_interface(str(ip_addr)).ip.version != 4: #This is ipv6 address ip_addr = key.replace( key.split(':')[0] + ':' + key.split(':')[1] + ':', '') neighbor_entries.append((vlan_name, mac, ip_addr)) syslog.syslog( syslog.LOG_INFO, "Neighbor entry: [Vlan: %s, Mac: %s, Ip: %s]" % (vlan_name, mac, ip_addr)) db.close(db.APPL_DB) with open(filename, 'w') as fp: json.dump(arp_output, fp, indent=2, separators=(',', ': ')) return neighbor_entries
def __init__(self, is_dbg_test): self.my_args = dispArgs() self.my_args.cfgdb = swsssdk.ConfigDBConnector() self.my_args.cfgdb.connect() self.my_args.appdb = swsssdk.SonicV2Connector(host='127.0.0.1') self.my_args.appdb.connect(self.my_args.appdb.APPL_DB) self.my_args.appdb.connect(self.my_args.appdb.COUNTERS_DB) self.my_args.appdb.connect(self.my_args.appdb.ASIC_DB) # create the full yang tree # for performance, only update the tree node requested self.oc_yph = YANGPathHelper() for k in ocTable.keys(): if ocTable[k]["cls"]: ocTable[k]["cls"](path_helper=self.oc_yph) # create obj for "/" to only return subtree of depth 1 openconfig_root_dpt_1(self.oc_yph) # create all interfaces to speed up processing request for interfaces later util_interface.interface_create_all_infs(self.oc_yph, is_dbg_test, self.my_args) # create default network instance util_nwi.nwi_create_dflt_nwi(self.oc_yph, is_dbg_test) # create default objects util_qos.qos_create_dflt_obj(self.oc_yph, is_dbg_test)
def start(action, restoration_time, ports, detection_time): """ Start PFC watchdog on port(s) """ configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) all_ports = get_all_ports(countersdb) if len(ports) == 0: ports = all_ports pfcwd_info = { 'detection_time': detection_time, } if action is not None: pfcwd_info['action'] = action if restoration_time is not None: pfcwd_info['restoration_time'] = restoration_time for port in ports: if port not in all_ports: continue configdb.mod_entry("PFC_WD_TABLE", port, None) configdb.mod_entry("PFC_WD_TABLE", port, pfcwd_info)
def stats(empty, queues): """ Show PFC Watchdog stats per queue """ db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.COUNTERS_DB) table = [] if len(queues) == 0: queues = get_all_queues(db) for queue in queues: stats_list = [] queue_oid = db.get(db.COUNTERS_DB, 'COUNTERS_QUEUE_NAME_MAP', queue) stats = db.get_all(db.COUNTERS_DB, 'COUNTERS:' + queue_oid) if stats is None: continue for stat in STATS_DESCRIPTION: line = stats.get(stat[1], '0') + '/' + stats.get(stat[2], '0') stats_list.append(line) if stats_list != ['0/0'] * len(STATS_DESCRIPTION) or empty: table.append([queue] + stats_list) click.echo( tabulate(table, STATS_HEADER, stralign='right', numalign='right', tablefmt='simple'))
def config(ports): """ Show PFC Watchdog configuration """ configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) table = [] all_ports = get_all_ports(countersdb) if len(ports) == 0: ports = all_ports for port in ports: config_list = [] config_entry = configdb.get_entry('PFC_WD_TABLE', port) if config_entry is None or config_entry == {}: continue for config in CONFIG_DESCRIPTION: line = config_entry.get(config[1], config[2]) config_list.append(line) table.append([port] + config_list) poll_interval = configdb.get_entry( 'PFC_WD_TABLE', 'GLOBAL').get('POLL_INTERVAL') if poll_interval is not None: click.echo("Changed polling interval to " + poll_interval + "ms") big_red_switch = configdb.get_entry( 'PFC_WD_TABLE', 'GLOBAL').get('BIG_RED_SWITCH') if big_red_switch is not None: click.echo("BIG_RED_SWITCH status is " + big_red_switch) click.echo(tabulate(table, CONFIG_HEADER, stralign='right', numalign='right', tablefmt='simple'))
def generate_arp_entries(filename, all_available_macs): db = swsssdk.SonicV2Connector() db.connect(db.APPL_DB, False) # Make one attempt only arp_output = [] keys = db.keys(db.APPL_DB, 'NEIGH_TABLE:*') keys = [] if keys is None else keys for key in keys: entry = db.get_all(db.APPL_DB, key) if entry['neigh'].lower() not in all_available_macs: # print me to log continue obj = { key: entry, 'OP': 'SET' } arp_output.append(obj) db.close(db.APPL_DB) with open(filename, 'w') as fp: json.dump(arp_output, fp, indent=2, separators=(',', ': ')) return
def read_neigh_table_to_maps(): db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.APPL_DB, False) intf_neigh_map = {} keys = db.keys(db.APPL_DB, 'NEIGH_TABLE:*') keys = [] if keys is None else keys for key in keys: key_split = key.split(':', 2) intf_name = key_split[1] if intf_name == 'lo': continue dst_ip = key_split[2] value = db.get_all(db.APPL_DB, key) if 'neigh' in value and 'family' in value: dmac = value['neigh'] family = value['family'] else: raise RuntimeError('Neigh table format is incorrect') if family not in ip_family: raise RuntimeError('Neigh table format is incorrect') ip_mac_pair = [] ip_mac_pair.append(dst_ip) ip_mac_pair.append(dmac) intf_neigh_map.setdefault(intf_name, {}).setdefault(family, []).append(ip_mac_pair) db.close(db.APPL_DB) return intf_neigh_map
def show_acl_resources(self): """ CRM Handler to display ACL recources information. """ countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) header = ("Stage", "Bind Point", "Resource Name", "Used Count", "Available Count") data = [] for stage in ["INGRESS", "EGRESS"]: for bind_point in ["PORT", "LAG", "VLAN", "RIF", "SWITCH"]: crm_stats = countersdb.get_all( countersdb.COUNTERS_DB, 'CRM:ACL_STATS:{0}:{1}'.format(stage, bind_point)) if crm_stats: for res in ["acl_group", "acl_table"]: data.append([ stage, bind_point, res, crm_stats['crm_stats_' + res + "_used"], crm_stats['crm_stats_' + res + "_available"] ]) click.echo() click.echo( tabulate(data, headers=header, tablefmt="simple", missingval="")) click.echo()
def show_resources(self, resource): """ CRM Handler to display resources information. """ countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) crm_stats = countersdb.get_all(countersdb.COUNTERS_DB, 'CRM:STATS') header = ("Resource Name", "Used Count", "Available Count") data = [] if crm_stats: if resource == 'all': for res in [ "ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor", "nexthop_group_member", "nexthop_group", "fdb_entry" ]: data.append([ res, crm_stats['crm_stats_' + res + "_used"], crm_stats['crm_stats_' + res + "_available"] ]) else: data.append([ resource, crm_stats['crm_stats_' + resource + "_used"], crm_stats['crm_stats_' + resource + "_available"] ]) else: print '\nCRM counters are not ready. They would be populated after the polling interval.' print '\n' print tabulate(data, headers=header, tablefmt="simple", missingval="") print '\n'
def generate_fdb_entries(filename): fdb_entries = [] db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.ASIC_DB, False) # Make one attempt only bridge_id_2_iface = get_map_bridge_port_id_2_iface_name(db) vlan_ifaces = get_vlan_ifaces() all_available_macs = set() map_mac_ip_per_vlan = {} for vlan in vlan_ifaces: vlan_id = int(vlan.replace('Vlan', '')) fdb_entry, available_macs, map_mac_ip_per_vlan[vlan] = get_fdb( db, vlan, vlan_id, bridge_id_2_iface) all_available_macs |= available_macs fdb_entries.extend(fdb_entry) db.close(db.ASIC_DB) with open(filename, 'w') as fp: json.dump(fdb_entries, fp, indent=2, separators=(',', ': ')) return all_available_macs, map_mac_ip_per_vlan
def generate_arp_entries(filename, all_available_macs): db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.APPL_DB, False) # Make one attempt only arp_output = [] arp_entries = [] keys = db.keys(db.APPL_DB, 'NEIGH_TABLE:*') keys = [] if keys is None else keys for key in keys: vlan_name = key.split(':')[1] ip_addr = key.split(':')[2] entry = db.get_all(db.APPL_DB, key) if (vlan_name, entry['neigh'].lower()) not in all_available_macs: # FIXME: print me to log continue obj = {key: entry, 'OP': 'SET'} arp_entries.append((vlan_name, entry['neigh'].lower(), ip_addr)) arp_output.append(obj) db.close(db.APPL_DB) with open(filename, 'w') as fp: json.dump(arp_output, fp, indent=2, separators=(',', ': ')) return arp_entries
def config(ports): """ Show PFC Watchdog configuration """ configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) table = [] all_ports = get_all_ports(countersdb) if len(ports) == 0: ports = all_ports for port in ports: config_list = [] config_entry = configdb.get_entry('PFC_WD_TABLE', port) if config_entry is None or config_entry == {}: continue for config in CONFIG_DESCRIPTION: line = config_entry.get(config[1], config[2]) config_list.append(line) table.append([port] + config_list) click.echo( tabulate(table, CONFIG_HEADER, stralign='right', numalign='right', tablefmt='simple'))
def show_acl_table_resources(self): """ CRM Handler to display ACL table information. """ countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) header = ("Table ID", "Resource Name", "Used Count", "Available Count") # Retrieve all ACL table keys from CRM:ACL_TABLE_STATS crm_acl_keys = countersdb.keys(countersdb.COUNTERS_DB, 'CRM:ACL_TABLE_STATS*') for key in crm_acl_keys or [None]: data = [] if key: id = key.replace('CRM:ACL_TABLE_STATS:', '') crm_stats = countersdb.get_all(countersdb.COUNTERS_DB, key) for res in ['acl_entry', 'acl_counter']: if ('crm_stats_' + res + '_used' in crm_stats) and ('crm_stats_' + res + '_available' in crm_stats): data.append([id, res, crm_stats['crm_stats_' + res + '_used'], crm_stats['crm_stats_' + res + '_available']]) print '\n' print tabulate(data, headers=header, tablefmt="simple", missingval="") print '\n'
def test__db_map_attributes(self): import swsssdk db1 = swsssdk.SonicV1Connector() self.assertTrue(all(hasattr(db1, db_name) for db_name in db1.db_map)) db2 = swsssdk.SonicV2Connector() self.assertTrue(all(hasattr(db2, db_name) for db_name in db2.db_map)) pass
def clean_bgp_eoiu_marker(self): db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.STATE_DB, False) db.delete(db.STATE_DB, "BGP_STATE_TABLE|IPv4|eoiu") db.delete(db.STATE_DB, "BGP_STATE_TABLE|IPv6|eoiu") db.close(db.STATE_DB) syslog.syslog('Cleaned ipv4 and ipv6 eoiu marker flags') return
def set_bgp_eoiu_marker(self, family, state): db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.STATE_DB, False) key = "BGP_STATE_TABLE|%s|eoiu" % family db.set(db.STATE_DB, key, 'state', state) timesamp = strftime("%Y-%m-%d %H:%M:%S", gmtime()) db.set(db.STATE_DB, key, 'timestamp', timesamp) db.close(db.STATE_DB) return
def enable_rates(): # set the default interval for rates counters_db = swsssdk.SonicV2Connector() counters_db.connect('COUNTERS_DB') counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_SMOOTH_INTERVAL', DEFAULT_SMOOTH_INTERVAL) counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_ALPHA', DEFAULT_ALPHA) counters_db.set('COUNTERS_DB', 'RATES:RIF', 'RIF_SMOOTH_INTERVAL', DEFAULT_SMOOTH_INTERVAL) counters_db.set('COUNTERS_DB', 'RATES:RIF', 'RIF_ALPHA', DEFAULT_ALPHA)
def start(action, restoration_time, ports, detection_time): """ Start PFC watchdog on port(s). To config all ports, use all as input. Example: sudo pfcwd start --action drop ports all detection-time 400 --restoration-time 400 """ if os.geteuid() != 0: exit("Root privileges are required for this operation") allowed_strs = ['ports', 'all', 'detection-time'] configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) all_ports = get_all_ports(countersdb) allowed_strs = allowed_strs + all_ports for p in ports: if p not in allowed_strs: raise click.BadOptionUsage( "Bad command line format. Try 'pfcwd start --help' for usage") if len(ports) == 0: ports = all_ports pfcwd_info = { 'detection_time': detection_time, } if action is not None: pfcwd_info['action'] = action if restoration_time is not None: pfcwd_info['restoration_time'] = restoration_time else: pfcwd_info['restoration_time'] = 2 * detection_time click.echo( "restoration time not defined; default to 2 times detection time: %d ms" % (2 * detection_time)) for port in ports: if port == "all": for p in all_ports: configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, p, None) configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, p, pfcwd_info) else: if port not in all_ports: continue configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, port, None) configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, port, pfcwd_info)
def __init__(self, is_dbg_test): self.my_args = dispArgs() self.my_args.cfgdb = swsssdk.ConfigDBConnector() self.my_args.cfgdb.connect() self.my_args.appdb = swsssdk.SonicV2Connector(host='127.0.0.1') self.my_args.appdb.connect(self.my_args.appdb.APPL_DB) self.my_args.appdb.connect(self.my_args.appdb.COUNTERS_DB) self.my_args.appdb.connect(self.my_args.appdb.ASIC_DB) # check if port table is ready is_pcfg_done = False chk_cnt = 0 while True: pcfg_val = self.my_args.appdb.get_all(self.my_args.appdb.APPL_DB, "PORT_TABLE:PortConfigDone") is_pcfg_done = pcfg_val != None chk_cnt += 1 if is_pcfg_done or chk_cnt % 3 == 1: util_utl.utl_log( "PORT TABLE was%sready...(%s)" % ([" not ", " "][is_pcfg_done], chk_cnt), logging.CRITICAL) if is_pcfg_done: break time.sleep(10) # create the full yang tree # for performance, only update the tree node requested self.oc_yph = YANGPathHelper() for k in ocTable.keys(): if ocTable[k]["cls"]: ocTable[k]["cls"](path_helper = self.oc_yph) # create obj for "/" to only return subtree of depth 1 openconfig_root_dpt_1(self.oc_yph) # create all interfaces to speed up processing request for interfaces later util_interface.interface_create_all_infs(self.oc_yph, is_dbg_test, self.my_args) # create default network instance util_nwi.nwi_create_dflt_nwi(self.oc_yph, is_dbg_test) # create default objects util_qos.qos_create_dflt_obj(self.oc_yph, is_dbg_test) # check if new teammgrd is used test_cmd = 'docker run --rm=true --privileged=true --entrypoint="/bin/bash" "docker-teamd" -c "[ -f /usr/bin/teammgrd ]"' util_interface.IS_NEW_TEAMMGRD = util_utl.utl_execute_cmd(test_cmd)
def _port_name_to_qsfp_index(self, port_name): # Strip "Ethernet" off port name if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): return -1 sonic_port_num = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):]) swss = swsssdk.SonicV2Connector() swss.connect(swss.APPL_DB) lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') # SONiC port nums are 0-based and increment by 4 # Arista QSFP indices are 1-based and increment by 1 return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(',')))
def run(self): """ Main method of the class """ self.facts['switch_capabilities'] = {} conn = swsssdk.SonicV2Connector(host='127.0.0.1') conn.connect(conn.STATE_DB) keys = conn.keys(conn.STATE_DB, 'SWITCH_CAPABILITY|*') for key in keys: capab = conn.get_all(conn.STATE_DB, key) self.facts['switch_capabilities'][key.split('|')[-1]] = capab self.module.exit_json(ansible_facts=self.facts)
def __init__(self): # list peer_l stores the Neighbor peer Ip address # dic peer_state stores the Neighbor peer state entries # list new_peer_l stores the new snapshot of Neighbor peer ip address # dic new_peer_state stores the new snapshot of Neighbor peer states self.peer_l = [] self.peer_state = {} self.new_peer_l = [] self.new_peer_state = {} self.cached_timestamp = 0 self.db = swsssdk.SonicV2Connector() self.db.connect(self.db.STATE_DB, False) client = self.db.get_redis_client(self.db.STATE_DB) self.pipe = client.pipeline() self.db.delete_all_by_pattern(self.db.STATE_DB, "NEIGH_STATE_TABLE|*")
def restore_update_kernel_neighbors(intf_neigh_map, timeout=DEF_TIME_OUT): # create object for netlink calls to kernel ipclass = IPRoute() mtime = monotonic.time.time start_time = mtime() is_intf_up.counter = 0 db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.STATE_DB, False) while (mtime() - start_time) < timeout: for intf, family_neigh_map in intf_neigh_map.items(): # only try to restore to kernel when link is up if is_intf_up(intf, db): src_mac = get_if_hwaddr(intf) intf_idx = ipclass.link_lookup(ifname=intf)[0] # create socket per intf to send packets s = conf.L2socket(iface=intf) # Only two families: 'IPv4' and 'IPv6' for family in ip_family.keys(): # if ip address assigned and if we have neighs in this family, restore them src_ip = first_ip_on_intf(intf, family) if src_ip and (family in family_neigh_map): neigh_list = family_neigh_map[family] for dst_ip, dmac in neigh_list: # use netlink to set neighbor entries set_neigh_in_kernel(ipclass, family, intf_idx, dst_ip, dmac) log_info( 'Sending Neigh with family: {}, intf_idx: {}, ip: {}, mac: {}' .format(family, intf_idx, dst_ip, dmac)) # sending arp/ns packet to update kernel neigh info s.send( build_arp_ns_pkt(family, src_mac, src_ip, dst_ip)) # delete this family on the intf del intf_neigh_map[intf][family] # close the pkt socket s.close() # if all families are deleted, remove the key if len(intf_neigh_map[intf]) == 0: del intf_neigh_map[intf] # map is empty, all neigh entries are restored if not intf_neigh_map: break time.sleep(CHECK_INTERVAL) db.close(db.STATE_DB)
def run(self): """ Run ACL capabilities facts collection. """ self.facts['acl_capabilities'] = {} namespace_list = multi_asic.get_namespace_list() swsssdk.SonicDBConfig.load_sonic_global_db_config() conn = swsssdk.SonicV2Connector(namespace=namespace_list[0]) conn.connect(conn.STATE_DB) keys = conn.keys(conn.STATE_DB, 'ACL_STAGE_CAPABILITY_TABLE|*') or [] for key in keys: capab = conn.get_all(conn.STATE_DB, key) self.facts['acl_capabilities'][key.split('|')[-1]] = capab self.module.exit_json(ansible_facts=self.facts)
def stop(ports): """ Stop PFC watchdog on port(s) """ configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) all_ports = get_all_ports(countersdb) if len(ports) == 0: ports = all_ports for port in ports: if port not in all_ports: continue configdb.mod_entry("PFC_WD_TABLE", port, None)
def run(self): """ Main method of the class """ self.facts['switch_capabilities'] = {} namespace_list = multi_asic.get_namespace_list() swsssdk.SonicDBConfig.load_sonic_global_db_config() conn = swsssdk.SonicV2Connector(namespace=namespace_list[0]) conn.connect(conn.STATE_DB) keys = conn.keys(conn.STATE_DB, 'SWITCH_CAPABILITY|*') for key in keys: capab = conn.get_all(conn.STATE_DB, key) self.facts['switch_capabilities'][key.split('|')[-1]] = capab self.module.exit_json(ansible_facts=self.facts)
def read_neigh_table_to_maps(): db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.APPL_DB, False) intf_neigh_map = {} # Key format: "NEIGH_TABLE:intf-name:ipv4/ipv6", examples below: # "NEIGH_TABLE:Ethernet122:100.1.1.200" # "NEIGH_TABLE:Ethernet122:fe80::2e0:ecff:fe3b:d6ac" # Value format: # 1) "neigh" # 2) "00:22:33:44:55:cc" # 3) "family" # 4) "IPv4" or "IPv6" keys = db.keys(db.APPL_DB, 'NEIGH_TABLE:*') keys = [] if keys is None else keys for key in keys: key_split = key.split(':', 2) intf_name = key_split[1] if intf_name == 'lo': continue dst_ip = key_split[2] value = db.get_all(db.APPL_DB, key) if 'neigh' in value and 'family' in value: dmac = value['neigh'] family = value['family'] else: raise RuntimeError('Neigh table format is incorrect') if family not in ip_family: raise RuntimeError('Neigh table format is incorrect') # build map like this: # { intf1 -> { { family1 -> [[ip1, mac1], [ip2, mac2] ...] } # { family2 -> [[ipM, macM], [ipN, macN] ...] } }, # intfX -> {...} # } ip_mac_pair = [] ip_mac_pair.append(dst_ip) ip_mac_pair.append(dmac) intf_neigh_map.setdefault(intf_name, {}).setdefault(family, []).append(ip_mac_pair) db.close(db.APPL_DB) return intf_neigh_map
def initialize_configdb(self): try: f_mac = os.popen( 'ip link show eth0 | grep ether | awk \'{print $2}\'') mac_addr = f_mac.read(17) last_byte = mac_addr[-2:] aligned_last_byte = format(int(int(str(last_byte), 16) + 1), '02x') mac_addr = mac_addr[:-2] + aligned_last_byte DBG_PRINT("start connect swss config-db to set device mac-address") swss = swsssdk.SonicV2Connector() swss.connect(swss.CONFIG_DB) swss.set(swss.CONFIG_DB, "DEVICE_METADATA|localhost", 'mac', mac_addr) mac_addr = swss.get(swss.CONFIG_DB, "DEVICE_METADATA|localhost", 'mac') DBG_PRINT("set device mac-address: %s" % mac_addr) except IOError as e: DBG_PRINT(str(e))
def stop(ports): """ Stop PFC watchdog on port(s) """ if os.geteuid() != 0: exit("Root privileges are required for this operation") configdb = swsssdk.ConfigDBConnector() configdb.connect() countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') countersdb.connect(countersdb.COUNTERS_DB) all_ports = get_all_ports(countersdb) if len(ports) == 0: ports = all_ports for port in ports: if port not in all_ports: continue configdb.mod_entry(CONFIG_DB_PFC_WD_TABLE_NAME, port, None)
def generate_default_route_entries(filename): db = swsssdk.SonicV2Connector(host='127.0.0.1') db.connect(db.APPL_DB, False) # Make one attempt only default_routes_output = [] ipv4_default = get_default_entries(db, '0.0.0.0/0') if ipv4_default is not None: default_routes_output.append(ipv4_default) ipv6_default = get_default_entries(db, '::/0') if ipv6_default is not None: default_routes_output.append(ipv6_default) db.close(db.APPL_DB) with open(filename, 'w') as fp: json.dump(default_routes_output, fp, indent=2, separators=(',', ': '))