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
    def _makeServer(self, server_info):
        if not server_info:
            return

        flavor = Flavor()
        flavor.setMemory(server_info["memory_mb"])
        flavor.setVCPUs(server_info["vcpus"])
        flavor.setStorage(server_info["root_gb"])

        if "instance_type" in server_info:
            flavor.setName(server_info["instance_type"])

        server = Server()
        server.setFlavor(flavor)
        server.setUserId(server_info["user_id"])
        server.setMetadata(server_info["metadata"])
        server.setDeletedAt(server_info["deleted_at"])
        server.setTerminatedAt(server_info["terminated_at"])
        server.setType()

        if "host" in server_info:
            server.setHost(server_info["host"])

        if "uuid" in server_info:
            server.setId(server_info["uuid"])
        elif "instance_id" in server_info:
            server.setId(server_info["instance_id"])

        if "project_id" in server_info:
            server.setProjectId(server_info["project_id"])
        elif "tenant_id" in server_info:
            server.setProjectId(server_info["tenant_id"])

        if "vm_state" in server_info:
            server.setState(server_info["vm_state"])
        elif "state" in server_info:
            server.setState(server_info["state"])

        return server
    def _makeServer(self, server_info):
        if not server_info:
            return

        flavor = Flavor()
        flavor.setMemory(server_info["memory_mb"])
        flavor.setVCPUs(server_info["vcpus"])
        flavor.setStorage(server_info["root_gb"])

        if "instance_type" in server_info:
            flavor.setName(server_info["instance_type"])

        server = Server()
        server.setFlavor(flavor)
        server.setUserId(server_info["user_id"])
        server.setMetadata(server_info["metadata"])
        server.setDeletedAt(server_info["deleted_at"])
        server.setTerminatedAt(server_info["terminated_at"])
        server.setType()

        if "host" in server_info:
            server.setHost(server_info["host"])

        if "uuid" in server_info:
            server.setId(server_info["uuid"])
        elif "instance_id" in server_info:
            server.setId(server_info["instance_id"])

        if "project_id" in server_info:
            server.setProjectId(server_info["project_id"])
        elif "tenant_id" in server_info:
            server.setProjectId(server_info["tenant_id"])

        if "vm_state" in server_info:
            server.setState(server_info["vm_state"])
        elif "state" in server_info:
            server.setState(server_info["state"])

        return server