github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/googlecompute/driver.go (about) 1 package googlecompute 2 3 import ( 4 "crypto/rsa" 5 "time" 6 ) 7 8 // Driver is the interface that has to be implemented to communicate 9 // with GCE. The Driver interface exists mostly to allow a mock implementation 10 // to be used to test the steps. 11 type Driver interface { 12 // CreateImage creates an image from the given disk in Google Compute 13 // Engine. 14 CreateImage(name, description, family, zone, disk string, image_labels map[string]string) (<-chan *Image, <-chan error) 15 16 // DeleteImage deletes the image with the given name. 17 DeleteImage(name string) <-chan error 18 19 // DeleteInstance deletes the given instance, keeping the boot disk. 20 DeleteInstance(zone, name string) (<-chan error, error) 21 22 // DeleteDisk deletes the disk with the given name. 23 DeleteDisk(zone, name string) (<-chan error, error) 24 25 // GetImage gets an image; tries the default and public projects. If 26 // fromFamily is true, name designates an image family instead of a 27 // particular image. 28 GetImage(name string, fromFamily bool) (*Image, error) 29 30 // GetImageFromProject gets an image from a specific project. If fromFamily 31 // is true, name designates an image family instead of a particular image. 32 GetImageFromProject(project, name string, fromFamily bool) (*Image, error) 33 34 // GetInstanceMetadata gets a metadata variable for the instance, name. 35 GetInstanceMetadata(zone, name, key string) (string, error) 36 37 // GetInternalIP gets the GCE-internal IP address for the instance. 38 GetInternalIP(zone, name string) (string, error) 39 40 // GetNatIP gets the NAT IP address for the instance. 41 GetNatIP(zone, name string) (string, error) 42 43 // GetSerialPortOutput gets the Serial Port contents for the instance. 44 GetSerialPortOutput(zone, name string) (string, error) 45 46 // ImageExists returns true if the specified image exists. If an error 47 // occurs calling the API, this method returns false. 48 ImageExists(name string) bool 49 50 // RunInstance takes the given config and launches an instance. 51 RunInstance(*InstanceConfig) (<-chan error, error) 52 53 // WaitForInstance waits for an instance to reach the given state. 54 WaitForInstance(state, zone, name string) <-chan error 55 56 // CreateOrResetWindowsPassword creates or resets the password for a user on an Windows instance. 57 CreateOrResetWindowsPassword(zone, name string, config *WindowsPasswordConfig) (<-chan error, error) 58 } 59 60 type InstanceConfig struct { 61 AcceleratorType string 62 AcceleratorCount int64 63 Address string 64 Description string 65 DiskSizeGb int64 66 DiskType string 67 Image *Image 68 Labels map[string]string 69 MachineType string 70 Metadata map[string]string 71 Name string 72 Network string 73 NetworkProjectId string 74 OmitExternalIP bool 75 OnHostMaintenance string 76 Preemptible bool 77 Region string 78 Scopes []string 79 Subnetwork string 80 Tags []string 81 Zone string 82 } 83 84 // WindowsPasswordConfig is the data structue that GCE needs to encrypt the created 85 // windows password. 86 type WindowsPasswordConfig struct { 87 key *rsa.PrivateKey 88 password string 89 UserName string `json:"userName"` 90 Modulus string `json:"modulus"` 91 Exponent string `json:"exponent"` 92 Email string `json:"email"` 93 ExpireOn time.Time `json:"expireOn"` 94 } 95 96 type windowsPasswordResponse struct { 97 UserName string `json:"userName"` 98 PasswordFound bool `json:"passwordFound"` 99 EncryptedPassword string `json:"encryptedPassword"` 100 Modulus string `json:"modulus"` 101 Exponent string `json:"exponent"` 102 ErrorMessage string `json:"errorMessage"` 103 }