Exemplo n.º 1
0
    def list(self, project, service_account_file=""):
        stub = image_pb2_grpc.ComputeImageServiceStub(channel.Channel())
        request = image_pb2.ListComputeImageRequest()
        request.service_account_file = service_account_file
        request.Project = project

        return stub.ListComputeImage(request).items
    def delete(self, project, name, service_account_file=""):
        stub = image_pb2_grpc.ComputeImageServiceStub(channel.Channel())
        request = image_pb2.DeleteComputeImageRequest()
        request.service_account_file = service_account_file
        request.Project = project

        request.Name = name

        response = stub.DeleteComputeImage(request)
Exemplo n.º 3
0
    def apply(self):
        stub = image_pb2_grpc.ComputeImageServiceStub(channel.Channel())
        request = image_pb2.ApplyComputeImageRequest()
        if Primitive.to_proto(self.description):
            request.resource.description = Primitive.to_proto(self.description)

        if Primitive.to_proto(self.disk_size_gb):
            request.resource.disk_size_gb = Primitive.to_proto(
                self.disk_size_gb)

        if Primitive.to_proto(self.family):
            request.resource.family = Primitive.to_proto(self.family)

        if ImageGuestOSFeatureArray.to_proto(self.guest_os_feature):
            request.resource.guest_os_feature.extend(
                ImageGuestOSFeatureArray.to_proto(self.guest_os_feature))
        if ImageImageEncryptionKey.to_proto(self.image_encryption_key):
            request.resource.image_encryption_key.CopyFrom(
                ImageImageEncryptionKey.to_proto(self.image_encryption_key))
        else:
            request.resource.ClearField("image_encryption_key")
        if Primitive.to_proto(self.labels):
            request.resource.labels = Primitive.to_proto(self.labels)

        if Primitive.to_proto(self.license):
            request.resource.license.extend(Primitive.to_proto(self.license))
        if Primitive.to_proto(self.name):
            request.resource.name = Primitive.to_proto(self.name)

        if ImageRawDisk.to_proto(self.raw_disk):
            request.resource.raw_disk.CopyFrom(
                ImageRawDisk.to_proto(self.raw_disk))
        else:
            request.resource.ClearField("raw_disk")
        if ImageShieldedInstanceInitialState.to_proto(
                self.shielded_instance_initial_state):
            request.resource.shielded_instance_initial_state.CopyFrom(
                ImageShieldedInstanceInitialState.to_proto(
                    self.shielded_instance_initial_state))
        else:
            request.resource.ClearField("shielded_instance_initial_state")
        if Primitive.to_proto(self.source_disk):
            request.resource.source_disk = Primitive.to_proto(self.source_disk)

        if ImageSourceDiskEncryptionKey.to_proto(
                self.source_disk_encryption_key):
            request.resource.source_disk_encryption_key.CopyFrom(
                ImageSourceDiskEncryptionKey.to_proto(
                    self.source_disk_encryption_key))
        else:
            request.resource.ClearField("source_disk_encryption_key")
        if Primitive.to_proto(self.source_image):
            request.resource.source_image = Primitive.to_proto(
                self.source_image)

        if ImageSourceImageEncryptionKey.to_proto(
                self.source_image_encryption_key):
            request.resource.source_image_encryption_key.CopyFrom(
                ImageSourceImageEncryptionKey.to_proto(
                    self.source_image_encryption_key))
        else:
            request.resource.ClearField("source_image_encryption_key")
        if Primitive.to_proto(self.source_image_id):
            request.resource.source_image_id = Primitive.to_proto(
                self.source_image_id)

        if Primitive.to_proto(self.source_snapshot):
            request.resource.source_snapshot = Primitive.to_proto(
                self.source_snapshot)

        if ImageSourceSnapshotEncryptionKey.to_proto(
                self.source_snapshot_encryption_key):
            request.resource.source_snapshot_encryption_key.CopyFrom(
                ImageSourceSnapshotEncryptionKey.to_proto(
                    self.source_snapshot_encryption_key))
        else:
            request.resource.ClearField("source_snapshot_encryption_key")
        if Primitive.to_proto(self.source_snapshot_id):
            request.resource.source_snapshot_id = Primitive.to_proto(
                self.source_snapshot_id)

        if ImageSourceTypeEnum.to_proto(self.source_type):
            request.resource.source_type = ImageSourceTypeEnum.to_proto(
                self.source_type)

        if Primitive.to_proto(self.storage_location):
            request.resource.storage_location.extend(
                Primitive.to_proto(self.storage_location))
        if ImageDeprecated.to_proto(self.deprecated):
            request.resource.deprecated.CopyFrom(
                ImageDeprecated.to_proto(self.deprecated))
        else:
            request.resource.ClearField("deprecated")
        if Primitive.to_proto(self.project):
            request.resource.project = Primitive.to_proto(self.project)

        request.service_account_file = self.service_account_file

        response = stub.ApplyComputeImage(request)
        self.archive_size_bytes = Primitive.from_proto(
            response.archive_size_bytes)
        self.description = Primitive.from_proto(response.description)
        self.disk_size_gb = Primitive.from_proto(response.disk_size_gb)
        self.family = Primitive.from_proto(response.family)
        self.guest_os_feature = ImageGuestOSFeatureArray.from_proto(
            response.guest_os_feature)
        self.image_encryption_key = ImageImageEncryptionKey.from_proto(
            response.image_encryption_key)
        self.labels = Primitive.from_proto(response.labels)
        self.license = Primitive.from_proto(response.license)
        self.name = Primitive.from_proto(response.name)
        self.raw_disk = ImageRawDisk.from_proto(response.raw_disk)
        self.shielded_instance_initial_state = ImageShieldedInstanceInitialState.from_proto(
            response.shielded_instance_initial_state)
        self.self_link = Primitive.from_proto(response.self_link)
        self.source_disk = Primitive.from_proto(response.source_disk)
        self.source_disk_encryption_key = ImageSourceDiskEncryptionKey.from_proto(
            response.source_disk_encryption_key)
        self.source_disk_id = Primitive.from_proto(response.source_disk_id)
        self.source_image = Primitive.from_proto(response.source_image)
        self.source_image_encryption_key = ImageSourceImageEncryptionKey.from_proto(
            response.source_image_encryption_key)
        self.source_image_id = Primitive.from_proto(response.source_image_id)
        self.source_snapshot = Primitive.from_proto(response.source_snapshot)
        self.source_snapshot_encryption_key = ImageSourceSnapshotEncryptionKey.from_proto(
            response.source_snapshot_encryption_key)
        self.source_snapshot_id = Primitive.from_proto(
            response.source_snapshot_id)
        self.source_type = ImageSourceTypeEnum.from_proto(response.source_type)
        self.status = ImageStatusEnum.from_proto(response.status)
        self.storage_location = Primitive.from_proto(response.storage_location)
        self.deprecated = ImageDeprecated.from_proto(response.deprecated)
        self.project = Primitive.from_proto(response.project)
    def hcl(self):
        stub = image_pb2_grpc.ComputeImageServiceStub(channel.Channel())
        request = image_pb2.ComputeImageAsHclRequest()
        if Primitive.to_proto(self.description):
            request.resource.description = Primitive.to_proto(self.description)

        if Primitive.to_proto(self.disk_size_gb):
            request.resource.disk_size_gb = Primitive.to_proto(
                self.disk_size_gb)

        if Primitive.to_proto(self.family):
            request.resource.family = Primitive.to_proto(self.family)

        if ImageGuestOsFeatureArray.to_proto(self.guest_os_feature):
            request.resource.guest_os_feature.extend(
                ImageGuestOsFeatureArray.to_proto(self.guest_os_feature))
        if ImageImageEncryptionKey.to_proto(self.image_encryption_key):
            request.resource.image_encryption_key.CopyFrom(
                ImageImageEncryptionKey.to_proto(self.image_encryption_key))
        else:
            request.resource.ClearField("image_encryption_key")
        if Primitive.to_proto(self.labels):
            request.resource.labels = Primitive.to_proto(self.labels)

        if Primitive.to_proto(self.license):
            request.resource.license.extend(Primitive.to_proto(self.license))
        if Primitive.to_proto(self.name):
            request.resource.name = Primitive.to_proto(self.name)

        if ImageRawDisk.to_proto(self.raw_disk):
            request.resource.raw_disk.CopyFrom(
                ImageRawDisk.to_proto(self.raw_disk))
        else:
            request.resource.ClearField("raw_disk")
        if ImageShieldedInstanceInitialState.to_proto(
                self.shielded_instance_initial_state):
            request.resource.shielded_instance_initial_state.CopyFrom(
                ImageShieldedInstanceInitialState.to_proto(
                    self.shielded_instance_initial_state))
        else:
            request.resource.ClearField("shielded_instance_initial_state")
        if Primitive.to_proto(self.source_disk):
            request.resource.source_disk = Primitive.to_proto(self.source_disk)

        if ImageSourceDiskEncryptionKey.to_proto(
                self.source_disk_encryption_key):
            request.resource.source_disk_encryption_key.CopyFrom(
                ImageSourceDiskEncryptionKey.to_proto(
                    self.source_disk_encryption_key))
        else:
            request.resource.ClearField("source_disk_encryption_key")
        if Primitive.to_proto(self.source_image):
            request.resource.source_image = Primitive.to_proto(
                self.source_image)

        if ImageSourceImageEncryptionKey.to_proto(
                self.source_image_encryption_key):
            request.resource.source_image_encryption_key.CopyFrom(
                ImageSourceImageEncryptionKey.to_proto(
                    self.source_image_encryption_key))
        else:
            request.resource.ClearField("source_image_encryption_key")
        if Primitive.to_proto(self.source_image_id):
            request.resource.source_image_id = Primitive.to_proto(
                self.source_image_id)

        if Primitive.to_proto(self.source_snapshot):
            request.resource.source_snapshot = Primitive.to_proto(
                self.source_snapshot)

        if ImageSourceSnapshotEncryptionKey.to_proto(
                self.source_snapshot_encryption_key):
            request.resource.source_snapshot_encryption_key.CopyFrom(
                ImageSourceSnapshotEncryptionKey.to_proto(
                    self.source_snapshot_encryption_key))
        else:
            request.resource.ClearField("source_snapshot_encryption_key")
        if Primitive.to_proto(self.source_snapshot_id):
            request.resource.source_snapshot_id = Primitive.to_proto(
                self.source_snapshot_id)

        if ImageSourceTypeEnum.to_proto(self.source_type):
            request.resource.source_type = ImageSourceTypeEnum.to_proto(
                self.source_type)

        if Primitive.to_proto(self.storage_location):
            request.resource.storage_location.extend(
                Primitive.to_proto(self.storage_location))
        if ImageDeprecated.to_proto(self.deprecated):
            request.resource.deprecated.CopyFrom(
                ImageDeprecated.to_proto(self.deprecated))
        else:
            request.resource.ClearField("deprecated")
        if Primitive.to_proto(self.project):
            request.resource.project = Primitive.to_proto(self.project)

        response = stub.ComputeImageAsHcl(request)
        return response.hcl