Example #1
0
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()
	}
}
Example #2
0
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)
}
Example #3
0
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)
}
Example #4
0
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)
}
Example #5
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 hwGrpUUID = flag.String("u", "", "UUID of the Hardware Group")
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")

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

	flag.Parse()
	if flag.NArg() != 0 && *location != "" {
		flag.Usage()
		os.Exit(1)
	} else if flag.NArg() == 1 {
		*location = flag.Arg(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)
	}

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

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

		table.SetHeader([]string{
			"Name", "Description",
			"#CPU", "#Disk", "Disk",
			"OS", "IP", "Power", "Who modified", "Modified date",
		})
		for _, s := range servers {
			table.Append([]string{
				s.Name, s.Description,
				fmt.Sprint(s.Cpu), fmt.Sprint(s.DiskCount), fmt.Sprint(s.TotalDiskSpaceGB),
				fmt.Sprintf("%25.25s", s.OperatingSystem), s.IPAddress,
				s.PowerState, fmt.Sprintf("%12.12s", s.ModifiedBy),
				s.DateModified.Format("Jan _2/06 15:04"),
			})
		}
		table.Render()
	}
}
Example #6
0
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)
}
Example #7
0
// addRawDisk adds storage in form of a raw disk to a server
// @client:   authenticated CLCv2 client
// @servname: server name
// @diskGB:   amount of storage in GB to add to @servname
func addRawDisk(client *clcv2.CLIClient, servname string, diskGB uint32) (statusId string) {
	/* First get the list of disks */
	server, err := client.GetServer(servname)
	if err != nil {
		exit.Fatalf("failed to list details of server %q: %s", servname, 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,
		}
	}

	statusId, err = client.ServerSetDisks(servname, append(disks,
		clcv2.ServerAdditionalDisk{
			SizeGB: diskGB,
			Type:   "raw",
		}))
	if err != nil {
		exit.Fatalf("failed to update the disk configuration on %q: %s", servname, err)
	}
	return statusId
}
Example #8
0
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)
		}
	}
}
Example #9
0
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)
}
Example #10
0
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)
}
Example #11
0
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)
}
Example #12
0
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)
}
Example #13
0
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)

	}
}
Example #14
0
File: list.go Project: 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()
}
Example #15
0
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)
}
Example #16
0
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))
}
Example #17
0
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()
}
Example #18
0
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)
	}

	reqId, err := client.SnapshotServer(flag.Arg(0), *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to take snapshot of server %s: %s", flag.Arg(0), err)
	}

	fmt.Println("Request ID for taking server snapshot:", reqId)
}
Example #19
0
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)
}
Example #20
0
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)
	}
}
Example #21
0
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)
}
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)
		}
	}
}
func main() {
	var policies []clcv2.SBSServerPolicy
	var day = time.Now()
	var date = flag.String("start", day.Format("2006-01-02"), "Day to query storage usage for")
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Server-Policy-ID | Server-Name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

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

	day, err := time.Parse("2006-01-02", *date)
	if err != nil {
		exit.Error("invalid backup query date %s (expected format: YYYY-MM-DD)", *date)
	}

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

	// First look up the corresponding Server Policy or Policies, since the query needs the Account Policy ID.
	if utils.LooksLikeServerName(flag.Arg(0)) {
		policies, err = client.SBSgetServerPolicyDetails(flag.Arg(0))
		if err != nil {
			exit.Fatalf("failed to list SBS policies for server %s: %s", flag.Arg(0), err)
		}
	} else {
		p, err := client.SBSgetServerPolicy(flag.Arg(0))
		if err != nil {
			exit.Fatalf("failed to list SBS Server Policy %s: %s", flag.Arg(0), err)
		}
		policies = []clcv2.SBSServerPolicy{*p}
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetAutoFormatHeaders(false)
	table.SetAlignment(tablewriter.ALIGN_CENTRE)
	table.SetAutoWrapText(false)
	table.SetHeader([]string{"Server",
		fmt.Sprintf("Usage on %s", day.Format("Mon, Jan 2 2006")),
		"Server Policy ID", "Account Policy ID",
	})

	for _, p := range policies {
		usage, err := client.SBSgetServerStorageUsage(p.AccountPolicyID, p.ID, day)
		if err != nil {
			exit.Fatalf("failed to obtain server %s storage use on %s: %s", p.ServerID, day.Format("2006-01-02"), err)
		}
		table.Append([]string{p.ServerID, humanize.Bytes(usage), p.ID, p.AccountPolicyID})
	}
	table.Render()
}
Example #24
0
func main() {
	// Allow two types of ID: (a) <major>:<minor> syntax, (b) <minor> syntax
	var reMajMin = regexp.MustCompile(`^\d+:\d+$`)
	var reMin = regexp.MustCompile(`^\d+$`)
	var ids []string

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

	flag.Parse()
	if flag.NArg() < 2 {
		flag.Usage()
		os.Exit(1)
	}

	for i := 1; i < flag.NArg(); i++ {
		if reMajMin.MatchString(flag.Arg(i)) {
			ids = append(ids, flag.Arg(i))
		} else if reMin.MatchString(flag.Arg(i)) {
			ids = append(ids, fmt.Sprintf("0:%s", flag.Arg(i)))
		} else {
			exit.Errorf("invalid disk ID %q", flag.Arg(i))
		}
	}

	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, 0)
	for i := range server.Details.Disks {
		if inStringArray(server.Details.Disks[i].Id, ids...) {
			fmt.Printf("Deleting disk %s (%d GB) ...\n", server.Details.Disks[i].Id, server.Details.Disks[i].SizeGB)
		} else {
			disks = append(disks, clcv2.ServerAdditionalDisk{
				Id:     server.Details.Disks[i].Id,
				SizeGB: server.Details.Disks[i].SizeGB,
			})
		}
	}

	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 updating the disks on %s: %s", flag.Arg(0), reqID)
	client.PollStatus(reqID, 5*time.Second)
}
Example #25
0
func main() {
	var acctAlias = flag.String("a", "", "Account alias of the account in question")
	var location = flag.String("l", "", "Data centre alias of the network (uses Home Data Centre by default)")
	var ips = flag.Bool("ips", false, "Also list IP addresses")
	var unclaimed = flag.Bool("free", false, "Also list unclaimed IP addresses (implies -ips)")
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Network-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)
	}

	details, err := client.GetNetworkDetails(flag.Arg(0), *acctAlias, *location)
	if err != nil {
		exit.Fatalf("Failed to query network details of %s: %s", flag.Arg(0), err)
	}

	if *simple {
		utils.PrintStruct(details)
	} else {
		fmt.Printf("Details for %s (%s) at %s:\n", details.Name, details.Description, details.Location)
		fmt.Printf("Gateway: %s\n", details.Gateway)
		fmt.Printf("Netmask: %s\n", details.NetworkMask)

		if !*ips && !*unclaimed {
			return
		}
		fmt.Printf("IP addresses:\n")

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

		table.SetHeader([]string{"Address", "Type", "Claimed", "Used by"})
		for _, ip := range details.IPAddresses {
			if ip.IsClaimed || *unclaimed {
				table.Append([]string{ip.Address, ip.AddressType, fmt.Sprint(ip.IsClaimed), ip.ServerName})
			}
		}
		table.Render()
	}
}
Example #26
0
func main() {
	var acctAlias = flag.String("a", "", "Account alias to use")
	var startDate = flag.String("start", "", "Start date of the query range")
	var endDate = flag.String("end", "", "End date of the query range")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Servername>\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)
	}

	hr, err := client.GetServerHourlyCharges(flag.Arg(0), *startDate, *endDate, *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain server hourly charges for %s: %s", flag.Arg(0), err)
	}

	fmt.Printf("Hourly charges for %s (%s) from %s until %s:\n", hr.ServerName, hr.AccountAlias,
		hr.StartDate.Time.Format("2 Jan 2006 3:04PM"), hr.EndDate.Time.Format("2 Jan 2006 3:04PM"))

	fmt.Printf("\tCharges for the current hour:      $%.2f\n", hr.Summary.CurrentHour)
	fmt.Printf("\tCharges for the previous hour:     $%.2f\n", hr.Summary.PreviousHour)
	fmt.Printf("\tCurrent charges so far this month: $%.2f\n", hr.Summary.MonthToDate)
	fmt.Printf("\tEstimated monthly costs:           $%.2f\n", hr.Summary.MonthlyEstimate)

	if len(hr.HourlyCharges) > 0 {
		fmt.Println("\nHourly charges:")
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_RIGHT)
		table.SetAutoWrapText(true)

		table.SetHeader([]string{"Hour", "CPU", "Memory", "Storage", "OS"})

		for _, ch := range hr.HourlyCharges {
			table.Append([]string{ch.Hour, ch.ProcessorCost,
				ch.MemoryCost, ch.StorageCost, ch.OSCost,
			})
		}
		table.Render()
	}
}
Example #27
0
func main() {
	var policies []clcv2.SBSServerPolicy

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Server-Policy-ID | Server-Name>\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())
	}

	if utils.LooksLikeServerName(flag.Arg(0)) {
		// Note: when using the server name instead of the Server Policy ID, sometimes the Status field is empty.
		policies, err = client.SBSgetServerPolicyDetails(flag.Arg(0))
		if err != nil {
			exit.Fatalf("failed to list SBS policies for server %s: %s", flag.Arg(0), err)
		}
	} else {
		// Query by Server Policy ID
		p, err := client.SBSgetServerPolicy(flag.Arg(0))
		if err != nil {
			exit.Fatalf("failed to list SBS Server Policy %s: %s", flag.Arg(0), err)
		}
		policies = []clcv2.SBSServerPolicy{*p}
	}

	if len(policies) == 0 {
		fmt.Printf("Nothing found for %s.\n", flag.Arg(0))
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.SetAutoWrapText(false)
		table.SetHeader([]string{"Server", "Server Policy ID", "Account Policy ID",
			"Status", "Region", "Account", "Unsubscribe Date", "Expiration Date"})

		for _, p := range policies {
			table.Append([]string{p.ServerID, p.ID, p.AccountPolicyID,
				p.Status, p.StorageRegion, p.ClcAccountAlias,
				fmt.Sprint(p.UnsubscribedDate), fmt.Sprint(p.ExpirationDate)})
		}
		table.Render()
	}
}
Example #28
0
File: list.go Project: 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.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)
	}

	templates, err := client.ListAvailableServerTemplates(*acctAlias, flag.Arg(0))
	if err != nil {
		exit.Fatalf("Failed to list available templates: %s", err)
	}

	if len(templates) == 0 {
		println("Empty result.")
	} else if *simple {
		for _, t := range templates {
			utils.PrintStruct(t)
		}
	} else {
		fmt.Printf("Server templates available at %s:\n", templates[0].Location)
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.SetAutoWrapText(true)

		table.SetHeader([]string{"Name", "Description", "OS", "#Disk", "Disk/GB"})

		for _, t := range templates {
			table.Append([]string{
				t.Name, t.Description, fmt.Sprint(t.OperatingSystem),
				fmt.Sprint(t.DiskCount), fmt.Sprint(t.TotalDiskSpaceGB),
			})
		}
		table.Render()
	}
}
func main() {
	var acctAlias = flag.String("a", "", "Account alias of the account that owns the servers")
	var hwGrpUUID = flag.String("u", "", "UUID of the Hardware Group")
	var location = flag.String("l", "", "The data center location")
	var beginDate = flag.String("b", "", "Only list servers modified later than this date (defaults to yesterday)")
	var endDate = flag.String("e", "", "Only list servers modified earlier than this date (defaults to now)")
	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.GetAllServersByModifiedDates(*acctAlias, *hwGrpUUID, *location, *beginDate, *endDate)
	if err != nil {
		exit.Fatalf("Failed to list all servers: %s", err)
	}

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

		table.SetHeader([]string{
			"Name", "Description",
			"#CPU", "#Disk", "Disk",
			"OS", "IP", "Power", "Who modified", "Modified date",
		})
		for _, s := range servers {
			table.Append([]string{
				s.Name, s.Description,
				fmt.Sprint(s.Cpu), fmt.Sprint(s.DiskCount), fmt.Sprint(s.TotalDiskSpaceGB),
				fmt.Sprintf("%25.25s", s.OperatingSystem), s.IPAddress,
				s.PowerState, fmt.Sprintf("%12.12s", s.ModifiedBy),
				s.DateModified.Format("Jan _2/06 15:04"),
			})
		}
		table.Render()
	}
}
Example #30
0
File: show.go Project: 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.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Template 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)
	}

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

	if *simple {
		utils.PrintStruct(template)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.SetAutoWrapText(false)

		table.SetHeader([]string{
			"Name", "Description", "OS",
			"CPU", "Disk",
			"Last Change",
		})
		table.Append([]string{
			template.Name, template.Description, fmt.Sprint(template.OperatingSystem),
			fmt.Sprint(template.Cpu),
			fmt.Sprintf("%d GB", template.TotalDiskSpaceGB),
			fmt.Sprintf("%s by %s", humanize.Time(template.DateModified.Time), template.ModifiedBy),
		})
		table.Render()
	}
}