def setInterfaceIpAddress(if_name, ip_addr, pfix_len): # Populate the attributes for the CPS Object # From the arguments if_index = cps_operations.getIfIndexFromName(if_name) ip_attributes = { "base-ip/ipv4/ifindex": if_index, "ip": ip_addr, "prefix-length": pfix_len } # Create CPS Object cps_utils.add_attr_type('base-ip/ipv4/address/ip', "ipv4") cps_obj = cps_utils.CPSObject('base-ip/ipv4/address', data=ip_attributes) # Create the CPS Transaction for object create cps_update = ('create', cps_obj.get()) transaction = cps_utils.CPSTransaction([cps_update]) # Verify return value ret = transaction.commit() if not ret: raise RuntimeError("Error changing interface ip address") Utils.cliLogger( "CPSOPErations: Changed interface ip address: " + ip_addr, 0)
def nas_lag_op(op, data_dict, commit=True): cps_utils.add_attr_type("base-lag/entry/mac-address", "mac") obj = cps_object.CPSObject(module=nas_lag_utils.get_lag_keys()[0], data=data_dict) obj.add_attr("if/interfaces/interface/type", "ianaift:ieee8023adLag") if commit: nas_ut.get_cb_method(op)(obj) else: return obj
def nas_lag_op(op, data_dict,commit=True): cps_utils.add_attr_type("base-lag/entry/mac-address", "mac") obj = cps_object.CPSObject( module=nas_lag_utils.get_lag_keys()[0], data=data_dict) obj.add_attr("if/interfaces/interface/type","ianaift:ieee8023adLag") if commit: nas_ut.get_cb_method(op)(obj) else: return obj
def __init__(self): BaseService.__init__(self) self.methods = { 'if_name_change': self.if_name_change, 'breakout': self.breakout, 'set-breakout-mode': self.set_breakout_mode, 'clear-counters': self.clear_counters, 'clear-eee-counters': self.clear_eee_counters, 'if_location_led': self.if_location_led, } for (key, parser) in MAP: cps_utils.add_attr_type(key, parser) self._rtx = Transaction()
def _setup_ut(self): cps_utils.add_attr_type('tunnel/tunnel-stats/tunnels/remote-ip/addr','ipv4') cps_utils.add_attr_type('tunnel/tunnel-stats/tunnels/local-ip/addr','ipv4') cps_utils.add_attr_type('tunnel/clear-tunnel-stats/input/remote-ip/addr','ipv4') cps_utils.add_attr_type('tunnel/clear-tunnel-stats/input/local-ip/addr','ipv4') _init_cmds = ["ip link add link e101-001-0 name e101-001-0.100 type vlan id 100", "brctl addbr br100", "ip link add vtep100 type vxlan id 100 local 10.1.1.1 dstport 4789", "brctl addif br100 vtep100", "brctl addif br100 e101-001-0.100"] for i in _init_cmds: self._run_cmds(i,True) time.sleep(0.5) self._run_cmds("bridge fdb add 00:00:00:00:00:00 dev vtep100 dst 10.1.1.2",True)
def __init__(self): BaseService.__init__(self) self.methods = { 'read': self.read, 'put': self.put, 'merge': self.merge, 'delete': self.delete, 'exists': self.exists, 'commit': self.commit, 'cancel': self.cancel, 'txid': self.txid, 'error': self.error } for (key, parser) in MAP: cps_utils.add_attr_type(key, parser) self._pathmap = PathMap() self._tx = {} self._rtx = Transaction() # set default handler self._pathmap.metadata({}, Handler()) for (fr_e, to_e) in REMAP: self._pathmap.metadata( fr_e, Handler(rewrite=True, strip_path=fr_e, add_path=to_e))
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()
def add_attr_type(): # Explicitly set attribute type as string for all SAD Authentication and Encryption attrs cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/ah/authentication-algorithm/hmac-sha1-96/hmac-sha1-96/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/ah/authentication-algorithm/hmac-md5-96/hmac-md5-96/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/ah/authentication-algorithm/hmac-aes-xcbc/hmac-aes-xcbc/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/esp/authentication/authentication-algorithm/hmac-sha1-96/hmac-sha1-96/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/esp/authentication/authentication-algorithm/hmac-md5-96/hmac-md5-96/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/esp/authentication/authentication-algorithm/hmac-aes-xcbc/hmac-aes-xcbc/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/esp/encryption/encryption-algorithm/des-cbc/des-cbc/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/esp/encryption/encryption-algorithm/des3-cbc/des3-cbd/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/esp/encryption/encryption-algorithm/aes-128-cbc/aes-128-cbc/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/esp/encryption/encryption-algorithm/aes-192-cbc/aes-192-cbc/key-str", "string") cps_utils.add_attr_type("eipsec/ipsec/sad/sad-entries/esp/encryption/encryption-algorithm/aes-256-cbc/aes-256-cbc/key-str", "string") cps_utils.add_attr_type("spd/eipsec/ipsec/spd/spd-entries/source-ip-address", "string") cps_utils.add_attr_type("spd/eipsec/ipsec/spd/spd-entries/destination-ip-address", "string") cps_utils.add_attr_type("ipsec-sad/eipsec/ipsec/sad/sad-entries/source-ip-address", "string") cps_utils.add_attr_type("ipsec-sad/eipsec/ipsec/sad/sad-entries/destination-ip-address", "string") return True
def get_if_key(): return nas_os_if_keys['interface'] def get_if_state_key(): return nas_os_if_keys['interface-state'] def get_physical_key(): return nas_os_if_keys['physical'] def get_fp_key(): return nas_os_if_keys['front-panel-port'] def get_hw_key(): return nas_os_if_keys['hardware-port'] cps_utils.add_attr_type('base-if-phy/front-panel-port/default-name', 'string') cps_utils.add_attr_type('if/interfaces/interface/name', 'string') cps_utils.add_attr_type('dell-if/if/interfaces/interface/phys-address', 'string') def set_obj_val(obj, key, val): obj.add_attr(key, val) def make_if_obj(d={}): return cps_object.CPSObject(module=get_if_key(), data=d) def make_if_state_obj(d={}): return cps_object.CPSObject(module=get_if_state_key(),qual='observed', data=d)
# FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. # # See the Apache Version 2.0 License for specific language governing # permissions and limitations under the License. import cps import cps_utils import nas_os_if_utils as nas_if import nas_front_panel_map as fp import cps_object import event_log as ev import time import bytearray_utils as ba cps_utils.add_attr_type('base-pas/media/port', 'uint8_t') cps_utils.add_attr_type('base-pas/media/slot', 'uint8_t') cps_utils.add_attr_type('base-pas/media/present', 'uint8_t') cps_utils.add_attr_type('base-pas/media/type', 'uint32_t') def get_all_media_info(): obj = cps_object.CPSObject(module='base-pas/media', qual='observed') media_list = [] cps.get([obj.get()], media_list) return media_list def get_media_info(media_id): obj = cps_object.CPSObject(module='base-pas/media', qual='observed',
import cps_utils cps_utils.add_attr_type("base-mac/table/mac-address", "mac") d = {"mac-address": "00:0a:0b:cc:0d:0e", "ifindex": 18, "vlan": "100"} obj = cps_utils.CPSObject('base-mac/table',data=d) tr_obj = ('delete', obj.get()) transaction = cps_utils.CPSTransaction([tr_obj]) ret = transaction.commit() if not ret: raise RuntimeError("Error deleting entry from MAC Table")
# Python code block to set IP address import cps_utils # Populate the attributes for the CPS object ifindex = 16 ip_addr = "10.0.0.1" pfix_len = 16 ip_attributes = { "base-ip/ipv4/ifindex": ifindex, "ip": ip_addr, "prefix-length": pfix_len } # Create CPS object cps_utils.add_attr_type('base-ip/ipv4/address/ip', "ipv4") cps_obj = cps_utils.CPSObject('base-ip/ipv4/address', data=ip_attributes) # Create the CPS transaction for object create cps_update = ('create', cps_obj.get()) transaction = cps_utils.CPSTransaction([cps_update]) # Check for failure ret = transaction.commit() if not ret: raise RuntimeError("Error ")
#Python code block to set IP address import cps_utils #Populate attributes for the CPS object ifindex = 16 ip_addr = '10.0.0.1' pfix_len = 16 ip_attributes = { 'base-ip/ipv4/ifindex': ifindex, 'ip': ip_addr, 'prefix-length': pfix_len } #Create CPS object cps_utils.add_attr_type('base-ip/ipv4/address/ip', 'ipv4') cps_obj = cps_utils.CPSObject('base-ip/ipv4/address', data=ip_attributes) #Create CPS transaction for object create cps_update = ('create', cps_obj.get()) transaction = cps_utils.CPSTransaction([cps_update]) #Commit transaction ret = transaction.commit() #Check for failure if not ret: raise RuntimeError('Error ') print 'Successfully created'
#Python code block to configure MAC address table entry import cps_utils #Register the attribute type cps_utils.add_attr_type('base-mac/table/mac-address', 'mac') #Define the MAC address, interface index and VLAN attributes d = {'mac-address': '00:0a:0b:cc:0d:0e', 'ifindex': 18, 'vlan': '100'} #Create a CPS object obj = cps_utils.CPSObject('base-mac/table', data=d) #Associate the operation to the CPS object tr_obj = ('create', obj.get()) #Create a transaction object transaction = cps_utils.CPSTransaction([tr_obj]) #Check for failure ret = transaction.commit() if not ret: raise RuntimeError('Error creating MAC Table Entry') print 'Successfully created'
import cps_utils import cps cps_utils.add_attr_type("base-mac/query/mac-address", "mac") d = {"mac-address": "00:0a:0b:cc:0d:0e","request-type":"2"} obj = cps_utils.CPSObject('base-mac/query', data= d) filter_list = [] filter_list.append(obj.get()) l = [] if cps.get(filter_list,l): if l: for ret_obj in l: cps_utils.print_obj(ret_obj) else: print "No objects found" else: print "No objects found" raise RuntimeError ("Error Getting MAC Table Entries")
#Python code block to request MAC address table entry import cps_utils import cps #Register the attribute type cps_utils.add_attr_type("base-mac/query/mac-address", "mac") #Define the MAC address request type d = {"mac-address": "00:0a:0b:cc:0d:0e","request-type":"2"} #Associate the get operation with the CPS object obj = cps_utils.CPSObject('base-mac/query', data= d) #Create an object filter list filter_list = [] filter_list.append(obj.get()) l = [] #Check for failure if cps.get(filter_list,l): if l: for ret_obj in l: cps_utils.print_obj(ret_obj) else: print "No objects found" else: print "No objects found" raise RuntimeError ("Error Getting MAC Table Entries")
def _mcast_set_attr_type(): cps_utils.add_attr_type("igmp-mld-snooping/rt/routing/control-plane-protocols/igmp-snooping/vlans/vlan/static-l2-multicast-group/source-addr", "string") cps_utils.add_attr_type("igmp-mld-snooping/rt/routing/control-plane-protocols/mld-snooping/vlans/vlan/static-l2-multicast-group/source-addr", "string")
# # THIS CODE IS PROVIDED ON AN #AS IS* BASIS, WITHOUT WARRANTIES OR # CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT # LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS # FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. # # See the Apache Version 2.0 License for specific language governing # permissions and limitations under the License. # import cps_utils # Populate the attributes for the CPS Object ifindex=16 ip_addr="10.0.0.1" pfix_len=16 ip_attributes = {"base-ip/ipv4/ifindex": ifindex,"ip":ip_addr,"prefix-length":pfix_len} # Create CPS Object cps_utils.add_attr_type('base-ip/ipv4/address/ip',"ipv4") cps_obj=cps_utils.CPSObject('base-ip/ipv4/address',data=ip_attributes) # Create the CPS Transaction for object create cps_update = ('create', cps_obj.get()) transaction = cps_utils.CPSTransaction([cps_update]) # Commit the transaction ret = transaction.commit() # Check for failure if not ret: raise RuntimeError ("Error ")
import cps_utils cps_utils.add_attr_type("base-mac/table/mac-address", "mac") d = {"mac-address": "00:0a:0b:cc:0d:0e", "ifindex": 18, "vlan": "100"} obj = cps_utils.CPSObject('base-mac/table', data=d) tr_obj = ('delete', obj.get()) transaction = cps_utils.CPSTransaction([tr_obj]) ret = transaction.commit() if not ret: raise RuntimeError("Error deleting entry from MAC Table")