Documentation ¶
Overview ¶
Package gcp implements Google Cloud API wrapper.
Index ¶
- Constants
- func GetComputeMetadata(key string, try int, interval time.Duration) ([]byte, error)
- type Compute
- func (c *Compute) CreateMacine(ctx context.Context, cfg InstanceConfig) (st *compute.Instance, err error)
- func (c *Compute) DeleteMachine(ctx context.Context, cfg InstanceConfig) (st *compute.Instance, err error)
- func (c *Compute) ListMachines(ctx context.Context, zone string) ([]*compute.Instance, error)
- func (c *Compute) SetMetadata(ctx context.Context, cfg InstanceConfig) error
- func (c *Compute) StartMachine(ctx context.Context, cfg InstanceConfig) (st *compute.Instance, err error)
- func (c *Compute) StopMachine(ctx context.Context, cfg InstanceConfig) (st *compute.Instance, err error)
- type InstanceConfig
- type Machine
- type Storage
- func (s *Storage) Close() error
- func (s *Storage) CopyPrefix(from string) error
- func (s *Storage) Delete(key string) error
- func (s *Storage) Get(key string) (io.ReadCloser, error)
- func (s *Storage) List() ([]string, error)
- func (s *Storage) Put(key string, data []byte) error
- func (s *Storage) TotalSize() (int64, error)
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) CopyPrefix ¶
CopyPrefix clones data from 'from' to the receiver storage. Objects are assumed to be copied within the same bucket.
func (*Storage) Get ¶
func (s *Storage) Get(key string) (io.ReadCloser, error)
Get returns data reader for the specified 'key'.