English | 简体中文
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.
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
Use go get
to install SDK:
$ go get -u github.com/capitalonline/cds-gic-sdk-go
// 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.
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.