fix(region): The latest api of Huawei cloud elb and eip is applicable (#19027)

This commit is contained in:
屈轩
2023-12-18 15:41:21 +08:00
committed by GitHub
parent ea5b0fd896
commit ce7dc3bfaf
17 changed files with 238 additions and 496 deletions

2
go.mod
View File

@@ -88,7 +88,7 @@ require (
k8s.io/client-go v0.19.3
k8s.io/cluster-bootstrap v0.19.3
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231215084755-601e4d02e207
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231218072105-9257091d5b31
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361

4
go.sum
View File

@@ -1201,8 +1201,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231215084755-601e4d02e207 h1:p2R9I3/DNwTJrD/RDQlF9a8xWYo4nXOs+B6KLZXqNSc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231215084755-601e4d02e207/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231218072105-9257091d5b31 h1:AdJrsaKEjnohmLNNr2WOUoFfG87GYRJ6JNXqnMuvTx8=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231218072105-9257091d5b31/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=

2
vendor/modules.txt vendored
View File

@@ -1465,7 +1465,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231215084755-601e4d02e207
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231218072105-9257091d5b31
## explicit; go 1.18
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing

View File

@@ -105,6 +105,7 @@ func jsonInvoke(cli *client.Client, apiName, path string, params map[string]inte
ECS_SERVICE_NAME,
KINESIS_SERVICE_NAME,
DYNAMODB_SERVICE_NAME,
PRICING_SERVICE_NAME,
}) {
method = "POST"
}

View File

@@ -27,7 +27,6 @@ type Client struct {
// 标记初始化状态
init bool
Balances *modules.SBalanceManager
Credentials *modules.SCredentialManager
Disks *modules.SDiskManager
Domains *modules.SDomainManager
@@ -130,7 +129,6 @@ func (self *Client) SetHttpClient(httpClient *http.Client) {
self.Users.SetHttpClient(httpClient)
self.Interface.SetHttpClient(httpClient)
self.Jobs.SetHttpClient(httpClient)
self.Balances.SetHttpClient(httpClient)
self.Port.SetHttpClient(httpClient)
self.Flavors.SetHttpClient(httpClient)
self.VpcRoutes.SetHttpClient(httpClient)
@@ -201,7 +199,6 @@ func (self *Client) initManagers() {
self.Users = modules.NewUserManager(self.cfg)
self.Interface = modules.NewInterfaceManager(self.cfg)
self.Jobs = modules.NewJobManager(self.cfg)
self.Balances = modules.NewBalanceManager(self.cfg)
self.Credentials = modules.NewCredentialManager(self.cfg)
self.Port = modules.NewPortManager(self.cfg)
self.Flavors = modules.NewFlavorManager(self.cfg)

View File

@@ -1,72 +0,0 @@
// Copyright 2019 Yunion
//
// 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 modules
import (
"fmt"
"yunion.io/x/cloudmux/pkg/multicloud/huawei/client/manager"
"yunion.io/x/cloudmux/pkg/multicloud/huawei/client/responses"
)
/*
https://support.huaweicloud.com/api-oce/zh-cn_topic_0075195195.html
客户运营能力API的Endpoint为“bss.cn-north-1.myhuaweicloud.com”。该Endpoint为全局Endpoint中国站所有区域均可使用。
如何获取合作伙伴ID https://support.huaweicloud.com/bpconsole_faq/zh-cn_topic_0081005893.html
注意事项:
客户查询自身的账户余额的时候只允许使用客户自身的AK/SK或者Token调用。
*/
type SBalanceManager struct {
domainId string // 租户ID
SResourceManager
}
type balanceCtx struct {
domainId string
}
// https://support.huaweicloud.com/api-bpconsole/zh-cn_topic_0075213309.html
// 这个manager非常特殊。url hardcode
func (self *balanceCtx) GetPath() string {
return fmt.Sprintf("%s/customer/account-mgr", self.domainId)
}
// 这个manager非常特殊。只有List 和 SetDomainId方法可用。其他方法未验证
func NewBalanceManager(cfg manager.IManagerConfig) *SBalanceManager {
return &SBalanceManager{SResourceManager: SResourceManager{
SBaseManager: NewBaseManager(cfg),
ServiceName: ServiceNameBSS,
Region: "cn-north-1",
ProjectId: "",
version: "v1.0",
Keyword: "account_balance",
KeywordPlural: "account_balances",
ResourceKeyword: "balances",
}}
}
func (self *SBalanceManager) List(querys map[string]string) (*responses.ListResult, error) {
if len(self.domainId) == 0 {
return nil, fmt.Errorf("domainId is emtpy.Use SetDomainId method to set.")
}
ctx := &balanceCtx{domainId: self.domainId}
return self.ListInContext(ctx, querys)
}
func (self *SBalanceManager) SetDomainId(domainId string) {
self.domainId = domainId
}

View File

@@ -21,7 +21,6 @@ import (
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/httputils"
@@ -31,68 +30,34 @@ import (
"yunion.io/x/cloudmux/pkg/multicloud"
)
type TInternetChargeType string
const (
InternetChargeByTraffic = TInternetChargeType("traffic")
InternetChargeByBandwidth = TInternetChargeType("bandwidth")
)
type Bandwidth struct {
ID string `json:"id"`
Name string `json:"name"`
Size int64 `json:"size"`
ShareType string `json:"share_type"`
PublicipInfo []PublicipInfo `json:"publicip_info"`
TenantID string `json:"tenant_id"`
BandwidthType string `json:"bandwidth_type"`
ChargeMode string `json:"charge_mode"`
BillingInfo string `json:"billing_info"`
EnterpriseProjectID string `json:"enterprise_project_id"`
}
type PublicipInfo struct {
PublicipID string `json:"publicip_id"`
PublicipAddress string `json:"publicip_address"`
PublicipType string `json:"publicip_type"`
IPVersion int64 `json:"ip_version"`
}
type SProfile struct {
UserID string `json:"user_id"`
ProductID string `json:"product_id"`
RegionID string `json:"region_id"`
OrderID string `json:"order_id"`
}
// https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090598.html
type SEipAddress struct {
region *SRegion
port *Port
multicloud.SEipBase
HuaweiTags
Alias string
ID string `json:"id"`
Status string `json:"status"`
Profile *SProfile `json:"profile,omitempty"`
Type string `json:"type"`
PublicIPAddress string `json:"public_ip_address"`
PrivateIPAddress string `json:"private_ip_address"`
TenantID string `json:"tenant_id"`
CreateTime time.Time `json:"create_time"`
BandwidthID string `json:"bandwidth_id"`
BandwidthShareType string `json:"bandwidth_share_type"`
BandwidthSize int64 `json:"bandwidth_size"`
BandwidthName string `json:"bandwidth_name"`
EnterpriseProjectID string `json:"enterprise_project_id"`
IPVersion int64 `json:"ip_version"`
PortId string `json:"port_id"`
EnterpriseProjectId string
Alias string
Id string
Status string
Type string
PublicIPAddress string
CreateTime time.Time
Bandwidth struct {
Id string
Size int
ShareType string
ChargeMode string
Name string
}
BillingInfo string
EnterpriseProjectId string
AssociateInstanceType string
AssociateInstanceId string
IPVersion int64
PortId string
}
func (self *SEipAddress) GetId() string {
return self.ID
return self.Id
}
func (self *SEipAddress) GetName() string {
@@ -103,7 +68,7 @@ func (self *SEipAddress) GetName() string {
}
func (self *SEipAddress) GetGlobalId() string {
return self.ID
return self.Id
}
func (self *SEipAddress) GetStatus() string {
@@ -124,18 +89,11 @@ func (self *SEipAddress) GetStatus() string {
}
func (self *SEipAddress) Refresh() error {
if self.IsEmulated() {
return nil
}
new, err := self.region.GetEip(self.ID)
eip, err := self.region.GetEip(self.Id)
if err != nil {
return err
}
return jsonutils.Update(self, new)
}
func (self *SEipAddress) IsEmulated() bool {
return false
return jsonutils.Update(self, eip)
}
func (self *SEipAddress) GetIpAddr() string {
@@ -146,84 +104,42 @@ func (self *SEipAddress) GetMode() string {
return api.EIP_MODE_STANDALONE_EIP
}
func (self *SEipAddress) GetPort() *Port {
if len(self.PortId) == 0 {
return nil
}
if self.port != nil {
return self.port
}
port, err := self.region.GetPort(self.PortId)
if err != nil {
return nil
} else {
self.port = &port
}
return self.port
}
func (self *SEipAddress) GetAssociationType() string {
if self.Status == "ELB" {
switch self.AssociateInstanceType {
case "ELB", "ELBV1":
return api.EIP_ASSOCIATE_TYPE_LOADBALANCER
}
if len(self.PortId) == 0 {
return ""
}
port, err := self.region.GetPort(self.PortId)
if err != nil {
log.Errorf("Get eip %s port %s error: %v", self.ID, self.PortId, err)
return ""
}
if strings.HasPrefix(port.DeviceOwner, "compute") {
return api.EIP_ASSOCIATE_TYPE_SERVER
}
switch port.DeviceOwner {
case "neutron:LOADBALANCER", "neutron:LOADBALANCERV2":
return api.EIP_ASSOCIATE_TYPE_LOADBALANCER
case "network:nat_gateway":
case "NATGW":
return api.EIP_ASSOCIATE_TYPE_NAT_GATEWAY
case "PORT":
return api.EIP_ASSOCIATE_TYPE_SERVER
default:
return port.DeviceOwner
return strings.ToLower(self.AssociateInstanceType)
}
}
func (self *SEipAddress) GetAssociationExternalId() string {
// network/0273a359d61847fc83405926c958c746/ext-floatingips?tenantId=0273a359d61847fc83405926c958c746&limit=2000
// 只能通过 port id 反查device id.
if len(self.PortId) > 0 {
port, _ := self.region.GetPort(self.PortId)
return port.DeviceID
if self.AssociateInstanceType == "PORT" {
port, err := self.region.GetPort(self.AssociateInstanceId)
if err == nil {
return port.DeviceID
}
}
return ""
return self.AssociateInstanceId
}
func (self *SEipAddress) GetBandwidth() int {
return int(self.BandwidthSize) // Mb
}
func (self *SEipAddress) GetINetworkId() string {
return ""
return self.Bandwidth.Size
}
func (self *SEipAddress) GetInternetChargeType() string {
// https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090603.html
bandwidth, err := self.region.GetEipBandwidth(self.BandwidthID)
if err != nil {
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
}
if bandwidth.ChargeMode == "traffic" {
if self.Bandwidth.ChargeMode == "traffic" {
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
}
return api.EIP_CHARGE_TYPE_BY_BANDWIDTH
}
func (self *SEipAddress) GetBillingType() string {
if self.Profile == nil {
if len(self.BillingInfo) > 0 {
return billing_api.BILLING_TYPE_POSTPAID
}
return billing_api.BILLING_TYPE_PREPAID
@@ -238,34 +154,46 @@ func (self *SEipAddress) GetExpiredAt() time.Time {
}
func (self *SEipAddress) Delete() error {
return self.region.DeallocateEIP(self.ID)
return self.region.DeallocateEIP(self.Id)
}
func (self *SEipAddress) Associate(conf *cloudprovider.AssociateConfig) error {
portId, err := self.region.GetInstancePortId(conf.InstanceId)
if err != nil {
return err
}
if len(self.PortId) > 0 {
if self.PortId == portId {
return nil
func (self *SEipAddress) Associate(opts *cloudprovider.AssociateConfig) error {
switch opts.AssociateType {
case api.EIP_ASSOCIATE_TYPE_SERVER:
portId, err := self.region.GetInstancePortId(opts.InstanceId)
if err != nil {
return errors.Wrapf(err, "GetInstancePortId")
}
return fmt.Errorf("eip %s aready associate with port %s", self.GetId(), self.PortId)
if len(self.PortId) > 0 {
if self.PortId == portId {
return nil
}
return fmt.Errorf("eip %s aready associate with port %s", self.GetId(), self.PortId)
}
err = self.region.AssociateEip(self.Id, portId, "PORT")
if err != nil {
return err
}
case api.EIP_ASSOCIATE_TYPE_LOADBALANCER:
err := self.region.AssociateEip(self.Id, opts.InstanceId, "ELB")
if err != nil {
return err
}
case api.EIP_ASSOCIATE_TYPE_NAT_GATEWAY:
err := self.region.AssociateEip(self.Id, opts.InstanceId, "NATGW")
if err != nil {
return err
}
default:
return errors.Wrapf(cloudprovider.ErrNotSupported, "associate type %s", opts.AssociateType)
}
err = self.region.AssociateEipWithPortId(self.ID, portId)
if err != nil {
return err
}
err = cloudprovider.WaitStatusWithDelay(self, api.EIP_STATUS_READY, 10*time.Second, 10*time.Second, 180*time.Second)
err := cloudprovider.WaitStatusWithDelay(self, api.EIP_STATUS_READY, 10*time.Second, 10*time.Second, 180*time.Second)
return err
}
func (self *SEipAddress) Dissociate() error {
err := self.region.DissociateEip(self.ID)
err := self.region.DissociateEip(self.Id)
if err != nil {
return err
}
@@ -273,7 +201,7 @@ func (self *SEipAddress) Dissociate() error {
}
func (self *SEipAddress) ChangeBandwidth(bw int) error {
return self.region.UpdateEipBandwidth(self.BandwidthID, bw)
return self.region.UpdateEipBandwidth(self.Bandwidth.Id, bw)
}
func (self *SRegion) GetInstancePortId(instanceId string) (string, error) {
@@ -291,17 +219,7 @@ func (self *SRegion) GetInstancePortId(instanceId string) (string, error) {
return ports[0].ID, nil
}
// https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090596.html
func (self *SRegion) AllocateEIP(opts *cloudprovider.SEip) (*SEipAddress, error) {
var ctype TInternetChargeType
switch opts.ChargeType {
case api.EIP_CHARGE_TYPE_BY_TRAFFIC:
ctype = InternetChargeByTraffic
case api.EIP_CHARGE_TYPE_BY_BANDWIDTH:
ctype = InternetChargeByBandwidth
}
// todo: 如何避免hardcode。集成到cloudmeta服务中
if len(opts.BGPType) == 0 {
switch self.GetId() {
case "cn-north-1", "cn-east-2", "cn-south-1":
@@ -332,7 +250,7 @@ func (self *SRegion) AllocateEIP(opts *cloudprovider.SEip) (*SEipAddress, error)
"name": opts.Name,
"size": opts.BandwidthMbps,
"share_type": "PER",
"charge_mode": ctype,
"charge_mode": opts.ChargeType,
},
"publicip": map[string]interface{}{
"type": opts.BGPType,
@@ -344,7 +262,7 @@ func (self *SRegion) AllocateEIP(opts *cloudprovider.SEip) (*SEipAddress, error)
if len(opts.ProjectId) > 0 {
params["enterprise_project_id"] = opts.ProjectId
}
resp, err := self.vpcCreate("publicips", params)
resp, err := self.post(SERVICE_VPC, "publicips", params)
if err != nil {
return nil, err
}
@@ -353,7 +271,7 @@ func (self *SRegion) AllocateEIP(opts *cloudprovider.SEip) (*SEipAddress, error)
}
func (self *SRegion) GetEip(eipId string) (*SEipAddress, error) {
resp, err := self.vpcGet("publicips/" + eipId)
resp, err := self.list(SERVICE_VPC, "eip/publicips/"+eipId, nil)
if err != nil {
return nil, err
}
@@ -362,30 +280,26 @@ func (self *SRegion) GetEip(eipId string) (*SEipAddress, error) {
}
func (self *SRegion) DeallocateEIP(eipId string) error {
_, err := self.vpcDelete("publicips/" + eipId)
_, err := self.delete(SERVICE_VPC, "publicips/"+eipId)
return err
}
func (self *SRegion) AssociateEip(eipId string, instanceId string) error {
portId, err := self.GetInstancePortId(instanceId)
if err != nil {
return err
}
return self.AssociateEipWithPortId(eipId, portId)
}
func (self *SRegion) AssociateEipWithPortId(eipId string, portId string) error {
func (self *SRegion) AssociateEip(eipId string, associateId, associateType string) error {
params := map[string]interface{}{
"publicip": map[string]interface{}{
"port_id": portId,
"associate_instance_id": associateId,
"associate_instance_type": associateType,
},
}
_, err := self.vpcUpdate("publicips/"+eipId, params)
res := fmt.Sprintf("eip/publicips/%s/associate-instance", eipId)
_, err := self.post(SERVICE_VPC, res, params)
return err
}
func (self *SRegion) DissociateEip(eipId string) error {
return self.AssociateEipWithPortId(eipId, "")
res := fmt.Sprintf("eip/publicips/%s/disassociate-instance", eipId)
_, err := self.post(SERVICE_VPC, res, nil)
return err
}
func (self *SRegion) UpdateEipBandwidth(bandwidthId string, bw int) error {
@@ -394,19 +308,10 @@ func (self *SRegion) UpdateEipBandwidth(bandwidthId string, bw int) error {
"size": bw,
},
}
_, err := self.vpcUpdate("bandwidths/"+bandwidthId, params)
_, err := self.put(SERVICE_VPC, "bandwidths/"+bandwidthId, params)
return err
}
func (self *SRegion) GetEipBandwidth(id string) (*Bandwidth, error) {
resp, err := self.vpcGet("bandwidths/" + id)
if err != nil {
return nil, err
}
ret := &Bandwidth{}
return ret, resp.Unmarshal(ret, "bandwidth")
}
func (self *SEipAddress) GetProjectId() string {
return self.EnterpriseProjectId
}
@@ -419,14 +324,25 @@ func (self *SRegion) GetEips(portId string, addrs []string) ([]SEipAddress, erro
if len(portId) > 0 {
query.Set("port_id", portId)
}
resp, err := self.vpcList("publicips", query)
if err != nil {
return nil, err
}
eips := []SEipAddress{}
err = resp.Unmarshal(&eips, "publicips")
if err != nil {
return nil, err
for {
resp, err := self.list(SERVICE_VPC, "eip/publicips", query)
if err != nil {
return nil, err
}
part := struct {
Publicips []SEipAddress
PageInfo sPageInfo
}{}
err = resp.Unmarshal(&part)
if err != nil {
return nil, err
}
eips = append(eips, part.Publicips...)
if len(part.Publicips) == 0 || len(part.PageInfo.NextMarker) == 0 {
break
}
query.Set("marker", part.PageInfo.NextMarker)
}
for i := range eips {
eips[i].region = self
@@ -477,5 +393,5 @@ func (self *SEipAddress) SetTags(tags map[string]string, replace bool) error {
if err != nil {
return errors.Wrap(err, "self.GetTags()")
}
return self.region.setEipTags(self.ID, existedTags, tags, replace)
return self.region.setEipTags(self.Id, existedTags, tags, replace)
}

View File

@@ -245,63 +245,6 @@ func (self *SHuaweiClient) newGeneralAPIClient() (*client.Client, error) {
return self.newRegionAPIClient("")
}
func (self *SHuaweiClient) lbList(regionId, resource string, query url.Values) (jsonutils.JSONObject, error) {
return self.list(SERVICE_ELB, regionId, resource, query)
}
func (self *SHuaweiClient) monitorList(resource string, query url.Values) (jsonutils.JSONObject, error) {
return self.list(SERVICE_CES, self.clientRegion, resource, query)
}
func (self *SHuaweiClient) monitorPost(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.post(SERVICE_CES, self.clientRegion, resource, params)
}
func (self *SHuaweiClient) lbGet(regionId, resource string) (jsonutils.JSONObject, error) {
return self.list(SERVICE_ELB, regionId, resource, nil)
}
func (self *SHuaweiClient) lbCreate(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.post(SERVICE_ELB, regionId, resource, params)
}
func (self *SHuaweiClient) lbUpdate(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.put(SERVICE_ELB, regionId, resource, params)
}
func (self *SHuaweiClient) lbDelete(regionId, resource string) (jsonutils.JSONObject, error) {
return self.delete(SERVICE_ELB, regionId, resource)
}
func (self *SHuaweiClient) vpcList(regionId, resource string, query url.Values) (jsonutils.JSONObject, error) {
return self.list(SERVICE_VPC, regionId, resource, query)
}
func (self *SHuaweiClient) vpcCreate(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.post(SERVICE_VPC, regionId, resource, params)
}
func (self *SHuaweiClient) vpcPost(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.post(SERVICE_VPC, regionId, resource, params)
}
func (self *SHuaweiClient) vpcGet(regionId, resource string) (jsonutils.JSONObject, error) {
return self.list(SERVICE_VPC, regionId, resource, nil)
}
func (self *SHuaweiClient) vpcDelete(regionId, resource string) (jsonutils.JSONObject, error) {
return self.delete(SERVICE_VPC, regionId, resource)
}
func (self *SHuaweiClient) vpcUpdate(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.put(SERVICE_VPC, regionId, resource, params)
}
func (self *SHuaweiClient) cdnDelete(resource string) (jsonutils.JSONObject, error) {
uri := fmt.Sprintf("https://cdn.myhuaweicloud.com/v1.0/%s", resource)
return self.request(httputils.DELETE, uri, url.Values{}, nil)
}
type akClient struct {
client *http.Client
aksk aksk.SignOptions
@@ -657,19 +600,11 @@ func (self *SHuaweiClient) GetIStorageById(id string) (cloudprovider.ICloudStora
return nil, cloudprovider.ErrNotFound
}
// 总账户余额
type SAccountBalance struct {
AvailableAmount float64
CreditAmount float64
DesignatedAmount float64
}
// 账户余额
// https://support.huaweicloud.com/api-oce/zh-cn_topic_0109685133.html
// https://console.huaweicloud.com/apiexplorer/#/openapi/BSS/debug?api=ShowCustomerAccountBalances
type SBalance struct {
Amount float64 `json:"amount"`
Currency string `json:"currency"`
AccountID string `json:"account_id"`
AccountId string `json:"account_id"`
AccountType int64 `json:"account_type"`
DesignatedAmount float64 `json:"designated_amount,omitempty"`
CreditAmount float64 `json:"credit_amount,omitempty"`
@@ -677,39 +612,22 @@ type SBalance struct {
}
// 这里的余额指的是所有租户的总余额
func (self *SHuaweiClient) QueryAccountBalance() (*SAccountBalance, error) {
domains, err := self.getEnabledDomains()
func (self *SHuaweiClient) QueryAccountBalance() (*SBalance, error) {
resp, err := self.list(SERVICE_BSS, "", "accounts/customer-accounts/balances", nil)
if err != nil {
return nil, err
}
result := &SAccountBalance{}
for _, domain := range domains {
balances, err := self.queryDomainBalances(domain.ID)
if err != nil {
return nil, err
}
for _, balance := range balances {
result.AvailableAmount += balance.Amount
result.CreditAmount += balance.CreditAmount
result.DesignatedAmount += balance.DesignatedAmount
}
}
return result, nil
}
// https://support.huaweicloud.com/api-bpconsole/zh-cn_topic_0075213309.html
func (self *SHuaweiClient) queryDomainBalances(domainId string) ([]SBalance, error) {
huawei, _ := self.newGeneralAPIClient()
huawei.Balances.SetDomainId(domainId)
balances := make([]SBalance, 0)
err := doListAll(huawei.Balances.List, nil, &balances)
ret := []SBalance{}
err = resp.Unmarshal(&ret, "account_balances")
if err != nil {
return nil, err
}
return balances, nil
for i := range ret {
if ret[i].AccountType == 1 {
return &ret[i], nil
}
}
return &SBalance{Currency: "CYN"}, nil
}
func (self *SHuaweiClient) GetISSLCertificates() ([]cloudprovider.ICloudSSLCertificate, error) {
@@ -884,10 +802,10 @@ func (self *SHuaweiClient) getUrl(service, regionId, resource string, method htt
url = fmt.Sprintf("https://iam.myhuaweicloud.com/v3/%s", resource)
}
case SERVICE_ELB:
url = fmt.Sprintf("https://elb.%s.myhuaweicloud.com/v2/%s/%s", regionId, self.projectId, resource)
url = fmt.Sprintf("https://elb.%s.myhuaweicloud.com/v3/%s/%s", regionId, self.projectId, resource)
case SERVICE_VPC:
version := "v1"
if strings.HasPrefix(resource, "vpc/") {
if strings.HasPrefix(resource, "vpc/") || strings.HasPrefix(resource, "eip/") {
version = "v3"
}
url = fmt.Sprintf("https://vpc.%s.myhuaweicloud.com/%s/%s/%s", regionId, version, self.projectId, resource)

View File

@@ -59,7 +59,6 @@ type SLoadbalancer struct {
HuaweiTags
region *SRegion
subnet *SNetwork
eip *SEipAddress
Description string `json:"description"`
ProvisioningStatus string `json:"provisioning_status"`
@@ -76,8 +75,14 @@ type SLoadbalancer struct {
VipSubnetId string `json:"vip_subnet_id"`
Id string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
VpcId string
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Publicips []struct {
PublicipId string
PublicipAddress string
IpVersion string
}
}
type Listener struct {
@@ -88,12 +93,23 @@ type Pool struct {
Id string `json:"id"`
}
func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
if self.GetEip() == nil {
return nil, nil
func (self *SLoadbalancer) GetEip() (*SEipAddress, error) {
for _, ip := range self.Publicips {
eip, err := self.region.GetEip(ip.PublicipId)
if err != nil {
return nil, err
}
return eip, nil
}
return nil, cloudprovider.ErrNotFound
}
return self.eip, nil
func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
eip, err := self.GetEip()
if err != nil {
return nil, err
}
return eip, nil
}
func (self *SLoadbalancer) GetId() string {
@@ -165,23 +181,8 @@ func (self *SLoadbalancer) GetNetwork() *SNetwork {
return self.subnet
}
func (self *SLoadbalancer) GetEip() *SEipAddress {
if self.eip == nil {
eips, _ := self.region.GetEips(self.VipPortId, nil)
for i := range eips {
self.eip = &eips[i]
}
}
return self.eip
}
func (self *SLoadbalancer) GetVpcId() string {
net := self.GetNetwork()
if net != nil {
return net.VpcID
}
return ""
return self.VpcId
}
func (self *SLoadbalancer) GetZoneId() string {
@@ -208,16 +209,15 @@ func (self *SLoadbalancer) GetLoadbalancerSpec() string {
}
func (self *SLoadbalancer) GetChargeType() string {
eip := self.GetEip()
eip, _ := self.GetEip()
if eip != nil {
return eip.GetInternetChargeType()
}
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
}
func (self *SLoadbalancer) GetEgressMbps() int {
eip := self.GetEip()
eip, _ := self.GetEip()
if eip != nil {
return eip.GetBandwidth()
}
@@ -303,7 +303,6 @@ func (self *SLoadbalancer) GetILoadBalancerBackendGroups() ([]cloudprovider.IClo
return iret, nil
}
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561549.html
func (self *SLoadbalancer) CreateILoadBalancerBackendGroup(opts *cloudprovider.SLoadbalancerBackendGroup) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
ret, err := self.region.CreateLoadBalancerBackendGroup(self.Id, opts)
if err != nil {
@@ -322,7 +321,7 @@ func (self *SLoadbalancer) CreateHealthCheck(backendGroupId string, healthcheck
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561548.html
func (self *SLoadbalancer) GetILoadBalancerBackendGroupById(groupId string) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
ret := &SElbBackendGroup{lb: self, region: self.region}
resp, err := self.region.lbGet("elb/pools/" + groupId)
resp, err := self.region.list(SERVICE_ELB, "elb/pools/"+groupId, nil)
if err != nil {
return nil, err
}
@@ -340,7 +339,7 @@ func (self *SLoadbalancer) CreateILoadBalancerListener(ctx context.Context, opts
func (self *SLoadbalancer) GetILoadBalancerListenerById(listenerId string) (cloudprovider.ICloudLoadbalancerListener, error) {
ret := &SElbListener{lb: self}
resp, err := self.region.lbGet("elb/listeners/" + listenerId)
resp, err := self.region.list(SERVICE_ELB, "elb/listeners/"+listenerId, nil)
if err != nil {
return nil, err
}
@@ -348,7 +347,7 @@ func (self *SLoadbalancer) GetILoadBalancerListenerById(listenerId string) (clou
}
func (self *SRegion) GetLoadbalancer(id string) (*SLoadbalancer, error) {
resp, err := self.lbGet("elb/loadbalancers/" + id)
resp, err := self.list(SERVICE_ELB, "elb/loadbalancers/"+id, nil)
if err != nil {
return nil, err
}
@@ -358,7 +357,7 @@ func (self *SRegion) GetLoadbalancer(id string) (*SLoadbalancer, error) {
func (self *SRegion) DeleteLoadBalancer(elbId string) error {
resource := fmt.Sprintf("elb/loadbalancers/%s", elbId)
_, err := self.lbDelete(resource)
_, err := self.delete(SERVICE_ELB, resource)
return err
}
@@ -402,7 +401,7 @@ func (self *SRegion) CreateLoadBalancerListener(listener *cloudprovider.SLoadbal
}
ret := &SElbListener{}
resp, err := self.lbCreate("elb/listeners", map[string]interface{}{"listener": params})
resp, err := self.post(SERVICE_ELB, "elb/listeners", map[string]interface{}{"listener": params})
if err != nil {
return nil, err
}
@@ -444,7 +443,7 @@ func (self *SRegion) CreateLoadBalancerBackendGroup(lbId string, opts *cloudprov
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "invalid protocol %s", opts.Protocol)
}
resp, err := self.lbCreate("elb/pools", map[string]interface{}{"pool": params})
resp, err := self.post(SERVICE_ELB, "elb/pools", map[string]interface{}{"pool": params})
if err != nil {
return nil, err
}
@@ -479,7 +478,7 @@ func (self *SRegion) CreateLoadBalancerHealthCheck(backendGroupId string, health
}
ret := SElbHealthCheck{region: self}
resp, err := self.lbCreate("elb/healthmonitors", map[string]interface{}{"healthmonitor": params})
resp, err := self.post(SERVICE_ELB, "elb/healthmonitors", map[string]interface{}{"healthmonitor": params})
if err != nil {
return ret, err
}
@@ -509,7 +508,7 @@ func (self *SRegion) UpdateLoadBalancerHealthCheck(healthCheckId string, healthC
}
ret := SElbHealthCheck{region: self}
resp, err := self.lbUpdate("elb/healthmonitors/"+healthCheckId, map[string]interface{}{"healthmonitor": params})
resp, err := self.put(SERVICE_ELB, "elb/healthmonitors/"+healthCheckId, map[string]interface{}{"healthmonitor": params})
if err != nil {
return ret, err
}
@@ -518,7 +517,7 @@ func (self *SRegion) UpdateLoadBalancerHealthCheck(healthCheckId string, healthC
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561565.html
func (self *SRegion) DeleteLoadbalancerHealthCheck(healthCheckId string) error {
_, err := self.lbDelete("elb/healthmonitors/" + healthCheckId)
_, err := self.delete(SERVICE_ELB, "elb/healthmonitors/"+healthCheckId)
return err
}
@@ -526,34 +525,10 @@ func (self *SLoadbalancer) SetTags(tags map[string]string, replace bool) error {
return cloudprovider.ErrNotSupported
}
func (self *SRegion) lbList(resource string, query url.Values) (jsonutils.JSONObject, error) {
return self.client.lbList(self.ID, resource, query)
}
func (self *SRegion) vpcList(resource string, query url.Values) (jsonutils.JSONObject, error) {
return self.client.vpcList(self.ID, resource, query)
}
func (self *SRegion) vpcCreate(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.client.vpcCreate(self.ID, resource, params)
}
func (self *SRegion) vpcGet(resource string) (jsonutils.JSONObject, error) {
return self.client.vpcGet(self.ID, resource)
}
func (self *SRegion) vpcDelete(resource string) (jsonutils.JSONObject, error) {
return self.client.vpcDelete(self.ID, resource)
}
func (self *SRegion) vpcUpdate(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.client.vpcUpdate(self.ID, resource, params)
}
func (self *SRegion) lbListAll(resource string, query url.Values, respKey string, retVal interface{}) error {
ret := jsonutils.NewArray()
for {
resp, err := self.lbList(resource, query)
resp, err := self.list(SERVICE_ELB, resource, query)
if err != nil {
return err
}
@@ -571,38 +546,53 @@ func (self *SRegion) lbListAll(resource string, query url.Values, respKey string
return ret.Unmarshal(retVal)
}
func (self *SRegion) lbGet(resource string) (jsonutils.JSONObject, error) {
return self.client.lbGet(self.ID, resource)
}
func (self *SRegion) lbDelete(resource string) (jsonutils.JSONObject, error) {
return self.client.lbDelete(self.ID, resource)
}
func (self *SRegion) lbCreate(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.client.lbCreate(self.ID, resource, params)
}
func (self *SRegion) lbUpdate(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
return self.client.lbUpdate(self.ID, resource, params)
}
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561535.html
func (self *SRegion) CreateLoadBalancer(loadbalancer *cloudprovider.SLoadbalancerCreateOptions) (*SLoadbalancer, error) {
subnet, err := self.getNetwork(loadbalancer.NetworkIds[0])
func (self *SRegion) CreateLoadBalancer(opts *cloudprovider.SLoadbalancerCreateOptions) (*SLoadbalancer, error) {
subnet, err := self.getNetwork(opts.NetworkIds[0])
if err != nil {
return nil, errors.Wrap(err, "SRegion.CreateLoadBalancer.getNetwork")
return nil, errors.Wrap(err, "getNetwork")
}
params := map[string]interface{}{
"name": loadbalancer.Name,
"vip_subnet_id": subnet.NeutronSubnetID,
"tenant_id": self.client.projectId,
"name": opts.Name,
"description": opts.Desc,
"vip_subnet_cidr_id": subnet.NeutronSubnetID,
"provider": "vlb",
"admin_state_up": true,
"guaranteed": true,
"project_id": self.client.projectId,
"charge_mode": "lcu",
}
if len(loadbalancer.Address) > 0 {
params["vip_address"] = loadbalancer.Address
if len(opts.ProjectId) > 0 {
params["enterprise_project_id"] = opts.ProjectId
}
resp, err := self.lbCreate("elb/loadbalancers", map[string]interface{}{"loadbalancer": params})
if len(opts.Address) > 0 {
params["vip_address"] = opts.Address
}
tags := []map[string]string{}
for k, v := range opts.Tags {
tags = append(tags, map[string]string{
"key": k,
"value": v,
})
}
if len(tags) > 0 {
params["tags"] = tags
}
if len(opts.EipId) > 0 {
params["publicip_ids"] = []string{opts.EipId}
}
err = self.fetchZones()
if err != nil {
return nil, errors.Wrapf(err, "fetchZones")
}
zoneIds := []string{}
for i := range self.izones {
zone := self.izones[i].(*SZone)
zoneIds = append(zoneIds, zone.ZoneName)
}
params["availability_zone_list"] = zoneIds
resp, err := self.post(SERVICE_ELB, "elb/loadbalancers", map[string]interface{}{"loadbalancer": params})
if err != nil {
return nil, err
}
@@ -611,13 +601,5 @@ func (self *SRegion) CreateLoadBalancer(loadbalancer *cloudprovider.SLoadbalance
if err != nil {
return nil, errors.Wrapf(err, "resp.Unmarshal")
}
// 创建公网类型ELB
if len(loadbalancer.EipId) > 0 {
err := self.AssociateEipWithPortId(loadbalancer.EipId, ret.VipPortId)
if err != nil {
return ret, errors.Wrap(err, "SRegion.CreateLoadBalancer.AssociateEipWithPortId")
}
}
return ret, nil
}

View File

@@ -97,17 +97,17 @@ func (self *SElbACL) Sync(acl *cloudprovider.SLoadbalancerAccessControlList) err
"whitelist": whiteList,
"enable_whitelist": acl.AccessControlEnable,
}
_, err := self.region.lbUpdate("elb/whitelists/"+self.GetId(), map[string]interface{}{"whitelist": params})
_, err := self.region.put(SERVICE_ELB, "elb/whitelists/"+self.GetId(), map[string]interface{}{"whitelist": params})
return err
}
func (self *SElbACL) Delete() error {
_, err := self.region.lbDelete("elb/whitelists/" + self.GetId())
_, err := self.region.delete(SERVICE_ELB, "elb/whitelists/"+self.GetId())
return err
}
func (self *SRegion) GetLoadBalancerAcl(aclId string) (*SElbACL, error) {
resp, err := self.lbGet("elb/whitelists/" + aclId)
resp, err := self.list(SERVICE_ELB, "elb/whitelists/"+aclId, nil)
if err != nil {
return nil, err
}
@@ -121,7 +121,7 @@ func (self *SRegion) GetLoadBalancerAcls(listenerId string) ([]SElbACL, error) {
if len(listenerId) > 0 {
query.Set("listener_id", listenerId)
}
resp, err := self.lbList("elb/whitelists", query)
resp, err := self.list(SERVICE_ELB, "elb/whitelists", query)
if err != nil {
return nil, err
}
@@ -143,7 +143,7 @@ func (self *SRegion) CreateLoadBalancerAcl(acl *cloudprovider.SLoadbalancerAcces
} else {
params["enable_whitelist"] = false
}
resp, err := self.lbCreate("elb/whitelists", map[string]interface{}{"whitelist": params})
resp, err := self.post(SERVICE_ELB, "elb/whitelists", map[string]interface{}{"whitelist": params})
if err != nil {
return nil, err
}

View File

@@ -119,7 +119,7 @@ func (self *SElbBackend) SyncConf(ctx context.Context, port, weight int) error {
"weight": weight,
}
res := fmt.Sprintf("elb/pools/%s/members/%s", self.backendGroup.GetId(), self.ID)
_, err := self.region.lbUpdate(res, map[string]interface{}{"member": params})
_, err := self.region.put(SERVICE_ELB, res, map[string]interface{}{"member": params})
return err
}
@@ -152,7 +152,7 @@ func (self *SRegion) getInstanceByIP(privateIP string) (*SInstance, error) {
func (self *SRegion) GetElbBackend(pool, id string) (*SElbBackend, error) {
res := fmt.Sprintf("elb/pools/%s/members/%s", pool, id)
resp, err := self.lbGet(res)
resp, err := self.list(SERVICE_ELB, res, nil)
if err != nil {
return nil, err
}

View File

@@ -340,7 +340,7 @@ func (self *SElbBackendGroup) Sync(ctx context.Context, group *cloudprovider.SLo
func (self *SRegion) GetLoadBalancerBackendGroup(backendGroupId string) (*SElbBackendGroup, error) {
ret := &SElbBackendGroup{region: self}
res := fmt.Sprintf("elb/pools/" + backendGroupId)
resp, err := self.lbGet(res)
resp, err := self.list(SERVICE_ELB, res, nil)
if err != nil {
return nil, err
}
@@ -349,7 +349,7 @@ func (self *SRegion) GetLoadBalancerBackendGroup(backendGroupId string) (*SElbBa
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561551.html
func (self *SRegion) DeleteLoadBalancerBackendGroup(id string) error {
_, err := self.lbDelete("elb/pools/" + id)
_, err := self.delete(SERVICE_ELB, "elb/pools/"+id)
return err
}
@@ -362,7 +362,7 @@ func (self *SRegion) AddLoadBalancerBackend(backendGroupId, subnetId, ipaddr str
"weight": weight,
}
ret := &SElbBackend{}
resp, err := self.lbCreate(fmt.Sprintf("elb/pools/%s/members", backendGroupId), map[string]interface{}{"member": params})
resp, err := self.post(SERVICE_ELB, fmt.Sprintf("elb/pools/%s/members", backendGroupId), map[string]interface{}{"member": params})
if err != nil {
return nil, err
}
@@ -370,13 +370,13 @@ func (self *SRegion) AddLoadBalancerBackend(backendGroupId, subnetId, ipaddr str
}
func (self *SRegion) RemoveLoadBalancerBackend(lbbgId string, backendId string) error {
_, err := self.lbDelete(fmt.Sprintf("elb/pools/%s/members/%s", lbbgId, backendId))
_, err := self.delete(SERVICE_ELB, fmt.Sprintf("elb/pools/%s/members/%s", lbbgId, backendId))
return err
}
func (self *SRegion) getLoadBalancerBackends(backendGroupId string) ([]SElbBackend, error) {
res := fmt.Sprintf("elb/pools/%s/members", backendGroupId)
resp, err := self.lbList(res, url.Values{})
resp, err := self.list(SERVICE_ELB, res, url.Values{})
if err != nil {
return nil, err
}
@@ -420,7 +420,7 @@ func (self *SRegion) getLoadBalancerAdminStateDownBackends(backendGroupId string
}
func (self *SRegion) GetLoadBalancerHealthCheck(healthCheckId string) (*SElbHealthCheck, error) {
resp, err := self.lbGet("elb/healthmonitors/" + healthCheckId)
resp, err := self.list(SERVICE_ELB, "elb/healthmonitors/"+healthCheckId, nil)
if err != nil {
return nil, err
}

View File

@@ -93,12 +93,12 @@ func (self *SElbCert) Sync(name, privateKey, publickKey string) error {
"private_key": privateKey,
"certificate": publickKey,
}
_, err := self.region.lbUpdate("elb/certificates/"+self.GetId(), params)
_, err := self.region.put(SERVICE_ELB, "elb/certificates/"+self.GetId(), params)
return err
}
func (self *SElbCert) Delete() error {
_, err := self.region.lbDelete("elb/certificates/" + self.GetId())
_, err := self.region.delete(SERVICE_ELB, "elb/certificates/"+self.GetId())
return err
}
@@ -121,7 +121,7 @@ func (self *SElbCert) GetExpireTime() time.Time {
}
func (self *SRegion) GetLoadBalancerCertificate(id string) (*SElbCert, error) {
resp, err := self.lbGet("elb/certificates/" + id)
resp, err := self.list(SERVICE_ELB, "elb/certificates/"+id, nil)
if err != nil {
return nil, err
}
@@ -136,7 +136,7 @@ func (self *SRegion) CreateLoadBalancerCertificate(cert *cloudprovider.SLoadbala
"private_key": cert.PrivateKey,
"certificate": cert.Certificate,
}
resp, err := self.lbCreate("elb/certificates", params)
resp, err := self.post(SERVICE_ELB, "elb/certificates", params)
if err != nil {
return nil, err
}
@@ -145,7 +145,7 @@ func (self *SRegion) CreateLoadBalancerCertificate(cert *cloudprovider.SLoadbala
}
func (self *SRegion) GetLoadBalancerCertificates() ([]SElbCert, error) {
resp, err := self.lbList("elb/certificates", url.Values{})
resp, err := self.list(SERVICE_ELB, "elb/certificates", url.Values{})
if err != nil {
return nil, err
}

View File

@@ -386,7 +386,7 @@ func (self *SElbListener) ChangeCertificate(ctx context.Context, opts *cloudprov
params := map[string]interface{}{
"default_tls_container_ref": opts.CertificateId,
}
_, err := self.lb.region.lbUpdate("elb/listeners/"+self.ID, map[string]interface{}{"listener": params})
_, err := self.lb.region.put(SERVICE_ELB, "elb/listeners/"+self.ID, map[string]interface{}{"listener": params})
return err
}
@@ -413,7 +413,7 @@ func (self *SElbListener) CreateILoadBalancerListenerRule(rule *cloudprovider.SL
func (self *SElbListener) GetILoadBalancerListenerRuleById(ruleId string) (cloudprovider.ICloudLoadbalancerListenerRule, error) {
ret := &SElbListenerPolicy{region: self.lb.region, lb: self.lb, listener: self}
resp, err := self.lb.region.lbGet("elb/l7policies/" + ruleId)
resp, err := self.lb.region.list(SERVICE_ELB, "elb/l7policies/"+ruleId, nil)
if err != nil {
return nil, err
}
@@ -586,7 +586,7 @@ func (self *SElbListener) ChangeScheduler(ctx context.Context, opts *cloudprovid
params := map[string]interface{}{
"pool": pool,
}
_, err = self.lb.region.lbUpdate(fmt.Sprintf("elb/pools/%s", lbbg.ID), params)
_, err = self.lb.region.put(SERVICE_ELB, fmt.Sprintf("elb/pools/%s", lbbg.ID), params)
return err
}
@@ -624,13 +624,13 @@ func (self *SElbListener) SetHealthCheck(ctx context.Context, opts *cloudprovide
params := map[string]interface{}{
"healthmonitor": heathmonitor,
}
_, err = self.lb.region.lbCreate("elb/healthmonitors", params)
_, err = self.lb.region.post(SERVICE_ELB, "elb/healthmonitors", params)
return err
}
params := map[string]interface{}{
"healthmonitor": heathmonitor,
}
_, err = self.lb.region.lbUpdate(fmt.Sprintf("elb/healthmonitors/%s", lbbg.HealthMonitorID), params)
_, err = self.lb.region.put(SERVICE_ELB, fmt.Sprintf("elb/healthmonitors/%s", lbbg.HealthMonitorID), params)
return err
}
@@ -639,7 +639,7 @@ func (self *SElbListener) Delete(ctx context.Context) error {
}
func (self *SRegion) DeleteElbListener(id string) error {
_, err := self.lbDelete("elb/listeners/" + id)
_, err := self.delete(SERVICE_ELB, "elb/listeners/"+id)
return err
}
@@ -663,7 +663,7 @@ func (self *SRegion) UpdateLoadBalancerListener(listenerId string, listener *clo
"X-Forwarded-ELB-IP": listener.XForwardedFor,
}
}
_, err := self.lbUpdate("elb/listeners/"+listenerId, map[string]interface{}{"listener": params})
_, err := self.put(SERVICE_ELB, "elb/listeners/"+listenerId, map[string]interface{}{"listener": params})
return err
}
@@ -674,7 +674,7 @@ func (self *SRegion) GetLoadBalancerPolicies(listenerId string) ([]SElbListenerP
query.Set("listener_id", listenerId)
}
resp, err := self.lbList("elb/l7policies", query)
resp, err := self.list(SERVICE_ELB, "elb/l7policies", query)
if err != nil {
return nil, err
}
@@ -685,7 +685,7 @@ func (self *SRegion) GetLoadBalancerPolicies(listenerId string) ([]SElbListenerP
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0116649234.html
func (self *SRegion) GetLoadBalancerPolicyRules(policyId string) ([]SElbListenerPolicyRule, error) {
resp, err := self.lbList(fmt.Sprintf("elb/l7policies/%s/rules", policyId), url.Values{})
resp, err := self.list(SERVICE_ELB, fmt.Sprintf("elb/l7policies/%s/rules", policyId), url.Values{})
if err != nil {
return nil, err
}
@@ -703,7 +703,7 @@ func (self *SRegion) CreateLoadBalancerPolicy(listenerID string, rule *cloudprov
"action": "REDIRECT_TO_POOL",
"redirect_pool_id": rule.BackendGroupId,
}
resp, err := self.lbCreate("elb/l7policies", map[string]interface{}{"l7policy": params})
resp, err := self.post(SERVICE_ELB, "elb/l7policies", map[string]interface{}{"l7policy": params})
if err != nil {
return nil, err
}
@@ -717,7 +717,7 @@ func (self *SRegion) CreateLoadBalancerPolicy(listenerID string, rule *cloudprov
"value": rule.Domain,
"compare_type": "EQUAL_TO",
}
_, err := self.lbCreate(fmt.Sprintf("elb/l7policies/%s/rules", ret.GetId()), map[string]interface{}{"rule": params})
_, err := self.post(SERVICE_ELB, fmt.Sprintf("elb/l7policies/%s/rules", ret.GetId()), map[string]interface{}{"rule": params})
if err != nil {
return ret, err
}
@@ -729,7 +729,7 @@ func (self *SRegion) CreateLoadBalancerPolicy(listenerID string, rule *cloudprov
"value": rule.Path,
"compare_type": "EQUAL_TO",
}
_, err := self.lbCreate(fmt.Sprintf("elb/l7policies/%s/rules", ret.GetId()), map[string]interface{}{"rule": params})
_, err := self.post(SERVICE_ELB, fmt.Sprintf("elb/l7policies/%s/rules", ret.GetId()), map[string]interface{}{"rule": params})
if err != nil {
return ret, err
}

View File

@@ -85,7 +85,7 @@ func (self *SElbListenerPolicy) GetStatus() string {
}
func (self *SElbListenerPolicy) Refresh() error {
resp, err := self.lb.region.lbGet("")
resp, err := self.lb.region.list(SERVICE_ELB, "elb/l7policies/"+self.ID, nil)
if err != nil {
return err
}
@@ -161,6 +161,6 @@ func (self *SElbListenerPolicy) Delete(ctx context.Context) error {
}
func (self *SRegion) DeleteLoadBalancerPolicy(policyId string) error {
_, err := self.lbDelete("elb/l7policies/" + policyId)
_, err := self.delete(SERVICE_ELB, "elb/l7policies/"+policyId)
return err
}

View File

@@ -82,7 +82,7 @@ func (self *SHuaweiClient) getServerMetrics(opts *cloudprovider.MetricListOption
})
}
params["metrics"] = metrics
resp, err := self.monitorPost("batch-query-metric-data", params)
resp, err := self.post(SERVICE_CES, self.clientRegion, "batch-query-metric-data", params)
if err != nil {
return nil, err
}
@@ -164,7 +164,7 @@ func (self *SHuaweiClient) getServerAgentMetrics(opts *cloudprovider.MetricListO
})
}
params["metrics"] = metrics
resp, err := self.monitorPost("batch-query-metric-data", params)
resp, err := self.post(SERVICE_CES, self.clientRegion, "batch-query-metric-data", params)
if err != nil {
return nil, err
}
@@ -235,7 +235,7 @@ func (self *SHuaweiClient) getRedisMetrics(opts *cloudprovider.MetricListOptions
})
}
params["metrics"] = metrics
resp, err := self.monitorPost("batch-query-metric-data", params)
resp, err := self.post(SERVICE_CES, self.clientRegion, "batch-query-metric-data", params)
if err != nil {
return nil, err
}
@@ -331,7 +331,7 @@ func (self *SHuaweiClient) getRdsMetrics(opts *cloudprovider.MetricListOptions)
})
}
params["metrics"] = metrics
resp, err := self.monitorPost("batch-query-metric-data", params)
resp, err := self.post(SERVICE_CES, self.clientRegion, "batch-query-metric-data", params)
if err != nil {
return nil, err
}
@@ -420,7 +420,7 @@ func (self *SHuaweiClient) getBucketMetrics(opts *cloudprovider.MetricListOption
})
}
params["metrics"] = metrics
resp, err := self.monitorPost("batch-query-metric-data", params)
resp, err := self.post(SERVICE_CES, self.clientRegion, "batch-query-metric-data", params)
if err != nil {
return nil, err
}
@@ -501,7 +501,7 @@ func (self *SHuaweiClient) getLoadbalancerMetrics(opts *cloudprovider.MetricList
})
}
params["metrics"] = metrics
resp, err := self.monitorPost("batch-query-metric-data", params)
resp, err := self.post(SERVICE_CES, self.clientRegion, "batch-query-metric-data", params)
if err != nil {
return nil, err
}

View File

@@ -196,9 +196,9 @@ func (self *SHuaweiProvider) GetBalance() (*cloudprovider.SBalanceInfo, error) {
if err != nil {
return ret, err
}
ret.Amount = balance.AvailableAmount
ret.Amount = balance.Amount
ret.Status = api.CLOUD_PROVIDER_HEALTH_NORMAL
if balance.AvailableAmount < 0.0 && balance.CreditAmount < 0.0 {
if balance.Amount < 0.0 && balance.CreditAmount < 0.0 {
ret.Status = api.CLOUD_PROVIDER_HEALTH_ARREARS
}
return ret, nil