当前位置: 首页>>代码示例>>Golang>>正文


Golang clcv2.NewCLIClient函数代码示例

本文整理汇总了Golang中github.com/grrtrr/clcv2.NewCLIClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCLIClient函数的具体用法?Golang NewCLIClient怎么用?Golang NewCLIClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewCLIClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	var days = flag.Int("days", 10, "Number of days to keep the snapshot for")

	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.CreateSnapshot(flag.Arg(0), *days)
	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:", statusId)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:26,代码来源:snapshot_take.go

示例2: main

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()
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:32,代码来源:show_account_policy.go

示例3: main

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)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:26,代码来源:set_memory.go

示例4: main

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)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:26,代码来源:bare_metal_capabilities.go

示例5: main

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)
	}
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:29,代码来源:snapshot_list.go

示例6: main

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)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:27,代码来源:get_credentials.go

示例7: 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

示例8: main

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, ", "))
	}
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:26,代码来源:ip.go

示例9: main

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)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:29,代码来源:create.go

示例10: 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

示例11: main

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)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:26,代码来源:set_cpu.go

示例12: main

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))
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:26,代码来源:set_description.go

示例13: main

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)
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:26,代码来源:maintenance_toggle.go

示例14: main

func main() {
	flag.Parse()

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

	policies, err := client.SBSgetPolicies()
	if err != nil {
		exit.Fatalf("failed to list SBS policies: %s", err)
	}

	if len(policies) == 0 {
		fmt.Println("No Account Policies defined.")
	} else {
		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"})

		for _, p := range policies {
			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()
	}
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:29,代码来源:list_account_policies.go

示例15: main

func main() {
	var simple = flag.Bool("simple", false, "Use simple (debugging) output format")

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

	vpn, err := client.GetVPN(flag.Arg(0))
	if err != nil {
		exit.Fatalf("failed to query VPN %s: %s", flag.Arg(0), err)
	}

	if *simple {
		pretty.Println(vpn)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoFormatHeaders(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)
		table.SetAutoWrapText(false)

		//		table.SetHeader([]string{"CLC => Remote", "CLC Nets",			"Remote", "Remote Nets", "ID", "Last Change",		})

		modifiedStr := humanize.Time(vpn.ChangeInfo.ModifiedDate)
		// The ModifiedBy field can be an email address, or an API Key (hex string)
		if _, err := hex.DecodeString(vpn.ChangeInfo.ModifiedBy); err == nil {
			modifiedStr += " via API Key"
		} else {
			modifiedStr += ", by " + vpn.ChangeInfo.ModifiedBy
		}

		table.Append([]string{fmt.Sprintf("%s subnets:", vpn.Local.LocationAlias), strings.Join(vpn.Local.Subnets, ", ")})
		table.Append([]string{fmt.Sprintf("%s endpoint:", vpn.Local.LocationAlias), vpn.Local.Address})
		table.Append([]string{fmt.Sprintf("%s endpoint:", vpn.Remote.SiteName), vpn.Remote.Address})
		table.Append([]string{fmt.Sprintf("%s subnets:", vpn.Remote.SiteName), strings.Join(vpn.Remote.Subnets, ", ")})
		table.Append([]string{"IKE configuration:", fmt.Sprintf("%s, %s/%s, Key: %q, NAT traversal: %t, Lifetime: %s",
			vpn.IKE.DiffieHellmanGroup,
			vpn.IKE.Encryption, vpn.IKE.Hashing, vpn.IKE.PreSharedKey,
			vpn.IKE.NatTraversal,
			time.Duration(vpn.IKE.Lifetime)*time.Second)})
		table.Append([]string{"IPsec configuration:", fmt.Sprintf("%s, %s/%s, %s, Lifetime: %s",
			vpn.IPsec.Pfs, vpn.IPsec.Encryption, vpn.IPsec.Hashing,
			strings.ToUpper(vpn.IPsec.Protocol), time.Duration(vpn.IPsec.Lifetime)*time.Second)})
		table.Append([]string{"Last change:", modifiedStr})

		table.Render()
	}
}
开发者ID:grrtrr,项目名称:clcv2,代码行数:59,代码来源:show.go


注:本文中的github.com/grrtrr/clcv2.NewCLIClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。