github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/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) (<-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 Address string 62 Description string 63 DiskSizeGb int64 64 DiskType string 65 Image *Image 66 MachineType string 67 Metadata map[string]string 68 Name string 69 Network string 70 NetworkProjectId string 71 OmitExternalIP bool 72 Preemptible bool 73 Region string 74 Scopes []string 75 ServiceAccountEmail string 76 Subnetwork string 77 Tags []string 78 Zone string 79 } 80 81 // WindowsPasswordConfig is the data structue that GCE needs to encrypt the created 82 // windows password. 83 type WindowsPasswordConfig struct { 84 key *rsa.PrivateKey 85 password string 86 UserName string `json:"userName"` 87 Modulus string `json:"modulus"` 88 Exponent string `json:"exponent"` 89 Email string `json:"email"` 90 ExpireOn time.Time `json:"expireOn"` 91 } 92 93 type windowsPasswordResponse struct { 94 UserName string `json:"userName"` 95 PasswordFound bool `json:"passwordFound"` 96 EncryptedPassword string `json:"encryptedPassword"` 97 Modulus string `json:"modulus"` 98 Exponent string `json:"exponent"` 99 ErrorMessage string `json:"errorMessage"` 100 }