diff --git a/bce/config.go b/bce/config.go index bbbb72e5..55a554f4 100644 --- a/bce/config.go +++ b/bce/config.go @@ -26,7 +26,7 @@ import ( // Constants and default values for the package bce const ( - SDK_VERSION = "0.9.179" + SDK_VERSION = "0.9.180" URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path DEFAULT_DOMAIN = "baidubce.com" DEFAULT_PROTOCOL = "http" diff --git a/doc/BCC.md b/doc/BCC.md index 6514d4aa..525cd747 100644 --- a/doc/BCC.md +++ b/doc/BCC.md @@ -712,6 +712,8 @@ createInstanceArgs := &CreateInstanceArgs{ RequestToken string "requestToken" // 设置要绑定的资源组id ResGroupId string "resGroupId" + // 设置竞价实例eip释放时自动释放 默认false不启用,true启用 + IsEipAutoRelatedDelete bool &IsEipAutoRelatedDelete } if res, err := bccClient.CreateBidInstance(createInstanceBySpecArgs); err != nil { fmt.Println("create instance failed: ", err) @@ -1420,6 +1422,27 @@ if err := bccClient.ModifyDeletionProtection(instanceId, args); err != nil { } ``` +> **提示:** +> - 只有付抢占实例允许设定关联eip释放策略 +> - true表示当抢占实例自动释放时,eip随之释放,false表示当抢占实例自动释放时,eip解绑,不随实例释放。默认设置为false + +### 设置eip随抢占实例自动释放 +使用以下代码可以为BCC抢占实例设置关联eip自动释放,实例当前设置可查询实例详情IsEipAutoRelatedDelete,默认false解绑,true关联释放: + +```go +args := &api.RelatedDeletePolicy { + IsEipAutoRelatedDelete: true, +} +// 设置你要操作的instanceId +instanceId := "your-choose-instance-id" + +if err := bccClient.ModifyRelatedDeletePolicy(instanceId, args); err != nil { + fmt.Println("ModifyRelatedDeletePolicy failed: ", err) +} else { + fmt.Println("ModifyRelatedDeletePolicy success.") +} +``` + > **提示:** > - 后付费和预付费均可开启释放保护 > - 已开启释放保护的实例将无法通过控制台或API释放,只有在关闭的情况下才能被手动释放。定时释放,欠费释放以及实例过期释放不受释放保护属性的影响 diff --git a/doc/DDCv2.md b/doc/DDCv2.md index c25934a5..06ca8ba6 100644 --- a/doc/DDCv2.md +++ b/doc/DDCv2.md @@ -983,8 +983,10 @@ fmt.Printf("update instance name success\n") // import ddcrds "github.com/baidubce/bce-sdk-go/services/ddc/v2" args := &ddcrds.SwitchArgs{ - // 立即切换 + // 该字段已废弃,请使用waitSwitch。立即切换 IsSwitchNow: true, + // 执行时机控制。0:立即变配;1:维护时间内执行;2:用户控制执行时机 + WaitSwitch: 0, } result, err := client.SwitchInstance(instanceId, args) if err != nil { @@ -1141,8 +1143,10 @@ args := &ddcrds.ResizeRdsArgs{ NodeAmount: 2, // 是否进行直接支付,默认true,设置为直接支付的变配订单会直接扣款,不需要再走支付逻辑,可选 IsDirectPay: false, - // 是否立即变配 RDS只支持立即变配 - IsResizeNow: true, + // 该字段已废弃,请使用WaitSwitch。是否立即变配 RDS只支持立即变配 + //IsResizeNow: true, + // 变配时间窗口控制。0:立即变配;1:维护时间内变配;2:用户控制执行时机 + WaitSwitch: 0, } orderIdResponse, err = client.ResizeRds(instanceId, args) if err != nil { diff --git a/services/appblb/model.go b/services/appblb/model.go index 0cf56bfb..d89c09bc 100644 --- a/services/appblb/model.go +++ b/services/appblb/model.go @@ -196,23 +196,27 @@ type DescribeRsMountResult struct { } type CreateLoadBalancerArgs struct { - ClientToken string `json:"-"` - Name string `json:"name,omitempty"` - Description string `json:"desc,omitempty"` - SubnetId string `json:"subnetId"` - VpcId string `json:"vpcId"` - ClusterProperty string `json:"clusterProperty"` - Type string `json:"type,omitempty"` - Address string `json:"address,omitempty"` - Eip string `json:"eip,omitempty"` - ResourceGroupId string `json:"resourceGroupId,omitempty"` - AutoRenewLength int `json:"autoRenewLength,omitempty"` - AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"` - PerformanceLevel string `json:"performanceLevel,omitempty"` - Billing *Billing `json:"billing,omitempty"` - Tags []model.TagModel `json:"tags,omitempty"` - AllowDelete *bool `json:"allowDelete,omitempty"` - AllocateIpv6 *bool `json:"allocateIpv6,omitempty"` + ClientToken string `json:"-"` + Name string `json:"name,omitempty"` + Description string `json:"desc,omitempty"` + SubnetId string `json:"subnetId"` + VpcId string `json:"vpcId"` + ClusterProperty string `json:"clusterProperty"` + Type string `json:"type,omitempty"` + Address string `json:"address,omitempty"` + Eip string `json:"eip,omitempty"` + ResourceGroupId string `json:"resourceGroupId,omitempty"` + AutoRenewLength int `json:"autoRenewLength,omitempty"` + AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"` + PerformanceLevel string `json:"performanceLevel,omitempty"` + Billing *Billing `json:"billing,omitempty"` + Tags []model.TagModel `json:"tags,omitempty"` + AllowDelete *bool `json:"allowDelete,omitempty"` + AllocateIpv6 *bool `json:"allocateIpv6,omitempty"` + Layer4ClusterExclusive *bool `json:"layer4ClusterExclusive,omitempty"` + Layer7ClusterExclusive *bool `json:"layer7ClusterExclusive,omitempty"` + Layer4ClusterId string `json:"layer4ClusterId,omitempty"` + Layer7ClusterId string `json:"layer7ClusterId,omitempty"` } type Billing struct { @@ -252,19 +256,21 @@ type DescribeLoadBalancersArgs struct { } type AppBLBModel struct { - BlbId string `json:"blbId"` - Name string `json:"name"` - Description string `json:"desc"` - Address string `json:"address"` - Status BLBStatus `json:"status"` - VpcId string `json:"vpcId"` - SubnetId string `json:"subnetId"` - PublicIp string `json:"publicIp"` - Layer4ClusterId string `json:"layer4ClusterId"` - Layer7ClusterId string `json:"layer7ClusterId"` - Tags []model.TagModel `json:"tags"` - EipRouteType string `json:"eipRouteType"` - AllowDelete bool `json:"allowDelete"` + BlbId string `json:"blbId"` + Name string `json:"name"` + Description string `json:"desc"` + Address string `json:"address"` + Status BLBStatus `json:"status"` + VpcId string `json:"vpcId"` + SubnetId string `json:"subnetId"` + PublicIp string `json:"publicIp"` + Layer4ClusterId string `json:"layer4ClusterId"` + Layer7ClusterId string `json:"layer7ClusterId"` + Tags []model.TagModel `json:"tags"` + EipRouteType string `json:"eipRouteType"` + AllowDelete bool `json:"allowDelete"` + Layer4ClusterExclusive bool `json:"layer4ClusterExclusive"` + Layer7ClusterExclusive bool `json:"layer7ClusterExclusive"` } type DescribeLoadBalancersResult struct { @@ -311,6 +317,8 @@ type DescribeLoadBalancerDetailResult struct { PaymentTiming string `json:"paymentTiming"` PerformanceLevel string `json:"performanceLevel"` ExpireTime string `json:"expireTime"` + AllowDelete bool `json:"allowDelete"` + VpcId string `json:"vpcId"` } type CreateAppTCPListenerArgs struct { diff --git a/services/bcc/api/instance.go b/services/bcc/api/instance.go index 81540b46..b0e8b21e 100644 --- a/services/bcc/api/instance.go +++ b/services/bcc/api/instance.go @@ -796,6 +796,34 @@ func ModifyDeletionProtection(cli bce.Client, instanceId string, reqBody *bce.Bo return nil } +// ModifyRelatedDeletePolicy - Modify RelatedDeletePolicy of specified instance +// +// PARAMS: +// - cli: the client agent which can perform sending request +// - instanceId: id of the instance +// - reqBody: the request body to set an instance +// RETURNS: +// - error: nil if success otherwise the specific error +func ModifyRelatedDeletePolicy(cli bce.Client, instanceId string, reqBody *bce.Body) error { + // Build the request + req := &bce.BceRequest{} + req.SetUri(getInstanceRelatedDeletePolicy(instanceId)) + req.SetMethod(http.PUT) + req.SetBody(reqBody) + + // Send request and get response + resp := &bce.BceResponse{} + if err := cli.SendRequest(req, resp); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + + defer func() { resp.Body().Close() }() + return nil +} + // ModifyInstanceAttribute - modify attribute of a specified instance // // PARAMS: diff --git a/services/bcc/api/model.go b/services/bcc/api/model.go index 3791295b..ebaff26a 100644 --- a/services/bcc/api/model.go +++ b/services/bcc/api/model.go @@ -105,53 +105,54 @@ const ( // Instance define instance model type InstanceModel struct { - InstanceId string `json:"id"` - SerialNumber string `json:"serialNumber"` - InstanceName string `json:"name"` - Hostname string `json:"hostname"` - InstanceType InstanceType `json:"instanceType"` - Spec string `json:"spec"` - Description string `json:"desc"` - Status InstanceStatus `json:"status"` - PaymentTiming string `json:"paymentTiming"` - CreationTime string `json:"createTime"` - ExpireTime string `json:"expireTime"` - ReleaseTime string `json:"releaseTime"` - PublicIP string `json:"publicIp"` - InternalIP string `json:"internalIp"` - CpuCount int `json:"cpuCount"` - IsomerismCard string `json:"isomerismCard"` - NpuVideoMemory string `json:"npuVideoMemory"` - GpuCard string `json:"gpuCard"` - FpgaCard string `json:"fpgaCard"` - CardCount string `json:"cardCount"` - MemoryCapacityInGB int `json:"memoryCapacityInGB"` - LocalDiskSizeInGB int `json:"localDiskSizeInGB"` - ImageId string `json:"imageId"` - NetworkCapacityInMbps int `json:"networkCapacityInMbps"` - PlacementPolicy string `json:"placementPolicy"` - ZoneName string `json:"zoneName"` - SubnetId string `json:"subnetId"` - VpcId string `json:"vpcId"` - AutoRenew bool `json:"autoRenew"` - KeypairId string `json:"keypairId"` - KeypairName string `json:"keypairName"` - DedicatedHostId string `json:"dedicatedHostId"` - Tags []model.TagModel `json:"tags"` - Ipv6 string `json:"ipv6"` - EniQuota int `json:"eniQuota"` - EriQuota int `json:"eriQuota"` - RdmaTypeApi string `json:"rdmaTypeApi"` - SwitchId string `json:"switchId"` - HostId string `json:"hostId"` - DeploysetId string `json:"deploysetId"` - RackId string `json:"rackId"` - NicInfo NicInfo `json:"nicInfo"` - EniNum string `json:"eniNum"` - DeploySetList []DeploySetSimpleModel `json:"deploysetList"` - DeletionProtection int `json:"deletionProtection"` - NetEthQueueCount string `json:"netEthQueueCount"` - Volumes []VolumeModel `json:"volumes"` + InstanceId string `json:"id"` + SerialNumber string `json:"serialNumber"` + InstanceName string `json:"name"` + Hostname string `json:"hostname"` + InstanceType InstanceType `json:"instanceType"` + Spec string `json:"spec"` + Description string `json:"desc"` + Status InstanceStatus `json:"status"` + PaymentTiming string `json:"paymentTiming"` + CreationTime string `json:"createTime"` + ExpireTime string `json:"expireTime"` + ReleaseTime string `json:"releaseTime"` + PublicIP string `json:"publicIp"` + InternalIP string `json:"internalIp"` + CpuCount int `json:"cpuCount"` + IsomerismCard string `json:"isomerismCard"` + NpuVideoMemory string `json:"npuVideoMemory"` + GpuCard string `json:"gpuCard"` + FpgaCard string `json:"fpgaCard"` + CardCount string `json:"cardCount"` + MemoryCapacityInGB int `json:"memoryCapacityInGB"` + LocalDiskSizeInGB int `json:"localDiskSizeInGB"` + ImageId string `json:"imageId"` + NetworkCapacityInMbps int `json:"networkCapacityInMbps"` + PlacementPolicy string `json:"placementPolicy"` + ZoneName string `json:"zoneName"` + SubnetId string `json:"subnetId"` + VpcId string `json:"vpcId"` + AutoRenew bool `json:"autoRenew"` + KeypairId string `json:"keypairId"` + KeypairName string `json:"keypairName"` + DedicatedHostId string `json:"dedicatedHostId"` + Tags []model.TagModel `json:"tags"` + Ipv6 string `json:"ipv6"` + EniQuota int `json:"eniQuota"` + EriQuota int `json:"eriQuota"` + RdmaTypeApi string `json:"rdmaTypeApi"` + SwitchId string `json:"switchId"` + HostId string `json:"hostId"` + DeploysetId string `json:"deploysetId"` + RackId string `json:"rackId"` + NicInfo NicInfo `json:"nicInfo"` + EniNum string `json:"eniNum"` + DeploySetList []DeploySetSimpleModel `json:"deploysetList"` + DeletionProtection int `json:"deletionProtection"` + NetEthQueueCount string `json:"netEthQueueCount"` + Volumes []VolumeModel `json:"volumes"` + IsEipAutoRelatedDelete bool `json:"isEipAutoRelatedDelete"` } type DeploySetSimpleModel struct { @@ -186,23 +187,23 @@ type BbcStock struct { } type NicInfo struct { - Status string `json:"status"` - MacAddress string `json:"macAddress"` - DeviceId string `json:"deviceId"` - VpcId string `json:"vpcId"` - EniId string `json:"eniId"` - Name string `json:"name"` - Type string `json:"type"` - CreatedTime string `json:"createdTime"` - SubnetType string `json:"subnetType"` - SubnetId string `json:"subnetId"` - EniNum int `json:"eniNum"` - Az string `json:"az"` - EniUuid string `json:"eniUuid"` - Description string `json:"description"` - Ips []IpModel `json:"ips"` - SecurityGroups []string `json:"securityGroups"` - EnterpriseSecurityGroups []string `json:"enterpriseSecurityGroups"` + Status string `json:"status"` + MacAddress string `json:"macAddress"` + DeviceId string `json:"deviceId"` + VpcId string `json:"vpcId"` + EniId string `json:"eniId"` + Name string `json:"name"` + Type string `json:"type"` + CreatedTime string `json:"createdTime"` + SubnetType string `json:"subnetType"` + SubnetId string `json:"subnetId"` + EniNum int `json:"eniNum"` + Az string `json:"az"` + EniUuid string `json:"eniUuid"` + Description string `json:"description"` + Ips []IpModel `json:"ips"` + SecurityGroups []string `json:"securityGroups"` + EnterpriseSecurityGroups []string `json:"enterpriseSecurityGroups"` } type IpModel struct { @@ -314,6 +315,7 @@ type CreateInstanceArgs struct { FileSystems []FileSystemModel `json:"fileSystems,omitempty"` IsOpenHostEye bool `json:"isOpenHostEye,omitempty"` ResGroupId string `json:"resGroupId,omitempty"` + IsEipAutoRelatedDelete bool `json:"isEipAutoRelatedDelete,omitempty"` } type CreateInstanceArgsV2 struct { @@ -772,43 +774,44 @@ type ListRecycleInstanceResult struct { } type InstanceModelV3 struct { - InstanceId string `json:"instanceId"` - InstanceName string `json:"instanceName"` - HostId string `json:"hostId"` - HostName string `json:"hostName"` - InstanceSpec string `json:"instanceSpec"` - Status InstanceStatus `json:"status"` - Description string `json:"description"` - PaymentTiming string `json:"paymentTiming"` - CreateTime string `json:"createTime"` - ExpireTime string `json:"expireTime"` - ReleaseTime string `json:"releaseTime"` - PrivateIpAddress string `json:"privateIpAddress"` - PublicIpAddress string `json:"publicIpAddress"` - Cpu int `json:"cpu"` - Memory int `json:"memory"` - GpuCard string `json:"gpuCard"` - FpgaCard string `json:"fpgaCard"` - CardCount int `json:"cardCount"` - DataVolumes []DataVolumeV3 `json:"dataVolumes"` - ImageId string `json:"imageId"` - NetworkCapacityInMbps InternetAccessible `json:"networkCapacityInMbps"` - ZoneName string `json:"zoneName"` - SubnetId string `json:"subnetId"` - VpcId string `json:"vpcId"` - AutoRenew bool `json:"autoRenew"` - KeypairId string `json:"keypairId"` - KeypairName string `json:"keypairName"` - HypervisorDedicatedId string `json:"hypervisorDedicatedId"` - Ipv6 string `json:"ipv6"` - Tags []model.TagModel `json:"tags"` - DeployId []string `json:"deployId"` - SerialNumber string `json:"serialNumber"` - SwitchId string `json:"switchId"` - RackId string `json:"rackId"` - NicInfo NicInfoV3 `json:"nicInfo"` - OsName string `json:"osName"` - OsType string `json:"osType"` + InstanceId string `json:"instanceId"` + InstanceName string `json:"instanceName"` + HostId string `json:"hostId"` + HostName string `json:"hostName"` + InstanceSpec string `json:"instanceSpec"` + Status InstanceStatus `json:"status"` + Description string `json:"description"` + PaymentTiming string `json:"paymentTiming"` + CreateTime string `json:"createTime"` + ExpireTime string `json:"expireTime"` + ReleaseTime string `json:"releaseTime"` + PrivateIpAddress string `json:"privateIpAddress"` + PublicIpAddress string `json:"publicIpAddress"` + Cpu int `json:"cpu"` + Memory int `json:"memory"` + GpuCard string `json:"gpuCard"` + FpgaCard string `json:"fpgaCard"` + CardCount int `json:"cardCount"` + DataVolumes []DataVolumeV3 `json:"dataVolumes"` + ImageId string `json:"imageId"` + NetworkCapacityInMbps InternetAccessible `json:"networkCapacityInMbps"` + ZoneName string `json:"zoneName"` + SubnetId string `json:"subnetId"` + VpcId string `json:"vpcId"` + AutoRenew bool `json:"autoRenew"` + KeypairId string `json:"keypairId"` + KeypairName string `json:"keypairName"` + HypervisorDedicatedId string `json:"hypervisorDedicatedId"` + Ipv6 string `json:"ipv6"` + Tags []model.TagModel `json:"tags"` + DeployId []string `json:"deployId"` + SerialNumber string `json:"serialNumber"` + SwitchId string `json:"switchId"` + RackId string `json:"rackId"` + NicInfo NicInfoV3 `json:"nicInfo"` + OsName string `json:"osName"` + OsType string `json:"osType"` + IsEipAutoRelatedDelete bool `json:"isEipAutoRelatedDelete"` } type NicInfoV3 struct { @@ -1000,9 +1003,9 @@ type ReleasePrepaidInstanceResponse struct { type DescribeTransferReservedInstancesRequest struct { ReservedInstanceIds []string `json:"reservedInstanceIds"` - TransferRecordIds []string `json:"transferRecordIds"` - Spec string `json:"spec"` - Status string `json:"status"` + TransferRecordIds []string `json:"transferRecordIds"` + Spec string `json:"spec"` + Status string `json:"status"` } type TransferReservedInstanceRequest struct { @@ -1033,52 +1036,52 @@ type AcceptTransferResponse struct { } type DescribeTransferInRecordsResponse struct { - TotalCount int `json:"totalCount"` - TransferRecords []TransferInRecord `json:"transferRecords"` + TotalCount int `json:"totalCount"` + TransferRecords []TransferInRecord `json:"transferRecords"` } type DescribeTransferOutRecordsResponse struct { - TotalCount int `json:"totalCount"` - TransferRecords []TransferOutRecord `json:"transferRecords"` + TotalCount int `json:"totalCount"` + TransferRecords []TransferOutRecord `json:"transferRecords"` } type TransferInRecord struct { - TransferRecordId string `json:"transferRecordId"` - GrantorUserId string `json:"grantorUserId"` - Status string `json:"status"` - ReservedInstanceInfo ReservedInstanceModel `json:"reservedInstanceInfo"` - ApplicationTime string `json:"applicationTime"` - ExpireTime string `json:"expireTime"` - EndTime string `json:"endTime"` + TransferRecordId string `json:"transferRecordId"` + GrantorUserId string `json:"grantorUserId"` + Status string `json:"status"` + ReservedInstanceInfo ReservedInstanceModel `json:"reservedInstanceInfo"` + ApplicationTime string `json:"applicationTime"` + ExpireTime string `json:"expireTime"` + EndTime string `json:"endTime"` } type TransferOutRecord struct { - TransferRecordId string `json:"transferRecordId"` - RecipientUserId string `json:"recipientUserId"` - Status string `json:"status"` - ReservedInstanceInfo ReservedInstanceModel `json:"reservedInstanceInfo"` - ApplicationTime string `json:"applicationTime"` - ExpireTime string `json:"expireTime"` - EndTime string `json:"endTime"` + TransferRecordId string `json:"transferRecordId"` + RecipientUserId string `json:"recipientUserId"` + Status string `json:"status"` + ReservedInstanceInfo ReservedInstanceModel `json:"reservedInstanceInfo"` + ApplicationTime string `json:"applicationTime"` + ExpireTime string `json:"expireTime"` + EndTime string `json:"endTime"` } type ReservedInstanceModel struct { - ReservedInstanceId string `json:"reservedInstanceId"` - ReservedInstanceName string `json:"reservedInstanceName"` - Scope string `json:"scope"` - ZoneName string `json:"zoneName"` - Spec string `json:"spec"` - ReservedType string `json:"reservedType"` - OfferingType string `json:"offeringType"` - OsType string `json:"osType"` - ReservedInstanceStatus string `json:"reservedInstanceStatus"` - InstanceCount int `json:"instanceCount"` - EffectiveTime string `json:"effectiveTime"` - ExpireTime string `json:"expireTime"` - AutoRenew bool `json:"autoRenew"` - RenewTimeUnit string `json:"renewTimeUnit"` - RenewTime int `json:"renewTime"` - NextRenewTime string `json:"nextRenewTime"` + ReservedInstanceId string `json:"reservedInstanceId"` + ReservedInstanceName string `json:"reservedInstanceName"` + Scope string `json:"scope"` + ZoneName string `json:"zoneName"` + Spec string `json:"spec"` + ReservedType string `json:"reservedType"` + OfferingType string `json:"offeringType"` + OsType string `json:"osType"` + ReservedInstanceStatus string `json:"reservedInstanceStatus"` + InstanceCount int `json:"instanceCount"` + EffectiveTime string `json:"effectiveTime"` + ExpireTime string `json:"expireTime"` + AutoRenew bool `json:"autoRenew"` + RenewTimeUnit string `json:"renewTimeUnit"` + RenewTime int `json:"renewTime"` + NextRenewTime string `json:"nextRenewTime"` } type InstanceDeleteResultModel struct { @@ -1205,6 +1208,11 @@ type ModifyChargeTypeCSDVolumeArgs struct { Billing *Billing `json:"billing"` } +type ResGroupInfo struct { + GroupId string `json:"groupId"` + GroupName string `json:"groupName"` +} + type ListCDSVolumeResult struct { Marker string `json:"marker"` IsTruncated bool `json:"isTruncated"` @@ -1241,6 +1249,7 @@ type VolumeModel struct { SourceSnapshotId string `json:"sourceSnapshotId"` SnapshotNum string `json:"snapshotNum"` Tags []model.TagModel `json:"tags"` + ResGroupInfos []ResGroupInfo `json:"resGroupInfos"` EnableAutoRenew bool `json:"enableAutoRenew"` AutoRenewTime int `json:"autoRenewTime"` Encrypted bool `json:"encrypted"` @@ -1307,6 +1316,7 @@ type CreateCDSVolumeArgs struct { InstanceId string `json:"instanceId"` ClusterId string `json:"clusterId"` Tags []model.TagModel `json:"tags"` + ResGroupId string `json:"resGroupId,omitempty"` AutoSnapshotPolicy []AutoSnapshotPolicy `json:"autoSnapshotPolicy"` ClientToken string `json:"-"` ChargeType string `json:"chargeType"` @@ -2174,6 +2184,10 @@ type DeletionProtectionArgs struct { DeletionProtection int `json:"deletionProtection"` } +type RelatedDeletePolicy struct { + IsEipAutoRelatedDelete bool `json:"isEipAutoRelatedDelete"` +} + type BatchDeleteInstanceWithRelateResourceArgs struct { RelatedReleaseFlag bool `json:"relatedReleaseFlag"` DeleteCdsSnapshotFlag bool `json:"deleteCdsSnapshotFlag"` diff --git a/services/bcc/api/util.go b/services/bcc/api/util.go index 8dc4243c..ec66c0fd 100644 --- a/services/bcc/api/util.go +++ b/services/bcc/api/util.go @@ -88,6 +88,7 @@ const ( REQUEST_TRANSFER_ACCEPT_URI = "/reserved/transfer/accept" REQUEST_TRANSFER_IN_URI = "/reserved/transfer/in/list" REQUEST_TRANSFER_OUT_URI = "/reserved/transfer/out/list" + REQUEST_RELATED_DELETE_POLICY = "/modifyRelatedDeletePolicy" ) func getInstanceUri() string { @@ -150,6 +151,10 @@ func getInstanceDeletionProtectionUri(id string) string { return URI_PREFIXV2 + REQUEST_INSTANCE_URI + "/" + id + REQUEST_DELETION_PROTECTION } +func getInstanceRelatedDeletePolicy(id string) string { + return URI_PREFIXV2 + REQUEST_INSTANCE_URI + "/" + id + REQUEST_RELATED_DELETE_POLICY +} + func Aes128EncryptUseSecreteKey(sk string, data string) (string, error) { if len(sk) < 16 { return "", fmt.Errorf("error secrete key") diff --git a/services/bcc/client.go b/services/bcc/client.go index c9cda90a..51044bd0 100644 --- a/services/bcc/client.go +++ b/services/bcc/client.go @@ -601,6 +601,25 @@ func (c *Client) ModifyDeletionProtection(instanceId string, args *api.DeletionP return api.ModifyDeletionProtection(c, instanceId, body) } +// ModifyRelatedDeletePolicy - Modify RelatedDeletePolicy of specified instance +// +// PARAMS: +// - instanceId: id of the instance +// - args: the arguments to ModifyRelatedDeletePolicy +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) ModifyRelatedDeletePolicy(instanceId string, args *api.RelatedDeletePolicy) error { + jsonBytes, jsonErr := json.Marshal(args) + if jsonErr != nil { + return jsonErr + } + body, err := bce.NewBodyFromBytes(jsonBytes) + if err != nil { + return err + } + return api.ModifyRelatedDeletePolicy(c, instanceId, body) +} + // ModifyInstanceAttribute - modify an instance's attribute // // PARAMS: @@ -2339,7 +2358,6 @@ func (c *Client) BatchRefundResource(arg *api.BatchRefundResourceArg) (*api.Batc return api.BatchRefundResource(c, arg) } - func (c *Client) GetAvailableImagesBySpec(args *api.GetAvailableImagesBySpecArg) (*api.GetAvailableImagesBySpecResult, error) { return api.GetAvailableImagesBySpec(c, args) } diff --git a/services/bcc/client_test.go b/services/bcc/client_test.go index af4fc9de..bc1d5d80 100644 --- a/services/bcc/client_test.go +++ b/services/bcc/client_test.go @@ -1875,6 +1875,23 @@ func TestGetAvailableStockWithSpec(t *testing.T) { fmt.Println(result) } +func TestModifyRelatedDeletePolicy(t *testing.T) { + + args := &api.RelatedDeletePolicy{ + IsEipAutoRelatedDelete: true, + } + err := BCC_CLIENT.ModifyRelatedDeletePolicy("i-ZMRzyU8f", args) + ExpectEqual(t.Errorf, err, nil) + instance, _ := BCC_CLIENT.GetInstanceDetail("i-ZMRzyU8f") + ExpectEqual(t.Errorf, instance.Instance.IsEipAutoRelatedDelete, true) + args = &api.RelatedDeletePolicy{ + IsEipAutoRelatedDelete: false, + } + _ = BCC_CLIENT.ModifyRelatedDeletePolicy("i-ZMRzyU8f", args) + ExpectEqual(t.Errorf, err, nil) + instance, _ = BCC_CLIENT.GetInstanceDetail("i-ZMRzyU8f") + ExpectEqual(t.Errorf, instance.Instance.IsEipAutoRelatedDelete, false) +} func TestTransferReservedInstanceOrder(t *testing.T) { args := &api.TransferReservedInstanceRequest{ @@ -1924,7 +1941,7 @@ func TestTransferInReservedInstanceOrders(t *testing.T) { TransferRecordIds: []string{ //"t-FoM4l1xI", }, - Spec: "bcc.g3.c1m1", + Spec: "bcc.g3.c1m1", Status: "timeout", } result, err := BCC_CLIENT.TransferInReservedInstanceOrders(args) @@ -1941,10 +1958,27 @@ func TestTransferOutReservedInstanceOrders(t *testing.T) { TransferRecordIds: []string{ "t-PKnSYeWh", }, - Spec: "bcc.ic4.c2m2", + Spec: "bcc.ic4.c2m2", Status: "fail", } result, err := BCC_CLIENT.TransferOutReservedInstanceOrders(args) ExpectEqual(t.Errorf, err, nil) fmt.Println(result) -} \ No newline at end of file +} + +func TestCreateVolumeWithResGroup(t *testing.T) { + args := &api.CreateCDSVolumeArgs{ + PurchaseCount: 1, + CdsSizeInGB: 40, + Billing: &api.Billing{ + PaymentTiming: api.PaymentTimingPostPaid, + }, + ResGroupId: "RESG-4xiymzjDzqX", + } + + result, _ := BCC_CLIENT.CreateCDSVolume(args) + BCC_TestCdsId = result.VolumeIds[0] + fmt.Print(BCC_TestCdsId) + res, _ := BCC_CLIENT.GetCDSVolumeDetail(BCC_TestCdsId) + fmt.Println(res.Volume) +} diff --git a/services/blb/blb.go b/services/blb/blb.go index f25eccc5..f9f6f837 100644 --- a/services/blb/blb.go +++ b/services/blb/blb.go @@ -232,3 +232,19 @@ func (c *Client) StartLoadBalancerAutoRenew(blbId string, args *StartLoadBalance WithBody(args). Do() } + +// RefundLoadBalancer - refund the specified LoadBalancer +// +// PARAMS: +// - blbId: LoadBalancer's ID +// - args: parameters to refund LoadBalancer +// RETURNS: +// - error: nil if ok otherwise the specific error +func (c *Client) RefundLoadBalancer(blbId string, args *RefundLoadBalancerArgs) error { + return bce.NewRequestBuilder(c). + WithMethod(http.PUT). + WithURL(getBlbRefundUriWithId(blbId)). + WithQueryParamFilter("clientToken", args.ClientToken). + WithBody(args). + Do() +} diff --git a/services/blb/client.go b/services/blb/client.go index 1b17a89c..83b1f40d 100644 --- a/services/blb/client.go +++ b/services/blb/client.go @@ -70,6 +70,10 @@ func getBlbAutoRenewUriWithId(id string) string { return URI_PREFIX + REQUEST_BLB_URL + "/autoRenew/" + id } +func getBlbRefundUriWithId(id string) string { + return URI_PREFIX + REQUEST_BLB_URL + "/refund/" + id +} + func getListenerUri(id string) string { return URI_PREFIX + REQUEST_BLB_URL + "/" + id + LISTENER_URL } diff --git a/services/blb/client_test.go b/services/blb/client_test.go index ca53757b..cc3ee947 100644 --- a/services/blb/client_test.go +++ b/services/blb/client_test.go @@ -78,13 +78,33 @@ func ExpectEqual(alert func(format string, args ...interface{}), } func TestClient_CreateLoadBalancer(t *testing.T) { + AllowDelete := false + AllocateIpv6 := true + Layer4ClusterExclusive := false + createArgs := &CreateLoadBalancerArgs{ + ClientToken: getClientToken(), + Name: "sdkBlb051103", + VpcId: "vpc-rfujg1q3zqqf", + SubnetId: "sbn-sx0zf4qbcbmp", + AllowDelete: &AllowDelete, + AllocateIpv6: &AllocateIpv6, + Layer4ClusterExclusive: &Layer4ClusterExclusive, + } + + createResult, err := BLB_CLIENT.CreateLoadBalancer(createArgs) + ExpectEqual(t.Errorf, nil, err) + + BLB_ID = createResult.BlbId +} + +func TestClient_CreatePrePayLoadBalancer(t *testing.T) { AllowDelete := false AllocateIpv6 := true createArgs := &CreateLoadBalancerArgs{ ClientToken: getClientToken(), - Name: "sdkBlb040101", - VpcId: VPC_TEST_ID, - SubnetId: SUBNET_TEST_ID, + Name: "sdkBlb051101", + VpcId: "vpc-rfujg1q3zqqf", + SubnetId: "sbn-sx0zf4qbcbmp", AutoRenewLength: 1, Billing: &Billing{ PaymentTiming: "Prepaid", @@ -446,6 +466,14 @@ func TestClient_StartLoadBalancerAutoRenew(t *testing.T) { ExpectEqual(t.Errorf, nil, err) } +func TestClient_RefundLoadBalancer(t *testing.T) { + updateArgs := &RefundLoadBalancerArgs{ + ClientToken: getClientToken(), + } + err := BLB_CLIENT.RefundLoadBalancer("lb-3d3d4a58", updateArgs) + ExpectEqual(t.Errorf, nil, err) +} + func getClientToken() string { return util.NewUUID() } diff --git a/services/blb/model.go b/services/blb/model.go index ff8d4bea..88fd6f55 100644 --- a/services/blb/model.go +++ b/services/blb/model.go @@ -38,23 +38,27 @@ type DescribeResultMeta struct { } type CreateLoadBalancerArgs struct { - ClientToken string `json:"-"` - Name string `json:"name,omitempty"` - Description string `json:"desc,omitempty"` - SubnetId string `json:"subnetId"` - VpcId string `json:"vpcId"` - ClusterProperty string `json:"clusterProperty"` - Type string `json:"type,omitempty"` - Address string `json:"address,omitempty"` - Eip string `json:"eip,omitempty"` - ResourceGroupId string `json:"resourceGroupId,omitempty"` - AutoRenewLength int `json:"autoRenewLength,omitempty"` - AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"` - PerformanceLevel string `json:"performanceLevel,omitempty"` - Billing *Billing `json:"billing,omitempty"` - Tags []model.TagModel `json:"tags,omitempty"` - AllowDelete *bool `json:"allowDelete,omitempty"` - AllocateIpv6 *bool `json:"allocateIpv6,omitempty"` + ClientToken string `json:"-"` + Name string `json:"name,omitempty"` + Description string `json:"desc,omitempty"` + SubnetId string `json:"subnetId"` + VpcId string `json:"vpcId"` + ClusterProperty string `json:"clusterProperty"` + Type string `json:"type,omitempty"` + Address string `json:"address,omitempty"` + Eip string `json:"eip,omitempty"` + ResourceGroupId string `json:"resourceGroupId,omitempty"` + AutoRenewLength int `json:"autoRenewLength,omitempty"` + AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"` + PerformanceLevel string `json:"performanceLevel,omitempty"` + Billing *Billing `json:"billing,omitempty"` + Tags []model.TagModel `json:"tags,omitempty"` + AllowDelete *bool `json:"allowDelete,omitempty"` + AllocateIpv6 *bool `json:"allocateIpv6,omitempty"` + Layer4ClusterExclusive *bool `json:"layer4ClusterExclusive,omitempty"` + Layer7ClusterExclusive *bool `json:"layer7ClusterExclusive,omitempty"` + Layer4ClusterId string `json:"layer4ClusterId,omitempty"` + Layer7ClusterId string `json:"layer7ClusterId,omitempty"` } type Billing struct { @@ -93,6 +97,10 @@ type StartLoadBalancerAutoRenewArgs struct { AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"` } +type RefundLoadBalancerArgs struct { + ClientToken string `json:"-"` +} + type DescribeLoadBalancersArgs struct { Address string Name string @@ -105,19 +113,21 @@ type DescribeLoadBalancersArgs struct { } type BLBModel struct { - BlbId string `json:"blbId"` - Name string `json:"name"` - Description string `json:"desc"` - Address string `json:"address"` - Status BLBStatus `json:"status"` - VpcId string `json:"vpcId"` - SubnetId string `json:"subnetId"` - PublicIp string `json:"publicIp"` - Layer4ClusterId string `json:"layer4ClusterId"` - Layer7ClusterId string `json:"layer7ClusterId"` - Tags []model.TagModel `json:"tags"` - EipRouteType string `json:"eipRouteType"` - AllowDelete bool `json:"allowDelete"` + BlbId string `json:"blbId"` + Name string `json:"name"` + Description string `json:"desc"` + Address string `json:"address"` + Status BLBStatus `json:"status"` + VpcId string `json:"vpcId"` + SubnetId string `json:"subnetId"` + PublicIp string `json:"publicIp"` + Layer4ClusterId string `json:"layer4ClusterId"` + Layer7ClusterId string `json:"layer7ClusterId"` + Tags []model.TagModel `json:"tags"` + EipRouteType string `json:"eipRouteType"` + AllowDelete bool `json:"allowDelete"` + Layer4ClusterExclusive bool `json:"layer4ClusterExclusive"` + Layer7ClusterExclusive bool `json:"layer7ClusterExclusive"` } type DescribeLoadBalancersResult struct { @@ -162,6 +172,8 @@ type DescribeLoadBalancerDetailResult struct { PaymentTiming string `json:"paymentTiming"` PerformanceLevel string `json:"performanceLevel"` ExpireTime string `json:"expireTime"` + AllowDelete bool `json:"allowDelete"` + VpcId string `json:"vpcId"` } type CreateTCPListenerArgs struct { diff --git a/services/bos/api/bucket.go b/services/bos/api/bucket.go index 97146b24..ea79f003 100644 --- a/services/bos/api/bucket.go +++ b/services/bos/api/bucket.go @@ -1206,7 +1206,7 @@ func PutBucketTag(cli bce.Client, bucket string, putBucketTagArgs *PutBucketTagA return nil } -func GetBucketTag(cli bce.Client, bucket string, ctx *BosContext) (*PutBucketTagArgs, error) { +func GetBucketTag(cli bce.Client, bucket string, ctx *BosContext) (*GetBucketTagResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) @@ -1219,7 +1219,7 @@ func GetBucketTag(cli bce.Client, bucket string, ctx *BosContext) (*PutBucketTag if resp.IsFail() { return nil, resp.ServiceError() } - result := &PutBucketTagArgs{} + result := &GetBucketTagResult{} if err := resp.ParseJsonBody(result); err != nil { return nil, err } diff --git a/services/bos/api/model.go b/services/bos/api/model.go index 61d4424d..914fa21d 100644 --- a/services/bos/api/model.go +++ b/services/bos/api/model.go @@ -637,6 +637,15 @@ type Tag struct { TagValue string `json:"tagValue"` } +type GetBucketTagResult struct { + Tags []BucketTag `json:"tag"` +} + +type BucketTag struct { + TagKey string `json:"tag_key"` + TagValue string `json:"tag_value"` +} + type BosContext struct { Bucket string PathStyleEnable bool diff --git a/services/bos/client.go b/services/bos/client.go index f5fbaeb1..aec79b24 100644 --- a/services/bos/client.go +++ b/services/bos/client.go @@ -945,6 +945,13 @@ func (c *Client) PutObjectFromFileWithCallback(bucket, object, fileName string, etag, putObjectResult, err := api.PutObject(c, bucket, object, body, args, c.BosContext) return etag, putObjectResult, err } + +func (c *Client) PutObjectWithCallback(bucket, object string, body *bce.Body, + args *api.PutObjectArgs) (string, *api.PutObjectResult, error) { + etag, putObjectResult, err := api.PutObject(c, bucket, object, body, args, c.BosContext) + return etag, putObjectResult, err +} + // CopyObject - copy a remote object to another one // // PARAMS: @@ -2282,7 +2289,7 @@ func (c *Client) PutBucketTag(bucket string, putBucketTagArgs *api.PutBucketTagA return api.PutBucketTag(c, bucket, putBucketTagArgs, c.BosContext) } -func (c *Client) GetBucketTag(bucket string) (*api.PutBucketTagArgs, error) { +func (c *Client) GetBucketTag(bucket string) (*api.GetBucketTagResult, error) { return api.GetBucketTag(c, bucket, c.BosContext) } diff --git a/services/ddc/v2/model.go b/services/ddc/v2/model.go index 529a4e3d..dfd08845 100644 --- a/services/ddc/v2/model.go +++ b/services/ddc/v2/model.go @@ -82,23 +82,23 @@ type CreateReadReplicaArgs struct { } type CreateHotBackupArgs struct { - ClientToken string `json:"-"` - Billing Billing `json:"billing,omitempty"` - PurchaseCount int `json:"purchaseCount,omitempty"` - SourceInstanceId string `json:"sourceInstanceId"` - InstanceName string `json:"instanceName,omitempty"` - CpuCount int `json:"cpuCount,omitempty"` - MemoryCapacity float64 `json:"memoryCapacity,omitempty"` - VolumeCapacity int `json:"volumeCapacity,omitempty"` - ZoneNames []string `json:"zoneNames,omitempty"` - VpcId string `json:"vpcId,omitempty"` - IsDirectPay bool `json:"isDirectPay,omitempty"` - Subnets []SubnetMap `json:"subnets,omitempty"` - Tags []TagModel `json:"tags,omitempty"` - DeployId string `json:"deployId,omitempty"` - PoolId string `json:"poolId,omitempty"` - AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"` - AutoRenewTime int `json:"autoRenewTime,omitempty"` + ClientToken string `json:"-"` + Billing Billing `json:"billing,omitempty"` + PurchaseCount int `json:"purchaseCount,omitempty"` + SourceInstanceId string `json:"sourceInstanceId"` + InstanceName string `json:"instanceName,omitempty"` + CpuCount int `json:"cpuCount,omitempty"` + MemoryCapacity float64 `json:"memoryCapacity,omitempty"` + VolumeCapacity int `json:"volumeCapacity,omitempty"` + ZoneNames []string `json:"zoneNames,omitempty"` + VpcId string `json:"vpcId,omitempty"` + IsDirectPay bool `json:"isDirectPay,omitempty"` + Subnets []SubnetMap `json:"subnets,omitempty"` + Tags []TagModel `json:"tags,omitempty"` + DeployId string `json:"deployId,omitempty"` + PoolId string `json:"poolId,omitempty"` + AutoRenewTimeUnit string `json:"autoRenewTimeUnit,omitempty"` + AutoRenewTime int `json:"autoRenewTime,omitempty"` } type Instance struct { @@ -139,8 +139,8 @@ type Instance struct { HostName string `json:"hostname,omitempty"` InstanceTopoForReadonly InstanceTopoForReadonly `json:"instanceTopoForReadonly,omitempty"` AutoRenewRule *AutoRenewRule `json:"autoRenewRule,omitempty"` - IsHotBackup bool `json:"isHotBackup"` - HotBackupList []HotBackup `json:"hotBackupList"` + IsHotBackup bool `json:"isHotBackup"` + HotBackupList []HotBackup `json:"hotBackupList"` } type AutoRenewRule struct { @@ -365,8 +365,8 @@ type InstanceModel struct { LongBBCId string `json:"longBBCId"` InstanceTopoForReadonly InstanceTopoForReadonly `json:"instanceTopoForReadonly,omitempty"` AutoRenewRule *AutoRenewRule `json:"autoRenewRule,omitempty"` - IsHotBackup bool `json:"isHotBackup"` - HotBackupList []HotBackup `json:"hotBackupList"` + IsHotBackup bool `json:"isHotBackup"` + HotBackupList []HotBackup `json:"hotBackupList"` } type TopoInstance struct { InstanceID string `json:"instanceId,omitempty"` @@ -403,9 +403,9 @@ type RoGroup struct { } type HotBackup struct { - InstanceId string `json:"instanceId"` - Status string `json:"status"` - InstanceName string `json:"instanceName"` + InstanceId string `json:"instanceId"` + Status string `json:"status"` + InstanceName string `json:"instanceName"` } type UpdateRoGroupArgs struct { @@ -803,6 +803,7 @@ type ResizeRdsArgs struct { NodeAmount int `json:"nodeAmount,omitempty"` IsDirectPay bool `json:"isDirectPay,omitempty"` IsResizeNow bool `json:"isResizeNow,omitempty"` + WaitSwitch int `json:"waitSwitch,omitempty"` } type OrderIdResponse struct { @@ -833,6 +834,7 @@ type RebootArgs struct { type SwitchArgs struct { IsSwitchNow bool `json:"isSwitchNow"` + WaitSwitch int `json:"waitSwitch,omitempty"` } type MaintainWindow struct { diff --git a/services/tag/tag/client.go b/services/tag/tag/client.go deleted file mode 100644 index 8db4f3a5..00000000 --- a/services/tag/tag/client.go +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 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. - */ - -// client.go - define the client for tag service - -package tag - -import "github.com/baidubce/bce-sdk-go/bce" - -const ( - URI_PREFIX = bce.URI_PREFIX - DEFAULT_ENDPOINT = "tag.baidubce.com" - URI_TAG_PREFIX = "v1/tag" - URI_RESOURCE_PREFIX = "v1/resource" - URI_QUERY_FULL_LIST = URI_TAG_PREFIX + "/queryFullList" - URI_TAG_RESOURCES = URI_TAG_PREFIX + "/tagResources" -) - -// Client of Group service is a kind of BceClient, so derived from BceClient -type Client struct { - *bce.BceClient -} - -func NewClient(ak, sk, endPoint string) (*Client, error) { - if len(endPoint) == 0 { - endPoint = DEFAULT_ENDPOINT - } - client, err := bce.NewBceClientWithAkSk(ak, sk, endPoint) - if err != nil { - return nil, err - } - return &Client{client}, nil -} - -func queryFullListUri() string { - return URI_PREFIX + URI_QUERY_FULL_LIST -} - -func tagsResourcesUri() string { - return URI_PREFIX + URI_TAG_RESOURCES -} - -func tagBaseUri() string { - return URI_PREFIX + URI_TAG_PREFIX -} -func resourceBaseUri() string { - return URI_PREFIX + URI_RESOURCE_PREFIX -} diff --git a/services/tag/tag/client_test.go b/services/tag/tag/client_test.go deleted file mode 100644 index 88f1d7cd..00000000 --- a/services/tag/tag/client_test.go +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright 2021 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 tag - -import ( - "encoding/json" - "fmt" - "github.com/baidubce/bce-sdk-go/util/log" - "os" - "path/filepath" - "reflect" - "runtime" - "testing" -) - -// For security reason, ak/sk should not hard write here. -type Conf struct { - AK string - SK string - Endpoint string -} - -var tagClient *Client - -func init() { - _, f, _, _ := runtime.Caller(0) - for i := 0; i < 7; i++ { - f = filepath.Dir(f) - } - conf := filepath.Join(f, "config.json") - fp, err := os.Open(conf) - if err != nil { - fmt.Printf("config json file of ak/sk not given: %+v\n", conf) - os.Exit(1) - } - decoder := json.NewDecoder(fp) - confObj := &Conf{} - decoder.Decode(confObj) - tagClient, _ = NewClient(confObj.AK, confObj.SK, confObj.Endpoint) - log.SetLogLevel(log.DEBUG) -} - -// ExpectEqual is the helper function for test each case -func ExpectEqual(alert func(format string, args ...interface{}), - expected interface{}, actual interface{}) bool { - expectedValue, actualValue := reflect.ValueOf(expected), reflect.ValueOf(actual) - equal := false - switch { - case expected == nil && actual == nil: - return true - case expected != nil && actual == nil: - equal = expectedValue.IsNil() - case expected == nil && actual != nil: - equal = actualValue.IsNil() - default: - if actualType := reflect.TypeOf(actual); actualType != nil { - if expectedValue.IsValid() && expectedValue.Type().ConvertibleTo(actualType) { - equal = reflect.DeepEqual(expectedValue.Convert(actualType).Interface(), actual) - } - } - } - if !equal { - _, file, line, _ := runtime.Caller(1) - alert("%s:%d: missmatch, expect %v but %v", file, line, expected, actual) - return false - } - return true -} - -func TestCreateTags(t *testing.T) { - args := &TagsRequest{ - Tags: []Tag{ - { - TagKey: "go_sdk_key", - TagValue: "go_sdk_val", - }, { - TagKey: "go_sdk_key", - TagValue: "go_sdk_val1", - }, - }, - } - jsonArgs, _ := json.Marshal(args) - t.Logf("request args:%s", string(jsonArgs)) - err := tagClient.CreateTags(args) - ExpectEqual(t.Errorf, err, nil) -} - -func TestDeleteTags(t *testing.T) { - args := &TagsRequest{ - Tags: []Tag{ - { - TagKey: "go_sdk_key", - TagValue: "go_sdk_val-del", - }, - { - TagKey: "go_sdk_key", - TagValue: "go_sdk_val-del1", - }, - }, - } - jsonArgs, _ := json.Marshal(args) - t.Logf("request args:%s", string(jsonArgs)) - err := tagClient.CreateTags(args) - ExpectEqual(t.Errorf, err, nil) - - t.Logf("request args:%s", string(jsonArgs)) - err = tagClient.DeleteTags(args) - ExpectEqual(t.Errorf, err, nil) -} - -func TestTagsResources(t *testing.T) { - tagKey := "go_sdk_key" - tagValue := "go_sdk_val" - region := "global" - resourceType := "APIGW" - res, err := tagClient.TagsResources(tagKey, tagValue, region, resourceType) - ExpectEqual(t.Errorf, err, nil) - jsonRes, _ := json.Marshal(res) - t.Logf("response jsonRes:%s", string(jsonRes)) -} - -func TestUserList(t *testing.T) { - tagKey := "go_sdk_key" - tagValue := "go_sdk_val" - res, err := tagClient.UserTagList(tagKey, tagValue) - ExpectEqual(t.Errorf, err, nil) - jsonRes, _ := json.Marshal(res) - t.Logf("response jsonRes:%s", string(jsonRes)) -} - -func TestCreateAssociationsByTag(t *testing.T) { - args := &CreateAssociationsByTagRequest{ - TagKey: "go_sdk_key", - TagValue: "go_sdk_val", - ServiceType: "APIGW", - Resource: []Resource{ - { - ResourceId: "58426", - ServiceType: "APIGW", - Region: "global", - }, - { - ResourceId: "58428", - ServiceType: "APIGW", - Region: "global", - }, - }, - } - jsonArgs, _ := json.Marshal(args) - t.Logf("request args:%s", string(jsonArgs)) - err := tagClient.CreateAssociationsByTag(args) - ExpectEqual(t.Errorf, err, nil) -} - -func TestDeleteAssociationsByTag(t *testing.T) { - args := &DeleteAssociationsByTagRequest{ - TagKey: "go_sdk_key", - TagValue: "go_sdk_val", - ServiceType: "APIGW", - Resource: []Resource{ - { - ResourceId: "58426", - ServiceType: "APIGW", - Region: "global", - }, - { - ResourceId: "58428", - ServiceType: "APIGW", - Region: "global", - }, - }, - } - jsonArgs, _ := json.Marshal(args) - t.Logf("request args:%s", string(jsonArgs)) - err := tagClient.DeleteAssociationsByTag(args) - ExpectEqual(t.Errorf, err, nil) -} - -func TestCreateAndAssign(t *testing.T) { - args := &CreateAndAssignTagRequest{ - ResourceWithTag: []ResourceWithTag{ - { - ResourceId: "58426", - ResourceUuid: "GWGP-w79NnAxhhoj", - ServiceType: "APIGW", - Region: "global", - Tags: []Tag{ - { - TagKey: "go_sdk_key", - TagValue: "go_sdk_val", - }, - { - TagKey: "go_sdk_key1", - TagValue: "go_sdk_val", - }, - }, - }, - }, - } - jsonArgs, _ := json.Marshal(args) - t.Logf("request args:%s", string(jsonArgs)) - err := tagClient.CreateAndAssign(args) - ExpectEqual(t.Errorf, err, nil) -} - -func TestDeleteTagAssociation(t *testing.T) { - - args := &DeleteTagAssociationRequest{ - Resource: &Resource{ - ResourceId: "58426", - ServiceType: "APIGW", - Region: "global", - }, - } - - jsonArgs, _ := json.Marshal(args) - t.Logf("request args:%s", string(jsonArgs)) - err := tagClient.DeleteTagAssociation(args) - ExpectEqual(t.Errorf, err, nil) -} - -func TestQueryFullList(t *testing.T) { - var strongAssociation = true - args := &FullTagListRequest{ - TagKey: "go_sdk_key", - TagValue: "go_sdk_val", - Regions: []string{ - "global", - }, - ServiceTypes: []string{ - "APIGW", - }, - ResourceIds: []string{}, - } - jsonArgs, _ := json.Marshal(args) - t.Logf("request args:%s", string(jsonArgs)) - res, err := tagClient.QueryFullList(strongAssociation, args) - ExpectEqual(t.Errorf, err, nil) - jsonRes, _ := json.Marshal(res) - t.Logf("response jsonRes:%s", string(jsonRes)) -} - -func TestQueryFullListArgsTooLarge(t *testing.T) { - var strongAssociation = true - var resourceIds []string - for i := 0; i < 201; i++ { - resourceIds = append(resourceIds, fmt.Sprintf("bcm5-qasandbox.sys-qa.com%d", i)) - } - - args := &FullTagListRequest{ - TagKey: "test_zmq_1213", - TagValue: "value_zmq", - Regions: []string{ - "bj", - }, - ServiceTypes: []string{ - "CDN", - }, - ResourceIds: resourceIds, - } - jsonArgs, _ := json.Marshal(args) - t.Logf("request args:%s", string(jsonArgs)) - res, err := tagClient.QueryFullList(strongAssociation, args) - ExpectEqual(t.Errorf, err, nil) - jsonRes, _ := json.Marshal(res) - t.Logf("response jsonRes:%s", string(jsonRes)) -} diff --git a/services/tag/tag/model.go b/services/tag/tag/model.go deleted file mode 100644 index a51f0c79..00000000 --- a/services/tag/tag/model.go +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2020 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. - */ - -// model.go - definitions of the request arguments and results data structure model - -package tag - -type Tag struct { - TagKey string `json:"tagKey"` - TagValue string `json:"tagValue"` -} - -type TagsRequest struct { - Tags []Tag `json:"tags"` -} - -type TagsResult struct { - Tags []Tag `json:"tags"` -} - -type Resource struct { - ResourceId string `json:"resourceId"` - ServiceType string `json:"serviceType"` - Region string `json:"region"` -} - -type TagAssociationFull struct { - TagAssociation - TagKey string `json:"tagKey"` - TagValue string `json:"tagValue"` - AssociationType int `json:"associationType"` -} - -type TagAssociation struct { - AccountId string `json:"accountId"` - ResourceId string `json:"resourceId"` - ResourceUuid string `json:"resourceUuid"` - Region string `json:"region"` - ServiceType string `json:"serviceType"` - TagId int64 `json:"tagId"` -} - -type TagResource struct { - ResourceType string `json:"resourceType"` - ResourceId string `json:"resourceId"` - Region string `json:"region"` -} - -type ResourceWithTag struct { - ResourceId string `json:"resourceId"` - ResourceUuid string `json:"resourceUuid"` - ServiceType string `json:"serviceType"` - Region string `json:"region"` - Tags []Tag `json:"tags"` - AssociationType string `json:"associationType"` -} - -type TagAssociationWithResources struct { - Tag - Resources []TagResource `json:"resources"` -} - -type TagsAssociationWithResources struct { - TagResources []TagAssociationWithResources `json:"tagResources"` -} - -type DeleteAssociationsByTagRequest struct { - TagKey string `json:"tagKey"` - TagValue string `json:"tagValue"` - ServiceType string `json:"serviceType"` - Resource []Resource `json:"resources"` -} - -type DeleteTagAssociationRequest struct { - Resource *Resource `json:"resource"` -} - -type CreateAssociationsByTagRequest struct { - TagKey string `json:"tagKey"` - TagValue string `json:"tagValue"` - ServiceType string `json:"serviceType"` - Resource []Resource `json:"resources"` -} - -type CreateAndAssignTagRequest struct { - ResourceWithTag []ResourceWithTag `json:"resources"` -} - -type FullTagListRequest struct { - TagKey string `json:"tagKey,omitempty"` - TagValue string `json:"tagValue,omitempty"` - Regions []string `json:"regions,omitempty"` - ServiceTypes []string `json:"serviceTypes,omitempty"` - ResourceIds []string `json:"resourceIds,omitempty"` -} - -type TagAssociationFulls struct { - TagAssociationFull []TagAssociationFull `json:"tagAssociationFulls"` -} diff --git a/services/tag/tag/tag.go b/services/tag/tag/tag.go deleted file mode 100644 index bbc53960..00000000 --- a/services/tag/tag/tag.go +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2020 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. - */ - -// tag.go - the resmanager APIs definition supported by the resmanager service -package tag - -import ( - "fmt" - "github.com/baidubce/bce-sdk-go/bce" - "github.com/baidubce/bce-sdk-go/http" - "strconv" -) - -// CreateTags https://cloud.baidu.com/doc/TAG/s/Okbrb3ral -func (c *Client) CreateTags(args *TagsRequest) error { - if args == nil { - return fmt.Errorf("unset args") - } - if len(args.Tags) == 0 { - return fmt.Errorf("unset tags") - } - err := bce.NewRequestBuilder(c). - WithMethod(http.PUT). - WithURL(tagBaseUri()). - WithQueryParam("create", ""). - WithBody(args). - WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). - Do() - return err -} - -// DeleteTags https://cloud.baidu.com/doc/TAG/s/Xkbrb3rhr -func (c *Client) DeleteTags(args *TagsRequest) error { - if args == nil { - return fmt.Errorf("unset args") - } - if len(args.Tags) == 0 { - return fmt.Errorf("unset tags") - } - err := bce.NewRequestBuilder(c). - WithMethod(http.PUT). - WithURL(tagBaseUri()). - WithQueryParam("delete", ""). - WithBody(args). - WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). - Do() - return err -} - -// TagsResources https://cloud.baidu.com/doc/TAG/s/Bkbrb3roy -func (c *Client) TagsResources(tagKey string, tagValue string, region string, resourceType string) (*TagsAssociationWithResources, error) { - result := &TagsAssociationWithResources{} - err := bce.NewRequestBuilder(c). - WithMethod(http.GET). - WithURL(tagsResourcesUri()). - WithQueryParamFilter("tagKey", tagKey). - WithQueryParamFilter("tagValue", tagValue). - WithQueryParamFilter("region", region). - WithQueryParamFilter("resourceType", resourceType). - WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). - WithResult(result). - Do() - return result, err -} - -// UserTagList https://cloud.baidu.com/doc/TAG/s/Ukbrb3r3d -func (c *Client) UserTagList(tagKey, tagValue string) (*TagsResult, error) { - - result := &TagsResult{} - err := bce.NewRequestBuilder(c). - WithMethod(http.GET). - WithURL(tagBaseUri()). - WithQueryParamFilter("tagKey", tagKey). - WithQueryParamFilter("tagValue", tagValue). - WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). - WithResult(result). - Do() - return result, err -} - -// CreateAssociationsByTag https://cloud.baidu.com/doc/TAG/s/rkm1yqvhz -func (c *Client) CreateAssociationsByTag(args *CreateAssociationsByTagRequest) error { - if args == nil { - return fmt.Errorf("unset args") - } - if len(args.TagKey) == 0 { - return fmt.Errorf("unset tagKey") - } - if len(args.TagValue) == 0 { - return fmt.Errorf("unset tagValue") - } - if len(args.ServiceType) == 0 { - return fmt.Errorf("unset serviceType") - } - if len(args.Resource) == 0 { - return fmt.Errorf("unset resource") - } - - err := bce.NewRequestBuilder(c). - WithMethod(http.POST). - WithURL(resourceBaseUri()). - WithBody(args). - WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). - Do() - return err -} - -// DeleteAssociationsByTag https://cloud.baidu.com/doc/TAG/s/7km1zf2j2 -func (c *Client) DeleteAssociationsByTag(args *DeleteAssociationsByTagRequest) error { - if args == nil { - return fmt.Errorf("unset args") - } - if len(args.TagKey) == 0 { - return fmt.Errorf("unset tagKey") - } - if len(args.TagValue) == 0 { - return fmt.Errorf("unset tagValue") - } - if len(args.ServiceType) == 0 { - return fmt.Errorf("unset serviceType") - } - if len(args.Resource) == 0 { - return fmt.Errorf("unset resource") - } - err := bce.NewRequestBuilder(c). - WithMethod(http.PUT). - WithURL(resourceBaseUri()). - WithBody(args). - WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). - Do() - return err -} - -// DeleteTagAssociation https://cloud.baidu.com/doc/TAG/s/wkm1sfady -func (c *Client) DeleteTagAssociation(args *DeleteTagAssociationRequest) error { - if args == nil { - return fmt.Errorf("unset args") - } - - if args.Resource == nil { - return fmt.Errorf("unset resource") - } - - err := bce.NewRequestBuilder(c). - WithMethod(http.PUT). - WithURL(tagBaseUri()). - WithQueryParam("deleteTagAssociation", ""). - WithBody(args). - WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). - Do() - return err -} - -// CreateAndAssign https://cloud.baidu.com/doc/TAG/s/Wkm1t1xca -func (c *Client) CreateAndAssign(args *CreateAndAssignTagRequest) error { - if args == nil { - return fmt.Errorf("unset args") - } - if len(args.ResourceWithTag) == 0 { - return fmt.Errorf("unset resources") - } - err := bce.NewRequestBuilder(c). - WithMethod(http.POST). - WithURL(tagBaseUri()). - WithQueryParam("createAndAssign", ""). - WithBody(args). - WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). - Do() - return err -} - -// QueryFullList https://cloud.baidu.com/doc/TAG/s/Ekm1tunjn -func (c *Client) QueryFullList(strongAssociation bool, args *FullTagListRequest) (*TagAssociationFulls, error) { - if args == nil { - return nil, fmt.Errorf("unset args") - } - result := &TagAssociationFulls{} - err := bce.NewRequestBuilder(c). - WithMethod(http.POST). - WithURL(queryFullListUri()). - WithQueryParamFilter("strongAssociation", strconv.FormatBool(strongAssociation)). - WithBody(args). - WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). - WithResult(result). - Do() - return result, err -}