func runCreate(cmd *cobra.Command, args []string) { if len(args) != 0 { fmt.Fprintf(os.Stderr, "Unrecognized args in ore create-instances: %v\n", args) os.Exit(2) } if createImageName == "" { fmt.Fprintf(os.Stderr, "Must specifcy GCE image with '-image' flag\n") os.Exit(2) } // if base name is unspecified use image name if createBaseName == "" { createBaseName = createImageName } var cloudConfig string if createConfig != "" { b, err := ioutil.ReadFile(createConfig) if err != nil { fmt.Fprintf(os.Stderr, "Could not read cloud config file: %v\n", err) os.Exit(1) } cloudConfig = string(b) } client, err := auth.GoogleClient() if err != nil { fmt.Fprintf(os.Stderr, "Authentication failed: %v\n", err) os.Exit(1) } opts := &platform.GCEOpts{ Client: client, CloudConfig: cloudConfig, Project: createProject, Zone: createZone, MachineType: createMachine, BaseName: createBaseName, Image: createImageName, } var vms []platform.Machine for i := 0; i < createNumInstances; i++ { vm, err := platform.GCECreateVM(opts) if err != nil { fmt.Fprintf(os.Stderr, "Failed creating vm: %v\n", err) os.Exit(1) } vms = append(vms, vm) fmt.Println("Instance created") } fmt.Printf("All instances created, add your ssh keys here: https://console.developers.google.com/project/%v/compute/metadata/sshKeys\n", createProject) for _, vm := range vms { fmt.Printf("To access %v use cmd:\n", vm.ID()) fmt.Printf("ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no core@%v\n", vm.IP()) } }
func runCreate(cmd *cobra.Command, args []string) { if len(args) != 0 { fmt.Fprintf(os.Stderr, "Unrecognized args in ore create-instances: %v\n", args) os.Exit(2) } var cloudConfig string if createConfig != "" { b, err := ioutil.ReadFile(createConfig) if err != nil { fmt.Fprintf(os.Stderr, "Could not read cloud config file: %v\n", err) os.Exit(1) } cloudConfig = string(b) } client, err := auth.GoogleClient() if err != nil { fmt.Fprintf(os.Stderr, "Authentication failed: %v\n", err) os.Exit(1) } api, err := compute.New(client) if err != nil { fmt.Fprintf(os.Stderr, "Api Client creation failed: %v\n", err) os.Exit(1) } var vms []platform.Machine for i := 0; i < createNumInstances; i++ { vm, err := platform.GCECreateVM(api, &opts, cloudConfig) if err != nil { fmt.Fprintf(os.Stderr, "Failed creating vm: %v\n", err) os.Exit(1) } vms = append(vms, vm) fmt.Println("Instance created") } fmt.Printf("All instances created, add your ssh keys here: https://console.developers.google.com/project/%v/compute/metadata/sshKeys\n", opts.Project) for _, vm := range vms { fmt.Printf("To access %v use cmd:\n", vm.ID()) fmt.Printf("ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no core@%v\n", vm.IP()) } }