Skip to content

Commit 1cb8f02

Browse files
committed
Add list volume api in bbc
1 parent 4d1dfd5 commit 1cb8f02

File tree

8 files changed

+213
-11
lines changed

8 files changed

+213
-11
lines changed

bce/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
// Constants and default values for the package bce
2828
const (
29-
SDK_VERSION = "0.9.29"
29+
SDK_VERSION = "0.9.20"
3030
URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path
3131
DEFAULT_DOMAIN = "baidubce.com"
3232
DEFAULT_PROTOCOL = "http"

doc/BBC.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,22 @@ if err := bbcClient.CreateRule(args); err != nil {
12381238
}
12391239
```
12401240

1241+
### 获取bbc本地盘信息列表
1242+
通过以下代码可以分页获取bbc本地盘信息列表
1243+
```go
1244+
queryArgs := &ListCDSVolumeArgs{
1245+
MaxKeys: 100,
1246+
InstanceId: "InstanceId",
1247+
Marker: "VolumeId",
1248+
ZoneName: "zoneName",
1249+
}
1250+
if res, err := BBC_CLIENT.ListCDSVolume(queryArgs); err != nil {
1251+
fmt.Println("list volume failed: ", err)
1252+
} else {
1253+
fmt.Println("list volume success, result: ", res)
1254+
}
1255+
```
1256+
12411257
### 启用维修平台预授权规则
12421258
通过以下代码启用维修平台预授权规则
12431259
```go
@@ -1250,4 +1266,4 @@ if err := bbcClient.EnableRule(args); err != nil {
12501266
} else {
12511267
fmt.Println("enable rule success")
12521268
}
1253-
```
1269+
```

services/bbc/cds.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package bbc
2+
3+
import (
4+
"github.com/baidubce/bce-sdk-go/bce"
5+
"github.com/baidubce/bce-sdk-go/http"
6+
"strconv"
7+
)
8+
9+
// ListCDSVolume - list all cds volumes with the given parameters
10+
//
11+
// PARAMS:
12+
// - cli: the client agent which can perform sending request
13+
// - queryArgs: the optional arguments to list cds volumes
14+
// RETURNS:
15+
// - *ListCDSVolumeResult: the result of cds volume list
16+
// - error: nil if success otherwise the specific error
17+
func ListCDSVolume(cli bce.Client, queryArgs *ListCDSVolumeArgs) (*ListCDSVolumeResult, error) {
18+
// Build the request
19+
req := &bce.BceRequest{}
20+
req.SetUri(getVolumeUri())
21+
req.SetMethod(http.GET)
22+
23+
if queryArgs != nil {
24+
if len(queryArgs.InstanceId) != 0 {
25+
req.SetParam("instanceId", queryArgs.InstanceId)
26+
}
27+
if len(queryArgs.ZoneName) != 0 {
28+
req.SetParam("zoneName", queryArgs.ZoneName)
29+
}
30+
if len(queryArgs.Marker) != 0 {
31+
req.SetParam("marker", queryArgs.Marker)
32+
}
33+
if queryArgs.MaxKeys != 0 {
34+
req.SetParam("maxKeys", strconv.Itoa(queryArgs.MaxKeys))
35+
}
36+
}
37+
38+
if queryArgs == nil || queryArgs.MaxKeys == 0 {
39+
req.SetParam("maxKeys", "1000")
40+
}
41+
42+
// Send request and get response
43+
resp := &bce.BceResponse{}
44+
if err := cli.SendRequest(req, resp); err != nil {
45+
return nil, err
46+
}
47+
if resp.IsFail() {
48+
return nil, resp.ServiceError()
49+
}
50+
51+
jsonBody := &ListCDSVolumeResult{}
52+
if err := resp.ParseJsonBody(jsonBody); err != nil {
53+
return nil, err
54+
}
55+
return jsonBody, nil
56+
}

services/bbc/client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,3 +936,14 @@ func (c *Client) BatchDeleteAutoRenewRules(args *BbcDeleteAutoRenewArgs) error {
936936
func (c *Client) DeleteInstanceIngorePayment(args *DeleteInstanceIngorePaymentArgs) (*DeleteInstanceResult, error) {
937937
return DeleteBbcIngorePayment(c, args)
938938
}
939+
940+
// ListCDSVolume - list all cds volume with the specific parameters
941+
//
942+
// PARAMS:
943+
// - args: the arguments to list all cds
944+
// RETURNS:
945+
// - *api.ListCDSVolumeResult: the result of list all CDS volume
946+
// - error: nil if success otherwise the specific error
947+
func (c *Client) ListCDSVolume(queryArgs *ListCDSVolumeArgs) (*ListCDSVolumeResult, error) {
948+
return ListCDSVolume(c, queryArgs)
949+
}

services/bbc/client_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ func TestCreateInstance(t *testing.T) {
106106
RaidId: BBC_TestRaidId,
107107
RootDiskSizeInGb: 40,
108108
PurchaseCount: 1,
109+
AdminPass: "AdminPass",
109110
ZoneName: BBC_TestZoneName,
110111
SubnetId: BBC_TestSubnetId,
112+
SecurityGroupId: BBC_TestSecurityGroupId,
111113
ClientToken: BBC_TestClientToken,
112114
Billing: Billing{
113115
PaymentTiming: PaymentTimingPostPaid,
@@ -130,7 +132,7 @@ func TestCreateInstance(t *testing.T) {
130132

131133
func TestListInstances(t *testing.T) {
132134
listArgs := &ListInstancesArgs{
133-
MaxKeys: 100,
135+
MaxKeys: 500,
134136
}
135137
res, err := BBC_CLIENT.ListInstances(listArgs)
136138
fmt.Println(res)
@@ -433,7 +435,7 @@ func TestGetCommonImage(t *testing.T) {
433435
}
434436

435437
func TestGetCustomImage(t *testing.T) {
436-
flavorIds := []string{"BBC-S3-02"}
438+
flavorIds := []string{"flavorId"}
437439
queryArgs := &GetFlavorImageArgs{
438440
FlavorIds: flavorIds,
439441
}
@@ -611,12 +613,26 @@ func TestBatchDeleteAutoRenewRules(t *testing.T) {
611613

612614
func TestDeleteInstanceIngorePayment(t *testing.T) {
613615
args := &DeleteInstanceIngorePaymentArgs{
614-
InstanceId: "i-htkPgy0d",
615-
RelatedReleaseFlag: false,
616+
InstanceId: "InstanceId",
617+
RelatedReleaseFlag: true,
616618
}
617619
if res, err := BBC_CLIENT.DeleteInstanceIngorePayment(args); err != nil {
618620
fmt.Println("delete instance failed: ", err)
619621
} else {
620622
fmt.Println("delelte instance success, result: ", res)
621623
}
622624
}
625+
626+
func TestListCDSVolume(t *testing.T) {
627+
queryArgs := &ListCDSVolumeArgs{
628+
MaxKeys: 100,
629+
InstanceId: "InstanceId",
630+
Marker: "VolumeId",
631+
ZoneName: "zoneName",
632+
}
633+
if res, err := BBC_CLIENT.ListCDSVolume(queryArgs); err != nil {
634+
fmt.Println("list volume failed: ", err)
635+
} else {
636+
fmt.Println("list volume success, result: ", res)
637+
}
638+
}

services/bbc/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,5 +793,5 @@ func getBatchDeleteAutoRenewRulesUri() string {
793793
}
794794

795795
func getRebuildBatchInstanceUri() string {
796-
return URI_PREFIX_V1 + REQUEST_INSTANCE_URI + REQUEST_BATCH_REBUILD_INSTANCE_URI;
796+
return URI_PREFIX_V1 + REQUEST_INSTANCE_URI + REQUEST_BATCH_REBUILD_INSTANCE_URI
797797
}

services/bbc/model.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,46 @@ const (
5858
ImageStatusError ImageStatus = "Error"
5959
)
6060

61+
type VolumeType string
62+
63+
const (
64+
VolumeTypeSYSTEM VolumeType = "System"
65+
VolumeTypeEPHEMERAL VolumeType = "Ephemeral"
66+
VolumeTypeCDS VolumeType = "Cds"
67+
)
68+
69+
type StorageType string
70+
71+
const (
72+
StorageTypeStd1 StorageType = "std1"
73+
StorageTypeHP1 StorageType = "hp1"
74+
StorageTypeCloudHP1 StorageType = "cloud_hp1"
75+
StorageTypeLocal StorageType = "local"
76+
StorageTypeSATA StorageType = "sata"
77+
StorageTypeSSD StorageType = "ssd"
78+
StorageTypeHDDThroughput StorageType = "HDD_Throughput"
79+
StorageTypeHdd StorageType = "hdd"
80+
)
81+
82+
type VolumeStatus string
83+
84+
const (
85+
VolumeStatusAVAILABLE VolumeStatus = "Available"
86+
VolumeStatusINUSE VolumeStatus = "InUse"
87+
VolumeStatusSNAPSHOTPROCESSING VolumeStatus = "SnapshotProcessing"
88+
VolumeStatusRECHARGING VolumeStatus = "Recharging"
89+
VolumeStatusDETACHING VolumeStatus = "Detaching"
90+
VolumeStatusDELETING VolumeStatus = "Deleting"
91+
VolumeStatusEXPIRED VolumeStatus = "Expired"
92+
VolumeStatusNOTAVAILABLE VolumeStatus = "NotAvailable"
93+
VolumeStatusDELETED VolumeStatus = "Deleted"
94+
VolumeStatusSCALING VolumeStatus = "Scaling"
95+
VolumeStatusIMAGEPROCESSING VolumeStatus = "ImageProcessing"
96+
VolumeStatusCREATING VolumeStatus = "Creating"
97+
VolumeStatusATTACHING VolumeStatus = "Attaching"
98+
VolumeStatusERROR VolumeStatus = "Error"
99+
)
100+
61101
type CreateInstanceArgs struct {
62102
FlavorId string `json:"flavorId"`
63103
ImageId string `json:"imageId"`
@@ -671,3 +711,61 @@ type SharedUser struct {
671711
AccountId string `json:"accountId,omitempty"`
672712
Account string `json:"account,omitempty"`
673713
}
714+
715+
type ListCDSVolumeArgs struct {
716+
MaxKeys int
717+
InstanceId string
718+
ZoneName string
719+
Marker string
720+
}
721+
722+
type ListCDSVolumeResult struct {
723+
Marker string `json:"marker"`
724+
IsTruncated bool `json:"isTruncated"`
725+
NextMarker string `json:"nextMarker"`
726+
MaxKeys int `json:"maxKeys"`
727+
Volumes []VolumeModel `json:"volumes"`
728+
}
729+
730+
type VolumeModel struct {
731+
Type VolumeType `json:"type"`
732+
StorageType StorageType `json:"storageType"`
733+
Id string `json:"id"`
734+
Name string `json:"name"`
735+
DiskSizeInGB int `json:"diskSizeInGB"`
736+
PaymentTiming string `json:"paymentTiming"`
737+
ExpireTime string `json:"expireTime"`
738+
Status VolumeStatus `json:"status"`
739+
Desc string `json:"desc"`
740+
Attachments []VolumeAttachmentModel `json:"attachments"`
741+
ZoneName string `json:"zoneName"`
742+
AutoSnapshotPolicy *AutoSnapshotPolicyModel `json:"autoSnapshotPolicy"`
743+
CreateTime string `json:"createTime"`
744+
IsSystemVolume bool `json:"isSystemVolume"`
745+
RegionId string `json:"regionId"`
746+
SourceSnapshotId string `json:"sourceSnapshotId"`
747+
SnapshotNum string `json:"snapshotNum"`
748+
Tags []model.TagModel `json:"tags"`
749+
Encrypted bool `json:"encrypted"`
750+
}
751+
752+
type VolumeAttachmentModel struct {
753+
VolumeId string `json:"volumeId"`
754+
InstanceId string `json:"instanceId"`
755+
Device string `json:"device"`
756+
Serial string `json:"serial"`
757+
}
758+
759+
type AutoSnapshotPolicyModel struct {
760+
CreatedTime string `json:"createdTime"`
761+
Id string `json:"id"`
762+
Status string `json:"status"`
763+
RetentionDays int `json:"retentionDays"`
764+
UpdatedTime string `json:"updatedTime"`
765+
DeletedTime string `json:"deletedTime"`
766+
LastExecuteTime string `json:"lastExecuteTime"`
767+
VolumeCount int `json:"volumeCount"`
768+
Name string `json:"name"`
769+
TimePoints []int `json:"timePoints"`
770+
RepeatWeekdays []int `json:"repeatWeekdays"`
771+
}

services/bbc/util.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const (
3131
REQUEST_SUBNET_URI = "/vpcSubnet"
3232
SECURITY_GROUP_URI = "/securitygroup"
3333

34-
REQUEST_IMAGE_URI = "/image"
35-
REQUEST_BATCHADDIP_URI = "/batchAddIp"
36-
REQUEST_BATCHDELIP_URI = "/batchDelIp"
34+
REQUEST_IMAGE_URI = "/image"
35+
REQUEST_BATCHADDIP_URI = "/batchAddIp"
36+
REQUEST_BATCHDELIP_URI = "/batchDelIp"
3737
REQUEST_BATCH_CREATE_AUTORENEW_RULES_URI = "/batchCreateAutoRenewRules"
3838
REQUEST_BATCH_Delete_AUTORENEW_RULES_URI = "/batchDeleteAutoRenewRules"
3939
REQUEST_BATCH_REBUILD_INSTANCE_URI = "/batchRebuild";
@@ -51,14 +51,15 @@ const (
5151
REQUEST_DEPLOY_SET_URI = "/deployset"
5252
REQUEST_INSTANCE_PORT_URI = "/vpcPort"
5353

54-
REQUEST_REPAIR_TASK_URI = "/task"
54+
REQUEST_REPAIR_TASK_URI = "/task"
5555
REQUEST_REPAIR_CLOSED_TASK_URI = "/closedTask"
5656

5757
REQUEST_RULE_URI = "/rule"
5858
REQUEST_CREATE_URI = "/create"
5959
REQUEST_DELETE_URI = "/delete"
6060
REQUEST_DISABLE_URI = "/disable"
6161
REQUEST_ENABLE_URI = "/enable"
62+
REQUEST_VOLUME_URI = "/volume"
6263
)
6364

6465
func Aes128EncryptUseSecreteKey(sk string, data string) (string, error) {
@@ -73,3 +74,7 @@ func Aes128EncryptUseSecreteKey(sk string, data string) (string, error) {
7374

7475
return hex.EncodeToString(crypted), nil
7576
}
77+
78+
func getVolumeUri() string {
79+
return URI_PREFIX_V1 + REQUEST_VOLUME_URI
80+
}

0 commit comments

Comments
 (0)