def init_profile(): while cps.enabled(nas_comm.yang.get_tbl('keys_id')['switch_key']) is False: nas_if.log_err('Switch profile service not yet ready') time.sleep(1) l = [] obj = cps_object.CPSObject( module='base-switch/switching-entities/switching-entity', qual='observed', data={'switch-id': 0}) if not cps.get([obj.get()], l): nas_if.log_info('Get profile : CPS GET FAILED') return False switch_obj = cps_object.CPSObject(obj=l[0]) try: profile = switch_obj.get_attr_data(current_profile) except: nas_if.log_info("Current profile missing in CPS get") return False nas_if.log_info('Get profile returned ' + str(profile)) profile = '/etc/opx/' + profile + '-base_port_physical_mapping_table.xml' if os.path.isfile(profile): fp.init(profile) return True else: nas_if.log_err('Profile file missing' + str(profile)) return False
def subscribe_events(): while cps.enabled(nas_comm.yang.get_value('fp_key', 'keys_id')) == False: #wait for front panel port objects to be ready nas_if.log_err('Media or front panel port object is not yet ready') time.sleep(1) if_thread = interfaceMonitorThread(1, "Interface event Monitoring Thread") if_thread.daemon = True if_thread.start()
def subscribe_events(): while cps.enabled(nas_comm.yang.get_value('media_key', 'keys_id')) == False: #wait for media and front panel port objects to be ready nas_if.log_err('Media or front panel port object is not yet ready') time.sleep(1) media_thread = mediaMonitorThread(2, "Media event Monitoring Thread") media_thread.daemon = True media_thread.start()
shutdwn = False # Install signal handlers. import signal signal.signal(signal.SIGTERM, sigterm_hdlr) # Initialization complete # Notify systemd: Daemon is ready systemd.daemon.notify("READY=1") # Wait for base MAC address to be ready. the script will wait until # chassis object is registered. srv_chk_cnt = 0 srv_chk_rate = 10 chassis_key = cps.key_from_name('observed','base-pas/chassis') while cps.enabled(chassis_key) == False: #wait for chassis object to be ready if srv_chk_cnt % srv_chk_rate == 0: nas_if.log_err('MAC address config: Base MAC address is not yet ready') time.sleep(1) srv_chk_cnt += 1 nas_if.log_info('Base MAC address service is ready after checking %d times' % srv_chk_cnt) srv_chk_cnt = 0 while cps.enabled(nas_comm.yang.get_value('physical_key', 'keys_id')) == False: if srv_chk_cnt % srv_chk_rate == 0: nas_if.log_info('MAC address config: Physical port service is not ready') time.sleep(1) srv_chk_cnt += 1 nas_if.log_info('Physical port service is ready after checking %d times' % srv_chk_cnt)
except: pass return True if not op == 'set': return False return True __event_handle = cps.event_connect() cps_handle = cps.obj_init() while True: if not cps.enabled(cps.key_from_name('target', 'base-acl/entry')): time.sleep(1) continue break #load ACL tables if not __validate_table(): print('Unable to create required ACL table for ACL model') sys.exit(1) print('INPUT - Table ID %d' % __table_in.extract_id()) print('OUTPUT - Table ID %d' % __table_out.extract_id()) __sync_file_to_db('acl-config.yaml') __resync()
signal.signal(signal.SIGTERM, sigterm_hdlr) # Notify systemd: Daemon is ready systemd.daemon.notify("READY=1") #if file exists means kernel snooping is not needed and some snooping #application might be running if mcast_os.path.isfile(snoop_cfg_file) is True: ev.logging("BASE_MCAST_SNOOP",ev.DEBUG,"MCAST_SVC","","",0,"Kernel IGMP/MLD snooping not needed") kernel_snooping_needed = False # Wait for interface service being ready interface_key = cps.key_from_name('target', 'dell-base-if-cmn/if/interfaces/interface') ev.logging("BASE_MCAST_SNOOP",ev.DEBUG,"MCAST_SVC","","",0,"Wait for interface object to be ready") while cps.enabled(interface_key) == False: time.sleep(1) ev.logging("BASE_MCAST_SNOOP",ev.DEBUG,"MCAST_SVC","","",0,"Interface object ready") # Few IP address attributes are in binaries, these ip address are treated as string type. _mcast_set_attr_type() handle = cps.obj_init() d = {} d['transaction'] = trans_cb #get is supported only for kernel snooping if kernel_snooping_needed is True: d['get'] = get_cb
def sigterm_hdlr(signum, frame): global shutdwn shutdwn = True if __name__ == '__main__': shutdwn = False # Install signal handlers. import signal signal.signal(signal.SIGTERM, sigterm_hdlr) # Wait for base MAC address to be ready. the script will wait until # chassis object is registered. chassis_key = cps.key_from_name('observed','base-pas/chassis') while cps.enabled(chassis_key) == False: #wait for chassis object to be ready nas_if.log_err('Create Interface: Base MAC address is not yet ready') time.sleep(1) fp_utils.init() while cps.enabled(nas_comm.get_value(nas_comm.keys_id, 'physical_key')) == False: nas_if.log_info('Create Interface: Physical port service is not ready') time.sleep(1) port_list = port_utils.get_phy_port_list() port_utils.phy_port_cache_init(port_list) handle = cps.obj_init()
if if_cache.exists(ifobj.get_attr_data('if/interfaces/interface/name')): nas_if.log_err( "Already exists.... " + str(ifobj.get_attr_data('if/interfaces/interface/name'))) return # create the object ch = {'operation': 'rpc', 'change': ifobj.get()} cps.transaction([ch]) nas_if.log_info("Interface Created : " + str(ifobj.get_attr_data('if/interfaces/interface/name'))) if __name__ == '__main__': while cps.enabled(nas_comm.yang.get_tbl('keys_id')['fp_key']) == False: nas_if.log_err('fetch front panel port info not ready ') time.sleep(1) #in seconds front_panel_ports = nas_if.FpPortCache() if front_panel_ports.len() == 0: nas_if.log_err('front panel port info not present') while cps.enabled( nas_comm.yang.get_tbl('keys_id')['physical_key']) == False: nas_if.log_err('physical port info not ready ') time.sleep(1) #in seconds port_cache = nas_if.PhyPortCache() if port_cache.len() == 0: nas_if.log_err('physical port info not present') if_cache = nas_if.IfCache()
return ' %s %d ' % (self.name, self.threadID) def sigterm_hdlr(signum, frame): global shutdwn shutdwn = True if __name__ == '__main__': shutdwn = False # Install signal handlers. import signal signal.signal(signal.SIGTERM, sigterm_hdlr) while cps.enabled(_media_key) == False or cps.enabled( _fp_port_key) == False: #wait for media and front panel port objects to be ready nas_if.log_err('Media or front panel port object is not yet ready') time.sleep(1) fp_utils.init() if_thread = interfaceMonitorThread(1, "Interface event Monitoring Thread") media_thread = mediaMonitorThread(2, "Media event Monitoring Thread") if_thread.daemon = True media_thread.daemon = True if_thread.start() media_thread.start() # Initialization complete
mac_addr = ma.if_get_mac_addr(**param_list) if mac_addr == None or len(mac_addr) == 0: nas_if.log_err('Failed to get mac address') return False cps_obj.add_attr(mac_attr_name, mac_addr) params['change'] = cps_obj.get() return True if __name__ == '__main__': # Wait for base MAC address to be ready. the script will wait until # chassis object is registered. chassis_key = cps.key_from_name('observed', 'base-pas/chassis') while cps.enabled(chassis_key) == False: #wait for chassis object to be ready nas_if.log_err('Create Interface: Base MAC address is not yet ready') time.sleep(1) fp.init('%s/etc/opx/base_port_physical_mapping_table.xml' % os.environ.get("OPX_INSTALL_PATH", "")) handle = cps.obj_init() d = {} d['get'] = get_cb d['transaction'] = set_cb cps.obj_register(handle, _fp_key, d) cps.obj_register(handle, _npu_lane_key, d) cps.obj_register(handle, _breakout_key, d)
def create_interface(obj): ifobj = nas_if.make_interface_from_phy_port(obj) if if_cache.exists(ifobj.get_attr_data('if/interfaces/interface/name')): nas_if.log_err("Already exists.... " + str(ifobj.get_attr_data('if/interfaces/interface/name'))) return # create the object ch = {'operation': 'rpc', 'change': ifobj.get()} cps.transaction([ch]) nas_if.log_info("Interface Created : " + str(ifobj.get_attr_data('if/interfaces/interface/name'))) if __name__ == '__main__': while cps.enabled(nas_comm.get_value(nas_comm.keys_id, "fp_key")) == False: nas_if.log_err('fetch front panel port info not ready ') time.sleep(1) #in seconds front_panel_ports = nas_if.FpPortCache() if front_panel_ports.len() == 0: nas_if.log_err('front panel port info not present') while cps.enabled(nas_comm.get_value(nas_comm.keys_id, "physical_key")) == False: nas_if.log_err('physical port info not ready ') time.sleep(1) #in seconds port_cache = nas_if.PhyPortCache() if port_cache.len() ==0: nas_if.log_err('physical port info not present') if_cache = nas_if.IfCache()