tessl install tessl/golang-cloud-google-com--go--compute@1.53.0Go client library for Google Cloud Compute Engine API providing programmatic access to manage virtual machines, disks, networks, and other compute resources
Storage clients manage VM images, disk snapshots, and storage pools for organizing and optimizing storage resources in Google Compute Engine.
The ImagesClient manages VM images that serve as templates for instance boot disks.
func NewImagesRESTClient(ctx context.Context, opts ...option.ClientOption) (*ImagesClient, error)Example:
import (
"context"
compute "cloud.google.com/go/compute/apiv1"
)
ctx := context.Background()
client, err := compute.NewImagesRESTClient(ctx)
if err != nil {
// handle error
}
defer client.Close()// Get retrieves a specific image
func (c *ImagesClient) Get(ctx context.Context, req *computepb.GetImageRequest, opts ...gax.CallOption) (*computepb.Image, error)
// GetFromFamily retrieves the latest image from an image family
func (c *ImagesClient) GetFromFamily(ctx context.Context, req *computepb.GetFromFamilyImageRequest, opts ...gax.CallOption) (*computepb.Image, error)
// List returns an iterator over images in a project
func (c *ImagesClient) List(ctx context.Context, req *computepb.ListImagesRequest, opts ...gax.CallOption) *ImageIterator
// Insert creates a new image
func (c *ImagesClient) Insert(ctx context.Context, req *computepb.InsertImageRequest, opts ...gax.CallOption) (*Operation, error)
// Patch partially updates an image
func (c *ImagesClient) Patch(ctx context.Context, req *computepb.PatchImageRequest, opts ...gax.CallOption) (*Operation, error)
// Delete deletes an image
func (c *ImagesClient) Delete(ctx context.Context, req *computepb.DeleteImageRequest, opts ...gax.CallOption) (*Operation, error)
// Deprecate marks an image as deprecated
func (c *ImagesClient) Deprecate(ctx context.Context, req *computepb.DeprecateImageRequest, opts ...gax.CallOption) (*Operation, error)Example - Get Image from Family:
import "cloud.google.com/go/compute/apiv1/computepb"
req := &computepb.GetFromFamilyImageRequest{
Project: "debian-cloud",
Family: "debian-11",
}
image, err := client.GetFromFamily(ctx, req)
if err != nil {
// handle error
}
fmt.Printf("Latest Debian 11 image: %s\n", *image.SelfLink)Example - Create Image from Disk:
import "google.golang.org/protobuf/proto"
insertReq := &computepb.InsertImageRequest{
Project: "my-project",
ImageResource: &computepb.Image{
Name: proto.String("my-custom-image"),
Family: proto.String("my-image-family"),
SourceDisk: proto.String("projects/my-project/zones/us-central1-a/disks/source-disk"),
Description: proto.String("Custom image created from disk"),
},
}
op, err := client.Insert(ctx, insertReq)
if err != nil {
// handle error
}
err = op.Wait(ctx)Example - Deprecate Image:
deprecateReq := &computepb.DeprecateImageRequest{
Project: "my-project",
Image: "old-image",
DeprecationStatusResource: &computepb.DeprecationStatus{
State: proto.String("DEPRECATED"),
Replacement: proto.String("projects/my-project/global/images/new-image"),
},
}
op, err := client.Deprecate(ctx, deprecateReq)// GetIamPolicy retrieves the IAM policy for an image
func (c *ImagesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyImageRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// SetIamPolicy sets the IAM policy for an image
func (c *ImagesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyImageRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// TestIamPermissions tests IAM permissions for an image
func (c *ImagesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsImageRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error)// SetLabels sets or updates resource labels on an image
func (c *ImagesClient) SetLabels(ctx context.Context, req *computepb.SetLabelsImageRequest, opts ...gax.CallOption) (*Operation, error)The SnapshotsClient manages disk snapshots for backup and disaster recovery.
func NewSnapshotsRESTClient(ctx context.Context, opts ...option.ClientOption) (*SnapshotsClient, error)// Get retrieves a specific snapshot
func (c *SnapshotsClient) Get(ctx context.Context, req *computepb.GetSnapshotRequest, opts ...gax.CallOption) (*computepb.Snapshot, error)
// List returns an iterator over snapshots
func (c *SnapshotsClient) List(ctx context.Context, req *computepb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator
// Insert creates a new snapshot (typically created via DisksClient.CreateSnapshot)
func (c *SnapshotsClient) Insert(ctx context.Context, req *computepb.InsertSnapshotRequest, opts ...gax.CallOption) (*Operation, error)
// Delete deletes a snapshot
func (c *SnapshotsClient) Delete(ctx context.Context, req *computepb.DeleteSnapshotRequest, opts ...gax.CallOption) (*Operation, error)Example - List Snapshots:
import "google.golang.org/api/iterator"
listReq := &computepb.ListSnapshotsRequest{
Project: "my-project",
}
it := client.List(ctx, listReq)
for {
snapshot, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// handle error
}
fmt.Printf("Snapshot: %s, Size: %d GB, Source: %s\n",
*snapshot.Name, *snapshot.DiskSizeGb, *snapshot.SourceDisk)
}Example - Delete Old Snapshot:
deleteReq := &computepb.DeleteSnapshotRequest{
Project: "my-project",
Snapshot: "old-snapshot",
}
op, err := client.Delete(ctx, deleteReq)
if err != nil {
// handle error
}
err = op.Wait(ctx)// GetIamPolicy retrieves the IAM policy for a snapshot
func (c *SnapshotsClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicySnapshotRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// SetIamPolicy sets the IAM policy for a snapshot
func (c *SnapshotsClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicySnapshotRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// TestIamPermissions tests IAM permissions for a snapshot
func (c *SnapshotsClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsSnapshotRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error)// SetLabels sets or updates resource labels on a snapshot
func (c *SnapshotsClient) SetLabels(ctx context.Context, req *computepb.SetLabelsSnapshotRequest, opts ...gax.CallOption) (*Operation, error)The InstantSnapshotsClient manages instant snapshots for rapid local backups.
func NewInstantSnapshotsRESTClient(ctx context.Context, opts ...option.ClientOption) (*InstantSnapshotsClient, error)// Get retrieves a specific instant snapshot
func (c *InstantSnapshotsClient) Get(ctx context.Context, req *computepb.GetInstantSnapshotRequest, opts ...gax.CallOption) (*computepb.InstantSnapshot, error)
// List returns an iterator over instant snapshots in a zone
func (c *InstantSnapshotsClient) List(ctx context.Context, req *computepb.ListInstantSnapshotsRequest, opts ...gax.CallOption) *InstantSnapshotIterator
// AggregatedList returns an iterator over instant snapshots across all zones
func (c *InstantSnapshotsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInstantSnapshotsRequest, opts ...gax.CallOption) *InstantSnapshotsScopedListPairIterator
// Insert creates a new instant snapshot
func (c *InstantSnapshotsClient) Insert(ctx context.Context, req *computepb.InsertInstantSnapshotRequest, opts ...gax.CallOption) (*Operation, error)
// Delete deletes an instant snapshot
func (c *InstantSnapshotsClient) Delete(ctx context.Context, req *computepb.DeleteInstantSnapshotRequest, opts ...gax.CallOption) (*Operation, error)// GetIamPolicy retrieves the IAM policy for an instant snapshot
func (c *InstantSnapshotsClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyInstantSnapshotRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// SetIamPolicy sets the IAM policy for an instant snapshot
func (c *InstantSnapshotsClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyInstantSnapshotRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// TestIamPermissions tests IAM permissions for an instant snapshot
func (c *InstantSnapshotsClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsInstantSnapshotRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error)// SetLabels sets or updates resource labels on an instant snapshot
func (c *InstantSnapshotsClient) SetLabels(ctx context.Context, req *computepb.SetLabelsInstantSnapshotRequest, opts ...gax.CallOption) (*Operation, error)The StoragePoolsClient manages storage pools for organizing and optimizing storage resources.
func NewStoragePoolsRESTClient(ctx context.Context, opts ...option.ClientOption) (*StoragePoolsClient, error)// Get retrieves a specific storage pool
func (c *StoragePoolsClient) Get(ctx context.Context, req *computepb.GetStoragePoolRequest, opts ...gax.CallOption) (*computepb.StoragePool, error)
// List returns an iterator over storage pools in a zone
func (c *StoragePoolsClient) List(ctx context.Context, req *computepb.ListStoragePoolsRequest, opts ...gax.CallOption) *StoragePoolIterator
// AggregatedList returns an iterator over storage pools across all zones
func (c *StoragePoolsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListStoragePoolsRequest, opts ...gax.CallOption) *StoragePoolsScopedListPairIterator
// Insert creates a new storage pool
func (c *StoragePoolsClient) Insert(ctx context.Context, req *computepb.InsertStoragePoolRequest, opts ...gax.CallOption) (*Operation, error)
// Update updates a storage pool
func (c *StoragePoolsClient) Update(ctx context.Context, req *computepb.UpdateStoragePoolRequest, opts ...gax.CallOption) (*Operation, error)
// Delete deletes a storage pool
func (c *StoragePoolsClient) Delete(ctx context.Context, req *computepb.DeleteStoragePoolRequest, opts ...gax.CallOption) (*Operation, error)// ListDisks lists disks in a storage pool
func (c *StoragePoolsClient) ListDisks(ctx context.Context, req *computepb.ListDisksStoragePoolsRequest, opts ...gax.CallOption) *StoragePoolListDisksIterator// GetIamPolicy retrieves the IAM policy for a storage pool
func (c *StoragePoolsClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyStoragePoolRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// SetIamPolicy sets the IAM policy for a storage pool
func (c *StoragePoolsClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyStoragePoolRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// TestIamPermissions tests IAM permissions for a storage pool
func (c *StoragePoolsClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsStoragePoolRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error)The SnapshotSettingsClient manages snapshot settings at the project level.
func NewSnapshotSettingsRESTClient(ctx context.Context, opts ...option.ClientOption) (*SnapshotSettingsClient, error)// Get retrieves snapshot settings for a project
func (c *SnapshotSettingsClient) Get(ctx context.Context, req *computepb.GetSnapshotSettingRequest, opts ...gax.CallOption) (*computepb.SnapshotSettings, error)
// Patch updates snapshot settings for a project
func (c *SnapshotSettingsClient) Patch(ctx context.Context, req *computepb.PatchSnapshotSettingRequest, opts ...gax.CallOption) (*Operation, error)The MachineImagesClient manages machine images that capture entire VM configurations including disks and metadata.
func NewMachineImagesRESTClient(ctx context.Context, opts ...option.ClientOption) (*MachineImagesClient, error)// Get retrieves a specific machine image
func (c *MachineImagesClient) Get(ctx context.Context, req *computepb.GetMachineImageRequest, opts ...gax.CallOption) (*computepb.MachineImage, error)
// List returns an iterator over machine images
func (c *MachineImagesClient) List(ctx context.Context, req *computepb.ListMachineImagesRequest, opts ...gax.CallOption) *MachineImageIterator
// Insert creates a new machine image
func (c *MachineImagesClient) Insert(ctx context.Context, req *computepb.InsertMachineImageRequest, opts ...gax.CallOption) (*Operation, error)
// Delete deletes a machine image
func (c *MachineImagesClient) Delete(ctx context.Context, req *computepb.DeleteMachineImageRequest, opts ...gax.CallOption) (*Operation, error)Example - Create Machine Image from Instance:
insertReq := &computepb.InsertMachineImageRequest{
Project: "my-project",
MachineImageResource: &computepb.MachineImage{
Name: proto.String("my-machine-image"),
SourceInstance: proto.String("projects/my-project/zones/us-central1-a/instances/my-instance"),
Description: proto.String("Backup of my-instance"),
},
}
op, err := client.Insert(ctx, insertReq)// GetIamPolicy retrieves the IAM policy for a machine image
func (c *MachineImagesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyMachineImageRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// SetIamPolicy sets the IAM policy for a machine image
func (c *MachineImagesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyMachineImageRequest, opts ...gax.CallOption) (*computepb.Policy, error)
// TestIamPermissions tests IAM permissions for a machine image
func (c *MachineImagesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsMachineImageRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error)The ImageFamilyViewsClient retrieves image family views showing the latest image in a family.
func NewImageFamilyViewsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ImageFamilyViewsClient, error)// Get retrieves the latest image from a family
func (c *ImageFamilyViewsClient) Get(ctx context.Context, req *computepb.GetImageFamilyViewRequest, opts ...gax.CallOption) (*computepb.ImageFamilyView, error)type Image struct {
ArchiveSizeBytes *int64
CreationTimestamp *string
Deprecated *DeprecationStatus
Description *string
DiskSizeGb *int64
Family *string
GuestOsFeatures []*GuestOsFeature
Id *uint64
ImageEncryptionKey *CustomerEncryptionKey
Kind *string
LabelFingerprint *string
Labels map[string]string
LicenseCodes []int64
Licenses []string
Name *string
RawDisk *RawDisk
SatisfiesPzi *bool
SatisfiesPzs *bool
SelfLink *string
ShieldedInstanceInitialState *InitialStateConfig
SourceDisk *string
SourceDiskEncryptionKey *CustomerEncryptionKey
SourceDiskId *string
SourceImage *string
SourceImageEncryptionKey *CustomerEncryptionKey
SourceImageId *string
SourceSnapshot *string
SourceSnapshotEncryptionKey *CustomerEncryptionKey
SourceSnapshotId *string
SourceType *string
Status *string
StorageLocations []string
}type Snapshot struct {
Architecture *string
AutoCreated *bool
ChainName *string
CreationSizeBytes *int64
CreationTimestamp *string
Description *string
DiskSizeGb *int64
DownloadBytes *int64
Id *uint64
Kind *string
LabelFingerprint *string
Labels map[string]string
LicenseCodes []int64
Licenses []string
LocationHint *string
Name *string
SatisfiesPzi *bool
SatisfiesPzs *bool
SelfLink *string
SnapshotEncryptionKey *CustomerEncryptionKey
SnapshotType *string
SourceDisk *string
SourceDiskEncryptionKey *CustomerEncryptionKey
SourceDiskForRecoveryCheckpoint *string
SourceDiskId *string
SourceInstantSnapshot *string
SourceInstantSnapshotEncryptionKey *CustomerEncryptionKey
SourceInstantSnapshotId *string
SourceSnapshotSchedulePolicy *string
SourceSnapshotSchedulePolicyId *string
Status *string
StorageBytes *int64
StorageBytesStatus *string
StorageLocations []string
}For regional storage resources:
See Regional Clients Documentation for details.