Skip to content

Commit

Permalink
Add features in hpas and bcc
Browse files Browse the repository at this point in the history
  • Loading branch information
liegu committed Feb 11, 2025
1 parent 8ac4e3d commit 868bf01
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 51 deletions.
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
发行说明:记录每次SDK更新的说明,最新版本的SDK包含以前所有版本的更新内容。
---------------------------------------------------------------------
【版本:v0.9.216】
涉及产品:HPAS
修改创建券、查询券、查询镜像列表等接口的参数命名
涉及产品:BCC
实例列表接口支持fuzzyInstanceName参数
【版本:v0.9.215】
涉及产品:BCC
变配相关接口新增是否开启Jumbo帧参数、创建相关接口支持传递超线程和numa参数
Expand Down
3 changes: 3 additions & 0 deletions services/bcc/api/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ func ListInstances(cli bce.Client, args *ListInstanceArgs) (*ListInstanceResult,
if len(args.EhcClusterId) != 0 {
req.SetParam("ehcClusterId", args.EhcClusterId)
}
if len(args.FuzzyInstanceName) != 0 {
req.SetParam("fuzzyInstanceName", args.FuzzyInstanceName)
}
}
if args == nil || args.MaxKeys == 0 {
req.SetParam("maxKeys", "1000")
Expand Down
39 changes: 20 additions & 19 deletions services/bcc/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,25 +776,26 @@ type CreateInstanceBySpecResult struct {
}

type ListInstanceArgs struct {
Marker string
MaxKeys int
InternalIp string
DedicatedHostId string
ZoneName string
KeypairId string
AutoRenew bool
InstanceIds string
InstanceNames string
CdsIds string
DeploySetIds string
SecurityGroupIds string
PaymentTiming string
Status string
Tags string
VpcId string
PrivateIps string
Ipv6Addresses string
EhcClusterId string
Marker string
MaxKeys int
InternalIp string
DedicatedHostId string
ZoneName string
KeypairId string
AutoRenew bool
InstanceIds string
InstanceNames string
CdsIds string
DeploySetIds string
SecurityGroupIds string
PaymentTiming string
Status string
Tags string
VpcId string
PrivateIps string
Ipv6Addresses string
EhcClusterId string
FuzzyInstanceName string
}

type ListInstanceResult struct {
Expand Down
9 changes: 9 additions & 0 deletions services/bcc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ func TestListInstances(t *testing.T) {
fmt.Println(res)
}

func TestListInstanceByFuzzyInstanceName(t *testing.T) {
listArgs := &api.ListInstanceArgs{
FuzzyInstanceName: "g80wwjst",
}
res, err := BCC_CLIENT.ListInstances(listArgs)
ExpectEqual(t.Errorf, err, nil)
fmt.Println(res)
}

func TestListInstancesByVpcAndIp(t *testing.T) {
listArgs := &api.ListInstanceArgs{
VpcId: "vpc-41avheyaawqc",
Expand Down
18 changes: 9 additions & 9 deletions services/hpas/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ func ModifyPasswordHpas(cli bce.Client, body *ModifyPasswordHpasReq) error {
return nil
}

// CreateHpasCoupon -
// CreateReservedHpas -
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - body:
// RETURNS:
// - *api.CreateHpasCouponResp:
// - *api.CreateReservedHpasResp:
// - error: the return error if any occurs
func CreateHpasCoupon(cli bce.Client, body *CreateHpasCouponReq) (*CreateHpasCouponResp, error) {
func CreateReservedHpas(cli bce.Client, body *CreateReservedHpasReq) (*CreateReservedHpasResp, error) {
req := &bce.BceRequest{}
req.SetMethod(http.POST)
path := "/"
Expand All @@ -294,23 +294,23 @@ func CreateHpasCoupon(cli bce.Client, body *CreateHpasCouponReq) (*CreateHpasCou
if resp.IsFail() {
return nil, resp.ServiceError()
}
res := &CreateHpasCouponResp{}
res := &CreateReservedHpasResp{}
if err := resp.ParseJsonBody(res); err != nil {
return nil, err
}
return res, nil
}

// DescribeCouponHpas -
// DescribeReservedHpas -
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - body:
// RETURNS:
// - *api.ListHpasCouponByPageResp:
// - *api.ListReservedHpasByPageResp:
// - error: the return error if any occurs
func DescribeCouponHpas(cli bce.Client, body *ListCouponHpasPageReq) (
*ListHpasCouponByPageResp, error) {
func DescribeReservedHpas(cli bce.Client, body *ListReservedHpasPageReq) (
*ListReservedHpasByPageResp, error) {
req := &bce.BceRequest{}
req.SetMethod(http.POST)
path := "/"
Expand All @@ -334,7 +334,7 @@ func DescribeCouponHpas(cli bce.Client, body *ListCouponHpasPageReq) (
if resp.IsFail() {
return nil, resp.ServiceError()
}
res := &ListHpasCouponByPageResp{}
res := &ListReservedHpasByPageResp{}
if err := resp.ParseJsonBody(res); err != nil {
return nil, err
}
Expand Down
26 changes: 26 additions & 0 deletions services/hpas/api/model_create_reserved_hpas_req.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2025 Baidu, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package api

type CreateReservedHpasReq struct {
Name string `json:"name,omitempty"`
ZoneName string `json:"zoneName,omitempty"`
AppType string `json:"appType,omitempty"`
AppPerformanceLevel string `json:"appPerformanceLevel,omitempty"`
BillingModel BillingModel `json:"billingModel,omitempty"`
PurchaseNum int `json:"purchaseNum,omitempty"`
EhcClusterId string `json:"ehcClusterId,omitempty"`
Tags []TagModel `json:"tags,omitempty"`
}
20 changes: 20 additions & 0 deletions services/hpas/api/model_create_reserved_hpas_resp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2025 Baidu, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package api

type CreateReservedHpasResp struct {
OrderId string `json:"orderId,omitempty"`
ReservedHpasIds []string `json:"reservedHpasIds,omitempty"`
}
3 changes: 0 additions & 3 deletions services/hpas/api/model_image_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ package api

type ImageResponse struct {
ImageId string `json:"imageId"`
ImageUuid string `json:"imageUuid"`
OsName string `json:"osName"`
OsArch string `json:"osArch"`
Name string `json:"name"`
ImageType string `json:"imageType"`
SupportedAppType []string `json:"supportedAppType"`
Expand Down
24 changes: 24 additions & 0 deletions services/hpas/api/model_list_reserved_hpas_by_page_resp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2025 Baidu, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package api

type ListReservedHpasByPageResp struct {
OrderBy string `json:"orderBy"`
Order string `json:"order"`
PageNo int32 `json:"pageNo"`
PageSize int32 `json:"pageSize"`
TotalCount int64 `json:"totalCount"`
ReservedHpasList []HpasReservedResponse `json:"reservedHpasList"`
}
25 changes: 25 additions & 0 deletions services/hpas/api/model_list_reserved_hpas_page_req.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2025 Baidu, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package api

type ListReservedHpasPageReq struct {
ReservedHpasIds []string `json:"reservedHpasIds,omitempty"`
Name string `json:"name,omitempty"`
ZoneName string `json:"zoneName,omitempty"`
ReservedHpasStatus string `json:"reservedHpasStatus,omitempty"`
AppType string `json:"appType,omitempty"`
PageNo int `json:"pageNo,omitempty"`
PageSize int `json:"pageSize,omitempty"`
}
29 changes: 29 additions & 0 deletions services/hpas/api/model_reserved_hpas_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2025 Baidu, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package api

type HpasReservedResponse struct {
ReservedHpasId string `json:"reservedHpasId"`
Name string `json:"name"`
ZoneName string `json:"zoneName"`
AppType string `json:"appType"`
OfferingType string `json:"offeringType"`
Status string `json:"status"`
ReservedHpasPeriod int `json:"reservedHpasPeriod"`
AppPerformanceLevel string `json:"appPerformanceLevel"`
CreateTime string `json:"createTime"`
ExpireTime string `json:"expireTime"`
Tags []TagResponse `json:"tags"`
}
20 changes: 10 additions & 10 deletions services/hpas/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,28 @@ func (c *Client) ModifyPasswordHpas(body *api.ModifyPasswordHpasReq) error {
return api.ModifyPasswordHpas(c, body)
}

// CreateHpasCoupon -
// CreateReservedHpas -
//
// PARAMS:
// - body: body参数
// RETURNS:
// - *api.CreateHpasCouponResp:
// - *api.CreateReservedHpasResp:
// - error: the return error if any occurs
func (c *Client) CreateHpasCoupon(body *api.CreateHpasCouponReq) (
*api.CreateHpasCouponResp, error) {
return api.CreateHpasCoupon(c, body)
func (c *Client) CreateReservedHpas(body *api.CreateReservedHpasReq) (
*api.CreateReservedHpasResp, error) {
return api.CreateReservedHpas(c, body)
}

// DescribeCouponHpas -
// DescribeReservedHpas -
//
// PARAMS:
// - body: body参数
// RETURNS:
// - *api.ListHpasCouponByPageResp:
// - *api.ListReservedHpasByPageResp:
// - error: the return error if any occurs
func (c *Client) DescribeCouponHpas(body *api.ListCouponHpasPageReq) (
*api.ListHpasCouponByPageResp, error) {
return api.DescribeCouponHpas(c, body)
func (c *Client) DescribeReservedHpas(body *api.ListReservedHpasPageReq) (
*api.ListReservedHpasByPageResp, error) {
return api.DescribeReservedHpas(c, body)
}

// ListHpas -
Expand Down
20 changes: 10 additions & 10 deletions services/hpas/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,28 @@ func TestModifyPasswordHpas(t *testing.T) {
ExpectEqual(t.Errorf, err, nil)
}

func TestCreateHpasCoupon(t *testing.T) {
createHpasCouponArgs := &api.CreateHpasCouponReq{
func TestCreateReservedHpas(t *testing.T) {
createReservedHpasReq := &api.CreateReservedHpasReq{
AppType: "llama2_7B_train",
AppPerformanceLevel: "10k",
Name: "create_hpas_test",
PurchaseNum: 1,
ZoneName: "cn-bj-a",
Tags: []api.TagModel{{TagKey: "test1", TagValue: "test1"}},
}
createResult, err := HPAS_CLIENT.CreateHpasCoupon(createHpasCouponArgs)
createResult, err := HPAS_CLIENT.CreateReservedHpas(createReservedHpasReq)
ExpectEqual(t.Errorf, err, nil)
fmt.Println(createResult)
Hpas_id = createResult.CouponHpasIds[0]
Hpas_id = createResult.ReservedHpasIds[0]
}

func TestDescribeCouponHpas(t *testing.T) {
listCouponHpasPageReq := &api.ListCouponHpasPageReq{
CouponHpasIds: []string{"k-eZgiHDOY"},
PageNo: 1,
PageSize: 10,
func TestDescribeReservedHpas(t *testing.T) {
listReservedHpasPageReq := &api.ListReservedHpasPageReq{
ReservedHpasIds: []string{"k-eZgiHDOY"},
PageNo: 1,
PageSize: 10,
}
describeResult, err := HPAS_CLIENT.DescribeCouponHpas(listCouponHpasPageReq)
describeResult, err := HPAS_CLIENT.DescribeReservedHpas(listReservedHpasPageReq)
ExpectEqual(t.Errorf, err, nil)
fmt.Println(describeResult)
}
Expand Down

0 comments on commit 868bf01

Please sign in to comment.