當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.SendRequest方法代碼示例

本文整理匯總了Golang中github.com/caicloud/anchnet-go.Client.SendRequest方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.SendRequest方法的具體用法?Golang Client.SendRequest怎麽用?Golang Client.SendRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/caicloud/anchnet-go.Client的用法示例。


在下文中一共展示了Client.SendRequest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: execAddSecurityGroupRule

func execAddSecurityGroupRule(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) != 2 {
		fmt.Fprintln(os.Stderr, "Rule name and security group ID required")
		os.Exit(1)
	}

	priority := getFlagInt(cmd, "priority")
	direction := getFlagInt(cmd, "direction")
	action := getFlagString(cmd, "action")
	protocol := getFlagString(cmd, "protocol")
	value1 := getFlagString(cmd, "value1")
	value2 := getFlagString(cmd, "value2")
	value3 := getFlagString(cmd, "value3")

	request := anchnet.AddSecurityGroupRulesRequest{
		SecurityGroupID: args[1],
		SecurityGroupRules: []anchnet.AddSecurityGroupRule{
			{
				SecurityGroupRuleName: args[0],
				Action:                anchnet.SecurityGroupRuleAction(action),
				Direction:             anchnet.SecurityGroupRuleDirection(direction),
				Protocol:              anchnet.SecurityGroupRuleProtocol(protocol),
				Priority:              priority,
				Value1:                value1,
				Value2:                value2,
				Value3:                value3,
			},
		},
	}
	var response anchnet.AddSecurityGroupRulesResponse
	sendResult(&response, out, "AddSecurityGroup", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:32,代碼來源:security_group_cli.go

示例2: execCreateUserProject

func execCreateUserProject(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "Login ID required, i.e. username")
		os.Exit(1)
	}

	sex := getFlagString(cmd, "sex")
	mobile := getFlagString(cmd, "mobile")
	passwd := getFlagString(cmd, "passwd")

	// use {userid}@caicloud.io as loginid which is supposed to be unique.
	loginID := args[0] + "@caicloud.io"

	request := anchnet.CreateUserProjectRequest{
		LoginID:     loginID,
		Sex:         sex,
		ProjectName: args[0],
		Email:       loginID,
		ContactName: args[0],
		Mobile:      mobile,
		LoginPasswd: passwd,
	}
	var response anchnet.CreateUserProjectResponse
	sendResult(&response, out, "CreateUserProject", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:25,代碼來源:user_project_cli.go

示例3: execWaitJob

func execWaitJob(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "Job id required")
		os.Exit(1)
	}

	count := getFlagInt(cmd, "count")
	status := getFlagString(cmd, "status")
	interval := getFlagInt(cmd, "interval")
	exitOnFail := getFlagBool(cmd, "exit_on_fail")

	for i := 0; i < count; i++ {
		request := anchnet.DescribeJobsRequest{
			JobIDs: []string{args[0]},
		}
		var response anchnet.DescribeJobsResponse
		err := client.SendRequest(request, &response)
		if err == nil && len(response.ItemSet) == 1 {
			// Return if there is no error and status matches.
			if string(response.ItemSet[0].Status) == status {
				return
			}
			// Return if there is no error, and status is failed + user wants early return.
			if response.ItemSet[0].Status == anchnet.JobStatusFailed && exitOnFail {
				fmt.Fprintf(os.Stderr, "Job %v failed", args[0])
				os.Exit(1)
			}
		}
		time.Sleep(time.Duration(interval) * time.Second)
	}
	fmt.Fprintf(os.Stderr, "Time out waiting for job %v", args[0])
	os.Exit(1)
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:33,代碼來源:job_cli.go

示例4: execCreateLoadBalancer

func execCreateLoadBalancer(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) != 2 {
		fmt.Fprintln(os.Stderr, "Load balancer name and public ips required")
		os.Exit(1)
	}

	lb_type := getFlagInt(cmd, "type")

	refs := strings.Split(args[1], ",")
	ips := make([]anchnet.CreateLoadBalancerIP, len(refs))
	for i, ip := range refs {
		ips[i].RefID = ip
	}

	request := anchnet.CreateLoadBalancerRequest{
		Product: anchnet.CreateLoadBalancerProduct{
			Loadbalancer: anchnet.CreateLoadBalancerLB{
				Name: args[0],
				Type: anchnet.LoadBalancerType(lb_type),
			},
			Eips: ips,
		},
	}
	var response anchnet.CreateLoadBalancerResponse
	sendResult(&response, out, "CreateLoadBalancer", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:26,代碼來源:lb_cli.go

示例5: execDeleteSecurityGroups

func execDeleteSecurityGroups(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) != 1 {
		fmt.Fprintln(os.Stderr, "Security group IDs required")
		os.Exit(1)
	}

	request := anchnet.DeleteSecurityGroupsRequest{
		SecurityGroupIDs: strings.Split(args[0], ","),
	}
	var response anchnet.DeleteSecurityGroupsResponse
	sendResult(&response, out, "DeleteSecurityGroups", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:12,代碼來源:security_group_cli.go

示例6: execTerminateInstances

func execTerminateInstances(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "Instance IDs required")
		os.Exit(1)
	}

	request := anchnet.TerminateInstancesRequest{
		InstanceIDs: strings.Split(args[0], ","),
	}
	var response anchnet.TerminateInstancesResponse
	sendResult(&response, out, "TerminateInstance", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:12,代碼來源:instance_cli.go

示例7: execDescribeVxnets

func execDescribeVxnets(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "Vxnet IDs required")
		os.Exit(1)
	}

	request := anchnet.DescribeVxnetsRequest{
		VxnetIDs: strings.Split(args[0], ","),
	}
	var response anchnet.DescribeVxnetsResponse
	sendResult(&response, out, "DescribeVxnet", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:12,代碼來源:vxnet_cli.go

示例8: execReleaseEips

func execReleaseEips(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "EIP IDs required")
		os.Exit(1)
	}

	request := anchnet.ReleaseEipsRequest{
		EipIDs: strings.Split(args[0], ","),
	}
	var response anchnet.ReleaseEipsResponse
	sendResult(&response, out, "ReleaseEips", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:12,代碼來源:eip_cli.go

示例9: execDescribeJob

func execDescribeJob(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "Job id required")
		os.Exit(1)
	}

	request := anchnet.DescribeJobsRequest{
		JobIDs: []string{args[0]},
	}
	var response anchnet.DescribeJobsResponse
	sendResult(&response, out, "DescribeJob", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:12,代碼來源:job_cli.go

示例10: execApplySecurityGroup

func execApplySecurityGroup(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) != 2 {
		fmt.Fprintln(os.Stderr, "Security group id and instance ids required")
		os.Exit(1)
	}

	request := anchnet.ApplySecurityGroupRequest{
		SecurityGroupID: args[0],
		InstanceIDs:     strings.Split(args[1], ","),
	}
	var response anchnet.ApplySecurityGroupResponse
	sendResult(&response, out, "ApplySecurityGroup", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:13,代碼來源:security_group_cli.go

示例11: execJoinVxnet

func execJoinVxnet(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) != 2 {
		fmt.Fprintln(os.Stderr, "Vxnet and instances IDs required")
		os.Exit(1)
	}

	request := anchnet.JoinVxnetRequest{
		VxnetID:     args[0],
		InstanceIDs: strings.Split(args[1], ","),
	}
	var response anchnet.JoinVxnetResponse
	sendResult(&response, out, "JobVxnet", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:13,代碼來源:vxnet_cli.go

示例12: execRevokeImageFromUsers

func execRevokeImageFromUsers(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) != 2 {
		fmt.Fprintln(os.Stderr, "Image id and user ids required")
		os.Exit(1)
	}

	request := anchnet.RevokeImageFromUsersRequest{
		ImageIDs: []string{args[0]},
		UserIDs:  strings.Split(args[1], ","),
	}
	var response anchnet.RevokeImageFromUsersResponse
	sendResult(&response, out, "RevokeImageToUsers", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:13,代碼來源:image_cli.go

示例13: execCaptureInstance

func execCaptureInstance(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) != 2 {
		fmt.Fprintln(os.Stderr, "Image name and instance id required")
		os.Exit(1)
	}

	request := anchnet.CaptureInstanceRequest{
		ImageName: args[0],
		Instance:  args[1],
	}
	var response anchnet.CaptureInstanceResponse
	sendResult(&response, out, "CaptureInstance", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:13,代碼來源:image_cli.go

示例14: execDescribeProjects

func execDescribeProjects(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "projectid required, e.g. pro-xxxxx")
		os.Exit(1)
	}

	request := anchnet.DescribeProjectsRequest{
		Projects: args[0],
	}

	var response anchnet.DescribeProjectsResponse
	sendResult(&response, out, "DescribeProjects", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:13,代碼來源:user_project_cli.go

示例15: execSearchSecurityGroup

func execSearchSecurityGroup(cmd *cobra.Command, args []string, client *anchnet.Client, out io.Writer) {
	if len(args) != 1 {
		fmt.Fprintln(os.Stderr, "Security group name required")
		os.Exit(1)
	}

	request := anchnet.DescribeSecurityGroupsRequest{
		SearchWord: args[0],
		Verbose:    1,
	}
	var response anchnet.DescribeSecurityGroupsResponse
	sendResult(&response, out, "SearchSecurityGroup", response.Code, client.SendRequest(request, &response))
}
開發者ID:caicloud,項目名稱:anchnet-go-sdk,代碼行數:13,代碼來源:security_group_cli.go


注:本文中的github.com/caicloud/anchnet-go.Client.SendRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。