def initClient(self, token, tenant_id): # use the unscoped token from the Horizon session to get a # real admin token that we can use to access Keystone and Barbican self.token_id = None self.auth_try = 0 try: info = { 'auth': { 'tenantId': tenant_id, 'token': { 'id': token } } } resp, body = self.post('/v2.0/tokens', body=info) if body and 'access' in body: access = body['access'] if 'token' in access: newToken = access['token'] self.token_id = newToken['id'] self.tenant_id = tenant_id except Exception as ex: exceptions.handle(self.request, ('Unable to get Keystone token.'))
def getSSMCEndpointForHost(self, host): try: # first get service id header = {'X-Auth-Token': self.token_id} resp, body = self.get( '/v3/services?name=ssmc-' + host, headers=header) if body and 'services' in body: services = body['services'] service = services[0] if service and 'id' in service: service_id = service['id'] # now get endpoint for this service if service_id: resp, body = self.get('/v3/endpoints?service_id=' + service_id, headers=header) if body and 'endpoints' in body: endpoints = body['endpoints'] endpoint = endpoints[0] return endpoint['url'] return None except Exception as ex: exceptions.handle(self.request, ('Unable to get SSMC Endpoint for host.'))
def getSSMCEndpoints(self): endpoints = [] # get all 3par-link services self.auth_try = 1 header = {'X-Auth-Token': self.token_id} try: resp, body = self.get( '/v3/services?type=3par-link', headers=header) if body and 'services' in body: services = body['services'] # get endpoint for each service for service in services: if service and 'id' in service: id = service['id'] endpt, name = self.getSSMCEndpointForServiceId(id) if endpt: endpointData = {} endpointData['id'] = service['id'] backend = name[5:] # remove 'ssmc-' prefix endpointData['backend'] = backend endpointData['endpoint'] = endpt['url'] endpoints.append(endpointData) return endpoints except Exception as ex: exceptions.handle(self.request, ('Unable to get SSMC Endpoints.'))
def deleteSSMCEndpoint(self, service_id): header = {'X-Auth-Token': self.token_id} try: # first delete endpoint for the service endpt, service_name = self.getSSMCEndpointForServiceId(service_id) resp = self.delete('/v3/endpoints/' + endpt['id'], headers=header) # now delete the service resp = self.delete('/v3/services/' + service_id, headers=header) except Exception as ex: exceptions.handle(self.request, 'Unable to delete SSMC Endpoint.')
def unauthenticateSSMC(self): """ This clears the authenticated session with the 3PAR server. """ # delete the session on the 3Par try: self.delete( '/foundation/REST/sessionservice/sessions/%s' % self.session_key) self.session_key = None except Exception as ex: exceptions.handle(self.request, ('Unable to log-off SSMC.'))
def getHostCapabilities(self, token, tenant_id, host): try: capabilities = [] self.auth_try = 1 header = {'X-Auth-Token': token} resp, body = self.get('/v2/' + tenant_id + '/capabilities/' + host, headers=header) if body and 'properties' in body: properties = body['properties'] for capability, details in properties.iteritems(): new_capability = {} new_capability['name'] = details['title'] new_capability['description'] = details['description'] capabilities.append(new_capability) return capabilities except Exception as ex: exceptions.handle(self.request, ('Unable to get Host capabilities.'))
def updateSSMCEndpointUrl(self, service_id, url): # first need to get endpoint id endpt, service_name = self.getSSMCEndpointForServiceId(service_id) endpt_id = endpt['id'] header = {'X-Auth-Token': self.token_id} # update endpoint for service try: info = { 'endpoint': { 'interface': 'admin', 'region': 'RegionOne', 'url': url, 'service_id': service_id } } resp, body = self.patch( '/v3/endpoints/' + endpt_id, headers=header, body=info) except Exception as ex: exceptions.handle(self.request, ('Unable to update SSMC Endpoint URL.'))