gcp

package
v0.0.0-...-492d7f2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PublicIP represents the index of the public IP address that GetIPs returns.
	PublicIP = 0

	// PrivateIP represents the private IP address that GetIPs returns.
	PrivateIP = 1

	// OperationTimeout represents Maximum time(Second) to wait for operation ready.
	OperationTimeout = 180

	// DevicePathPrefix represents the prefix of the path given to the
	// disks attached to an instance. If a disk named "disk1" is attached
	// to an instance, it's path on the GCE instance becomes
	// "/dev/disk/by-id/google-disk1". This name can be used to reference
	// the device for mounting, resizing, and so on, from within the
	// instance.
	DevicePathPrefix = "/dev/disk/by-id/google-"
)

Variables

View Source
var SSHTimeout = 3 * time.Minute

SSHTimeout is the maximum time to wait before failing to GetSSH. This is not thread-safe.

Functions

This section is empty.

Types

type Account

type Account struct {
	// AccountFile: Represents the JSON file required to authenticate a
	// Google cloud service account
	AccountFile string

	// Scopes: Represents access scopes with which API call is made
	Scopes []string
	// contains filtered or unexported fields
}

Account represents a Google cloud account. It is used to make non VM related calls such as GetProjectList()

func (*Account) GetProjectList

func (acc *Account) GetProjectList() ([]Project, error)

GetProjectList: Gets list of projects

type Disk

type Disk struct {
	Name        string
	DiskType    string
	DiskSizeGb  int
	AutoDelete  bool // Auto delete disk
	Description string
}

Disk represents the GCP Disk. See https://cloud.google.com/compute/docs/disks/?hl=en_US&_ga=1.115106433.702756738.1463769954

type DiskType

type DiskType struct {
	Name              string `json:"name,omitempty"`
	Description       string `json:"description,omitempty"`
	ValidDiskSize     string `json:"valid_size,omitempty"`
	DefaultDiskSizeGb int64  `json:"default_disk_size_gb,omitempty,string"`
}

DiskType defines GCP disk type

type Endpoint

type Endpoint struct {
	// Protocol can be one of the following well known protocol strings
	// (tcp, udp, icmp, esp, ah, sctp) which are supported by GCP
	Protocol string
	Ports    []string
}

Endpoint represents the protocol and ports configured in a firewall

type Image

type Image struct {
	Id                uint64 `json:"id,omitempty,string"`
	CreationTimestamp string `json:"creation_timestamp,omitempty"`
	// DeprecationStatus indicates whether the image is depcrecated. If the
	// image is not deprecated it will have an empty string.
	DeprecationStatus string `json:"deprecation_status,omitempty"`
	// DeprecationReplacement provides the url of the image which is a
	// replacement of this deprecated image. If this image is not deprecated
	// it's value will be an empty string.
	DeprecationReplacement string `json:"deprecation_replacement,omitempty"`
	Description            string `json:"description,omitempty"`
	DiskSizeGb             int64  `json:"disk_size_gb,omitempty,string"`
	Family                 string `json:"family,omitempty"`
	Name                   string `json:"name,omitempty"`
	Status                 string `json:"status,omitempty"`
}

Image represents a GCE image

type InstanceData

type InstanceData struct {
	Name              string          `json:"name,omitempty"`
	Id                uint64          `json:"id,omitempty,string"`
	Status            string          `json:"status,omitempty"`
	CreationTimestamp string          `json:"creation_timestamp,omitempty"`
	PrivateIpv4       string          `json:"private_ipv4,omitempty"`
	PublicIpv4        string          `json:"public_ipv4,omitempty"`
	Volumes           []StorageDevice `json:"volumes,omitempty"`
}

InstanceData represents the details of a launched GCE instance

type MachineType

type MachineType struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	GuestCpus   int64  `json:"cpus,omitempty"`
	MemoryMb    int64  `json:"memory_mb,omitempty"`
	IsSharedCpu *bool  `json:"is_shared_cpu,omitempty"`
	// Maximum persistent disks allowed
	MaximumPersistentDisks int64 `json:"max_persistent_disks,omitempty"`
	// Maximum total persistent disks size (GB) allowed
	MaximumPersistentDisksSizeGb int64 `json:"max_persistent_disks_size_gb,omitempty,string"`
}

MachineType defines GCP machine type (aka flavors)

type Network

type Network struct {
	Name                  string   `json:"name,omitempty"`
	Description           string   `json:"description,omitempty"`
	Id                    uint64   `json:"id,omitempty,string"`
	AutoCreateSubnetworks *bool    `json:"auto_create_subnetworks,omitempty"`
	IPv4Range             string   `json:"ipv4_range,omitempty"`
	CreationTimestamp     string   `json:"creation_timestamp,omitempty"`
	Subnetworks           []string `json:"subnetworks,omitempty"`
}

Network defines a VPC network in GCP

type Project

type Project struct {
	// Name represents project name
	Name string `json:"name,omitempty"`
	// ProjectID represents the unique, user-assigned ID of the project
	ProjectID string `json:"project_id,omitempty"`
	// ProjectNumber represents the google-assigned unique project number
	ProjectNumber int64 `json:"project_number,omitempty,string"`
	// LifecycleState is a read-only field giving state of the project
	LifecycleState string `json:"lifecycle_state,omitempty"`
	// CreateTime gives the project creation time
	CreateTime string `json:"create_time,omitempty"`
}

Project represents a Google cloud project

type Region

type Region struct {
	Name        string   `json:"name,omitempty"`
	Description string   `json:"description,omitempty"`
	Zones       []string `json:"zones,omitempty"`
	Status      string   `json:"status,omitempty"`
}

Region represents a GCP region

type StorageDevice

type StorageDevice struct {
	Name       string `json:"name,omitempty"`
	DevicePath string `json:"device_path,omitempty"`
	Boot       *bool  `json:"boot,omitempty"`
	AutoDelete *bool  `json:"auto_delete,omitempty"`
	// Interface specifies the disk interface to use for attaching this disk, which
	// is either SCSI or NVME. The default is SCSI. Persistent disks must
	// always use SCSI and the request will fail if you attempt to attach
	// a persistent disk in any other format than SCSI. Local SSDs can use
	// either NVME or SCSI.
	Interface string `json:"interface,omitempty"`
}

StorageDevice represents a disk attached to a GCE instance

type Subnetwork

type Subnetwork struct {
	Name              string `json:"name,omitempty"`
	Description       string `json:"description,omitempty"`
	Id                uint64 `json:"id,omitempty,string"`
	CreationTimestamp string `json:"creation_timestamp,omitempty"`
	GatewayAddress    string `json:"gateway_address,omitempty"`
	Network           string `json:"network,omitempty"`
	Region            string `json:"region,omitempty"`
	IpCidrRange       string `json:"ipv4_range,omitempty"`
}

Subnetwork represents a GCP subnetwork in a region

type VM

type VM struct {
	Name        string
	Description string
	Zone        string
	MachineType string
	Preemptible bool // Preemptible instances will be terminates after they run for 24 hours.

	SourceImage   string   //Required
	ImageProjects []string //Required

	Disks []Disk // At least one disk is required, the first one is booted device

	Network          string
	Subnetwork       string
	UseInternalIP    bool
	PrivateIPAddress string

	Scopes  []string //Access scopes
	Project string   //GCE project
	Tags    []string //Instance Tags

	AccountFile string

	SSHCreds     ssh.Credentials
	SSHPublicKey string

	Firewall  string // required when modifying firewall rules
	Endpoints []Endpoint

	// RawDiskSource is the full Google Cloud Storage URL where the raw disk
	// image is stored. It is required only for creating a new image from
	// a raw disk.
	RawDiskSource string
	// contains filtered or unexported fields
}

VM defines a GCE virtual machine.

func (*VM) AddEndpoints

func (vm *VM) AddEndpoints() error

AddEndpoints adds new endpoints to the given firewall

func (*VM) AddNewDisks

func (vm *VM) AddNewDisks() ([]StorageDevice, error)

AddNewDisks create new disks as per given specifications and then attaches to the given instance.

func (*VM) CreateImage

func (vm *VM) CreateImage() error

CreateImage: Creates a new image from raw disk

func (*VM) DeleteDisks

func (vm *VM) DeleteDisks() error

DeleteDisks cleans up all the disks attached to the GCE instance.

func (*VM) DeleteImage

func (vm *VM) DeleteImage() error

DeleteImage: Deletes an image

func (*VM) DeleteVMDisks

func (vm *VM) DeleteVMDisks() error

DeleteVMDisk detaches the given disks from the instance and deletes them

func (*VM) Destroy

func (vm *VM) Destroy() error

Destroy deletes the VM on GCE.

func (*VM) GetDiskTypeList

func (vm *VM) GetDiskTypeList() ([]DiskType, error)

GetDiskTypeList gets the list of available disk types

func (*VM) GetIPs

func (vm *VM) GetIPs() ([]net.IP, error)

GetIPs returns a slice of IP addresses assigned to the VM.

func (*VM) GetImageList

func (vm *VM) GetImageList() ([]Image, error)

GetImageList lists images available in given projects

func (*VM) GetInstance

func (vm *VM) GetInstance() (*InstanceData, error)

GetInstance gets instance details

func (*VM) GetMachineTypeList

func (vm *VM) GetMachineTypeList() ([]MachineType, error)

GetMachineTypeList gets the list of available machine types (aka flavors)

func (*VM) GetName

func (vm *VM) GetName() string

GetName returns the name of the virtual machine.

func (*VM) GetNetworkList

func (vm *VM) GetNetworkList() ([]Network, error)

GetNetworkList gets the list of VPC networks

func (*VM) GetRegionList

func (vm *VM) GetRegionList() ([]Region, error)

GetRegionList gets the list of available regions

func (*VM) GetSSH

func (vm *VM) GetSSH(options ssh.Options) (ssh.Client, error)

GetSSH returns an SSH client connected to the instance.

func (*VM) GetState

func (vm *VM) GetState() (string, error)

GetState retrieve the instance status.

func (*VM) GetSubnetworkList

func (vm *VM) GetSubnetworkList() ([]Subnetwork, error)

GetSubnetworkList gets the list of subnetworks

func (*VM) GetZoneList

func (vm *VM) GetZoneList() ([]Zone, error)

GetZoneList gets the list of available zones

func (*VM) Halt

func (vm *VM) Halt() error

Halt stops a GCE instance.

func (*VM) InsertSSHKey

func (vm *VM) InsertSSHKey(publicKey string) error

InsertSSHKey uploads new ssh key into the GCE instance.

func (*VM) IsInstance

func (vm *VM) IsInstance() (bool, error)

IsInstance checks if the given instance is present in GCP. Returns true if instance is available else false.

func (*VM) Provision

func (vm *VM) Provision() error

Provision creates a virtual machine on GCE. It returns an error if there was a problem during creation.

func (*VM) RemoveEndpoints

func (vm *VM) RemoveEndpoints() error

RemoveEndpoints removes given endpoints from the given firewall

func (*VM) Reset

func (vm *VM) Reset() error

Reset a GCE instance.

func (*VM) Resume

func (vm *VM) Resume() error

Resume is not supported, return the error.

func (*VM) Start

func (vm *VM) Start() error

Start a stopped GCE instance.

func (*VM) Suspend

func (vm *VM) Suspend() error

Suspend is not supported, return the error.

func (*VM) ValidateAuth

func (vm *VM) ValidateAuth() error

ValidateAuth: returns error if credentials are incorrect

type Zone

type Zone struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Region      string `json:"region,omitempty"`
	Status      string `json:"status,omitempty"`
}

Zone represents a GCP zone

Jump to

Keyboard shortcuts

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