def obj_reg(): # IPSec Object Registration ipsec_handle = cps.obj_init() reg = {'get': ipsec_get_cb, 'transaction': ipsec_trans_cb} for i in _ipsec_keys.keys(): if i.find('eipsec') == -1: continue cps.obj_register(ipsec_handle, _ipsec_keys[i], reg)
def transaction_callback(methods, params): if params[ operation ] == set : #Set operation requested #Extract the attributes from the request object attr_1 = params[ change ][ data ][ attr_1 ] attr_n = params[ change ][ data ][ attr_n ] #Do something with them -- program hardware, #update the configuration, etc. return True if params[ operation ] == create : return True if params[ operation ] == delete : return True if params[ operation ] == action : return True return False #Obtain a handle to the CPS API service handle = cps.obj_init()
def transaction_callback(methods, params): if params[ operation ] == set : # Set operation requested # Extract the attributes from the request object attr_1 = params[ change ][ data ][ attr_1 ] attr_n = params[ change ][ data ][ attr_n ] # Do something with them -- program hardware, # update the configuration, etc. return True if params[ operation ] == create : return True if params[ operation ] == delete : return True if params[ operation ] == action : return True return False # Obtain a handle to the CPS API service handle = cps.obj_init()
def main(): '''Run the dhcp agent''' def get_cb(method, params): '''CPS get callback''' logging.debug("Get CB invoked with %s", "{}".format(params)) fobj = cps_object.CPSObject(obj=params['filter']) params['list'].extend(agent.get(fobj.get())) return True def trans_cb(method, params): '''CPS transaction callback''' logging.debug("Trans CB invoked with %s", "{}".format(params)) return agent.transaction(params['change']) agent = None cps_utils.add_attr_type('dhcp-agent/if/interfaces/interface/dhcp-server', 'ipv4') aparser = ArgumentParser(description=main.__doc__) aparser.add_argument( '--file', help='the file containing the dhcp agent config if used in mock mode', type=str) aparser.add_argument('--verbose', help='verbosity level', type=int) args = vars(aparser.parse_args()) if args.get('verbose') is not None: logging.getLogger().setLevel(logging.DEBUG) agent = Agent(mock=args.get("file")) dict_cb = {"get": get_cb, "transaction": trans_cb} # disable cps pylint warnings - they are spurious # pylint: disable=no-member handle = cps.obj_init() # pylint: disable=no-member cps.obj_register(handle, cps.key_from_name("target", DHCPPATH_P), dict_cb) agent.main_loop()
if _m_info.duplex != None: _data['duplex'] = nas_if.to_yang_duplex(_m_info.duplex) elem = cps_object.CPSObject(module='base-media/media-info', data=_data) resp.append(elem.get()) def get_cb(methods, params): _media_obj = cps_object.CPSObject(obj=params['filter']) resp = params['list'] if _media_obj.get_key() == _media_key: _gen_media_list(_media_obj, resp) else: return False return True if __name__ == '__main__': init('%s/etc/opx/phy_media_default_npu_setting.xml' % os.environ.get("OPX_INSTALL_PATH", "")) handle = cps.obj_init() d = {} d['get'] = get_cb cps.obj_register(handle, _media_key, d) while True: time.sleep(1)
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) srv_chk_cnt = 0 while cps.enabled(nas_comm.yang.get_value('fp_key', 'keys_id')) == False: if srv_chk_cnt % srv_chk_rate == 0: nas_if.log_info('MAC address config: Front panel port service is not ready') time.sleep(1) srv_chk_cnt += 1 nas_if.log_info('Front panel port service is ready after checking %d times' % srv_chk_cnt) # Register MAc address allocation handler get_mac_hdl = cps.obj_init() d = {} d['transaction'] = get_mac_cb cps.obj_register(get_mac_hdl, nas_comm.yang.get_value('get_mac_key', 'keys_id'), d) fp_cache = nas_if.FpPortCache() fp_thread = fpMonitorThread(1, 'Front panel port monitor thread') fp_thread.daemon = True fp_thread.start() # Lock to protect front panel port cache updated by thread fp_lock = threading.Lock() # Wait until a signal is received while False == shutdwn:
print "Attempting to delete address ", addr, name if dn_base_ip_tool.del_ip_addr(addr, name): return True print "Failed to execute request..." except Exception as e: print "Faild to commit operation.", e print params return False if __name__ == '__main__': if len(sys.argv) > 1: l = [] _get_ip_objs(cps_object.CPSObject('base-ip/ipv4'), l) for i in l: cps_utils.print_obj(i) sys.exit(1) handle = cps.obj_init() d = {} d['get'] = get_cb d['transaction'] = trans_cb for i in _keys.keys(): if i.find('base-ip') == -1: continue cps.obj_register(handle, _keys[i], d) while True: time.sleep(1)
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() # Register Front Panel POrt and HW port object handler fp_utils.nas_fp_cps_register(handle) # Register for Port Group handler pg_utils.nas_pg_cps_register(handle) # Register for Hybrid Group handler hg_utils.nas_hg_cps_register(handle) # Register Logical Interface handler d = {} d['transaction'] = set_intf_cb cps.obj_register(handle, nas_comm.get_value(nas_comm.keys_id, 'set_intf_key'), d)