def retrievePortCaptureFileForAssignedPorts(self, destinationFolder): """ Retrieve the port captured files to the specified destinationFolder. Parameter: destinationFolder: The folder location on where to store the captured files """ communtiyListUrl = "%s/ixload/test/activeTest/communityList" % self.sessionIdUrl response = self.get(communtiyListUrl) communityList = response.json() destinationFolder = destinationFolder.replace("\\\\", "\\") for community in communityList: communityObjectId = community['objectID'] portListUrl = "%s/%s/network/portList" % (communtiyListUrl, communityObjectId) response = self.get(portListUrl) portList = response.json() for port in portList: portObjectId = port['objectID'] portId = port['id'] captureUrl = portListUrl + "/%s/restCaptureFile" % portObjectId capturePayload = self.get(captureUrl, downloadStream=True) captureName = "Capture_%s_%s.cap" % (communityObjectId, portId) captureFile = '/'.join([destinationFolder, captureName]) fileHandle = None self.logInfo('retrievePortCaptureFileForAssignedPorts: Saved as: {}'.format(captureFile)) try: with open(captureFile, 'wb') as fileHandle: for chunk in capturePayload.iter_content(chunk_size=1024): fileHandle.write(chunk) except IOError: self.logError("retrievePortCaptureFileForAssignedPorts: Could not open or create file, please check path and/or permissions") return 2 finally: if fileHandle: fileHandle.close()