本文整理汇总了Golang中github.com/grrtrr/exit.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var parentUUID string
var parentGroup = flag.String("g", "", "UUID or Name (if unique and -l present) of the parent Hardware Group")
var location = flag.String("l", "", "Data centre location to use for resolving -g <Group-Name>")
var desc = flag.String("t", "", "Textual description of the new group")
var acctAlias = flag.String("a", "", "Account alias to use")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <New Group Name>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *parentGroup == "" {
flag.Usage()
os.Exit(1)
}
/* parentGroup may be hex uuid or group name */
if _, err := hex.DecodeString(*parentGroup); err == nil {
parentUUID = *parentGroup
} else if *location == "" {
exit.Errorf("Using -g <Group-Name> requires -l <Location> to be set")
}
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)
}
if parentUUID == "" {
if group, err := client.GetGroupByName(*parentGroup, *location, *acctAlias); err != nil {
exit.Errorf("Failed to resolve group name %q: %s", *parentGroup, err)
} else if group == nil {
exit.Errorf("No group named %q was found on %s", *parentGroup, *location)
} else {
parentUUID = group.UUID
}
}
g, err := client.CreateHardwareGroup(*acctAlias, parentUUID, flag.Arg(0), *desc)
if err != nil {
exit.Fatalf("Failed to create hardware group %q: %s", flag.Arg(0), err)
}
fmt.Println("New Group: ", g.Name)
fmt.Println("UUID: ", g.UUID)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:49,代码来源:create.go
示例2: main
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)
}
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:33,代码来源:deployment_status.go
示例3: main
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)
}
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:33,代码来源:find_server_by_ip.go
示例4: main
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)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:60,代码来源:disk_resize.go
示例5: main
func main() {
var parentGroup = flag.String("g", "", "UUID or Name (if unique and -l present) of the parent Hardware Group")
var location = flag.String("l", "", "Data centre location to use for resolving -g <Group-Name>")
var desc = flag.String("t", "", "Textual description of the new group")
var parentUUID string
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <New Group Name>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *parentGroup == "" {
flag.Usage()
os.Exit(1)
}
/* parentGroup may be hex uuid or group name */
if _, err := hex.DecodeString(*parentGroup); err == nil {
parentUUID = *parentGroup
} else if *location == "" {
exit.Errorf("Using -g <Group-Name> requires -l <Location> to be set")
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
if parentUUID == "" { /* resolve group name */
if group, err := client.GetGroupByName(*parentGroup, *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", *parentGroup, err)
} else if group == nil {
exit.Errorf("No group named %q was found in %s", *parentGroup, *location)
} else {
parentUUID = group.Id
}
}
g, err := client.CreateGroup(flag.Arg(0), parentUUID, *desc, []clcv2.SimpleCustomField{})
if err != nil {
exit.Fatalf("failed to create hardware group %q: %s", flag.Arg(0), err)
}
fmt.Println("New Group: ", g.Name)
fmt.Println("UUID: ", g.Id)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:46,代码来源:create.go
示例6: main
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)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:57,代码来源:disk_remove.go
示例7: main
func main() {
var hwGroup = flag.String("g", "", "UUID or name (if unique) of the HW group to restore this group to")
var location = flag.String("l", "", "Data centre alias (to resolve group and/or network ID)")
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 || *hwGroup == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
/* hwGroup may be hex uuid or group name */
if _, err := hex.DecodeString(*hwGroup); err == nil {
/* already looks like a HEX ID */
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using a HW Group UUID (%s)", *hwGroup)
} else {
fmt.Printf("Resolving ID of Hardware Group %q ...\n", *hwGroup)
if group, err := client.GetGroupByName(*hwGroup, *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", *hwGroup, err)
} else if group == nil {
exit.Errorf("No group named %q was found in %s", *hwGroup, *location)
} else {
*hwGroup = group.Id
}
}
statusId, err := client.RestoreGroup(flag.Arg(0), *hwGroup)
if err != nil {
exit.Fatalf("failed to restore group %s: %s", flag.Arg(0), err)
}
fmt.Println("Request ID for restoring group:", statusId)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:43,代码来源:restore.go
示例8: main
func main() {
var uuid string /* UUID of the HW group to delete */
var location = flag.String("l", "", "Data center location if using HW Group-Name")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <HW Group-Name or UUID>\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())
}
/* If the first argument decodes as a hex value, assume it is a Hardware Group UUID */
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
uuid = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location (-l argument) when not using a HW Group UUID")
} else {
fmt.Printf("Resolving group UUID of %s in %s ...\n", flag.Arg(0), *location)
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
uuid = grp.Id
}
}
reqId, err := client.DeleteGroup(uuid)
if err != nil {
exit.Fatalf("failed to delete hardware group: %s", err)
}
fmt.Printf("Status ID for group deletion: %s\n", reqId)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:42,代码来源:delete.go
示例9: main
func main() {
var (
query = flag.String("q", "none", "Filter IP addresses; one of 'none', 'claimed', 'free', or 'all'")
location = flag.String("l", os.Getenv("CLC_LOCATION"), "Data centre alias (needed to resolve IDs)")
simple = flag.Bool("simple", false, "Use simple (debugging) output format")
)
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] -l <Location> <Network-ID (hex)>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
/* Location is required (despite hex id), an empty location leads to a "404 Not Found" response. */
if flag.NArg() != 1 || *location == "" {
flag.Usage()
os.Exit(1)
} else if !inStringArray(*query, "none", "claimed", "free", "all") {
exit.Errorf("Invalid IP query %q. Try -h")
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
details, err := client.GetNetworkDetails(*location, flag.Arg(0), *query)
if err != nil {
exit.Fatalf("failed to query network details of %s: %s", flag.Arg(0), err)
}
if *simple {
pretty.Println(details)
} else {
fmt.Printf("Details of %s (%s):\n", details.Name, details.Description)
fmt.Printf("CIDR: %s\n", details.Cidr)
fmt.Printf("Gateway: %s\n", details.Gateway)
fmt.Printf("Type: %s\n", details.Type)
fmt.Printf("VLAN: %d\n", details.Vlan)
if len(details.IpAddresses) > 0 {
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_RIGHT)
table.SetAutoWrapText(false)
table.SetHeader([]string{"Address", "Claimed", "Server", "Type"})
for _, i := range details.IpAddresses {
table.Append([]string{i.Address, fmt.Sprint(i.Claimed), i.Server, i.Type})
}
table.Render()
}
}
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:54,代码来源:details.go
示例10: main
func main() {
var group = flag.String("g", "", "UUID or name of the new parent group")
var location = flag.String("l", "", "Location to use if -g refers to a Group-Name")
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 || *group == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
if _, err := hex.DecodeString(*group); err == nil {
/* Looks like a Group UUID */
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if -g (%s) is not a UUID", *group)
} else {
if grp, err := client.GetGroupByName(*group, *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", *group, err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", *group, *location)
} else {
*group = grp.Id
}
}
err = client.ServerSetGroup(flag.Arg(0), *group)
if err != nil {
exit.Fatalf("failed to change the parent group on %q: %s", flag.Arg(0), err)
}
fmt.Printf("Successfully changed the parent group of %s to %s.\n", flag.Arg(0), *group)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:41,代码来源:set_group.go
示例11: main
func main() {
var location = flag.String("l", "", "Location to use if using a Group-Name instead of a UUID")
var uuid string
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group Name or UUID>\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())
}
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
uuid = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using Group UUID (%s)", flag.Arg(0))
} else {
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
uuid = grp.Id
}
}
statusId, err := client.ArchiveGroup(uuid)
if err != nil {
exit.Fatalf("failed to archive group %s: %s", flag.Arg(0), err)
}
fmt.Println("Request ID for archiving group:", statusId)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:41,代码来源:archive.go
示例12: main
func main() {
var group string /* UUID of the group to change */
var newName = flag.String("n", "", "New name for the group")
var location = flag.String("l", "", "Location to use if using a Group-Name instead of a UUID")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group Name or UUID>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *newName == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
group = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using Group UUID (%s)", flag.Arg(0))
} else {
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
group = grp.Id
}
}
if err = client.GroupSetName(group, *newName); err != nil {
exit.Fatalf("failed to change the name of %q: %s", flag.Arg(0), err)
}
fmt.Printf("Successfully changed the name of %s to %q.\n", flag.Arg(0), *newName)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:41,代码来源:set_name.go
示例13: CollapseIpRanges
// Collapse an unsorted array @in of IPv4 addresses into sorted ranges in @out.
func CollapseIpRanges(in []string) (out []string) {
var start, end, prev net.IP
var ips []net.IP
for _, ip_string := range in {
ip := net.ParseIP(ip_string)
if ip == nil {
exit.Errorf("Invalid IP address %q", ip_string)
}
ip = ip.To4()
if ip == nil {
exit.Errorf("Not an IPv4 address: %q", ip_string)
}
ips = append(ips, ip)
}
sort.Stable(byIPv4Address(ips))
for _, ip := range ips {
if prev != nil && reflect.DeepEqual(ip[:3], prev[:3]) && ip[3] == prev[3]+1 {
end = ip
} else {
if end != nil {
out = append(out, fmt.Sprintf("%s-%d", start, end[3]))
end = nil
} else if prev != nil {
out = append(out, prev.String())
}
start = ip
}
prev = ip
}
if end != nil {
out = append(out, fmt.Sprintf("%s-%d", start, end[3]))
}
return out
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:38,代码来源:ip_utils.go
示例14: main
func main() {
var child string /* UUID of the group to relocate */
var parent = flag.String("g", "", "UUID or name of the new parent group")
var location = flag.String("l", "", "Location to use if using Group Name instead of UUID")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group Name or UUID>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *parent == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
child = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using Group UUID (%s)", flag.Arg(0))
} else {
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
child = grp.Id
}
}
if _, err := hex.DecodeString(*parent); err == nil {
/* Looks like a Group UUID */
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if parent (-g %s) is not a UUID", *parent)
} else {
if grp, err := client.GetGroupByName(*parent, *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", *parent, err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", *parent, *location)
} else {
*parent = grp.Id
}
}
err = client.GroupSetParent(child, *parent)
if err != nil {
exit.Fatalf("failed to change the parent group of %q: %s", flag.Arg(0), err)
}
fmt.Printf("Successfully changed the parent group of %s to %s.\n", flag.Arg(0), *parent)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:56,代码来源:set_parent.go
示例15: main
func main() {
var acctAlias = flag.String("a", "", "Account alias of the account in question")
var location = flag.String("l", "", "Data center location of @Group-Name")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group-Name>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *location == "" {
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(*location, *acctAlias)
if err != nil {
exit.Fatalf("Failed to obtain hardware groups: %s", err)
}
if len(groups) == 0 {
exit.Errorf("Empty result.")
}
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 {
if g.Name == flag.Arg(0) {
table.Append([]string{g.Name, g.UUID, g.ParentUUID, fmt.Sprint(g.IsSystemGroup)})
}
}
table.Render()
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:44,代码来源:uuid.go
示例16: showGroup
// Show group details
// @client: authenticated CLCv1 Client
// @uuid: hardware group UUID to use
// @acctAlias: account alias to use (leave blank to use default)
// @location: data centre location (needed to resolve @uuid)
func showGroup(client *clcv1.Client, uuid, acctAlias, location string) {
if location == "" {
exit.Errorf("Location is required in order to show the group hierarchy starting at %s", uuid)
}
root, err := client.GetGroupHierarchy(location, acctAlias, true)
if err != nil {
exit.Fatalf("Failed to look up groups at %s: %s", location, err)
}
start := root
if uuid != "" {
start = clcv1.FindGroupNode(root, func(g *clcv1.GroupNode) bool {
return g.UUID == uuid
})
if start == nil {
exit.Fatalf("Failed to look up UUID %s at %s", uuid, location)
}
}
clcv1.PrintGroupHierarchy(start, "")
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:24,代码来源:clc_action.go
示例17: main
func main() {
var uuid string
var simple = flag.Bool("simple", false, "Use simple (debugging) output format")
var location = flag.String("l", "", "Location to use if using a Group-Name instead of a UUID")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group Name or UUID>\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())
}
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
uuid = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using Group UUID (%s)", flag.Arg(0))
} else {
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
uuid = grp.Id
}
}
bd, err := client.GetGroupBillingDetails(uuid)
if err != nil {
exit.Fatalf("failed to query billing details of group %s: %s", flag.Arg(0), err)
}
if *simple {
pretty.Println(bd)
} else {
var totalMonthTod, totalMonthEst float64
if rootGroup, ok := bd.Groups[uuid]; !ok {
exit.Fatalf("Query result does not contain queried group %s", uuid)
} else {
fmt.Printf("Billing details of %s as of %s:\n", rootGroup.Name,
bd.Date.Format("Monday, 2 Jan 2006, 15:04 MST"))
}
for k, v := range bd.Groups {
if k == uuid || len(v.Servers) == 0 {
continue
}
fmt.Printf("\nServer details of %q (%s):\n", v.Name, k)
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_RIGHT)
table.SetAutoWrapText(true)
table.SetHeader([]string{"Server", "Template Cost", "Archive Cost", "Current Hour",
"Month to Date", "Monthly Estimate"})
for s, sbd := range v.Servers {
table.Append([]string{strings.ToUpper(s),
fmt.Sprintf("$%.2f", sbd.TemplateCost),
fmt.Sprintf("$%.2f", sbd.ArchiveCost),
fmt.Sprintf("$%.2f", sbd.CurrentHour),
fmt.Sprintf("$%.2f", sbd.MonthToDate),
fmt.Sprintf("$%.2f", sbd.MonthlyEstimate),
})
totalMonthTod += sbd.MonthToDate
totalMonthEst += sbd.MonthlyEstimate
}
table.Render()
}
fmt.Printf("\nTotal month to date: $%.2f\n", totalMonthTod)
fmt.Printf("Total monthly estimate: $%.2f\n", totalMonthEst)
}
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:84,代码来源:billing_details.go
示例18: main
func main() {
var uuid string
var simple = flag.Bool("simple", false, "Use simple (debugging) output format")
var location = flag.String("l", "", "Location to use if using a Group-Name instead of a UUID")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <Group Name or UUID>\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())
}
if _, err := hex.DecodeString(flag.Arg(0)); err == nil {
uuid = flag.Arg(0)
} else if *location == "" {
exit.Errorf("Need a location argument (-l) if not using Group UUID (%s)", flag.Arg(0))
} else {
if grp, err := client.GetGroupByName(flag.Arg(0), *location); err != nil {
exit.Errorf("failed to resolve group name %q: %s", flag.Arg(0), err)
} else if grp == nil {
exit.Errorf("No group named %q was found in %s", flag.Arg(0), *location)
} else {
uuid = grp.Id
}
}
rootNode, err := client.GetGroup(uuid)
if err != nil {
exit.Fatalf("failed to query HW group %s: %s", flag.Arg(0), err)
}
if *simple {
pretty.Println(rootNode)
} else {
fmt.Printf("Group %q in %s:\n", rootNode.Name, rootNode.LocationId)
fmt.Printf("ID: %s\n", rootNode.Id)
fmt.Printf("Description: %s\n", rootNode.Description)
fmt.Printf("Type: %s\n", rootNode.Type)
fmt.Printf("Status: %s\n", rootNode.Status)
if len(rootNode.CustomFields) > 0 {
fmt.Println("Custom fields:", rootNode.CustomFields)
}
// ChangeInfo
createdStr := humanize.Time(rootNode.ChangeInfo.CreatedDate)
/* The CreatedBy field can be an email address, or an API Key (hex string) */
if _, err := hex.DecodeString(rootNode.ChangeInfo.CreatedBy); err == nil {
createdStr += " via API Key"
} else {
createdStr += " by " + rootNode.ChangeInfo.CreatedBy
}
fmt.Printf("Created: %s\n", createdStr)
modifiedStr := humanize.Time(rootNode.ChangeInfo.ModifiedDate)
/* The ModifiedBy field can be an email address, or an API Key (hex string) */
if _, err := hex.DecodeString(rootNode.ChangeInfo.ModifiedBy); err == nil {
modifiedStr += " via API Key"
} else {
modifiedStr += " by " + rootNode.ChangeInfo.ModifiedBy
}
fmt.Printf("Modified: %s\n", modifiedStr)
// Servers
fmt.Printf("#Servers: %d\n", rootNode.Serverscount)
if rootNode.Serverscount > 0 {
var servers []string
if sl := clcv2.ExtractLinks(rootNode.Links, "server"); len(sl) > 0 {
for _, s := range sl {
servers = append(servers, s.Id)
}
fmt.Printf("Servers: %s\n", strings.Join(servers, ", "))
}
}
// Sub-groups
if len(rootNode.Groups) > 0 {
fmt.Printf("\nGroups of %s:\n", rootNode.Name)
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(true)
table.SetHeader([]string{"Name", "UUID", "Description", "#Servers", "Type"})
for _, g := range rootNode.Groups {
table.Append([]string{g.Name, g.Id, g.Description, fmt.Sprint(g.Serverscount), g.Type})
}
table.Render()
} else {
fmt.Printf("Sub-groups: none\n")
//.........这里部分代码省略.........
开发者ID:grrtrr,项目名称:clcv2,代码行数:101,代码来源:show.go
示例19: main
//.........这里部分代码省略.........
req.Cpu = *numCpu
}
if *memGB != 0 {
req.MemoryGB = *memGB
}
if *desc != "" {
req.Description = *desc
} else if src.Description == "" {
req.Description = fmt.Sprintf("Clone of %s", src.Name)
} else {
req.Description = fmt.Sprintf("%s (cloned from %s)", src.Description, src.Name)
}
if *extraDrv != 0 {
req.AdditionalDisks = append(req.AdditionalDisks,
clcv2.ServerAdditionalDisk{SizeGB: uint32(*extraDrv), Type: "raw"})
}
if *ttl != 0 { /* Date/time that the server should be deleted. */
req.Ttl = new(time.Time)
*req.Ttl = time.Now().Add(*ttl)
}
/* hwGroup may be hex uuid or group name */
if *hwGroup != "" {
req.GroupId = *hwGroup
if _, err := hex.DecodeString(*hwGroup); err != nil {
log.Printf("Resolving ID of Hardware Group %q in %s ...", *hwGroup, src.LocationId)
if group, err := client.GetGroupByName(*hwGroup, src.LocationId); err != nil {
exit.Fatalf("failed to resolve group name %q: %s", *hwGroup, err)
} else if group == nil {
exit.Errorf("No group named %q was found in %s", *hwGroup, src.LocationId)
} else {
req.GroupId = group.Id
}
}
}
/* net is supposed to be a (hex) ID, but allow network names, too */
if *net == "" {
log.Printf("Determining network ID used by %s ...", src.Name)
if nets, err := client.GetServerNets(src); err != nil {
exit.Fatalf("failed to query networks of %s: %s", src.Name, err)
} else if len(nets) == 0 {
// No network information found for the server, even though it has an IP.
// This can happen when the server is owned by a sub-account, and uses a
// network that is owned by the parent account. In this case, the sub-account
// is prevented from querying details of the parent account, due to insufficient
// permission.
log.Printf("Unable to determine network details - querying %s deployable networks ...", src.LocationId)
capa, err := client.GetDeploymentCapabilities(src.LocationId)
if err != nil {
exit.Fatalf("failed to determine %s Deployment Capabilities: %s", src.LocationId, err)
}
fmt.Println("Please specify the network ID for the clone manually via -net, using this information:")
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(false)
table.SetHeader([]string{"Name", "Type", "Account", "Network ID"})
for _, net := range capa.DeployableNetworks {
table.Append([]string{net.Name, net.Type, net.AccountID, net.NetworkId})
开发者ID:grrtrr,项目名称:clcv2,代码行数:67,代码来源:clone.go
示例20: main
func main() {
var net = flag.String("net", "", "ID or name of the Network to use (required)")
var location = flag.String("l", "", "Data centre alias (to resolve network name if not using hex ID)")
var ip = flag.String("ip", "", "IP address on -net (optional, default is automatic assignment)")
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(0)
}
client, err := clcv2.NewCLIClient()
if err != nil {
exit.Fatal(err.Error())
}
/* net is supposed to be a (hex) ID, but allow network names, too */
if *net != "" {
if _, err := hex.DecodeString(*net); err == nil {
/* already looks like a HEX ID */
} else {
fmt.Printf("Resolving network id of %q ...\n", *net)
if *location == "" {
fmt.Printf("Querying location details of %s ...\n", flag.Arg(0))
src, err := client.GetServer(flag.Arg(0))
if err != nil {
exit.Fatalf("failed to list details of server %q: %s", flag.Arg(0), err)
}
*location = src.LocationId
}
if netw, err := client.GetNetworkIdByName(*net, *location); err != nil {
exit.Errorf("failed to resolve network name %q: %s", *net, err)
} else if netw == nil {
exit.Errorf("no network named %q was found in %s", *net, *location)
} else {
*net = netw.Id
}
}
} else { /* Network ID is mandatory for this request to complete. */
var IPs []string
fmt.Println("This request requires a network ID via -net:")
fmt.Printf("Querying details of %s ...\n", flag.Arg(0))
src, err := client.GetServer(flag.Arg(0))
if err != nil {
exit.Fatalf("failed to list details of server %q: %s", flag.Arg(0), err)
}
*location = src.LocationId
for _, ip := range src.Details.IpAddresses {
if ip.Internal != "" {
IPs = append(IPs, ip.Internal)
}
}
fmt.Printf("%s current IP configuration: %s\n", flag.Arg(0), strings.Join(IPs, ", "))
fmt.Printf("Querying available networks in %s ...\n", *location)
capa, err := client.GetDeploymentCapabilities(*location)
if err != nil {
exit.Fatalf("failed to determine deployable networks in %s: %s", *location, err)
}
fmt.Printf("These are the networks deployable in %s:\n", *location)
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoWrapText(false)
table.SetHeader([]string{"Name", "Type", "Account", "Network ID"})
for _, net := range capa.DeployableNetworks {
table.Append([]string{net.Name, net.Type, net.AccountID, net.NetworkId})
}
table.Render()
exit.Errorf("please specify a network ID via -net (using the selection above).")
}
if err = client.ServerAddNic(flag.Arg(0), *net, *ip); err != nil {
exit.Fatalf("failed to add NIC to %s: %s", flag.Arg(0), err)
}
fmt.Printf("Successfully added a secondary NIC to %s.\n", flag.Arg(0))
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:89,代码来源:additional_nic_add.go
注:本文中的github.com/grrtrr/exit.Errorf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论