cds-gic-sdk-go

module
v0.3.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: Apache-2.0

README

English | 简体中文

CapitalOnline Cloud SDK for Go

The project is aim to build the golang sdk for CapitalOnline Cloud Platform. It allows to access CapitalOnline Cloud Service such as GIC,GBS,GPN and manage your resources easily.

It is based on the official Open API.

Features

You can find all the available actions from here. List some of them below:

  • Instance Management
    • CreateInstance
    • DeleteInstance
    • StopInstance
    • RebootInstance
    • ModifyInstanceChargeType
  • Virtual Datacenter Management
    • DescribeVdc
    • CreateVdc
    • DeleteVdc
    • CreatePublicNetwork
    • CreatePrivateNetwork
  • Security Group Management
    • CreateSecurityGroup
    • DeleteSecurityGroup
    • ForceDeleteSecurityGroup
    • DescribeSecurityGroupAttribute
    • ModifySecurityGroupAttribute
  • And More

Installation

Use go get to install SDK:

$ go get -u github.com/capitalonline/cds-gic-sdk-go

Examples

    	// Init a credential with Access Key Id and Secret Access Key
	// You can apply them from the CDS web portal
	credential := common.NewCredential(
		os.Getenv("CDS_SECRET_ID"),
		os.Getenv("CDS_SECRET_KEY"),
	)

	// init a client profile with method type
	cpf := profile.NewClientProfile()

	// Example: Get vdc
	cpf.HttpProfile.ReqMethod = "GET"
	vdcClient, _ := vdc.NewClient(credential, "", cpf)
	descVdcRequest := vdc.DescribeVdcRequest()

	// comment out the line below, you can get all the vdc data
	descVdcRequest.RegionId = common.StringPtr(Shanghai)
	descVdcResponse, err := vdcClient.DescribeVdc(descVdcRequest)
	if err != nil {
		fmt.Println("API request fail:", err.Error())
	} else {
		fmt.Println(descVdcResponse.ToJsonString())
	}

	// Example: Create vdc
	cpf.HttpProfile.ReqMethod = "POST"
	vdcClient, _ = vdc.NewClient(credential, "", cpf)
	createVdcRequest := vdc.NewAddVdcRequest()
	createVdcRequest.RegionId = common.StringPtr(Beijing)
	createVdcRequest.VdcName = common.StringPtr("beijing-vdc")
	createVdcRequest.PublicNetwork = &vdc.PublicNetwork{
		// the account of public IP
		IPNum: common.IntPtr(8),
		// the bandwidth of public network
		Qos:           common.IntPtr(10),
		Name:          common.StringPtr("pubnet"),
		BillingMethod: common.StringPtr("Bandwidth"),
		Type:          common.StringPtr("Bandwidth_BGP"),
	}
	createVdcResponse, err := vdcClient.CreateVdc(createVdcRequest)
	if err != nil {
		fmt.Println("API request fail:", err.Error())
	} else {
		fmt.Printf("Task: %v, code: %v", *createVdcResponse.TaskId, *createVdcResponse.Code)
	}

Find more from example.

Contributing

We work hard to provide a high-quality and useful SDK for CapitalOnline Cloud, and we greatly value feedback and contributions from our community. Please submit your issuesor pull requests through GitHub.

References

License

Apache License v2.0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL