Documentation ¶
Overview ¶
Package gce communicates with compute engine
Index ¶
- Constants
- func BuildGceService(serviceEmail string, key []byte) (*compute.Service, error)
- type BySnapshotName
- type Manager
- func (m *Manager) AddInstancesIntoInstanceGroup(projectID, zone, instanceGroupName string, instances []string) (*compute.Operation, error)
- func (m *Manager) AddInstancesIntoTargetPool(projectID, region, targetPool string, instances []string) (*compute.Operation, error)
- func (m *Manager) AttachTags(projectID, zone, vmName string, addedTags []string) (*compute.Operation, error)
- func (m *Manager) DeleteDisk(projectID, zone, diskName string) error
- func (m *Manager) DeleteInstanceTemplate(projectID, templateName string) (*compute.Operation, error)
- func (m *Manager) DeleteVM(projectID, zone, vmName string) error
- func (m *Manager) DetachTags(projectID, zone, vmName string, removedTages []string) (*compute.Operation, error)
- func (m *Manager) GetDisk(projectID, zone, diskName string) (*compute.Disk, error)
- func (m *Manager) GetInstanceGroup(projectID, zone, instanceGroupName string) (*compute.InstanceGroup, error)
- func (m *Manager) GetInstanceGroupManager(projectID, zone, instanceGroupManagerName string) (*compute.InstanceGroupManager, error)
- func (m *Manager) GetInstanceTemplate(projectID, templateName string) (*compute.InstanceTemplate, error)
- func (m *Manager) GetLatestSnapshot(prefix string, snapshots []*compute.Snapshot) (*compute.Snapshot, error)
- func (m *Manager) GetNatIP(vm *compute.Instance) string
- func (m *Manager) GetNetworkIP(vm *compute.Instance) string
- func (m *Manager) GetSnapshot(projectID, snapshot string) (*compute.Snapshot, error)
- func (m *Manager) GetSnapshotOfDisk(disk *compute.Disk) string
- func (m *Manager) GetTargetPool(projectID, region, targetPool string) (*compute.TargetPool, error)
- func (m *Manager) GetVM(projectID, zone, vmName string) (*compute.Instance, error)
- func (m *Manager) InitVMFromTemplate(templateFile []byte, zone string) (*compute.Instance, error)
- func (m *Manager) ListDisks(projectID, zone string) (*compute.DiskList, error)
- func (m *Manager) ListImages(projectID string) (*compute.ImageList, error)
- func (m *Manager) ListInstanceGroupManagers(projectID, zone string) (*compute.InstanceGroupManagerList, error)
- func (m *Manager) ListInstanceGroupsByZone(projectID, zone string, isPrefix func(string) bool) []string
- func (m *Manager) ListInstanceTemplates(projectID, filter string) ([]*compute.InstanceTemplate, error)
- func (m *Manager) ListInstancesInInstanceGroup(projectID, zone, instanceGroupName string) ([]string, error)
- func (m *Manager) ListSnapshots(projectID string) ([]*compute.Snapshot, error)
- func (m *Manager) ListVMs(projectID, zone string) (*compute.InstanceList, error)
- func (m *Manager) ListVMsWithFilter(projectID, zone, filter string) (*compute.InstanceList, error)
- func (m *Manager) NewDisk(projectID, zone, name, sourceSnapshot string, sizeGb int64) error
- func (m *Manager) NewInstanceTemplate(projectID string, template *compute.InstanceTemplate) error
- func (m *Manager) NewVM(projectID, zone string, vm *compute.Instance) error
- func (m *Manager) PatchInstanceMachineType(machineTypeURI, targetType string) string
- func (m *Manager) ProbeDiskCreation(projectID, zone, diskName string, observer chan<- bool)
- func (m *Manager) ProbeInstanceTemplateCreation(projectID, templateName string, observer chan<- bool)
- func (m *Manager) ProbeVMMachineTypeChanged(projectID, zone, vmName, machineType string, observer chan<- bool)
- func (m *Manager) ProbeVMRunning(projectID, zone, vmName string, observer chan<- bool)
- func (m *Manager) ProbeVMStopped(projectID, zone, vmName string, observer chan<- bool)
- func (m *Manager) RemoveInstancesFromTargetPool(projectID, region, targetPool string, instances []string) (*compute.Operation, error)
- func (m *Manager) RemoveInstancesIntoInstanceGroup(projectID, zone, instanceGroupName string, instances []string) (*compute.Operation, error)
- func (m *Manager) ResetInstance(projectID, zone, vmName string) (*compute.Operation, error)
- func (m *Manager) SetInstanceTemplate(projectID, zone, instanceGroupManager, instanceTemplate string) error
- func (m *Manager) SetMachineType(projectID, zone, vmName, machineType string) error
- func (m *Manager) StartVM(projectID, zone, vmName string, vcc VMConditionChecker) (*compute.Operation, error)
- func (m *Manager) StopVM(projectID, zone, vmName string, vcc VMConditionChecker) (*compute.Operation, error)
- type VMConditionChecker
Constants ¶
const ( // VMCreationTimeout is timeout of VM creation to running VMCreationTimeout = 180 * time.Second // VMStoppingTimeout is timeout of VM running to stopped VMStoppingTimeout = 180 * time.Second // DiskCreationTimeout is timeout of disk creation DiskCreationTimeout = 180 * time.Second // VMSetMachineTypeTimeout is timeout of set machine type VMSetMachineTypeTimeout = 180 * time.Second // InstanceTemplateCreationTimeout is timeout of creating instance template InstanceTemplateCreationTimeout = 180 * time.Second // VMStatusTerminated ... VMStatusTerminated = "TERMINATED" // VMStatusRunning ... VMStatusRunning = "RUNNING" )
Variables ¶
This section is empty.
Functions ¶
func BuildGceService ¶
BuildGceService builds the singlton service for Manager
Types ¶
type BySnapshotName ¶
type BySnapshotName []*compute.Snapshot
BySnapshotName is used to sort all gce snapshot by name
func (BySnapshotName) Len ¶
func (a BySnapshotName) Len() int
func (BySnapshotName) Less ¶
func (a BySnapshotName) Less(i, j int) bool
func (BySnapshotName) Swap ¶
func (a BySnapshotName) Swap(i, j int)
type Manager ¶
type Manager struct {
Service *compute.Service `inject:""`
}
Manager is for low level communication with Google Compute Engine.
func (*Manager) AddInstancesIntoInstanceGroup ¶
func (m *Manager) AddInstancesIntoInstanceGroup( projectID, zone, instanceGroupName string, instances []string) ( *compute.Operation, error)
AddInstancesIntoInstanceGroup adds instances into some instance group https://godoc.org/google.golang.org/api/compute/v1#InstanceGroupsService.AddInstances
func (*Manager) AddInstancesIntoTargetPool ¶
func (m *Manager) AddInstancesIntoTargetPool( projectID, region, targetPool string, instances []string) (*compute.Operation, error)
AddInstancesIntoTargetPool adds instances into the target pool of load balancer https://godoc.org/google.golang.org/api/compute/v1#TargetPoolsService.AddInstance
func (*Manager) AttachTags ¶
func (m *Manager) AttachTags(projectID, zone, vmName string, addedTags []string) (*compute.Operation, error)
AttachTags attaches tags onto VM.
func (*Manager) DeleteDisk ¶
DeleteDisk deletes disk. https://godoc.org/google.golang.org/api/compute/v1#DisksService.Delete
func (*Manager) DeleteInstanceTemplate ¶
func (m *Manager) DeleteInstanceTemplate(projectID, templateName string) (*compute.Operation, error)
DeleteInstanceTemplate ... https://godoc.org/google.golang.org/api/compute/v1#InstanceTemplatesService.Delete
func (*Manager) DeleteVM ¶
DeleteVM deletes a VM. https://godoc.org/google.golang.org/api/compute/v1#InstancesService.Delete
func (*Manager) DetachTags ¶
func (m *Manager) DetachTags(projectID, zone, vmName string, removedTages []string) (*compute.Operation, error)
DetachTags detaches tags from VM.
func (*Manager) GetDisk ¶
GetDisk gets disk. https://godoc.org/google.golang.org/api/compute/v1#DisksService.Get
func (*Manager) GetInstanceGroup ¶
func (m *Manager) GetInstanceGroup(projectID, zone, instanceGroupName string) ( *compute.InstanceGroup, error)
GetInstanceGroup - https://godoc.org/google.golang.org/api/compute/v1#InstanceGroupsService.Get
func (*Manager) GetInstanceGroupManager ¶
func (m *Manager) GetInstanceGroupManager(projectID, zone, instanceGroupManagerName string) ( *compute.InstanceGroupManager, error)
GetInstanceGroupManager ... https://godoc.org/google.golang.org/api/compute/v1#InstanceGroupManagersService.Get
func (*Manager) GetInstanceTemplate ¶
func (m *Manager) GetInstanceTemplate(projectID, templateName string) (*compute.InstanceTemplate, error)
GetInstanceTemplate ... https://godoc.org/google.golang.org/api/compute/v1#InstanceTemplatesService.Get
func (*Manager) GetLatestSnapshot ¶
func (m *Manager) GetLatestSnapshot(prefix string, snapshots []*compute.Snapshot) (*compute.Snapshot, error)
GetLatestSnapshot gets latest snapshot with specified prefix in its name
func (*Manager) GetNetworkIP ¶
GetNetworkIP gets internal IP address from VM
func (*Manager) GetSnapshot ¶
GetSnapshot gets the specific snapshot https://godoc.org/google.golang.org/api/compute/v1#SnapshotsService.Get
func (*Manager) GetSnapshotOfDisk ¶
GetSnapshotOfDisk gets the snapshot name of the disk
func (*Manager) GetTargetPool ¶
GetTargetPool - https://godoc.org/google.golang.org/api/compute/v1#TargetPoolsService.Get
func (*Manager) GetVM ¶
GetVM gets a VM. If VM not existed, return nil. https://godoc.org/google.golang.org/api/compute/v1#InstancesService.Get
func (*Manager) InitVMFromTemplate ¶
InitVMFromTemplate builds the sample VM from template
func (*Manager) ListDisks ¶
ListDisks lists all disks. https://godoc.org/google.golang.org/api/compute/v1#DisksService.List
func (*Manager) ListImages ¶
ListImages lists all images. https://godoc.org/google.golang.org/api/compute/v1#ImagesService.List
func (*Manager) ListInstanceGroupManagers ¶
func (m *Manager) ListInstanceGroupManagers(projectID, zone string) ( *compute.InstanceGroupManagerList, error)
ListInstanceGroupManagers ... https://godoc.org/google.golang.org/api/compute/v1#InstanceGroupManagersService.List
func (*Manager) ListInstanceGroupsByZone ¶
func (m *Manager) ListInstanceGroupsByZone(projectID, zone string, isPrefix func(string) bool) []string
ListInstanceGroupsByZone lists all instance groups in specified zone with filter condition https://godoc.org/google.golang.org/api/compute/v1#InstanceGroupsService.List
func (*Manager) ListInstanceTemplates ¶
func (m *Manager) ListInstanceTemplates(projectID, filter string) ([]*compute.InstanceTemplate, error)
ListInstanceTemplates lists all instance templates which satisfies filter condition https://godoc.org/google.golang.org/api/compute/v1#InstanceTemplatesService.List
func (*Manager) ListInstancesInInstanceGroup ¶
func (m *Manager) ListInstancesInInstanceGroup(projectID, zone, instanceGroupName string) ([]string, error)
ListInstancesInInstanceGroup lists all instances under some instance group https://godoc.org/google.golang.org/api/compute/v1#InstanceGroupsService.ListInstances
func (*Manager) ListSnapshots ¶
ListSnapshots gets all snapshots of the project. https://godoc.org/google.golang.org/api/compute/v1#SnapshotsService.List
func (*Manager) ListVMs ¶
ListVMs lists all VMs. https://godoc.org/google.golang.org/api/compute/v1#InstancesService.List
func (*Manager) ListVMsWithFilter ¶
ListVMsWithFilter lists VMs with filter. https://godoc.org/google.golang.org/api/compute/v1#InstancesService.List
func (*Manager) NewDisk ¶
NewDisk creates a new disk by specified snapshot. https://godoc.org/google.golang.org/api/compute/v1#DisksService.Insert
func (*Manager) NewInstanceTemplate ¶
NewInstanceTemplate ... https://godoc.org/google.golang.org/api/compute/v1#InstanceTemplatesService.Insert
func (*Manager) NewVM ¶
NewVM creates a new VM. This method blocks till the status of created VM to be RUNNING or will be timeout if it takes over `VMCreationTimeout`. https://godoc.org/google.golang.org/api/compute/v1#InstancesService.Insert
func (*Manager) PatchInstanceMachineType ¶
PatchInstanceMachineType replaces the last part of machineTypeURI with targetType
func (*Manager) ProbeDiskCreation ¶
ProbeDiskCreation probes the disk status till its status is READY or timeout
func (*Manager) ProbeInstanceTemplateCreation ¶
func (m *Manager) ProbeInstanceTemplateCreation(projectID, templateName string, observer chan<- bool)
ProbeInstanceTemplateCreation ...
func (*Manager) ProbeVMMachineTypeChanged ¶
func (m *Manager) ProbeVMMachineTypeChanged( projectID, zone, vmName, machineType string, observer chan<- bool)
ProbeVMMachineTypeChanged probes if the machineType of VM has been changed
func (*Manager) ProbeVMRunning ¶
ProbeVMRunning probes the VM status till its status is RUNNING or timeout
func (*Manager) ProbeVMStopped ¶
ProbeVMStopped probes the instance status till its status is Stopping or timeout
func (*Manager) RemoveInstancesFromTargetPool ¶
func (m *Manager) RemoveInstancesFromTargetPool( projectID, region, targetPool string, instances []string) (*compute.Operation, error)
RemoveInstancesFromTargetPool removes instances from the target pool of load balancer https://godoc.org/google.golang.org/api/compute/v1#TargetPoolsService.RemoveInstance
func (*Manager) RemoveInstancesIntoInstanceGroup ¶
func (m *Manager) RemoveInstancesIntoInstanceGroup( projectID, zone, instanceGroupName string, instances []string) ( *compute.Operation, error)
RemoveInstancesIntoInstanceGroup adds instances into some instance group https://godoc.org/google.golang.org/api/compute/v1#InstanceGroupsService.RemoveInstances
func (*Manager) ResetInstance ¶
ResetInstance resets a instance. https://godoc.org/google.golang.org/api/compute/v1#InstancesService.Reset
func (*Manager) SetInstanceTemplate ¶
func (m *Manager) SetInstanceTemplate(projectID, zone, instanceGroupManager, instanceTemplate string) error
SetInstanceTemplate ... https://godoc.org/google.golang.org/api/compute/v1#InstanceGroupManagersService.SetInstanceTemplate
func (*Manager) SetMachineType ¶
SetMachineType changes the machine type for a stopped instance to the machine type specified in the request. https://godoc.org/google.golang.org/api/compute/v1#InstancesService.SetMachineType
func (*Manager) StartVM ¶
func (m *Manager) StartVM(projectID, zone, vmName string, vcc VMConditionChecker) (*compute.Operation, error)
StartVM starts a VM. parameter `vcc` is the checker function to check if the VM is successfully started. https://godoc.org/google.golang.org/api/compute/v1#InstancesService.Start
func (*Manager) StopVM ¶
func (m *Manager) StopVM(projectID, zone, vmName string, vcc VMConditionChecker) (*compute.Operation, error)
StopVM stops a VM. parameter `vcc` is the checker function to check if the VM is successfully stopped. https://godoc.org/google.golang.org/api/compute/v1#InstancesService.Stop
type VMConditionChecker ¶
VMConditionChecker return a bool value by checking condition inside VM