def getCapFile(self, port, typeOfCapture='data', saveToTempLocation='c:\\Temp', localLinuxLocation='.', appendToSavedCapturedFile=None): """ Get the latest captured .cap file from ReST API server to local Linux drive. Parameters port: Format:[IxiaIpAddress, slotNumber, cardNumber] Example: [ixChassisIp, '2', '1'] typeOfCapture: data|control saveToTempLocation: For Windows: Where to temporary save the .cap file on the ReST API server: Provide any path with double backslashes: C:\\Temp. The folder will be created if it doesn't exists. For Linux, value= 'linux'. localLinuxLocation: Where to save the .cap file on the local Linux machine. appendToSavedCapturedFile: Add a text string to the captured file. Example: captureObj.getCapFile([ixChassisIp, '2', '1'], 'control', 'c:\\Temp', '/home/hgee/test') Syntaxes: PATCH: /vport/2 DATA: {'rxMode': 'captureAndMeasure'} PATCH: /vport/2/capture DATA: {'softwareEnabled': False, 'hardwareEnabled': True} # Set traffic item to send continuous packets PATCH: /traffic/trafficItem/1/configElement//transmissionControl DATA: {'type': 'continuous'} POST: /traffic/trafficItem/operations/generate DATA: {"arg1": ["/api/v1/sessions//ixnetwork/traffic/trafficItem/1"]} POST: /traffic/operations/apply DATA: {"arg1": "/api/v1/sessions//ixnetwork/traffic"} POST: /traffic/operations/start DATA: {"arg1": "https://192.168.70.12/api/v1/sessions//ixnetwork/traffic"} Start continuous traffic POST: /ixnetwork/operations/startcapture POST: /ixnetwork/operations/stopcapture POST: /ixnetwork/operations/savecapturefiles DATA: {"arg1": "packetCaptureFolder"} <-- This could be any name. Just a temporary folder to store the captured file. Wait for the /operations/savecapturefiles/ to complete. May take up to a minute or more. For Windows API server: POST: /ixnetwork/operations/copyfile DATA: {"arg1": "c:\\Results\\port2_HW.cap", "arg2": "/api/v1/sessions/1/ixnetwork/files/port2_HW.cap"} GET: /ixnetwork/files?filename=port2_HW.cap For Linux API server: POST: /ixnetwork/operations/copyfile DATA: {"arg1": "captures/packetCaptureFolder/port2_HW.cap", "arg2": "/api/v1/sessions//ixnetwork/files/port2_HW.cap"} GET: /ixnetwork/files?filename=captures/packetCaptureFolder/port2_HW.cap """ # For Linux API server if '\\' not in saveToTempLocation: # For Linux API server, need to give a name for a temporary folder saveToTempLocation = 'packetCaptureFolder' # For Linux API server, must get the vport name and cannot modify the vport name. vport = self.portMgmtObj.getVports([port])[0] response = self.ixnObj.get(self.ixnObj.httpHeader + vport) vportName = response.json()['name'] vportName = vportName.replace('/', '_') vportName = vportName.replace(' ', '_') self.ixnObj.logInfo('vportName: {}'.format(vportName)) if appendToSavedCapturedFile != None: data = {'arg1': saveToTempLocation, 'arg2': appendToSavedCapturedFile} else: data = {'arg1': saveToTempLocation} response = self.ixnObj.post(self.ixnObj.sessionUrl+'/operations/savecapturefiles', data=data) self.ixnObj.waitForComplete(response, self.ixnObj.httpHeader+ response.json()['url'], timeout=300) capfilePathName = response.json()['result'][0] # example capfilePathName: 'c:\\Results\\1-7-2_HW.cap' if typeOfCapture == 'control': if '\\' not in saveToTempLocation: # For Linux capFileToGet = '/home/ixia_apps/web/platform/apps-resources/ixnetworkweb/configs/captures/{0}/{1}_SW.cap'.format( saveToTempLocation, vportName) else: # For Windows capFileToGet = capfilePathName if typeOfCapture == 'data': if '\\' not in saveToTempLocation: # For Linux capFileToGet = '/home/ixia_apps/web/platform/apps-resources/ixnetworkweb/configs/captures/{0}/{1}_HW.cap'.format( saveToTempLocation, vportName) else: capFileToGet = capfilePathName fileMgmtObj = FileMgmt(self.ixnObj) if self.ixnObj.serverOs in ['windows', 'windowsConnectionMgr']: fileMgmtObj.copyFileWindowsToLocalLinux(windowsPathAndFileName=capFileToGet, localPath=localLinuxLocation, renameDestinationFile=None) if self.ixnObj.serverOs == 'linux': # Parse out captures/packetCaptureFolder/_HW.cap match = re.search('.*(captures.*)', capFileToGet) pathExtension = match.group(1) fileMgmtObj.copyFileLinuxToLocalLinux(linuxApiServerPathAndFileName=capFileToGet, localPath=localLinuxLocation, renameDestinationFile=None, linuxApiServerPathExtension=pathExtension)