()
| 23 | ) |
| 24 | |
| 25 | func runGCPCmd() *cobra.Command { |
| 26 | var ( |
| 27 | name string |
| 28 | zoneFlag string |
| 29 | machineFlag string |
| 30 | keysFlag string |
| 31 | projectFlag string |
| 32 | skipCleanup bool |
| 33 | nestedVirt bool |
| 34 | vTPM bool |
| 35 | data string |
| 36 | dataPath string |
| 37 | ) |
| 38 | |
| 39 | cmd := &cobra.Command{ |
| 40 | Use: "gcp", |
| 41 | Short: "launch a GCP instance", |
| 42 | Long: `Launch a GCP instance. |
| 43 | 'image' specifies either the name of an already uploaded GCP image, |
| 44 | or the full path to a image file which will be uploaded before it is run. |
| 45 | `, |
| 46 | Args: cobra.ExactArgs(1), |
| 47 | Example: "linuxkit run gcp [options] [image]", |
| 48 | RunE: func(cmd *cobra.Command, args []string) error { |
| 49 | image := args[0] |
| 50 | |
| 51 | if data != "" && dataPath != "" { |
| 52 | return errors.New("cannot specify both -data and -data-file") |
| 53 | } |
| 54 | |
| 55 | if name == "" { |
| 56 | name = image |
| 57 | } |
| 58 | |
| 59 | if dataPath != "" { |
| 60 | dataB, err := os.ReadFile(dataPath) |
| 61 | if err != nil { |
| 62 | return fmt.Errorf("unable to read metadata file: %v", err) |
| 63 | } |
| 64 | data = string(dataB) |
| 65 | } |
| 66 | |
| 67 | zone := getStringValue(zoneVar, zoneFlag, defaultZone) |
| 68 | machine := getStringValue(machineVar, machineFlag, defaultMachine) |
| 69 | keys := getStringValue(keysVar, keysFlag, "") |
| 70 | project := getStringValue(projectVar, projectFlag, "") |
| 71 | |
| 72 | client, err := NewGCPClient(keys, project) |
| 73 | if err != nil { |
| 74 | return fmt.Errorf("unable to connect to GCP: %v", err) |
| 75 | } |
| 76 | |
| 77 | if err = client.CreateInstance(name, image, zone, machine, disks, &data, nestedVirt, vTPM, true); err != nil { |
| 78 | return err |
| 79 | } |
| 80 | |
| 81 | if err = client.ConnectToInstanceSerialPort(name, zone); err != nil { |
| 82 | return err |
no test coverage detected