vms

package
v1.2.20210816 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package vms defines logic for managing a pool of virtual machines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	InstanceName       string
	ServiceAccountName string
	ProxyURL           string
	ApplicationImage   string
	BackendID          string
	ProxiedHostname    string
}

A Config holds the creation-time parameters for a per-user VM.

type Pool

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

A Pool is a collection of unallocated virtual machines.

func NewPool

func NewPool(ctx context.Context, computeService *compute.Service, iamService *iam.Service, proxyAdmin *proxy.Admin, proxyURL, proxiedHostname, project, zone, network, machineType, applicationImage string) (*Pool, error)

NewPool creates a new VM pool in the given project/zone combination.

The `applicationImage` value specifies the full path of a Docker image that will run on the VM once the user's disk has been attached to it.

The user's disk will be volume mounted into the Docker container at `/content`.

func (*Pool) DeleteVM

func (p *Pool) DeleteVM(vm *compute.Instance) error

func (*Pool) Fill

func (p *Pool) Fill(ctx context.Context) ([]*compute.Instance, error)

Fill ensures that the pool contains the target number of free VMs.

func (*Pool) FreeVMs

func (p *Pool) FreeVMs() ([]*compute.Instance, error)

FreeVMs returns the list of unallocated VMs in the pool

func (*Pool) KillOldVMs

func (p *Pool) KillOldVMs(idleBackends []string) error

func (*Pool) TooOldVMs

func (p *Pool) TooOldVMs(vms []*compute.Instance, idleBackends []string) ([]*compute.Instance, error)

TooOldVMs computes the list of all VMs that are too old under three criteria:

  1. Having sat idle for too long (i.e. wasting money).
  2. Having been assigned to a user for too long (as a form of abuse prevention).
  3. Being unassigned and created too long ago (i.e. potentially running an out-of-date image).

func (*Pool) WaitForVM

func (pool *Pool) WaitForVM(ctx context.Context, userEmail string) (*compute.Instance, error)

Jump to

Keyboard shortcuts

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