def loadConfigFile(self, configFile, localFile=True): """ Description Load a saved config file. Parameters configFile: (str): The full path including the saved config filename. If the config file is in a Windows filesystem, the format is c:\\path\\bgp.ixncfg If you are executing the script from Linux and the config file is in local Linux filesystem, the format is /path/bgp.ixncfg and localFile=True. localFile: (bool): For Windows API server and Connection Mgr running on a Windows server only. Set to False if the config file is in the Windows API server filesystem. """ if localFile == False: # The config file is located in Windows fileName = configFile.split('\\')[-1] copyFileUrl = self.ixnObj.sessionUrl+'/operations/copyfile' destinationPath = '{0}/ixnetwork/files/'.format(self.ixnObj.headlessSessionId) + fileName response = self.ixnObj.post(copyFileUrl,data={"arg1": configFile, "arg2": destinationPath}) self.ixnObj.waitForComplete(response, self.ixnObj.httpHeader+'/'+response.json()['url'], silentMode=False, timeout=30) if localFile == True: if os.path.exists(configFile) is False: raise IxNetRestApiException("Config file doesn't exists: %s" % configFile) if self.ixnObj.serverOs == 'linux': octetStreamHeader = {'content-type': 'application/octet-stream', 'x-api-key': self.ixnObj.apiKey} else: octetStreamHeader = {'content-type': 'application/octet-stream'} fileName = configFile.split('/')[-1] # Read the config file self.ixnObj.logInfo('\nReading saved config file') with open(configFile, mode='rb') as byteFile: configContents = byteFile.read() configContents = io.BytesIO(configContents) # Upload it to the server and give it any name you want for the filename uploadFile = self.ixnObj.sessionUrl+'/files?filename='+fileName self.ixnObj.logInfo('\nUploading file to server: %s' % uploadFile) # Note: # There is no status checking for this POST. This command is synchronous. The server won't return until it's done. # The response payload: {'absolute': None, 'files': [{'name': 'bgp_ngpf_8.30.ixncfg', 'length': 177791, 'modifiedUnixTime': 1572009307, # 'createdUnixTime': 1568302806}], 'directories': []} response = self.ixnObj.post(uploadFile, data=configContents, noDataJsonDumps=True, headers=octetStreamHeader, silentMode=False) loadConfigUrl = self.ixnObj.sessionUrl+'/operations/loadconfig' # Set the payload to load the given filename: /api/v1/sessions/{id}/ixnetwork/files/ospfNgpf_8.10.ixncfg payload = {'arg1': '{0}/ixnetwork/files/{1}'.format(self.ixnObj.headlessSessionId, fileName)} # Tell the server to load the config file if localFile == True: response = self.ixnObj.post(loadConfigUrl, data=payload) if localFile == False: response = self.ixnObj.post(loadConfigUrl, data=payload) self.ixnObj.waitForComplete(response, self.ixnObj.httpHeader+response.json()['url'], silentMode=False, timeout=140)