def getServices(self): try: response = self.getResource("/services", "GET") except requests.exceptions.HTTPError as ex: response = ex.response.json() raise Exception("error on retrieving the services list: %s" % response["error"]["message"]) services = [] if response: services_info = response["services"] for info in services_info: service = Service() service.setId(info["id"]) service.setName(info["name"]) service.setType(info["type"]) service.setDescription(info["description"]) service.setEnabled(info["enabled"]) for endpoint_info in service.get("endpoints"): endpoint = Endpoint() endpoint.setId(endpoint_info["id"]) endpoint.setInterface(endpoint_info["interface"]) endpoint.setRegion(endpoint_info["region"]) endpoint.setRegionId(endpoint_info["region_id"]) endpoint.setURL(endpoint_info["url"]) service.getEndpoints().append(endpoint) services.append(service) return services
def getEndpoints(self): try: response = self.getResource("/endpoints", "GET") except requests.exceptions.HTTPError as ex: response = ex.response.json() raise Exception("error on retrieving the endpoints list: %s" % response["error"]["message"]) endpoints = [] if response: endpoints_info = response["endpoints"] for info in endpoints_info: endpoint = Endpoint() endpoint.setId(info["id"]) endpoint.setName(info["name"]) endpoint.setInterface(info["interface"]) endpoint.setRegion(info["region"]) endpoint.setRegionId(info["region_id"]) endpoint.setServiceId(info["service_id"]) endpoint.setURL(info["url"]) endpoint.setEnabled(info["enabled"]) endpoints.append(endpoint) return endpoints
def getService(self, id=None, name=None): if id: try: response = self.getResource("/services/%s" % id, "GET") except requests.exceptions.HTTPError as ex: response = ex.response.json() raise Exception("error on retrieving the service info (id=%r)" ": %s" % (id, response["error"]["message"])) if response: info = response["service"] service = Service() service.setId(info["id"]) service.setName(info["name"]) service.setType(info["type"]) service.setDescription(info["description"]) service.setEnabled(info["enabled"]) for endpoint_info in info.get("endpoints", []): endpoint = Endpoint() endpoint.setId(endpoint_info["id"]) endpoint.setInterface(endpoint_info["interface"]) endpoint.setRegion(endpoint_info["region"]) endpoint.setRegionId(endpoint_info["region_id"]) endpoint.setURL(endpoint_info["url"]) service.getEndpoints().append(endpoint) return service elif name: services = self.getServices() if services: for service in services: if service.getName() == name: return service return None
def getEndpoint(self, id=None, service_id=None): if id: try: response = self.getResource("/endpoints/%s" % id, "GET") except requests.exceptions.HTTPError as ex: response = ex.response.json() raise Exception( "error on retrieving the endpoint (id=%r): %s" % (id, response["error"]["message"])) if response: info = response["endpoint"] endpoint = Endpoint() endpoint.setId(info["id"]) endpoint.setName(info["name"]) endpoint.setInterface(info["interface"]) endpoint.setRegion(info["region"]) endpoint.setRegionId(info["region_id"]) endpoint.setServiceId(info["service_id"]) endpoint.setURL(info["url"]) endpoint.setEnabled(info["enabled"]) return endpoint elif service_id: try: endpoints = self.getEndpoints() except requests.exceptions.HTTPError as ex: response = ex.response.json() raise Exception( "error on retrieving the endpoints list (serviceId=%r)" % response["error"]["message"]) if endpoints: for endpoint in endpoints: if endpoint.getServiceId() == service_id: return endpoint return None
def getServices(self): try: response = self.getResource("/services", "GET") except requests.exceptions.HTTPError as ex: response = ex.response.json() raise SynergyError("error on retrieving the services list: %s" % response["error"]["message"]) services = [] if response: services_info = response["services"] for info in services_info: service = Service() service.setId(info["id"]) service.setName(info["name"]) service.setType(info["type"]) service.setDescription(info["description"]) service.setEnabled(info["enabled"]) for endpoint_info in service.get("endpoints"): endpoint = Endpoint() endpoint.setId(endpoint_info["id"]) endpoint.setInterface(endpoint_info["interface"]) endpoint.setRegion(endpoint_info["region"]) endpoint.setRegionId(endpoint_info["region_id"]) endpoint.setURL(endpoint_info["url"]) service.getEndpoints().append(endpoint) services.append(service) return services
def getService(self, id=None, name=None): if id: try: response = self.getResource("/services/%s" % id, "GET") except requests.exceptions.HTTPError as ex: response = ex.response.json() message = response["error"]["message"] raise SynergyError("error on retrieving the service info " "(id=%r): %s" % (id, message)) if response: info = response["service"] service = Service() service.setId(info["id"]) service.setName(info["name"]) service.setType(info["type"]) service.setDescription(info["description"]) service.setEnabled(info["enabled"]) for endpoint_info in info.get("endpoints", []): endpoint = Endpoint() endpoint.setId(endpoint_info["id"]) endpoint.setInterface(endpoint_info["interface"]) endpoint.setRegion(endpoint_info["region"]) endpoint.setRegionId(endpoint_info["region_id"]) endpoint.setURL(endpoint_info["url"]) service.getEndpoints().append(endpoint) return service elif name: services = self.getServices() if services: for service in services: if service.getName() == name: return service return None
def getEndpoints(self): try: response = self.getResource("/endpoints", "GET") except requests.exceptions.HTTPError as ex: response = ex.response.json() raise SynergyError("error on retrieving the endpoints list: %s" % response["error"]["message"]) endpoints = [] if response: endpoints_info = response["endpoints"] for info in endpoints_info: endpoint = Endpoint() endpoint.setId(info["id"]) endpoint.setName(info["name"]) endpoint.setInterface(info["interface"]) endpoint.setRegion(info["region"]) endpoint.setRegionId(info["region_id"]) endpoint.setServiceId(info["service_id"]) endpoint.setURL(info["url"]) endpoint.setEnabled(info["enabled"]) endpoints.append(endpoint) return endpoints
def getEndpoint(self, id=None, service_id=None): if id: try: response = self.getResource("/endpoints/%s" % id, "GET") except requests.exceptions.HTTPError as ex: response = ex.response.json() raise SynergyError("error on retrieving the endpoint (id=%r): " "%s" % (id, response["error"]["message"])) if response: info = response["endpoint"] endpoint = Endpoint() endpoint.setId(info["id"]) endpoint.setName(info["name"]) endpoint.setInterface(info["interface"]) endpoint.setRegion(info["region"]) endpoint.setRegionId(info["region_id"]) endpoint.setServiceId(info["service_id"]) endpoint.setURL(info["url"]) endpoint.setEnabled(info["enabled"]) return endpoint elif service_id: try: endpoints = self.getEndpoints() except requests.exceptions.HTTPError as ex: response = ex.response.json() message = response["error"]["message"] raise SynergyError("error on retrieving the endpoints list " "(id=%r): %s" % (service_id, message)) if endpoints: for endpoint in endpoints: if endpoint.getServiceId() == service_id: return endpoint return None