def connectToLinuxApiServer(self, linuxServerIp, linuxServerIpPort, username='admin', password='admin', verifySslCert=False, timeout=120): """ Description Connect to a Linux API server. Parameters linuxServerIp: (str): The Linux API server IP address. username: (str): Login username. Default = admin. password: (str): Login password. Default = admin. verifySslCert: (str): Default: None. The SSL Certificate for secure access verification. timeout: (int): Default:120. The timeout to wait for the Linux API server to start up. Problem: In case the linux api server is installed in a chassis and the DNS is misconfigured, it takes longer to start up. Syntax POST: /api/v1/auth/session """ self.verifySslCert = verifySslCert if self.apiKey is None: # 1: Connect to the Linux API server url = 'https://{0}:{1}/api/v1/auth/session'.format(linuxServerIp, linuxServerIpPort) self.logInfo('connectToLinuxApiServer: %s' % url) response = self.post(url, data={'username': username, 'password': password}, ignoreError=True) if not str(response.status_code).startswith('2'): raise IxNetRestApiException('\nLogin username/password failed\n') self.apiKey = response.json()['apiKey'] url = 'https://{0}:{1}/api/v1/sessions'.format(linuxServerIp, linuxServerIpPort) if self.webQuickTest == False: data = {'applicationType': 'ixnrest'} if self.webQuickTest == True: data = {'applicationType': 'ixnetwork'} self.jsonHeader = {'content-type': 'application/json', 'x-api-key': self.apiKey} self.logInfo('linuxServerCreateSession') response = self.post(url, data=data, headers=self.jsonHeader) self.sessionIdNumber = response.json()['id'] response = self.get(url+'/'+str(self.sessionIdNumber)) # https://192.168.70.108/ixnetworkweb/api/v1/sessions/7 self.sessionId = response.json()['links'][0]['href'] # Remove the redirect /ixnetworkweb from the URL. IxNetwork 8.50 will resolve this. self.sessionId = self.sessionId.replace('ixnetworkweb/', '') # https://10.10.10.1:443 matchHeader = re.match('(https://[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(:[0-9]+)?)', self.sessionId) self.httpHeader = matchHeader.group(1) if ':' not in self.httpHeader: self.httpHeader + '/' + linuxServerIpPort self.sessionUrl = self.sessionId+'/ixnetwork' # /api/v1/sessions/4/ixnetwork match = re.match('.*(/api.*)', self.sessionId) self.apiSessionId = match.group(1) + '/ixnetwork' # 3: Start the new session response = self.post(self.sessionId+'/operations/start') if self.linuxServerWaitForSuccess(response.json()['url'], timeout=timeout) == 1: raise IxNetRestApiException if self.webQuickTest == True: self.sessionId = 'https://{0}/ixnetworkweb/api/v1/sessions/{1}'.format(linuxServerIp, self.sessionIdNumber) self.sessionUrl = 'https://{0}/ixnetworkweb/api/v1/sessions/{1}/ixnetwork'.format(linuxServerIp, self.sessionIdNumber) self.httpHeader = self.sessionUrl.split('/api')[0] # If an API-Key is provided, then verify the session ID connection. if self.apiKey: self.get(self.sessionId)