import imp import json import ng_openstack.openstackRequest import ng_openstack.settings import os from ng_openstack.logger import log class Openstack_Keystone(): def __init__(self, requestor): self.serviceData={} self.catalogData={} self.projectData={} self.requestor=requestor def getAllProjects(_self): _self.projectData=_self.requestor.make_request("GET", "projects", "", os.getenv("OS_AUTH_URL")).json() return _self.projectData def getCatalog(_self): catalogData=_self.requestor.make_request("GET", "endpoints", "", os.getenv("OS_AUTH_URL")).json() serviceData=_self.requestor.make_request("GET", "services", "", os.getenv("OS_AUTH_URL")).json() # print(serviceData) _self.serviceData=serviceData _self.catalogData=catalogData return catalogData def getServicebyID(_self,id): # print(_self.serviceData) for _service in _self.serviceData['services']: if str(_service['id']).lower()==str(id).lower(): # print(_service) return(_service) def getServicebyName(_self,name): for _service in _self.serviceData['services']: if str(_service['name']).lower()==str(name).lower(): # print(_service) return(_service) def getEndpointByServiceIDAndInterface(_self,id,interface): for _endpoint in _self.catalogData['endpoints']: if str(_endpoint['service_id']).lower()==str(id).lower(): if str(_endpoint['interface']).lower()==str(interface).lower(): # print(_endpoint) return(_endpoint) def getEndpointByNameIDAndInterface(_self,name,interface): id=_self.getServicebyName(name)['id'] for _endpoint in _self.catalogData['endpoints']: if str(_endpoint['service_id']).lower()==str(id).lower(): if str(_endpoint['interface']).lower()==str(interface).lower(): # print(_endpoint) return(_endpoint) def createProject(_self,name,description): log.info("Creating a project") data={ "project": { "description": description, "enabled": True, "is_domain": False, "name": name } } _self.newProjectData=_self.requestor.make_request("POST", "projects", data, os.getenv("OS_AUTH_URL")).json() return _self.newProjectData