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()
	}
}
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)
		}
	}
}
Example #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 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 #4
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 #5
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 #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
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()
	}
}
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 #9
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()
	}
}
Example #10
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()
	}
}
Example #11
0
File: list.go Project: grrtrr/clcv1
func main() {
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")

	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)
	}

	users, err := client.GetUsers(flag.Arg(0))
	if err != nil {
		exit.Fatalf("Failed to list users of %s: %s", flag.Arg(0), err)
	}

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

		table.SetHeader([]string{"Username", "First", "Last", "Email", "Roles"})
		for _, u := range users {
			table.Append([]string{u.UserName, u.FirstName, u.LastName,
				u.EmailAddress, fmt.Sprint(u.Roles)})
		}
		table.Render()
	}
}
Example #12
0
File: list.go Project: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias of the account in question")
	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()

	/* The Location argument is always required */
	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)
	}

	groups, err := client.GetGroups(flag.Arg(0), *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain hardware groups: %s", err)
	}

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

		table.SetHeader([]string{"Name", "UUID", "Parent UUID", "System Group?"})
		for _, g := range groups {
			table.Append([]string{g.Name, g.UUID, g.ParentUUID, fmt.Sprint(g.IsSystemGroup)})
		}
		table.Render()
	}
}
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.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Username>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}
	flag.Parse()

	if flag.NArg() != 1 || *acctAlias == "" {
		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)
	}

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

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

		table.SetHeader([]string{"User", "SAML", "First", "Last", "Email", "Roles"})
		table.Append([]string{
			user.UserName, user.SAMLUserName,
			user.FirstName, user.LastName,
			user.EmailAddress, fmt.Sprint(user.Roles),
		})
		table.Render()
	}
}
Example #14
0
func main() {
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")
	var location = flag.String("l", "", "Data center location")
	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)
	}

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

	if *location != "" {
		fmt.Printf("Archived servers in %s:\n", *location)
	}
	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"})
		for _, s := range servers {
			table.Append([]string{s.Name, s.Description})
		}
		table.Render()
	}

}
Example #15
0
File: list.go Project: grrtrr/clcv1
func main() {
	var acctAlias = flag.String("a", "", "Account alias of the account in question")
	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]))
		fmt.Fprintf(os.Stderr, "       Leave Location emtpy to mean home datacenter.\n")
		flag.PrintDefaults()
	}
	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)
	}

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

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

		table.SetHeader([]string{"Gateway", "Name", "Description", "Account", "Location"})
		for _, l := range networks {
			table.Append([]string{l.Gateway, l.Name, l.Description, l.AccountAlias, l.Location})
		}
		table.Render()
	}
}
Example #16
0
func main() {
	var visib = flag.Int("v", 1, "The visibility level of the Blueprint")
	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)
	}

	blueprints, err := client.GetBlueprints(&clcv1.SearchBlueprintReq{Visibility: *visib})
	if err != nil {
		exit.Fatalf("Failed to list blueprints: %s", err)
	}

	for _, b := range blueprints {
		utils.PrintStruct(b)
	}
}
Example #17
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)
	}

	templates, err := client.GetServerTemplates()
	if err != nil {
		exit.Fatalf("Failed to list account server templates: %s", err)
	}

	if len(templates) == 0 {
		println("Empty result.")
	} else if *simple {
		for _, t := range templates {
			utils.PrintStruct(t)
		}
	} else {
		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", "Loc"})

		for _, t := range templates {
			table.Append([]string{
				t.Name, t.Description, fmt.Sprint(t.OperatingSystem),
				fmt.Sprint(t.DiskCount), fmt.Sprint(t.TotalDiskSpaceGB),
				t.Location,
			})
		}
		table.Render()
	}
}
Example #18
0
File: list.go Project: grrtrr/clcv1
func main() {
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")
	var status = flag.Int("s", 1, "Status type to look for: 1 - All, 2 - Pending, 3 - Complete, 4 - Error")
	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)
	}

	requests, err := client.ListQueueRequests(clcv1.ItemStatus(*status))
	if err != nil {
		exit.Fatalf("Failed to list queue requests: %s", err)
	}

	if *simple {
		for _, r := range requests {
			utils.PrintStruct(r)
		}
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.SetAutoWrapText(false)

		table.SetHeader([]string{"ID", "Status", "%", "Step", "Title", "Date"})
		for _, r := range requests {
			table.Append([]string{fmt.Sprint(r.RequestID), r.CurrentStatus,
				fmt.Sprint(r.PercentComplete), fmt.Sprint(r.StepNumber),
				r.RequestTitle,
				r.StatusDate.Format("Mon, _2 Jan 2006 15:04:05 MST"),
			})
		}

		table.Render()
	}
}
Example #19
0
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]  <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)
	}

	srvEst, err := client.GetServerEstimate(flag.Arg(0), *acctAlias)
	if err != nil {
		exit.Fatalf("Failed to obtain server estimate for %s: %s", flag.Arg(0), err)
	}

	if *simple {
		utils.PrintStruct(srvEst)
	} else {
		fmt.Printf("Usage and corresponding monthly estimate for %s:\n", flag.Arg(0))
		fmt.Printf("Charges incurred this hour:   $%.2f\n", srvEst.CurrentHour)
		fmt.Printf("Charges during previous hour: $%.2f\n", srvEst.PreviousHour)
		fmt.Printf("Charges incurred up to today: $%.2f\n", srvEst.MonthToDate)
		fmt.Printf("Predicted monthly cost:       $%.2f\n", srvEst.MonthlyEstimate)
	}
}
Example #20
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]  <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)
	}

	server, 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(server)
	} else {
		grp, err := client.GetGroupByUUID(server.HardwareGroupUUID, server.Location, *acctAlias)
		if err != nil {
			exit.Fatalf("Failed to resolve group UUID: %s", err)
		}

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

		table.SetHeader([]string{
			"Name", "Group", "Description", "OS",
			"CPU", "Disk",
			"IP", "Power", "Last Change",
		})

		/* Also display public IP address(es) if configured. */
		IPs := []string{server.IPAddress}
		for _, ip := range server.IPAddresses {
			if ip.IsPublic() {
				IPs = append([]string{ip.Address}, IPs...)
			}
		}

		modifiedStr := humanize.Time(server.DateModified.Time)
		/* The ModifiedBy field can be an email address, or an API Key (hex string) */
		if _, err := hex.DecodeString(server.ModifiedBy); err == nil {
			modifiedStr += " via API Key"
		} else if len(server.ModifiedBy) > 6 {
			modifiedStr += " by " + server.ModifiedBy[:6]
		} else {
			modifiedStr += " by " + server.ModifiedBy
		}

		table.Append([]string{
			server.Name, grp.Name, server.Description, fmt.Sprint(server.OperatingSystem),
			fmt.Sprint(server.Cpu), fmt.Sprintf("%dGB", server.TotalDiskSpaceGB),
			strings.Join(IPs, " "),
			server.PowerState, modifiedStr,
		})
		table.Render()
	}
}