gcp

package
v0.0.0-...-2cf41ae Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MetadataKeyShutdownAt is the instance key to represents the time that this instance should be deleted.
	MetadataKeyShutdownAt = "shutdown-at"
)

Variables

This section is empty.

Functions

func ConvertLocalTimeToUTC

func ConvertLocalTimeToUTC(timezone, shutdownAt string) (time.Time, error)

ConvertLocalTimeToUTC converts local time to UTC

func CreateVMXEnabledImage

func CreateVMXEnabledImage(ctx context.Context, cc *ComputeCLIClient, baseImageProject, baseImage string) error

CreateVMXEnabledImage creates vmx-enabled image

func MakeVMXEnabledImageURL

func MakeVMXEnabledImageURL(projectID string) string

MakeVMXEnabledImageURL returns vmx-enabled image URL in the project

func RetryWithSleep

func RetryWithSleep(ctx context.Context, max int, d time.Duration, f func(ctx context.Context) error, logger func(err error)) error

RetryWithSleep invoke f until it succeeds or reach to max.

func SleepContext

func SleepContext(ctx context.Context, d time.Duration) error

SleepContext sleeps for d, Returned err is not nil if ctx is canceled

Types

type AppConfig

type AppConfig struct {
	Shutdown ShutdownConfig `yaml:"shutdown"`
}

AppConfig is configuration for GAE app

type AutoShutdownConfig

type AutoShutdownConfig struct {
	Timezone   string `yaml:"timezone"`
	ShutdownAt string `yaml:"shutdown-at"`
}

AutoShutdownConfig is configuration for automatically shutting down host-vm instance

type CommonConfig

type CommonConfig struct {
	Project        string `yaml:"project"`
	ServiceAccount string `yaml:"serviceaccount"`
	Zone           string `yaml:"zone"`
}

CommonConfig is common configuration for GCP

type ComputeCLIClient

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

ComputeCLIClient is GCP compute client using "gcloud compute"

func NewComputeCLIClient

func NewComputeCLIClient(cfg *Config, instance string) *ComputeCLIClient

NewComputeCLIClient returns ComputeCLIClient

func (*ComputeCLIClient) AttachHomeDisk

func (cc *ComputeCLIClient) AttachHomeDisk(ctx context.Context) error

AttachHomeDisk attaches home disk image to host-vm instance

func (*ComputeCLIClient) CreateHomeDisk

func (cc *ComputeCLIClient) CreateHomeDisk(ctx context.Context) error

CreateHomeDisk creates home disk image

func (*ComputeCLIClient) CreateHostVMInstance

func (cc *ComputeCLIClient) CreateHostVMInstance(ctx context.Context) error

CreateHostVMInstance creates host-vm instance

func (*ComputeCLIClient) CreateVMXEnabledImage

func (cc *ComputeCLIClient) CreateVMXEnabledImage(ctx context.Context) error

CreateVMXEnabledImage create GCE vmx-enabled image

func (*ComputeCLIClient) CreateVMXEnabledInstance

func (cc *ComputeCLIClient) CreateVMXEnabledInstance(ctx context.Context, baseImageProject, baseImage string) error

CreateVMXEnabledInstance creates vmx-enabled instance

func (*ComputeCLIClient) CreateVolumeSnapshot

func (cc *ComputeCLIClient) CreateVolumeSnapshot(ctx context.Context) error

CreateVolumeSnapshot creates home volume snapshot

func (*ComputeCLIClient) DeleteInstance

func (cc *ComputeCLIClient) DeleteInstance(ctx context.Context) error

DeleteInstance deletes given instance

func (*ComputeCLIClient) DeleteVMXEnabledImage

func (cc *ComputeCLIClient) DeleteVMXEnabledImage(ctx context.Context) error

DeleteVMXEnabledImage create GCE vmx-enabled image

func (*ComputeCLIClient) ExtendInstance

func (cc *ComputeCLIClient) ExtendInstance(ctx context.Context) error

ExtendInstance extends 2 hours from now for given instance to prevent auto deletion

func (*ComputeCLIClient) ResizeHomeDisk

func (cc *ComputeCLIClient) ResizeHomeDisk(ctx context.Context) error

ResizeHomeDisk resizes home disk image

func (*ComputeCLIClient) RestoreVolumeFromSnapshot

func (cc *ComputeCLIClient) RestoreVolumeFromSnapshot(ctx context.Context, destZone string) error

RestoreVolumeFromSnapshot restores home volume in the target zone

func (*ComputeCLIClient) RunSetupHostVM

func (cc *ComputeCLIClient) RunSetupHostVM(ctx context.Context) error

RunSetupHostVM executes "setup host-vm" on the instance through ssh

func (*ComputeCLIClient) RunSetupVMXEnabled

func (cc *ComputeCLIClient) RunSetupVMXEnabled(ctx context.Context, optionalPackages []string) error

RunSetupVMXEnabled executes "setup vmx-enabled" on the instance through ssh

func (*ComputeCLIClient) StopInstance

func (cc *ComputeCLIClient) StopInstance(ctx context.Context) error

StopInstance stops given instance

func (*ComputeCLIClient) Upload

func (cc *ComputeCLIClient) Upload(ctx context.Context, file, target, mode string) error

Upload uploads a file to the instance through ssh

func (*ComputeCLIClient) UploadSetupCommand

func (cc *ComputeCLIClient) UploadSetupCommand(ctx context.Context) error

UploadSetupCommand uploads the "setup" command on the instance through ssh

func (*ComputeCLIClient) WaitInstance

func (cc *ComputeCLIClient) WaitInstance(ctx context.Context) error

WaitInstance waits given instance until online

type ComputeClient

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

ComputeClient is GCP compute client with go client

func NewComputeClient

func NewComputeClient(
	ctx context.Context,
	projectID string,
	zone string,
) (*ComputeClient, error)

NewComputeClient returns ComputeClient

func (*ComputeClient) Create

func (c *ComputeClient) Create(
	instanceName string,
	serviceAccountEmail string,
	machineType string,
	numLocalSSDs int,
	imageURL string,
	startupScript string,
) error

Create creates a compute instance with running startup script

func (*ComputeClient) Delete

func (c *ComputeClient) Delete(name string) error

Delete deletes a GCP instance

func (*ComputeClient) DeleteWithZone

func (c *ComputeClient) DeleteWithZone(zone, name string) error

DeleteWithZone deletes a GCP instance in the zone

func (*ComputeClient) GetAggregatedNameList

func (c *ComputeClient) GetAggregatedNameList(filter string) (map[string][]string, error)

GetAggregatedNameList gets a list of existing GCP instances with the given filter from all zones

func (*ComputeClient) GetNameSet

func (c *ComputeClient) GetNameSet(filter string) (map[string]struct{}, error)

GetNameSet gets a list of existing GCP instances with the given filter

type ComputeConfig

type ComputeConfig struct {
	MachineType      string             `yaml:"machine-type"`
	NumLocalSSDs     int                `yaml:"local-ssd"`
	BootDiskSizeGB   int                `yaml:"boot-disk-sizeGB"`
	OptionalPackages []string           `yaml:"optional-packages"`
	HostVM           HostVMConfig       `yaml:"host-vm"`
	AutoShutdown     AutoShutdownConfig `yaml:"auto-shutdown"`

	// backward compatibility
	VMXEnabled struct {
		OptionalPackages []string `yaml:"optional-packages"`
	} `yaml:"vmx-enabled"`
}

ComputeConfig is configuration for GCE

type Config

type Config struct {
	Common  CommonConfig  `yaml:"common"`
	App     AppConfig     `yaml:"app"`
	Compute ComputeConfig `yaml:"compute"`
}

Config is configuration for necogcp command and GAE app

func NecoTestConfig

func NecoTestConfig(projectID, zone string) *Config

NecoTestConfig returns configuration for neco-test

func NewConfig

func NewConfig() (*Config, error)

NewConfig returns Config

type HostVMConfig

type HostVMConfig struct {
	HomeDisk       bool `yaml:"home-disk"`
	HomeDiskSizeGB int  `yaml:"home-disk-sizeGB"`
	Preemptible    bool `yaml:"preemptible"`
}

HostVMConfig is configuration for host-vm instance

type SecretClient

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

func NewSecretClient

func NewSecretClient(
	ctx context.Context,
	projectID string,
) (*SecretClient, error)

NewSecretClient returns SecretClient

func (*SecretClient) CreateSecretFromData

func (c *SecretClient) CreateSecretFromData(expireTime time.Time, secretID string, data []byte) error

func (*SecretClient) Exists

func (c *SecretClient) Exists(secretID string) (bool, error)

func (*SecretClient) GetSecret

func (c *SecretClient) GetSecret(secretID string) (*secretmanagerpb.Secret, error)

type ShutdownConfig

type ShutdownConfig struct {
	Stop            []string      `yaml:"stop"`
	Exclude         []string      `yaml:"exclude"`
	Expiration      time.Duration `yaml:"expiration"`
	Timezone        string        `yaml:"timezone"`
	ShutdownAt      string        `yaml:"shutdown-at"`
	AdditionalZones []string      `yaml:"additional-zones"`
}

ShutdownConfig is automatic shutdown configuration

type Snapshot

type Snapshot struct {
	Name   string `json:"name"`
	Status string `json:"status"`
}

Snapshot is GCP snapshot object

Jump to

Keyboard shortcuts

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