def arePortsAvailable(self, portList, raiseException=True): """ Description: Verify if any of the portList is owned. Parameter: : A list of ports in a list. portList: [ ['192.168.70.11', '1', '1'], ['192.168.70.11', '2', '1'] ] raiseException: : To continue or not to continue if there is an error. Return: - List of ports that are currently owned - 0: If portList are available """ # Verify if the portList has duplicates. self.verifyForDuplicatePorts(portList) self.ixnObj.logInfo('Verify if ports are currently owned') portOwnedList = [] for port in portList: chassisIp = port[0] cardId = port[1] portId = port[2] try: queryData = {"from": "/availableHardware", "nodes": [{"node": "chassis", "properties": ["ip"], "where": [{"property": "ip", "regex": chassisIp}]}, {"node": "card", "properties": ["cardId"], "where": [{"property": "cardId", "regex": cardId}]}, {"node": "port", "properties": ["portId", "owner"], "where": [{"property": "portId", "regex": portId}]}]} self.ixnObj.logInfo('Querying for %s/%s/%s' % (chassisIp, cardId, portId)) queryResponse = self.ixnObj.query(data=queryData, silentMode=False) queryResponse.json()['result'][0]['chassis'][0]['ip'] queryResponse.json()['result'][0]['chassis'][0]['card'][0]['id'] queryResponse.json()['result'][0]['chassis'][0]['card'][0]['port'][0]['portId'] except: raise IxNetRestApiException('\nNot found: {0}:{1}:{2}'.format(chassisIp, cardId, portId)) self.ixnObj.logInfo('Port currently owned by: %s' % queryResponse.json()['result'][0]['chassis'][0]['card'][0]['port'][0]['owner']) if queryResponse.json()['result'][0]['chassis'][0]['card'][0]['port'][0]['owner'] != '': self.ixnObj.logInfo('Port is still owned: {0}/cardId:{1}/portId:{2}'.format(chassisIp, cardId, portId)) portOwnedList.append([chassisIp, cardId, portId]) self.ixnObj.logInfo('Ports are still owned: %s' % portOwnedList) if portOwnedList != []: if raiseException: raise IxNetRestApiException('arePortsAvailable: Ports are still owned') else: return portOwnedList return 0