mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): The latest api of Huawei cloud elb and eip is applicable (#19028)
This commit is contained in:
@@ -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.20231215084758-720b4cd7bf3e
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231218072118-36b6dd2a146b
|
||||
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
|
||||
|
||||
@@ -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.20231215084758-720b4cd7bf3e h1:u7STaGPLvoc98IShtsHoWv2xJVDpUJC/Y5QVmA+qN3c=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231215084758-720b4cd7bf3e/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231218072118-36b6dd2a146b h1:qeI8NpnqmOea7UFYTgy+hiOvyfykOKzVoIBfeV1nM6o=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231218072118-36b6dd2a146b/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=
|
||||
|
||||
Vendored
+1
-1
@@ -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.20231215084758-720b4cd7bf3e
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231218072118-36b6dd2a146b
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+7
@@ -29,6 +29,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
|
||||
// eks only
|
||||
@@ -88,6 +89,12 @@ func jsonInvoke(cli *client.Client, apiName, path string, params map[string]inte
|
||||
}
|
||||
}
|
||||
}
|
||||
if utils.IsInStringArray(cli.ServiceName, []string{
|
||||
PRICING_SERVICE_NAME,
|
||||
}) {
|
||||
method = "POST"
|
||||
}
|
||||
|
||||
op := &request.Operation{
|
||||
Name: apiName,
|
||||
HTTPMethod: method,
|
||||
|
||||
-3
@@ -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)
|
||||
|
||||
-72
@@ -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
|
||||
}
|
||||
+7
-4
@@ -15,6 +15,7 @@
|
||||
package huawei
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -233,9 +234,11 @@ type SAccessKey struct {
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) GetAKSK(id string) ([]cloudprovider.SAccessKey, error) {
|
||||
obj, err := self.getAKSKList(id)
|
||||
query := url.Values{}
|
||||
query.Set("user_id", id)
|
||||
obj, err := self.list(SERVICE_IAM, "", "OS-CREDENTIAL/credentials", query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.getAKSKList")
|
||||
return nil, errors.Wrap(err, "list credential")
|
||||
}
|
||||
aks := make([]SAccessKey, 0)
|
||||
obj.Unmarshal(&aks, "credentials")
|
||||
@@ -257,7 +260,7 @@ func (self *SHuaweiClient) CreateAKSK(id, name string) (*cloudprovider.SAccessKe
|
||||
"description": name,
|
||||
},
|
||||
}
|
||||
obj, err := self.createAKSK(params)
|
||||
obj, err := self.post(SERVICE_IAM, "", "OS-CREDENTIAL/credentials", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.createAKSK")
|
||||
}
|
||||
@@ -272,7 +275,7 @@ func (self *SHuaweiClient) CreateAKSK(id, name string) (*cloudprovider.SAccessKe
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) DeleteAKSK(accessKey string) error {
|
||||
_, err := self.deleteAKSK(accessKey)
|
||||
_, err := self.delete(SERVICE_IAM, "", "OS-CREDENTIAL/credentials/"+accessKey)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+102
-186
@@ -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)
|
||||
}
|
||||
|
||||
+46
-215
@@ -57,29 +57,35 @@ const (
|
||||
HUAWEI_INTERNATIONAL_CLOUDENV = "InternationalCloud"
|
||||
HUAWEI_CHINA_CLOUDENV = "ChinaCloud"
|
||||
|
||||
HUAWEI_DEFAULT_REGION = "cn-north-1"
|
||||
HUAWEI_API_VERSION = "2018-12-25"
|
||||
HUAWEI_DEFAULT_REGION = "cn-north-1"
|
||||
HUAWEI_CERT_DEFAULT_REGION = "cn-north-4"
|
||||
HUAWEI_API_VERSION = "2018-12-25"
|
||||
|
||||
SERVICE_IAM = "iam"
|
||||
SERVICE_ELB = "elb"
|
||||
SERVICE_VPC = "vpc"
|
||||
SERVICE_CES = "ces"
|
||||
SERVICE_RDS = "rds"
|
||||
SERVICE_ECS = "ecs"
|
||||
SERVICE_EPS = "eps"
|
||||
SERVICE_EVS = "evs"
|
||||
SERVICE_BSS = "bss"
|
||||
SERVICE_SFS = "sfs-turbo"
|
||||
SERVICE_CTS = "cts"
|
||||
SERVICE_NAT = "nat"
|
||||
SERVICE_BMS = "bms"
|
||||
SERVICE_CCI = "cci"
|
||||
SERVICE_CSBS = "csbs"
|
||||
SERVICE_IMS = "ims"
|
||||
SERVICE_AS = "as"
|
||||
SERVICE_CCE = "cce"
|
||||
SERVICE_DCS = "dcs"
|
||||
SERVICE_MODELARTS = "modelarts"
|
||||
SERVICE_IAM = "iam"
|
||||
SERVICE_ELB = "elb"
|
||||
SERVICE_VPC = "vpc"
|
||||
SERVICE_CES = "ces"
|
||||
SERVICE_RDS = "rds"
|
||||
SERVICE_ECS = "ecs"
|
||||
SERVICE_EPS = "eps"
|
||||
SERVICE_EVS = "evs"
|
||||
SERVICE_BSS = "bss"
|
||||
SERVICE_SFS = "sfs-turbo"
|
||||
SERVICE_CTS = "cts"
|
||||
SERVICE_NAT = "nat"
|
||||
SERVICE_BMS = "bms"
|
||||
SERVICE_CCI = "cci"
|
||||
SERVICE_CSBS = "csbs"
|
||||
SERVICE_IMS = "ims"
|
||||
SERVICE_AS = "as"
|
||||
SERVICE_CCE = "cce"
|
||||
SERVICE_DCS = "dcs"
|
||||
SERVICE_MODELARTS = "modelarts"
|
||||
SERVICE_SCM = "scm"
|
||||
SERVICE_CDN = "cdn"
|
||||
SERVICE_GAUSSDB = "gaussdb"
|
||||
SERVICE_GAUSSDB_NOSQL = "gaussdb-nosql"
|
||||
SERVICE_FUNCTIONGRAPH = "functiongraph"
|
||||
)
|
||||
|
||||
var HUAWEI_REGION_CACHES sync.Map
|
||||
@@ -239,159 +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) {
|
||||
url := fmt.Sprintf("https://elb.%s.myhuaweicloud.com/v2/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.GET, url, query, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) monitorList(resource string, query url.Values) (jsonutils.JSONObject, error) {
|
||||
url := fmt.Sprintf("https://ces.%s.myhuaweicloud.com/v1.0/%s/%s", self.clientRegion, self.projectId, resource)
|
||||
return self.request(httputils.GET, url, query, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) monitorPost(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
url := fmt.Sprintf("https://ces.%s.myhuaweicloud.com/V1.0/%s/%s", self.clientRegion, self.projectId, resource)
|
||||
return self.request(httputils.POST, url, nil, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolNetworkList(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v1/%s/networks", self.clientRegion, self.projectId)
|
||||
return self.request(httputils.GET, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolNetworkCreate(params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v1/%s/networks", self.clientRegion, self.projectId)
|
||||
return self.request(httputils.POST, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (cli *SHuaweiClient) modelartsPoolNetworkDetail(networkName string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v1/%s/networks/%s", cli.clientRegion, cli.projectId, networkName)
|
||||
return cli.request(httputils.GET, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolById(poolName string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/pools/%s", self.clientRegion, self.projectId, poolName)
|
||||
return self.request(httputils.GET, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolList(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/%s", self.clientRegion, self.projectId, resource)
|
||||
return self.request(httputils.GET, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (cli *SHuaweiClient) modelartsPoolListWithStatus(resource, status string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/%s", cli.clientRegion, cli.projectId, resource)
|
||||
value := url.Values{}
|
||||
value.Add("status", status)
|
||||
return cli.request(httputils.GET, uri, value, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolCreate(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/%s", self.clientRegion, self.projectId, resource)
|
||||
return self.request(httputils.POST, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolDelete(resource, poolName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/pools/%s", self.clientRegion, self.projectId, poolName)
|
||||
return self.request(httputils.DELETE, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolUpdate(poolName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/pools/%s", self.clientRegion, self.projectId, poolName)
|
||||
urlValue := url.Values{}
|
||||
urlValue.Add("time_range", "")
|
||||
urlValue.Add("statistics", "")
|
||||
urlValue.Add("period", "")
|
||||
return self.patchRequest(httputils.PATCH, uri, urlValue, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolMonitor(poolName string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/pools/%s/monitor", self.clientRegion, self.projectId, poolName)
|
||||
return self.request(httputils.GET, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsResourceflavors(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v1/%s/%s", self.clientRegion, self.projectId, resource)
|
||||
return self.request(httputils.GET, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) getAKSKList(userId string) (jsonutils.JSONObject, error) {
|
||||
params := url.Values{}
|
||||
params.Set("user_id", userId)
|
||||
uri := fmt.Sprintf("https://iam.cn-north-4.myhuaweicloud.com/v3.0/OS-CREDENTIAL/credentials")
|
||||
return self.request(httputils.GET, uri, params, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) deleteAKSK(accesskey string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://iam.cn-north-4.myhuaweicloud.com/v3.0/OS-CREDENTIAL/credentials/%s", accesskey)
|
||||
return self.request(httputils.DELETE, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) createAKSK(params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://iam.cn-north-4.myhuaweicloud.com/v3.0/OS-CREDENTIAL/credentials")
|
||||
return self.request(httputils.POST, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) lbGet(regionId, resource string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://elb.%s.myhuaweicloud.com/v2/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.GET, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) lbCreate(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://elb.%s.myhuaweicloud.com/v2/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.POST, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) lbUpdate(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://elb.%s.myhuaweicloud.com/v2/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.PUT, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) lbDelete(regionId, resource string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://elb.%s.myhuaweicloud.com/v2/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.DELETE, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) vpcList(regionId, resource string, query url.Values) (jsonutils.JSONObject, error) {
|
||||
url := fmt.Sprintf("https://vpc.%s.myhuaweicloud.com/v1/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.GET, url, query, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) vpcCreate(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://vpc.%s.myhuaweicloud.com/v1/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.POST, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) vpcPost(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://vpc.%s.myhuaweicloud.com/v1/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.POST, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) vpcGet(regionId, resource string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://vpc.%s.myhuaweicloud.com/v1/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.GET, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) vpcDelete(regionId, resource string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://vpc.%s.myhuaweicloud.com/v1/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.DELETE, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) vpcUpdate(regionId, resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://vpc.%s.myhuaweicloud.com/v1/%s/%s", regionId, self.projectId, resource)
|
||||
return self.request(httputils.PUT, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) sslcertList(regionId, resource string, query url.Values) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://scm.%s.myhuaweicloud.com/v3/%s", regionId, resource)
|
||||
return self.request(httputils.GET, uri, query, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) sslcertExport(regionId, resource string, scID string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://scm.%s.myhuaweicloud.com/v3/%s/%s/export", regionId, resource, scID)
|
||||
return self.request(httputils.POST, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
type akClient struct {
|
||||
client *http.Client
|
||||
aksk aksk.SignOptions
|
||||
@@ -399,9 +252,12 @@ type akClient struct {
|
||||
|
||||
func (self *akClient) Do(req *http.Request) (*http.Response, error) {
|
||||
req.Header.Del("Accept")
|
||||
if req.Method == string(httputils.GET) || req.Method == string(httputils.DELETE) || req.Method == string(httputils.PATCH) {
|
||||
if req.Method == string(httputils.GET) || req.Method == string(httputils.DELETE) || req.Method == string(httputils.PATCH) && !strings.HasPrefix(req.Host, "modelarts") {
|
||||
req.Header.Del("Content-Length")
|
||||
}
|
||||
if strings.HasPrefix(req.Host, "modelarts") && req.Method == string(httputils.PATCH) {
|
||||
req.Header.Set("Content-Type", "application/merge-patch+json")
|
||||
}
|
||||
aksk.Sign(req, self.aksk)
|
||||
return self.client.Do(req)
|
||||
}
|
||||
@@ -741,19 +597,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"`
|
||||
@@ -761,39 +609,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) GetVersion() string {
|
||||
@@ -979,10 +810,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)
|
||||
|
||||
+77
-95
@@ -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
|
||||
}
|
||||
|
||||
+5
-5
@@ -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
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
+6
-6
@@ -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
|
||||
}
|
||||
|
||||
+5
-5
@@ -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
|
||||
}
|
||||
|
||||
+12
-12
@@ -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
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
+26
-14
@@ -15,6 +15,8 @@
|
||||
package huawei
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -113,7 +115,7 @@ type SModelartsNetworkStatus struct {
|
||||
|
||||
func (self *SRegion) GetIModelartsPools() ([]cloudprovider.ICloudModelartsPool, error) {
|
||||
pools := make([]SModelartsPool, 0)
|
||||
resObj, err := self.client.modelartsPoolList("pools", nil)
|
||||
resObj, err := self.list(SERVICE_MODELARTS, "pools", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "region.GetPools")
|
||||
}
|
||||
@@ -134,7 +136,7 @@ func (self *SRegion) CreateIModelartsPool(args *cloudprovider.ModelartsPoolCreat
|
||||
if len(args.Cidr) == 0 {
|
||||
args.Cidr = "192.168.20.0/24"
|
||||
}
|
||||
netObj, err := self.client.modelartsPoolNetworkList("network", nil)
|
||||
netObj, err := self.list(SERVICE_MODELARTS, "network", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.GetPools")
|
||||
}
|
||||
@@ -154,7 +156,7 @@ func (self *SRegion) CreateIModelartsPool(args *cloudprovider.ModelartsPoolCreat
|
||||
}
|
||||
netId, _ = createNetObj.GetString("metadata", "name")
|
||||
for i := 0; i < 10; i++ {
|
||||
netDetailObj, err := self.client.modelartsPoolNetworkDetail(netId)
|
||||
netDetailObj, err := self.list(SERVICE_MODELARTS, "networks/"+netId, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.NetworkDetail")
|
||||
}
|
||||
@@ -192,7 +194,7 @@ func (self *SRegion) CreateIModelartsPool(args *cloudprovider.ModelartsPoolCreat
|
||||
},
|
||||
},
|
||||
}
|
||||
obj, err := self.client.modelartsPoolCreate("pools", params)
|
||||
obj, err := self.post(SERVICE_MODELARTS, "pools", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.CreatePools")
|
||||
}
|
||||
@@ -221,11 +223,12 @@ func (region *SRegion) waitCreate(pool *SModelartsPool) (cloudprovider.ICloudMod
|
||||
}
|
||||
|
||||
func (self *SRegion) DeletePool(poolName string) (jsonutils.JSONObject, error) {
|
||||
return self.client.modelartsPoolDelete("pools", poolName, nil)
|
||||
resource := fmt.Sprintf("pools/%s", poolName)
|
||||
return self.delete(SERVICE_MODELARTS, resource)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIModelartsPoolById(poolId string) (cloudprovider.ICloudModelartsPool, error) {
|
||||
obj, err := self.client.modelartsPoolById(poolId)
|
||||
obj, err := self.list(SERVICE_MODELARTS, "pools/"+poolId, nil)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "not found") {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "")
|
||||
@@ -243,7 +246,8 @@ func (self *SRegion) GetIModelartsPoolById(poolId string) (cloudprovider.ICloudM
|
||||
}
|
||||
|
||||
func (self *SRegion) MonitorPool(poolId string) (*SModelartsMetrics, error) {
|
||||
resObj, err := self.client.modelartsPoolMonitor(poolId, nil)
|
||||
resource := fmt.Sprintf("pools/%s/monitor", poolId)
|
||||
resObj, err := self.list(SERVICE_MODELARTS, resource, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "send request error")
|
||||
}
|
||||
@@ -287,7 +291,7 @@ type ModelartsStatistics struct {
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) GetPoolNetworks(poolName string) (jsonutils.JSONObject, error) {
|
||||
return self.modelartsPoolNetworkList(poolName, nil)
|
||||
return self.list(SERVICE_MODELARTS, self.clientRegion, "networks", nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) CreatePoolNetworks(cidr string) (jsonutils.JSONObject, error) {
|
||||
@@ -304,7 +308,7 @@ func (self *SHuaweiClient) CreatePoolNetworks(cidr string) (jsonutils.JSONObject
|
||||
"cidr": cidr,
|
||||
},
|
||||
}
|
||||
return self.modelartsPoolNetworkCreate(params)
|
||||
return self.post(SERVICE_MODELARTS, self.clientRegion, "networks", params)
|
||||
}
|
||||
|
||||
func (self *SModelartsPool) GetCreatedAt() time.Time {
|
||||
@@ -404,7 +408,7 @@ func (self *SModelartsPool) SetAutoRenew(bc billing.SBillingCycle) error {
|
||||
|
||||
func (self *SModelartsPool) RefreshForCreate() error {
|
||||
self.Status.Resource = SNodeStatus{}
|
||||
pool, err := self.region.client.modelartsPoolById(self.GetId())
|
||||
pool, err := self.region.list(SERVICE_MODELARTS, "pools/"+self.GetId(), nil)
|
||||
if err == nil {
|
||||
return pool.Unmarshal(self)
|
||||
}
|
||||
@@ -413,9 +417,11 @@ func (self *SModelartsPool) RefreshForCreate() error {
|
||||
}
|
||||
|
||||
pools := make([]SModelartsPool, 0)
|
||||
resObj, err := self.region.client.modelartsPoolListWithStatus("pools", "failed", nil)
|
||||
params := url.Values{}
|
||||
params.Add("status", "failed")
|
||||
resObj, err := self.region.list(SERVICE_MODELARTS, "pools", params)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "modelartsPoolListWithStatus")
|
||||
return errors.Wrap(err, "list failed pools")
|
||||
}
|
||||
|
||||
err = resObj.Unmarshal(&pools, "items")
|
||||
@@ -434,7 +440,8 @@ func (self *SModelartsPool) RefreshForCreate() error {
|
||||
|
||||
func (self *SModelartsPool) Refresh() error {
|
||||
self.Status.Resource = SNodeStatus{}
|
||||
pool, err := self.region.client.modelartsPoolById(self.GetId())
|
||||
resource := fmt.Sprintf("pools/%s", self.GetId())
|
||||
pool, err := self.region.list(SERVICE_MODELARTS, resource, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -486,6 +493,11 @@ func (self *SModelartsPool) ChangeConfig(opts *cloudprovider.ModelartsPoolChange
|
||||
"resources": res,
|
||||
},
|
||||
}
|
||||
_, err := self.region.client.modelartsPoolUpdate(self.Metadata.Name, params)
|
||||
resource := fmt.Sprintf("pools/%s", self.Metadata.Name)
|
||||
urlValue := url.Values{}
|
||||
urlValue.Add("time_range", "")
|
||||
urlValue.Add("statistics", "")
|
||||
urlValue.Add("period", "")
|
||||
_, err := self.region.patch(SERVICE_MODELARTS, resource, urlValue, params)
|
||||
return err
|
||||
}
|
||||
|
||||
+2
-3
@@ -61,11 +61,10 @@ type SModelartsResourceflavorsStatus struct {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIModelartsPoolSku() ([]cloudprovider.ICloudModelartsPoolSku, error) {
|
||||
params := make(map[string]interface{})
|
||||
resourceflavors := make([]SModelartsPoolSku, 0)
|
||||
obj, err := self.client.modelartsResourceflavors("resourceflavors", params)
|
||||
obj, err := self.list(SERVICE_MODELARTS, "resourceflavors", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "region.modelartsResourceflavors")
|
||||
return nil, errors.Wrap(err, "list")
|
||||
}
|
||||
obj.Unmarshal(&resourceflavors, "items")
|
||||
res := make([]cloudprovider.ICloudModelartsPoolSku, len(resourceflavors))
|
||||
|
||||
+9
-7
@@ -15,6 +15,7 @@
|
||||
package huawei
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -81,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
|
||||
}
|
||||
@@ -163,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
|
||||
}
|
||||
@@ -234,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
|
||||
}
|
||||
@@ -330,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
|
||||
}
|
||||
@@ -419,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
|
||||
}
|
||||
@@ -500,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
|
||||
}
|
||||
@@ -552,7 +553,8 @@ func (self *SHuaweiClient) getLoadbalancerMetrics(opts *cloudprovider.MetricList
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) getModelartsPoolMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
resp, err := self.modelartsPoolMonitor(opts.ResourceId, nil)
|
||||
resource := fmt.Sprintf("pools/%s/monitor", opts.ResourceId)
|
||||
resp, err := self.list(SERVICE_MODELARTS, self.clientRegion, resource, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+4
@@ -76,6 +76,10 @@ func (self *SRegion) post(service, resource string, params map[string]interface{
|
||||
return self.client.post(service, self.ID, resource, params)
|
||||
}
|
||||
|
||||
func (self *SRegion) patch(service, resource string, query url.Values, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
return self.client.patch(service, self.ID, resource, query, params)
|
||||
}
|
||||
|
||||
func (self *SRegion) getECSClient() (*client.Client, error) {
|
||||
var err error
|
||||
|
||||
|
||||
+4
-4
@@ -190,7 +190,7 @@ func (r *SRegion) GetSSLCertificates(size, offset int) ([]SSSLCertificate, int,
|
||||
"sort_key": []string{"certExpiredTime"},
|
||||
"sort_dir": []string{"DESC"},
|
||||
}
|
||||
resp, err := r.client.sslcertList(r.ID, "scm/certificates", params)
|
||||
resp, err := r.list(SERVICE_SCM, "scm/certificates", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "CertificateList")
|
||||
}
|
||||
@@ -206,17 +206,17 @@ func (r *SRegion) GetSSLCertificates(size, offset int) ([]SSSLCertificate, int,
|
||||
}
|
||||
|
||||
func (r *SRegion) GetCertificate(certId string) (*SSSLCertificate, error) {
|
||||
resp, err := r.client.sslcertExport(r.ID, "scm/certificates", certId)
|
||||
resource := fmt.Sprintf("scm/certificates/%s/export", certId)
|
||||
resp, err := r.post(SERVICE_SCM, resource, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "DescribeCertificateDetail")
|
||||
}
|
||||
|
||||
cert := &SSSLCertificate{}
|
||||
cert := &SSSLCertificate{region: r}
|
||||
err = resp.Unmarshal(cert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Unmarshal")
|
||||
}
|
||||
cert.region = r
|
||||
|
||||
return cert, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user