gce

package
v0.0.0-...-bfad91c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package gce is a lightweight testable wrapper around GCE compute APIs needed for the gcagent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GCE

type GCE struct {
	// contains filtered or unexported fields
}

GCE is a wrapper for Google Compute Engine services.

func NewGCEClient

func NewGCEClient(ctx context.Context) (*GCE, error)

NewGCEClient creates a new GCE service wrapper.

func (*GCE) AddResourcePolicies

func (g *GCE) AddResourcePolicies(ctx context.Context, project, zone, diskName string, resourcePolicies []string) (*compute.Operation, error)

AddResourcePolicies adds the given resource policies of a disk.

func (*GCE) AttachDisk

func (g *GCE) AttachDisk(ctx context.Context, diskName string, instanceName, project, dataDiskZone string) error

AttachDisk attaches the disk with the given name to the instance.

func (*GCE) CreateSnapshot

func (g *GCE) CreateSnapshot(ctx context.Context, project string, snapshotReq *compute.Snapshot) (*compute.Operation, error)

CreateSnapshot creates a new standard snapshot.

func (*GCE) DetachDisk

func (g *GCE) DetachDisk(ctx context.Context, instanceName, project, dataDiskZone, dataDiskName, dataDiskDeviceName string) error

DetachDisk detaches given disk from the instance.

func (*GCE) DiskAttachedToInstance

func (g *GCE) DiskAttachedToInstance(project, zone, instanceName, diskName string) (string, bool, error)

DiskAttachedToInstance returns the device name of the disk attached to the instance.

func (*GCE) GetAddress

func (g *GCE) GetAddress(project, location, name string) (*compute.Address, error)

GetAddress retrieves a GCE Address defined by the project, location, and name provided.

func (*GCE) GetAddressByIP

func (g *GCE) GetAddressByIP(project, region, subnetwork, ip string) (*compute.Address, error)

GetAddressByIP attempts to find a ComputeAddress object with a given IP. The string is assumed to be an exact match, so a full IPv4 address is expected. A region should be supplied, or "" to search for a global address.

func (*GCE) GetDisk

func (g *GCE) GetDisk(project, zone, disk string) (*compute.Disk, error)

GetDisk retrieves a GCE Persistent Disk defined by the project zone and name provided.

func (*GCE) GetFilestore

func (g *GCE) GetFilestore(project, zone, name string) (*file.Instance, error)

GetFilestore attempts to retrieve the filestore instance addressed by the provided project, location, and name.

func (*GCE) GetFilestoreByIP

func (g *GCE) GetFilestoreByIP(project, location, ip string) (*file.ListInstancesResponse, error)

GetFilestoreByIP attempts to locate a GCE Filestore instance defined by the project, location, and IP Address provided.

func (*GCE) GetFilestoreInstance

func (g *GCE) GetFilestoreInstance(project, location, filestore string) (*file.Instance, error)

GetFilestoreInstance retrieves a GCE Filestore Instance defined by the project, location, and name provided.

func (*GCE) GetForwardingRule

func (g *GCE) GetForwardingRule(project, location, name string) (*compute.ForwardingRule, error)

GetForwardingRule retrieves a GCE Forwarding rule defined by the project, zone, and name provided.

func (*GCE) GetForwardingRuleByIP

func (g *GCE) GetForwardingRuleByIP(project, ip string) (*compute.ForwardingRule, error)

GetForwardingRuleByIP retrieves a GCE Forwarding rule defined by the project, and IP address provided.

func (*GCE) GetHealthCheck

func (g *GCE) GetHealthCheck(project, name string) (*compute.HealthCheck, error)

GetHealthCheck attempts to retrieve the compute HealthCheck object addressed by the provided project and name.

func (*GCE) GetInstance

func (g *GCE) GetInstance(project, zone, instance string) (*compute.Instance, error)

GetInstance retrieves a GCE Instance defined by the project, zone, and name provided.

func (*GCE) GetInstanceByIP

func (g *GCE) GetInstanceByIP(project, ip string) (*compute.Instance, error)

GetInstanceByIP retrieves a GCE Instance defined by the project, and IP provided. May return nil if an instance with the corresponding IP cannot be found.

func (*GCE) GetInstanceGroup

func (g *GCE) GetInstanceGroup(project, zone, name string) (*compute.InstanceGroup, error)

GetInstanceGroup retrieves a GCE Instance Group rule defined by the project, zone, and name provided.

func (*GCE) GetNetwork

func (g *GCE) GetNetwork(name, project string) (*compute.Network, error)

GetNetwork retrieves the network with the given name and project.

func (*GCE) GetRegionalBackendService

func (g *GCE) GetRegionalBackendService(project, region, service string) (*compute.BackendService, error)

GetRegionalBackendService retrieves a GCE Backend Service defined by the project, region, and name provided.

func (*GCE) GetSecret

func (g *GCE) GetSecret(ctx context.Context, projectID, secretName string) (string, error)

GetSecret accesses the secret manager for the specified project ID and returns the stored password.

func (*GCE) GetSubnetwork

func (g *GCE) GetSubnetwork(name, project, region string) (*compute.Subnetwork, error)

GetSubnetwork retrieves the subnetwork with the given name, project, and region.

func (*GCE) GetURIForIP

func (g *GCE) GetURIForIP(project, ip, region, subnetwork string) (string, error)

GetURIForIP attempts to locate the URI for any object that is related to the IP address provided.

func (*GCE) ListDisks

func (g *GCE) ListDisks(project, zone, filter string) (*compute.DiskList, error)

ListDisks retrieves GCE Persistent Disks defined by the project, sone, and filter provided.

func (*GCE) ListInstanceGroupInstances

func (g *GCE) ListInstanceGroupInstances(project, zone, name string) (*compute.InstanceGroupsListInstances, error)

ListInstanceGroupInstances retrieves a list of GCE Instances in the Instance group defined by the project, zone, and name provided.

func (*GCE) ListSnapshots

func (g *GCE) ListSnapshots(ctx context.Context, project string) (*compute.SnapshotList, error)

ListSnapshots lists the snapshots for a given project.

func (*GCE) ListZoneOperations

func (g *GCE) ListZoneOperations(project, zone, filter string, maxResults int64) (*compute.OperationList, error)

ListZoneOperations retrieves a list of Operations resources defined by the project, and zone provided. Results will be filtered according to the provided filter string, and limit the number of results to maxResults.

func (*GCE) OverrideComputeBasePath

func (g *GCE) OverrideComputeBasePath(basePath string)

OverrideComputeBasePath overrides the base path of the GCE clients.

func (*GCE) RemoveResourcePolicies

func (g *GCE) RemoveResourcePolicies(ctx context.Context, project, zone, diskName string, resourcePolicies []string) (*compute.Operation, error)

RemoveResourcePolicies removes the given resource policies of a disk.

func (*GCE) SetLabels

func (g *GCE) SetLabels(ctx context.Context, project, zone, diskName, labelFingerprint string, labels map[string]string) (*compute.Operation, error)

SetLabels sets the labels for a given disk.

func (*GCE) WaitForDiskOpCompletionWithRetry

func (g *GCE) WaitForDiskOpCompletionWithRetry(ctx context.Context, op *compute.Operation, project, dataDiskZone string) error

WaitForDiskOpCompletionWithRetry waits for the given compute operation to complete. We sleep for 120s between retries a total 10 times => max_wait_duration = 10*120 = 20 Minutes

func (*GCE) WaitForInstantSnapshotConversionCompletionWithRetry

func (g *GCE) WaitForInstantSnapshotConversionCompletionWithRetry(ctx context.Context, op *compute.Operation, project, diskZone, snapshotName string) error

WaitForInstantSnapshotConversionCompletionWithRetry waits for the given compute operation to complete. We sleep for 30s between retries a total 480 times => max_wait_duration = 30*480 = 4 Hours

func (*GCE) WaitForSnapshotCreationCompletionWithRetry

func (g *GCE) WaitForSnapshotCreationCompletionWithRetry(ctx context.Context, op *compute.Operation, project, diskZone, snapshotName string) error

WaitForSnapshotCreationCompletionWithRetry waits for the given compute operation to complete. We sleep for 1s between retries a total 300 times => max_wait_duration = 5 minutes

func (*GCE) WaitForSnapshotUploadCompletionWithRetry

func (g *GCE) WaitForSnapshotUploadCompletionWithRetry(ctx context.Context, op *compute.Operation, project, diskZone, snapshotName string) error

WaitForSnapshotUploadCompletionWithRetry waits for the given compute operation to complete. We sleep for 30s between retries a total 480 times => max_wait_duration = 30*480 = 4 Hours

Directories

Path Synopsis
Package fake provides a fake version of the GCE struct to return canned responses in unit tests.
Package fake provides a fake version of the GCE struct to return canned responses in unit tests.
Package fakehttp provides a HTTP server to serve hard-coded responses for unit tests.
Package fakehttp provides a HTTP server to serve hard-coded responses for unit tests.
Package metadataserver performs requests to the metadata server of a GCE instance.
Package metadataserver performs requests to the metadata server of a GCE instance.
Package wlm provides a simple service interface for using the Data Warehouse WriteInsight API.
Package wlm provides a simple service interface for using the Data Warehouse WriteInsight API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL