コード例 #1
0
ファイル: locations.go プロジェクト: grrtrr/clcv1
func main() {
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")
	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	locations, err := client.GetLocations()
	if err != nil {
		exit.Fatalf("Failed to list queue requests: %s", err)
	}

	if len(locations) == 0 {
		println("Empty result.")
	} else if *simple {
		for _, l := range locations {
			utils.PrintStruct(l)
		}
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.SetAutoWrapText(false)

		table.SetHeader([]string{"Alias", "Region"})
		for _, l := range locations {
			table.Append([]string{l.Alias, l.Region})
		}
		table.Render()
	}
}
コード例 #2
0
ファイル: snapshot_delete.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var snapName = flag.String("s", "", "The name of the Snapshot to delete")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *snapName == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	err = client.DeleteSnapshot(*snapName, flag.Arg(0), *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to delete snapshot on %s: %s", flag.Arg(0), err)
	}

	fmt.Printf("Successfully deleted snapshot %q from %s.\n", *snapName, flag.Arg(0))
}
コード例 #3
0
func main() {
	var acctAlias = flag.String("a", "", "Account alias of the account that owns the servers")
	var location = flag.String("l", "", "The data center location")
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")

	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	servers, err := client.GetAllServersForAccountHierarchy(*acctAlias, *location)
	if err != nil {
		exit.Fatalf("Failed to list all servers: %s", err)
	}

	// FIXME: simple representation only, since currently not able to test
	//       (StatusCode 2, null result)
	*simple = true
	if len(servers) == 0 {
		println("Empty result.")
	} else if *simple {
		for _, s := range servers {
			utils.PrintStruct(s)
		}
	}
}
コード例 #4
0
ファイル: account_summary.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")

	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	acctSummary, err := client.GetAccountSummary(*acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain account billing summary of %s: %s", *acctAlias, err)
	}

	if *simple {
		utils.PrintStruct(acctSummary)
	} else {
		fmt.Printf("Total charges during this hour:     $%.2f\n", acctSummary.CurrentHour)
		fmt.Printf("Total charges during previous hour: $%.2f\n", acctSummary.PreviousHour)
		fmt.Printf("Total hourly charges this month:    $%.2f\n", acctSummary.MonthToDate)
		fmt.Printf("Total one-time charges this month:  $%.2f\n", acctSummary.OneTimeCharges)
		fmt.Printf("Total overall charges this month:   $%.2f\n", acctSummary.MonthToDateTotal)
		fmt.Printf("Corresponding monthly estimate:     $%.2f\n", acctSummary.MonthlyEstimate)

	}
}
コード例 #5
0
ファイル: rootGroup.go プロジェクト: grrtrr/clcv1
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Location>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}
	flag.Parse()

	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	rootGroup, err := client.GetRootGroup(flag.Arg(0))
	if err != nil {
		exit.Fatalf("Failed to list root group: %s", err)
	}

	fmt.Println("Location:   ", flag.Arg(0))
	fmt.Println("Root Group: ", rootGroup.Name)
	fmt.Println("UUID:       ", rootGroup.UUID)
}
コード例 #6
0
ファイル: disk_resize.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var busId = flag.String("bus", "", "The SCSI bus ID of the disk")
	var devId = flag.String("dev", "", "The SCSI device ID of the disk")
	var newSize = flag.Int("s", 0, "The expanded size of the disk")
	var expand = flag.Bool("e", false, "Expand the filesystem on the disk after the resize")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *busId == "" || *devId == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.ResizeDisk(flag.Arg(0), *acctAlias, *busId, *devId, *newSize, *expand)
	if err != nil {
		exit.Fatalf("Failed to resize disk on %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for resizing server disk:", reqId)
}
コード例 #7
0
ファイル: template_from_server.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var password = flag.String("pass", "", "Administrator/root password for the server to convert")
	var templAlias = flag.String("alias", "TEMPL", "The alias for the Template to create")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *password == "" || *templAlias == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.ConvertServerToTemplate(flag.Arg(0), *password, *templAlias, *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to convert %s into a template: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for converting server:", reqId)
}
コード例 #8
0
ファイル: deployment_status.go プロジェクト: grrtrr/clcv1
func main() {
	var location = flag.String("l", "", "The location of the deployment to retrieve status for (required)")
	var pollIntvl = flag.Int("i", 1, "Poll interval in seconds (to monitor progress")
	var acctAlias = flag.String("a", "", "Account alias to use")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Request-ID>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *location == "" {
		flag.Usage()
		os.Exit(1)
	}

	reqId, err := strconv.ParseUint(flag.Arg(0), 10, 32)
	if err != nil {
		exit.Errorf("Invalid Request ID %q: %s", flag.Arg(0), err)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	err = client.PollDeploymentStatus(int(reqId), *location, *acctAlias, *pollIntvl)
	if err != nil {
		exit.Fatalf("Failed to poll status of request ID %d: %s", reqId, err)
	}
}
コード例 #9
0
ファイル: show_account_policy.go プロジェクト: grrtrr/clcv2
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Account-Policy-ID>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(0)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	p, err := client.SBSgetPolicy(flag.Arg(0))
	if err != nil {
		exit.Fatalf("failed to list SBS account policy %s: %s", flag.Arg(0), err)
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.SetAutoWrapText(false)
	table.SetHeader([]string{"Name", "Policy ID", "OS", "Status", "Freq/h", "Ret/d", "Paths"})

	table.Append([]string{p.Name, p.PolicyID, p.OsType, p.Status, fmt.Sprint(p.BackupIntervalHours),
		fmt.Sprint(p.RetentionDays), strings.Join(p.Paths, ", ")})
	table.Render()
}
コード例 #10
0
ファイル: details.go プロジェクト: grrtrr/clcv1
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s <Account-Alias>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(0)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	acctDetails, err := client.GetAccountDetails(flag.Arg(0))
	if err != nil {
		exit.Fatalf("Failed to obtain account details of %s: %s", flag.Arg(0), err)
	}

	utils.PrintStruct(acctDetails)
}
コード例 #11
0
ファイル: convert_to_server.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var hwGrpUUID = flag.String("u", "", "UUID of the Hardware Group to place the converted server in")
	var password = flag.String("pass", "", "New administrator/root password for the converted server")
	var network = flag.String("net", "", "Name of the network to use for the converted server")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *password == "" || *hwGrpUUID == "" || *network == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.ConvertTemplateToServer(flag.Arg(0), *password, *hwGrpUUID, *network, *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to generate a server from %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for converting template:", reqId)
}
コード例 #12
0
ファイル: set_cpu.go プロジェクト: grrtrr/clcv2
func main() {
	var cpus = flag.Int("cpu", 0, "The number of CPU cores to set for this server")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *cpus == 0 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	statusId, err := client.ServerSetCpus(flag.Arg(0), fmt.Sprint(*cpus))
	if err != nil {
		exit.Fatalf("failed to change the number of CPUs on %q: %s", flag.Arg(0), err)
	}

	fmt.Printf("Status Id for changing the #CPUs on %s: %s\n", flag.Arg(0), statusId)
}
コード例 #13
0
ファイル: set_description.go プロジェクト: grrtrr/clcv2
func main() {
	var description = flag.String("desc", "", "New description to use for the server")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *description == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	err = client.ServerSetDescription(flag.Arg(0), *description)
	if err != nil {
		exit.Fatalf("failed to change the description on %q: %s", flag.Arg(0), err)
	}

	fmt.Printf("Successfully changed the description on %s.\n", flag.Arg(0))
}
コード例 #14
0
ファイル: disk_resize.go プロジェクト: grrtrr/clcv2
func main() {
	var size = flag.Uint("size", 0, "New size of the disk in GB")
	// Allow the same ID types as in disk_remove.go
	var reMajMin = regexp.MustCompile(`^\d+:\d+$`)
	var reMin = regexp.MustCompile(`^\d+$`)
	var id string

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Server-Name>  <Disk-ID>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 2 || *size == 0 {
		flag.Usage()
		os.Exit(1)
	} else if reMajMin.MatchString(flag.Arg(1)) {
		id = flag.Arg(1)
	} else if reMin.MatchString(flag.Arg(1)) {
		id = fmt.Sprintf("0:%s", flag.Arg(1))
	} else {
		exit.Errorf("invalid disk ID %q", flag.Arg(1))
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	server, err := client.GetServer(flag.Arg(0))
	if err != nil {
		exit.Fatalf("failed to list details of server %q: %s", flag.Arg(0), err)
	}

	disks := make([]clcv2.ServerAdditionalDisk, len(server.Details.Disks))
	for i := range server.Details.Disks {
		disks[i] = clcv2.ServerAdditionalDisk{
			Id:     server.Details.Disks[i].Id,
			SizeGB: server.Details.Disks[i].SizeGB,
		}
		if disks[i].Id == id {
			// The API does not allow to reduce the size of an existing disk.
			if uint32(*size) <= disks[i].SizeGB {
				fmt.Printf("Disk %s size is already at %d GB.\n", id, disks[i].SizeGB)
				os.Exit(0)
			}
			fmt.Printf("Changing disk %s size from %d to %d GB ...\n",
				id, disks[i].SizeGB, *size)
			disks[i].SizeGB = uint32(*size)
		}
	}

	reqID, err := client.ServerSetDisks(flag.Arg(0), disks)
	if err != nil {
		exit.Fatalf("failed to update the disk configuration on %q: %s", flag.Arg(0), err)
	}

	log.Printf("Status Id for resizing the disk on %s: %s", flag.Arg(0), reqID)
	client.PollStatus(reqID, 10*time.Second)
}
コード例 #15
0
ファイル: find_server_by_ip.go プロジェクト: grrtrr/clcv2
func main() {
	var location = flag.String("l", "", "Alias of the data centre the server resides in")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <IP Address>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *location == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	iad, err := client.GetNetworkDetailsByIp(flag.Arg(0), *location)
	if err != nil {
		exit.Fatalf("failed to look up %s: %s", flag.Arg(0), err)
	} else if iad == nil {
		exit.Errorf("No match found for %s in %s", flag.Arg(0), *location)
	}

	// The 'Server' field is not necessarily filled in, hence we need to test here.
	if iad.Server != "" {
		fmt.Printf("%s is used by %s.\n", iad.Address, iad.Server)
	} else {
		fmt.Printf("%s is in %s use in %s, but the server name is not disclosed.\n", iad.Address, iad.Type, *location)
	}
}
コード例 #16
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  Location-Alias\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
		os.Exit(0)
	}
	flag.Parse()

	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	capa, err := client.GetBareMetalCapabilities(flag.Arg(0))
	if err != nil {
		exit.Fatalf("failed to query bare-metal capabilities of %s: %s", flag.Arg(0), err)
	}

	fmt.Printf("Datacenter %s:\n", flag.Arg(0))
	pretty.Println(capa)
}
コード例 #17
0
ファイル: set_memory.go プロジェクト: grrtrr/clcv2
func main() {
	var memory = flag.Int("mem", 0, "The amount of memory (in GB) to set for this server")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *memory == 0 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	statusId, err := client.ServerSetMemory(flag.Arg(0), fmt.Sprint(*memory))
	if err != nil {
		exit.Fatalf("failed to change the amount of Memory on %q: %s", flag.Arg(0), err)
	}

	fmt.Printf("Status Id for changing the memory on %s: %s\n", flag.Arg(0), statusId)
}
コード例 #18
0
ファイル: snapshot_list.go プロジェクト: grrtrr/clcv2
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()

	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	snapshot, err := client.GetServerSnapshot(flag.Arg(0))
	if err != nil {
		exit.Fatalf("failed to query snapshots of %s: %s", flag.Arg(0), err)
	}

	if snapshot == nil {
		fmt.Printf("Server %s does not have any snapshots.\n", flag.Arg(0))
	} else {
		fmt.Printf("Snapshot of %s: %s\n", flag.Arg(0), snapshot.Name)
	}
}
コード例 #19
0
ファイル: maintenance_toggle.go プロジェクト: grrtrr/clcv2
func main() {
	var maintenance = flag.Bool("m", true, "Turn maintenance mode on (-m) or off (-m=false)")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	statusId, err := client.ServerSetMaintenance(flag.Arg(0), *maintenance)
	if err != nil {
		exit.Fatalf("failed to modify maintenance mode on server %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for maintenance mode status change:", statusId)
}
コード例 #20
0
ファイル: custom_fields.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")

	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	customFields, err := client.GetCustomFields(*acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain Custom Fields of %s: %s", *acctAlias, err)
	}

	if len(customFields) == 0 {
		println("Empty result.")
	} else {
		for _, cf := range customFields {
			utils.PrintStruct(cf)
		}
	}
}
コード例 #21
0
ファイル: maintenance.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var maintenance = flag.Bool("m", false, "Turn maintenance mode on (-m) or off (-m=false)")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <HW Group UUID>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.HardwareGroupMaintenance(*maintenance, flag.Arg(0), *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to modify maintenance mode: %s", err)
	}

	fmt.Println("Request ID for group maintenance status change:", reqId)
}
コード例 #22
0
ファイル: get_credentials.go プロジェクト: grrtrr/clcv2
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()

	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	credentials, err := client.GetServerCredentials(flag.Arg(0))
	if err != nil {
		exit.Fatalf("failed to obtain the credentials of server %q: %s", flag.Arg(0), err)
	}

	fmt.Printf("Credentials for %s:\n", flag.Arg(0))
	fmt.Printf("User:     %s\n", credentials.Username)
	fmt.Printf("Password: \"%s\"\n", credentials.Password)
}
コード例 #23
0
ファイル: restore.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var hwGrpUUID = flag.String("u", "", "UUID of the Hardware Group to restore the server to")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.RestoreServer(flag.Arg(0), *acctAlias, *hwGrpUUID)
	if err != nil {
		exit.Fatalf("Failed to restore server %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for restoring server:", reqId)
}
コード例 #24
0
ファイル: ip.go プロジェクト: grrtrr/clcv2
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Server Name> [<Server Name> ...]\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() == 0 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	for _, srv := range flag.Args() {
		ips, err := client.GetServerIPs(srv)
		if err != nil {
			exit.Fatalf("failed to list details of server %q: %s", srv, err)
		}

		fmt.Printf("%-20s %s\n", srv+":", strings.Join(ips, ", "))
	}
}
コード例 #25
0
ファイル: history.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")

	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	bh, err := client.GetBillingHistory(*acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain billing history: %s", err)
	}

	fmt.Printf("Billing history for %s:\n", bh.AccountAlias)
	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_RIGHT)
	table.SetAutoWrapText(true)

	table.SetHeader([]string{"Date", "Debit", "Credit", "ID", "Description"})

	for _, le := range bh.BillingHistory {
		table.Append([]string{
			le.Date.Time.Format("Jan 2006"),
			fmt.Sprintf("%.2f", le.Debit),
			fmt.Sprintf("%.2f", le.Credit),
			le.InvoiceID, le.Description,
		})
	}
	table.Render()
}
コード例 #26
0
ファイル: create.go プロジェクト: grrtrr/clcv2
func main() {
	var location = flag.String("l", "", "Location alias of data centre to host load balancer")
	var desc = flag.String("desc", "", "Textual description of the load balancer")
	var status = flag.String("status", "enabled", "Whether to an 'enabled' or 'disabled' load balancer")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Load Balancer Name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	fmt.Println(flag.NArg())
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	lb, err := client.CreateSharedLoadBalancer(flag.Arg(0), *desc, *status, *location)
	if err != nil {
		exit.Fatalf("failed to create shared load balancer %q: %s", flag.Arg(0), err)
	}

	fmt.Printf("Created %s load balancer %s, %q with IP %s\n", *location, lb.ID, lb.Name, lb.IpAddress)
}
コード例 #27
0
ファイル: get_credentials.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()

	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	credentials, err := client.GetServerCredentials(flag.Arg(0), *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain the credentials of server %q: %s", flag.Arg(0), err)
	}

	fmt.Printf("Credentials for %s:\n", flag.Arg(0))
	fmt.Printf("User:     %s\n", credentials.Username)
	fmt.Printf("Password: '******'\n", credentials.Password)
}
コード例 #28
0
ファイル: list.go プロジェクト: grrtrr/clcv1
func main() {
	flag.Parse()

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	accts, err := client.GetAccounts()
	if err != nil {
		exit.Fatalf("Failed to obtain account list: %s", err)
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.SetAutoWrapText(true)

	table.SetHeader([]string{"Account", "Parent", "Location", "Business Name"})
	for _, a := range accts {
		var acct = a.AccountAlias

		if !a.IsActive {
			acct += " (INACTIVE)"
		}
		table.Append([]string{acct, a.ParentAlias, a.Location, a.BusinessName})
	}
	table.Render()
}
コード例 #29
0
ファイル: archive.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <HW Group UUID>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.ArchiveHardwareGroup(flag.Arg(0), *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to archive Hardware Group %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for group archival:", reqId)
}
コード例 #30
0
ファイル: disk_delete.go プロジェクト: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var busId = flag.String("bus", "", "The SCSI bus ID of the disk")
	var devId = flag.String("dev", "", "The SCSI device ID of the disk")
	var force = flag.Bool("force", false, "Override safety checks required for primary/OS disks")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <server-name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	if flag.NArg() != 1 || *busId == "" || *devId == "" {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
	if err != nil {
		exit.Fatal(err.Error())
	} else if err := client.Logon("", ""); err != nil {
		exit.Fatalf("Login failed: %s", err)
	}

	reqId, err := client.DeleteDisk(flag.Arg(0), *acctAlias, *busId, *devId, *force)
	if err != nil {
		exit.Fatalf("Failed to delete disk on %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for server disk deletion:", reqId)
}