github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/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, image_licenses []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 DisableDefaultServiceAccount bool 66 DiskSizeGb int64 67 DiskType string 68 Image *Image 69 Labels map[string]string 70 MachineType string 71 Metadata map[string]string 72 Name string 73 Network string 74 NetworkProjectId string 75 OmitExternalIP bool 76 OnHostMaintenance string 77 Preemptible bool 78 Region string 79 ServiceAccountEmail string 80 Scopes []string 81 Subnetwork string 82 Tags []string 83 Zone string 84 } 85 86 // WindowsPasswordConfig is the data structure that GCE needs to encrypt the created 87 // windows password. 88 type WindowsPasswordConfig struct { 89 key *rsa.PrivateKey 90 password string 91 UserName string `json:"userName"` 92 Modulus string `json:"modulus"` 93 Exponent string `json:"exponent"` 94 Email string `json:"email"` 95 ExpireOn time.Time `json:"expireOn"` 96 } 97 98 type windowsPasswordResponse struct { 99 UserName string `json:"userName"` 100 PasswordFound bool `json:"passwordFound"` 101 EncryptedPassword string `json:"encryptedPassword"` 102 Modulus string `json:"modulus"` 103 Exponent string `json:"exponent"` 104 ErrorMessage string `json:"errorMessage"` 105 }