gcp

package
v0.0.0-...-ca65d48 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2018 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package gcp implements Google Cloud API wrapper.

Index

Constants

View Source
const ComputeVersion = "https://www.googleapis.com/compute/v1"

ComputeVersion is the API version of Google Cloud Compute.

Variables

This section is empty.

Functions

func GetComputeMetadata

func GetComputeMetadata(key string, try int, interval time.Duration) ([]byte, error)

GetComputeMetadata fetches the metadata from instance or project. e.g. curl -L http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip -H 'Metadata-Flavor:Google'

Types

type Compute

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

Compute is a helper layer to wrap complex Google Compute API call logic.

func NewCompute

func NewCompute(ctx context.Context, scope string, key []byte) (*Compute, error)

NewCompute returns a Google Cloud Compute client. Create/Download the key file from https://console.cloud.google.com/apis/credentials.

func (*Compute) CreateMacine

func (c *Compute) CreateMacine(ctx context.Context, cfg InstanceConfig) (st *compute.Instance, err error)

CreateMacine creates a virtual machines in the zone. 'memory' is the number of GBs for RAM.

func (*Compute) DeleteMachine

func (c *Compute) DeleteMachine(ctx context.Context, cfg InstanceConfig) (st *compute.Instance, err error)

DeleteMachine deletes a virtual machines in the zone.

func (*Compute) ListMachines

func (c *Compute) ListMachines(ctx context.Context, zone string) ([]*compute.Instance, error)

ListMachines lists virtual machines in a zone.

func (*Compute) SetMetadata

func (c *Compute) SetMetadata(ctx context.Context, cfg InstanceConfig) error

SetMetadata sets metadata to the instance.

func (*Compute) StartMachine

func (c *Compute) StartMachine(ctx context.Context, cfg InstanceConfig) (st *compute.Instance, err error)

StartMachine starts a virtual machines in the zone.

func (*Compute) StopMachine

func (c *Compute) StopMachine(ctx context.Context, cfg InstanceConfig) (st *compute.Instance, err error)

StopMachine stops a virtual machines in the zone.

type InstanceConfig

type InstanceConfig struct {
	Zone string
	Name string

	OS         string
	CPU        int
	Memory     int
	DiskSizeGB int

	// OnHostMaintenance is either MIGRATE or TERMINATE.
	// If you do not want your instance to live migrate, you can
	// choose to terminate and optionally restart your instance.
	// With this option, Google Compute Engine will signal your
	// instance to shut down, wait for a short period of time
	// for your instance to shut down cleanly, terminate the instance,
	// and restart it away from the maintenance event.
	// https://cloud.google.com/compute/docs/instances/setting-instance-scheduling-options
	OnHostMaintenance string

	// MetadataItems maps metadata key to its value
	// (e.g. set Ignition configuration value with key 'user-data' for Container Linux).
	MetadataItems map[string]string

	Tags []string
	// contains filtered or unexported fields
}

InstanceConfig represents GCP Compute Engine VM config.

type Machine

type Machine struct {
	Created            string
	Name               string
	ID                 string
	Zone               string
	InternalIP         string
	ExternalIP         string
	Status             string
	SourceImageLicense string
	SourceImage        string
}

Machine represents a virtual machine in Google Compute Engine.

func ConvertToMachine

func ConvertToMachine(v compute.Instance) Machine

ConvertToMachine converts to Machine (human-readable).

type Storage

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

Storage is a helper layer to wrap complex Storage logic.

func NewStorage

func NewStorage(ctx context.Context, bucket, scope string, key []byte, prefix string) (*Storage, error)

NewStorage returns a new Google Cloud Storage client, creating bucket if not exists. 'key' is a Google Developers service account JSON key. Create/Download the key file from https://console.cloud.google.com/apis/credentials.

func (*Storage) Close

func (s *Storage) Close() error

Close closes the Client. Close need not be called at program exit.

func (*Storage) CopyPrefix

func (s *Storage) CopyPrefix(from string) error

CopyPrefix clones data from 'from' to the receiver storage. Objects are assumed to be copied within the same bucket.

func (*Storage) Delete

func (s *Storage) Delete(key string) error

Delete deletes data for the specified 'key'.

func (*Storage) Get

func (s *Storage) Get(key string) (io.ReadCloser, error)

Get returns data reader for the specified 'key'.

func (*Storage) List

func (s *Storage) List() ([]string, error)

List lists all keys.

func (*Storage) Put

func (s *Storage) Put(key string, data []byte) error

Put writes 'data' with 'key' as a file name in the storage. The actual path will be namespaced with version and prefix.

func (*Storage) TotalSize

func (s *Storage) TotalSize() (int64, error)

TotalSize returns the total size of storage.

Jump to

Keyboard shortcuts

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