Skip to content

Commit

Permalink
Add some features in bbc, bcc and eip
Browse files Browse the repository at this point in the history
  • Loading branch information
duanliguo committed Apr 28, 2021
1 parent b396ef7 commit d8643b2
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 76 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bce-sdk-go
| |--bbc //物理服务器
| |--bcc //云服务器
| |--bec //百度边缘计算
| |--bie //百度智能边缘
| |--bie //百度边缘计算
| |--bls //日志服务
| |--bos //BOS服务目录
| | |--bos_client.go //BOS客户端入口
Expand Down
2 changes: 2 additions & 0 deletions doc/DDC.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ args := &ddc.CreateRdsArgs{
DeployId:"xxxyyy-123",
// 资源池id 必选
PoolId:"xxxyzzzyy-123",
// 创建双机版主实例支持选择同步方式 Semi_sync:开启半同步/Async:异步
SyncMode:"Semi_sync",
}
result, err := client.CreateRds(args)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion services/bbc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func init() {
f = filepath.Dir(f)
}
conf := filepath.Join(f, "config.json")
fmt.Println(conf)
fp, err := os.Open(conf)
if err != nil {
fmt.Println("config json file of ak/sk not given: ", conf)
Expand Down Expand Up @@ -334,7 +335,10 @@ func TestDeleteImage(t *testing.T) {
}

func TestGetOperationLog(t *testing.T) {
queryArgs := &GetOperationLogArgs{}
queryArgs := &GetOperationLogArgs{
StartTime: "2021-03-28T15:00:27Z",
EndTime: "2021-03-30T15:00:27Z",
}
rep, err := BBC_CLIENT.GetOperationLog(queryArgs)
fmt.Println(rep)
ExpectEqual(t.Errorf, err, nil)
Expand Down
1 change: 1 addition & 0 deletions services/bbc/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ type InstanceModel struct {
ExpireTime string `json:"expireTime"`
PublicIp string `json:"publicIp"`
InternalIp string `json:"internalIp"`
RdmaIp string `json:"rdmaIp"`
ImageId string `json:"imageId"`
FlavorId string `json:"flavorId"`
Zone string `json:"zone"`
Expand Down
40 changes: 40 additions & 0 deletions services/bcc/api/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,46 @@ func GetAllStocks(cli bce.Client) (*GetAllStocksResult, error) {
return jsonBody, nil
}

// GetStockWithDeploySet - get the bcc's stock with deploySet
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - args: the arguments to get the bcc's stock with deploySet
// RETURNS:
// - *GetAllStocksResult: the result of the bcc's stock
// - error: nil if success otherwise the specific error
func GetStockWithDeploySet(cli bce.Client, args *GetStockWithDeploySetArgs) (*GetStockWithDeploySetResults, error) {
// Build the request
req := &bce.BceRequest{}
req.SetUri(getStockWithDeploySet())
req.SetMethod(http.POST)

jsonBytes, err := json.Marshal(args)
if err != nil {
return nil, err
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return nil, err
}
req.SetBody(body)

// Send request and get response
resp := &bce.BceResponse{}
if err := cli.SendRequest(req, resp); err != nil {
return nil, err
}
if resp.IsFail() {
return nil, resp.ServiceError()
}

jsonBody := &GetStockWithDeploySetResults{}
if err := resp.ParseJsonBody(jsonBody); err != nil {
return nil, err
}
return jsonBody, nil
}

func GetInstanceCreateStock(cli bce.Client, args *CreateInstanceStockArgs) (*InstanceStockResult, error) {
// Build the request
req := &bce.BceRequest{}
Expand Down
9 changes: 9 additions & 0 deletions services/bcc/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@ type ResizeInstanceStockArgs struct {
InstanceId string `json:"instanceId"`
}

type GetStockWithDeploySetArgs struct {
Spec string `json:"spec"`
DeploySetIds []string `json:"deploySetIds"`
}

type GetStockWithDeploySetResults struct {
BccStocks []BccStock `json:"bccStocks"`
}

type InstanceStockResult struct {
FlaovrId string `json:"flavorId"`
Count int `json:"Count"`
Expand Down
5 changes: 5 additions & 0 deletions services/bcc/api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const (
REQUEST_BATCH_CREATE_AUTORENEW_RULES_URI = "/batchCreateAutoRenewRules"
REQUEST_BATCH_Delete_AUTORENEW_RULES_URI = "/batchDeleteAutoRenewRules"
REQUEST_GET_ALL_STOCKS = "/getAllStocks"
REQUEST_GET_STOCK_WITH_DEPLOYSET = "/getStockWithDeploySet"
)

func getInstanceUri() string {
Expand Down Expand Up @@ -243,6 +244,10 @@ func getAllStocks() string {
return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_GET_ALL_STOCKS
}

func getStockWithDeploySet() string {
return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_GET_STOCK_WITH_DEPLOYSET
}

func getCreateInstanceStock() string {
return URI_PREFIXV2 + REQUEST_INSTANCE_URI + "/stock/createInstance"
}
Expand Down
9 changes: 9 additions & 0 deletions services/bcc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,15 @@ func (c *Client) GetAllStocks() (*api.GetAllStocksResult, error) {
return api.GetAllStocks(c)
}

// GetStockWithDeploySet - get the bcc's stock with deploySet
//
// RETURNS:
// - *GetStockWithDeploySetResults: the result of the bcc's stock
// - error: nil if success otherwise the specific error
func (c *Client) GetStockWithDeploySet(args *api.GetStockWithDeploySetArgs) (*api.GetStockWithDeploySetResults, error) {
return api.GetStockWithDeploySet(c, args)
}

func (c *Client) GetInstanceCreateStock(args *api.CreateInstanceStockArgs) (*api.InstanceStockResult, error) {
return api.GetInstanceCreateStock(c, args)
}
Expand Down
64 changes: 30 additions & 34 deletions services/bcc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func TestCreateInstance(t *testing.T) {
func TestCreateInstanceBySpec(t *testing.T) {
DeploySetIds := []string{"DeploySetId"}
createInstanceBySpecArgs := &api.CreateInstanceBySpecArgs{
ImageId: "ImageId",
Spec: "bcc.g4.c2m8",
ImageId: "m-mcDaCc3x",
Spec: "bcc.l3.c16m64",
Name: "sdkTest2",
AdminPass: "123qaz!@#",
ZoneName: "cn-bj-a",
Expand Down Expand Up @@ -143,9 +143,9 @@ func TestCreateInstanceV3(t *testing.T) {
},
},
PurchaseCount: 1,
InstanceName: "sdkTest8",
Password: "123qaz!@#",
ZoneName: "cn-bj-b",
InstanceName: "sdkTest8",
Password: "123qaz!@#",
ZoneName: "cn-bj-b",
Billing: api.Billing{
PaymentTiming: api.PaymentTimingPostPaid,
Reservation: &api.Reservation{
Expand Down Expand Up @@ -214,7 +214,6 @@ func TestListInstances(t *testing.T) {
res, err := BCC_CLIENT.ListInstances(listArgs)
ExpectEqual(t.Errorf, err, nil)
fmt.Println(res)
fmt.Println(res.Instances[0].DeploySetList)
}

func TestListRecycleInstances(t *testing.T) {
Expand Down Expand Up @@ -496,13 +495,18 @@ func TestDeleteAutoSnapshotPolicy(t *testing.T) {
}

func TestListCDSVolume(t *testing.T) {
queryArgs := &api.ListCDSVolumeArgs{}
_, err := BCC_CLIENT.ListCDSVolume(queryArgs)
queryArgs := &api.ListCDSVolumeArgs{
InstanceId: BCC_TestBccId,
}
res, err := BCC_CLIENT.ListCDSVolume(queryArgs)
ExpectEqual(t.Errorf, err, nil)
fmt.Println(res)
}

func TestListCDSVolumeV3(t *testing.T) {
queryArgs := &api.ListCDSVolumeArgs{}
queryArgs := &api.ListCDSVolumeArgs{
InstanceId: BCC_TestBccId,
}
res, err := BCC_CLIENT.ListCDSVolumeV3(queryArgs)
fmt.Println(res)
ExpectEqual(t.Errorf, err, nil)
Expand Down Expand Up @@ -746,15 +750,15 @@ func TestDeleteImage(t *testing.T) {
}

func TestDeleteInstance(t *testing.T) {
err := BCC_CLIENT.DeleteInstance("BCC_TestBccId")
err := BCC_CLIENT.DeleteInstance(BCC_TestBccId)
ExpectEqual(t.Errorf, err, nil)
}

func TestDeleteInstanceWithRelateResource(t *testing.T) {
args := &api.DeleteInstanceWithRelateResourceArgs{
BccRecycleFlag: false,
}
err := BCC_CLIENT.DeleteInstanceWithRelateResource("BCC_TestBccId", args)
err := BCC_CLIENT.DeleteInstanceWithRelateResource(BCC_TestBccId, args)
ExpectEqual(t.Errorf, err, nil)
}

Expand All @@ -777,10 +781,10 @@ func TestListFlavorSpec(t *testing.T) {

func TestGetPriceBySpec(t *testing.T) {
args := &api.GetPriceBySpecArgs{
SpecId: "bcc.b1.c8m16",
SpecId: "g1",
Spec: "",
PaymentTiming: "Postpaid",
ZoneName: "cn-bj-c",
ZoneName: "cn-gz-b",
PurchaseCount: 1,
PurchaseLength: 1,
}
Expand Down Expand Up @@ -837,26 +841,6 @@ func TestGetDeploySet(t *testing.T) {
ExpectEqual(t.Errorf, err, nil)
}

//func TestUpdateInstanceDeploySet(t *testing.T) {
// queryArgs := &api.UpdateInstanceDeployArgs{
// InstanceId: "i-p5AgGD2V",
// DeploySetIds: []string{"dset-wFhQIXid", "dset-NxOwQacM"},
// }
// rep, err := BCC_CLIENT.UpdateInstanceDeploySet(queryArgs)
// fmt.Println(rep)
// ExpectEqual(t.Errorf, err, nil)
//}
//
//func TestDelInstanceDeploySet(t *testing.T) {
// queryArgs := &api.DelInstanceDeployArgs{
// DeploySetId: "dset-2mekjKVo",
// InstanceIds: []string{"i-D73858x1"},
// }
// rep, err := BCC_CLIENT.DelInstanceDeploySet(queryArgs)
// fmt.Println(rep)
// ExpectEqual(t.Errorf, err, nil)
//}

func TestResizeInstanceBySpec(t *testing.T) {
resizeArgs := &api.ResizeInstanceArgs{
Spec: "Spec",
Expand Down Expand Up @@ -960,7 +944,7 @@ func TestInstancePurchaseReserved(t *testing.T) {
},
RelatedRenewFlag: "",
}
err := BCC_CLIENT.InstancePurchaseReserved("i-C2NZiShJ", purchaseReservedArgs)
err := BCC_CLIENT.InstancePurchaseReserved(BCC_TestBccId, purchaseReservedArgs)
//fmt.Print(err)
ExpectEqual(t.Errorf, err, nil)
}
Expand Down Expand Up @@ -1158,3 +1142,15 @@ func TestGetAllStocks(t *testing.T) {
fmt.Println("get all stocks success, result: ", res)
}
}

func TestGetStockWithDeploySet(t *testing.T) {
args := &api.GetStockWithDeploySetArgs{
Spec: "bcc.g3.c2m8",
DeploySetIds: []string{"dset-Wz2RRXSp"},
}
if res, err := BCC_CLIENT.GetStockWithDeploySet(args); err != nil {
fmt.Println("get stock with deploySet failed: ", err)
} else {
fmt.Println("get stock with deploySet, result: ", res)
}
}
Loading

0 comments on commit d8643b2

Please sign in to comment.