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 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 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 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