Example #1
0
    def getServer(self):
        server = None

        if self.instance:
            instance_data = self.instance["nova_object.data"]
            flavor_data = instance_data["flavor"]["nova_object.data"]

            flavor = Flavor()
            flavor.setId(flavor_data["flavorid"])
            flavor.setName(flavor_data["name"])
            flavor.setMemory(flavor_data["memory_mb"])
            flavor.setVCPUs(flavor_data["vcpus"])
            flavor.setStorage(flavor_data["root_gb"])

            server = Server()
            server.setFlavor(flavor)
            server.setId(instance_data["uuid"])
            server.setUserId(instance_data["user_id"])
            server.setProjectId(instance_data["project_id"])
            server.setCreatedAt(instance_data["created_at"])
            server.setMetadata(instance_data["metadata"])
            server.setKeyName(instance_data["key_name"])

            if "user_data" in instance_data:
                user_data = instance_data["user_data"]
                if user_data:
                    server.setUserData(utils.decodeBase64(user_data))

        return server
    def fromDict(cls, request_dict):
        request = Request()
        request.data = request_dict["data"]
        request.action = request_dict["action"]
        request.context = request_dict["context"]

        if "instances" in request.data:
            instance = request.data["instances"][0]
        else:
            build_request = request.data["build_requests"][0]
            instance = build_request["nova_object.data"]["instance"]

        instance_data = instance["nova_object.data"]

        request.id = instance_data["uuid"]
        request.user_id = instance_data["user_id"]
        request.project_id = instance_data["project_id"]

        created_at = instance_data["created_at"]
        request.created_at = datetime.strptime(created_at,
                                               "%Y-%m-%dT%H:%M:%SZ")

        flavor_data = instance_data["flavor"]["nova_object.data"]
        flavor = Flavor()
        flavor.setId(flavor_data["flavorid"])
        flavor.setName(flavor_data["name"])
        flavor.setMemory(flavor_data["memory_mb"])
        flavor.setVCPUs(flavor_data["vcpus"])
        flavor.setStorage(flavor_data["root_gb"])

        server = Server()
        server.setFlavor(flavor)
        server.setId(instance_data["uuid"])
        server.setUserId(instance_data["user_id"])
        server.setProjectId(instance_data["project_id"])
        server.setCreatedAt(instance_data["created_at"])
        server.setMetadata(instance_data["metadata"])
        server.setUserData(instance_data["user_data"])
        server.setKeyName(instance_data["key_name"])
        server.setType()

        request.server = server

        if "filter_properties" in request.data:
            filter_properties = request.data["filter_properties"]
            request.retry = filter_properties.get("retry", {})
        else:
            request_spec = request.data["request_specs"][0]
            nova_object = request_spec["nova_object.data"]
            request.retry = nova_object.get("retry", {})

        if not request.retry:
            request.retry = {}

        return request