def getServer(self, id, detail=False): try: response_data = self.getResource("servers/" + id, "GET") except requests.exceptions.HTTPError as ex: raise SynergyError("error on retrieving the server info (id=%r)" ": %s" % (id, ex.response.json())) server = None if response_data: server_data = response_data["server"] server = Server() server.setId(server_data["id"]) server.setName(server_data["name"]) server.setKeyName(server_data["key_name"]) server.setMetadata(server_data["metadata"]) server.setUserData(server_data.get("OS-EXT-SRV-ATTR:user_data", None)) server.setType() server.setState(server_data["OS-EXT-STS:vm_state"]) server.setUserId(server_data["user_id"]) server.setProjectId(server_data["tenant_id"]) server.setCreatedAt(server_data["created"]) server.setUpdatedAt(server_data.get("updated", None)) server.setLaunchedAt( server_data.get("OS-SRV-USG:launched_at", None)) server.setTerminatedAt( server_data.get("OS-SRV-USG:terminated_at", None)) if detail: server.setFlavor(self.getFlavor(server_data["flavor"]["id"])) return server
def getServer(self, id, detail=False): try: response_data = self.getResource("servers/" + id, "GET") except requests.exceptions.HTTPError as ex: raise Exception("error on retrieving the server info (id=%r)" ": %s" % (id, ex.response.json())) server = None if response_data: server_data = response_data["server"] server = Server() server.setId(server_data["id"]) server.setName(server_data["name"]) server.setKeyName(server_data["key_name"]) server.setMetadata(server_data["metadata"]) server.setState(server_data["OS-EXT-STS:vm_state"]) server.setUserId(server_data["user_id"]) server.setProjectId(server_data["tenant_id"]) server.setCreatedAt(server_data["created"]) server.setUpdatedAt(server_data.get("updated", None)) server.setLaunchedAt( server_data.get("OS-SRV-USG:launched_at", None)) server.setTerminatedAt( server_data.get("OS-SRV-USG:terminated_at", None)) if "user_data" in server_data: user_data = server_data["user_data"] server.setUserData(utils.decodeBase64(user_data)) if detail: server.setFlavor(self.getFlavor(server_data["flavor"]["id"])) return server
def getServers(self, detail=False, status=None): params = {} if status: params["status"] = status url = "servers/detail" try: response_data = self.getResource(url, "GET", params) except requests.exceptions.HTTPError as ex: response = ex.response.json() raise Exception("error on retrieving the servers list" ": %s" % (id, response)) servers = [] if response_data: for server_data in response_data["servers"]: server = Server() server.setId(server_data["id"]) server.setName(server_data["name"]) server.setKeyName(server_data["key_name"]) server.setMetadata(server_data["metadata"]) server.setState(server_data["OS-EXT-STS:vm_state"]) server.setUserId(server_data["user_id"]) server.setProjectId(server_data["tenant_id"]) server.setCreatedAt(server_data["created"]) server.setUpdatedAt(server_data.get("updated", None)) server.setLaunchedAt( server_data.get("OS-SRV-USG:launched_at", None)) server.setTerminatedAt( server_data.get("OS-SRV-USG:terminated_at", None)) if "user_data" in server_data: user_data = server_data["user_data"] server.setUserData(utils.decodeBase64(user_data)) if detail: server.setFlavor( self.getFlavor(server_data["flavor"]["id"])) servers.append(server) return servers
def getServers(self, detail=False, status=None): params = {} if status: params["status"] = status url = "servers/detail" try: response_data = self.getResource(url, "GET", params) except requests.exceptions.HTTPError as ex: response = ex.response.json() raise SynergyError("error on retrieving the servers list" ": %s" % (id, response)) servers = [] if response_data: for server_data in response_data["servers"]: server = Server() server.setId(server_data["id"]) server.setName(server_data["name"]) server.setKeyName(server_data["key_name"]) server.setMetadata(server_data["metadata"]) server.setUserData(server_data.get("OS-EXT-SRV-ATTR:user_data", None)) server.setType() server.setState(server_data["OS-EXT-STS:vm_state"]) server.setUserId(server_data["user_id"]) server.setProjectId(server_data["tenant_id"]) server.setCreatedAt(server_data["created"]) server.setUpdatedAt(server_data.get("updated", None)) server.setLaunchedAt( server_data.get("OS-SRV-USG:launched_at", None)) server.setTerminatedAt( server_data.get("OS-SRV-USG:terminated_at", None)) if detail: server.setFlavor(self.getFlavor( server_data["flavor"]["id"])) servers.append(server) return servers