def configOspf(self, obj=None, routerId=None, port=None, portName=None, ngpfEndpointName=None, hostIp=None, **kwargs): """ Description Create or modify OSPF. If creating a new OSPF, provide an IPv4 object handle. If modifying a OSPF, there are five options. 2-6 will query for the OSPF object handle. 1> Provide the OSPF object handle using the obj parameter. 2> Set routerId. 3> Set port: The physical port. 4> Set portName: The vport port name. 5> Set NGPF OSPF name that you configured. 6> Set hostIp: The src IP. Parameters IPv4 object handle example: obj: /api/v1/sessions/1/ixnetwork/topology/1/deviceGroup/1/ethernet/1/ipv4/1 OSPF object handle example: obj: /api/v1/sessions/1/ixnetwork/topology/1/deviceGroup/1/ethernet/1/ipv4/1/ospfv2/1 routerId: : The router ID IP address. port: : Format: [ixChassisIp, str(cardNumber), str(portNumber)] portName: : The virtual port name. ngpfEndpointName: : The name that you configured for the NGPF endpoint. hostIp: : The source IP address to query for the object. kwargs: OSPF configuration attributes. The attributes could be obtained from the IxNetwork API browser. Syntax POST: /api/v1/sessions/{id}/ixnetwork/topology/{id}/deviceGroup/{id}/ethernet/{id}/ipv4/{id}/ospfv2 PATCH: /api/v1/sessions/{id}/ixnetwork/topology/{id}/deviceGroup/{id}/ethernet/{id}/ipv4/{id}/ospfv2/{id} Example: ospfObj1 = configOspf(ipv4Obj, name = 'ospf_1', areaId = '0', neighborIp = '1.1.1.2', helloInterval = '10', areaIdIp = '0.0.0.0', networkType = 'pointtomultipoint', deadInterval = '40') Return /api/v1/sessions/{id}/ixnetwork/topology/{id}/deviceGroup/{id}/ethernet/{id}/ipv4/{id}/ospfv2/{id} """ # To create new OSPF object if obj != None: if 'ospf' not in obj: ospfUrl = self.ixnObj.httpHeader+obj+'/ospfv2' self.ixnObj.logInfo('Create new OSPFv2 in NGPF') response = self.ixnObj.post(ospfUrl) # /api/v1/sessions/1/ixnetwork/topology/1/deviceGroup/1/ethernet/1/ipv4/1/ospfv2/1 ospfObj = response.json()['links'][0]['href'] # To modify OSPF if 'ospf' in obj: ospfObj = obj # To modify if ngpfEndpointName: ospfObj = self.getNgpfObjectHandleByName(ngpfEndpointName=ngpfEndpointName, ngpfEndpointObject='ospfv2') # To modify if port: x = self.getProtocolListByPortNgpf(port=port) ospfObj = self.getProtocolObjFromProtocolList(x['deviceGroup'], 'ospvv2')[0] # To modify if portName: x = self.getProtocolListByPortNgpf(portName=portName) ospfObj = self.getProtocolObjFromProtocolList(x['deviceGroup'], 'ospfv2')[0] # To modify if routerId: ospfObj = self.getNgpfObjectHandleByRouterId(routerId=routerId, ngpfEndpointObject='ospfv2') # To modify if hostIp: x = self.getProtocolListByHostIpNgpf(hostIp) ospfObj = self.getProtocolObjFromHostIp(x, protocol='ospfv2') ospfObjResponse = self.ixnObj.get(self.ixnObj.httpHeader+ospfObj) if 'name' in kwargs: self.ixnObj.patch(self.ixnObj.httpHeader+ospfObj, data={'name': kwargs['name']}) for key,value in ospfObjResponse.json().items(): if key != 'links': if bool(re.search('multivalue', str(value))) == True: if key in kwargs: multiValue = ospfObjResponse.json()[key] self.ixnObj.logInfo('Configuring OSPF multivalue attribute: %s' % key) self.ixnObj.patch(self.ixnObj.httpHeader+multiValue+"/singleValue", data={'value': kwargs[key]}) else: if key in kwargs: self.ixnObj.patch(self.ixnObj.httpHeader+ospfObj, data={key: kwargs[key]}) # Anish added ospfv2AttributeList = ['lsaRefreshTime','lsaRetransmitTime','interFloodLsUpdateBurstGap'] if (any(attribute in ospfv2AttributeList for attribute in kwargs)): ospfRouterUrl = self.ixnObj.httpHeader+ospfObj.split('ethernet')[0]+'ospfv2Router' ospfRouterObjResponse = self.ixnObj.get(ospfRouterUrl+'/'+str(self.ixnObj.get(ospfRouterUrl).json()[0]['id'])) for key, value in ospfRouterObjResponse.json().items(): if key != 'links': if bool(re.search('multivalue', str(value))) == True: if key in kwargs: multiValue = ospfRouterObjResponse.json()[key] self.ixnObj.logInfo('Configuring OSPF Router multivalue attribute: %s' % key) self.configMultivalue(multiValue, 'singleValue', data={'value': kwargs[key]}) else: if key in kwargs: self.ixnObj.patch(self.ixnObj.httpHeader + ospfRouterObjResponse, data={key: kwargs[key]}) # Anish added ospfv2TrafficEngAttributeList = ['metricLevel'] if (any(attribute in ospfv2TrafficEngAttributeList for attribute in kwargs)): ospfTrafficEngObj = ospfObj + '/ospfTrafficEngineering' ospfTrafficEngObjResponse = self.ixnObj.get(self.ixnObj.httpHeader+ospfTrafficEngObj) for key, value in ospfTrafficEngObjResponse.json().items(): if key != 'links': if bool(re.search('multivalue', str(value))) == True: if key in kwargs: multiValue = ospfTrafficEngObjResponse.json()[key] self.ixnObj.logInfo('Configuring OSPF Router multivalue attribute: %s' % key) self.configMultivalue(multiValue, 'singleValue', data={'value': kwargs[key]}) else: if key in kwargs: self.ixnObj.patch(self.ixnObj.httpHeader + ospfTrafficEngObjResponse, data={key: kwargs[key]}) self.configuredProtocols.append(ospfObj) return ospfObj