Esempio n. 1
0
func runDestroy(cmd *cobra.Command, args []string) {
	if len(args) != 0 {
		fmt.Fprintf(os.Stderr, "Unrecognized args in ore list cmd: %v\n", args)
		os.Exit(2)
	}

	// avoid wiping out all instances in project or mishaps with short destroyPrefixes
	if destroyPrefix == "" || len(destroyPrefix) < 2 {
		fmt.Fprintf(os.Stderr, "Please specify a prefix of length 2 or greater with -prefix\n")
		os.Exit(1)
	}

	client, err := auth.GoogleClient()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Authentication failed: %v\n", err)
		os.Exit(1)
	}

	vms, err := platform.GCEListVMs(client, destroyProject, destroyZone, destroyPrefix)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed listing vms: %v\n", err)
		os.Exit(1)
	}
	var count int
	for _, vm := range vms {
		err := platform.GCEDestroyVM(client, destroyProject, destroyZone, vm.ID())
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed destroying vm: %v\n", err)
			os.Exit(1)
		}
		count++
	}
	fmt.Printf("%v instance(s) scheduled for deletion\n", count)
}
Esempio n. 2
0
func runList(cmd *cobra.Command, args []string) {
	if len(args) != 0 {
		fmt.Fprintf(os.Stderr, "Unrecognized args in plume list cmd: %v\n", args)
		os.Exit(2)
	}

	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)
	}
	vms, err := platform.GCEListVMs(api, &opts, opts.BaseName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed listing vms: %v\n", err)
		os.Exit(1)
	}
	for _, vm := range vms {
		fmt.Printf("%v:\n", vm.ID())
		fmt.Printf(" extIP: %v\n", vm.IP())
	}
}
Esempio n. 3
0
func runList(cmd *cobra.Command, args []string) {
	if len(args) != 0 {
		fmt.Fprintf(os.Stderr, "Unrecognized args in plume list cmd: %v\n", args)
		os.Exit(2)
	}

	client, err := auth.GoogleClient()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Authentication failed: %v\n", err)
		os.Exit(1)
	}

	vms, err := platform.GCEListVMs(client, listProject, listZone, listPrefix)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed listing vms: %v\n", err)
		os.Exit(1)
	}
	for _, vm := range vms {
		fmt.Printf("%v:\n", vm.ID())
		fmt.Printf(" extIP: %v\n", vm.IP())
	}

}