def assignPorts(self, portList, forceTakePortOwnership=True, createVports=False, rawTraffic=False, configPortName=True, timeout=900): """ Description Assuming that you already connected to an ixia chassis and ports are available for usage. Use this API to assign physical ports to the virtual ports. Parameters portList: : A list of ports in a list: [ [ixChassisIp, '1','1'], [ixChassisIp, '1','2'] ] forceTakePortOwnership: : True = Forcefully take ownership of portList. createVports: : Optional: If True: Create vports to the amount of portList. If False: Automatically create vport on the server side. Optimized for port bootup performance. rawTraffic: : If traffic item is raw, then vport needs to be /vport/{id}/protocols resetPortCput: : Default=False. Some cards like the Novus 10GigLan requires a cpu reboot. timeout: : Timeout for port up state. Default=600 seconds. Syntaxes POST: /api/v1/sessions/{id}/ixnetwork/operations/assignports data={arg1: [{arg1: ixChassisIp, arg2: 1, arg3: 1}, {arg1: ixChassisIp, arg2: 1, arg3: 2}], arg2: [], arg3: ['/api/v1/sessions/{1}/ixnetwork/vport/1', '/api/v1/sessions/{1}/ixnetwork/vport/2'], arg4: true} <-- True will clear port ownership headers={'content-type': 'application/json'} GET: /api/v1/sessions/{id}/ixnetwork/operations/assignports/1 data={} headers={} Expecting: RESPONSE: SUCCESS """ # Verify if the portList has duplicates. self.verifyForDuplicatePorts(portList) # Verify if there is existing vports. If yes, user either loaded a saved config file or # the configuration already has vports. # If loading a saved config file and reassigning ports, assign ports to existing vports. response = self.ixnObj.get(self.ixnObj.sessionUrl+'/vport') # If response.json() != [], means there are existing vports created already. if response.json() != []: mode = 'modify' preamble = self.ixnObj.sessionUrl.split('/api')[1] vportList = ["/api%s/vport/%s" % (preamble, str(i["id"])) for i in response.json()] if len(vportList) != len(portList): raise IxNetRestApiException('assignPorts: The amount of configured virtual ports:{0} is not equal to the amount of portList:{1}'.format(len(vportList), len(portList))) else: if createVports == False: vportList = [] if createVports: self.createVports(portList) response = self.ixnObj.get(self.ixnObj.sessionUrl+'/vport') preamble = self.ixnObj.sessionUrl.split('/api')[1] vportList = ["/api%s/vport/%s" % (preamble, str(i["id"])) for i in response.json()] if len(vportList) != len(portList): raise IxNetRestApiException('assignPorts: The amount of configured virtual ports:{0} is not equal to the amount of portList:{1}'.format(len(vportList), len(portList))) #data = {"arg1": [], "arg2": [], "arg3": vportList, "arg4": 'true'} data = {"arg1": [], "arg2": [], "arg3": vportList, "arg4": forceTakePortOwnership} [data["arg1"].append({"arg1":str(chassis), "arg2":str(card), "arg3":str(port)}) for chassis,card,port in portList] url = self.ixnObj.sessionUrl+'/operations/assignports' response = self.ixnObj.post(url, data=data) response = self.ixnObj.waitForComplete(response, url + '/' + response.json()['id'], silentMode=False, timeout=timeout, ignoreException=True) # Ignore these verifications. Avoid trying to resolve too many issues. ''' if response.json()['state'] in ['ERROR', 'EXCEPTION']: # Some cards like the Novus 10gLan sometimes requires a cpu reboot. # To reboot the port cpu, the ports have to be assigned to a vport first. # So it has to be done at this spot. self.resetPortCpu(vportList=vportList, portList=portList) self.verifyPortState() raise IxNetRestApiException('assignPort Error: {}'.format(response.json()['message'])) elif response.json()['state'] == 'IN_PROGRESS': raise IxNetRestApiException('assignPort Error: Port failed to boot up after 120 seconds') else: response = self.ixnObj.get(self.ixnObj.sessionUrl+'/vport') for vport in response.json(): chassisIp = vport['assignedTo'].split(':')[0] slot = vport['assignedTo'].split(':')[1] port = vport['assignedTo'].split(':')[2] currentPort = [chassisIp, int(slot), int(port)] for chassis,card,port in portList: currentPortList = [chassis, int(card), int(port)] if set(currentPort) & set(currentPortList): if 'License Failed' in vport['connectionStatus']: raise IxNetRestApiException('Port License failed.') if vport['connectionStatus'] == 'connectedLinkDown': raise IxNetRestApiException('Port link connection is down: {0}'.format(vport['assignedTo'])) ''' # Verify if port license was the cause of the assignport failure if response.json()['state'] in ['ERROR', 'EXCEPTION']: vportResponse = self.ixnObj.get(self.ixnObj.sessionUrl+'/vport') for vport in vportResponse.json(): chassisIp = vport['assignedTo'].split(':')[0] slot = vport['assignedTo'].split(':')[1] port = vport['assignedTo'].split(':')[2] currentPort = [chassisIp, int(slot), int(port)] for chassis,card,port in portList: currentPortList = [chassis, int(card), int(port)] if set(currentPort) & set(currentPortList): if 'License Failed' in vport['connectionStatus']: raise IxNetRestApiException('Port License failed.') if vport['connectionStatus'] == 'connectedLinkDown': raise IxNetRestApiException('Port link connection is down: {0}'.format(vport['assignedTo'])) raise IxNetRestApiException('AssignPort failed: {}'.format(response.json())) if response.json()['state'] == 'IN_PROGRESS': raise IxNetRestApiException('AssignPort failed: It has been 10 minutes and the ports have not booted up successful. Something is wrong. Maybe you need to reboot the port CPU.') if configPortName: # Name the vports for vportObj in self.getAllVportList(): port = self.getPhysicalPortFromVport([vportObj])[0] chassisIp = port.split(':')[0] card = port.split(':')[1] port = port.split(':')[2] self.ixnObj.patch(self.ixnObj.httpHeader+vportObj, data={'name': 'Port'+card+'_'+port}) if rawTraffic: vportProtocolList = [] for vport in self.getAllVportList(): vportProtocolList.append(vport+'/protocols') return vportProtocolList else: return vportList