yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/client/modules/mod_orders.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package modules
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"yunion.io/x/jsonutils"
    21  
    22  	"yunion.io/x/cloudmux/pkg/multicloud/huawei/client/manager"
    23  	"yunion.io/x/cloudmux/pkg/multicloud/huawei/client/responses"
    24  )
    25  
    26  // domian 客户账号ID https://support.huaweicloud.com/oce_faq/zh-cn_topic_0113714840.html
    27  type SOrderManager struct {
    28  	orderCtx manager.IManagerContext
    29  	SResourceManager
    30  }
    31  
    32  type orderCtx struct {
    33  	domainId string
    34  }
    35  
    36  // {domain_id}/common/
    37  // 这个manager非常特殊。url hardcode
    38  func (self *orderCtx) GetPath() string {
    39  	return fmt.Sprintf("%s/common", self.domainId)
    40  }
    41  
    42  // 客户运营能力API的Endpoint为“bss.cn-north-1.myhuaweicloud.com”。该Endpoint为全局Endpoint,中国站所有区域均可使用。
    43  // https://support.huaweicloud.com/api-oce/zh-cn_topic_0084961226.html
    44  func NewOrderManager(cfg manager.IManagerConfig) *SOrderManager {
    45  	return &SOrderManager{SResourceManager: SResourceManager{
    46  		SBaseManager:  NewBaseManager(cfg),
    47  		ServiceName:   ServiceNameBSS,
    48  		Region:        "cn-north-1",
    49  		ProjectId:     "",
    50  		version:       "v1.0",
    51  		Keyword:       "",
    52  		KeywordPlural: "",
    53  
    54  		ResourceKeyword: "order-mgr",
    55  	}}
    56  }
    57  
    58  func (self *SOrderManager) SetDomainId(domainId string) error {
    59  	if len(domainId) == 0 {
    60  		return fmt.Errorf("SetDomainId domain id should not be emtpy")
    61  	}
    62  
    63  	self.orderCtx = &orderCtx{domainId: domainId}
    64  	return nil
    65  }
    66  
    67  // 查询客户包周期资源列表  https://support.huaweicloud.com/api-oce/zh-cn_topic_0084961226.html
    68  func (self *SOrderManager) List(querys map[string]string) (*responses.ListResult, error) {
    69  	return nil, fmt.Errorf("Not Suppport List Order")
    70  }
    71  
    72  // 查询订单的资源开通详情 https://support.huaweicloud.com/api-oce/api_order_00001.html
    73  func (self *SOrderManager) Get(id string, querys map[string]string) (jsonutils.JSONObject, error) {
    74  	if self.orderCtx == nil {
    75  		return nil, fmt.Errorf("domainId is emtpy.Use SetDomainId method to set.")
    76  	}
    77  
    78  	// !!!特殊调用
    79  	return self.GetInContextWithSpec(self.orderCtx, "orders-resource", id, querys, "")
    80  }
    81  
    82  func (self *SOrderManager) PerformAction(action string, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
    83  	request := self.newRequest("POST", id, action, self.orderCtx)
    84  	request.SetContent([]byte(getContent(params)))
    85  
    86  	return self._do(request, "")
    87  }
    88  
    89  func (self *SOrderManager) GetPeriodResourceList(querys map[string]string) (*responses.ListResult, error) {
    90  	if self.orderCtx == nil {
    91  		return nil, fmt.Errorf("domainId is emtpy.Use SetDomainId method to set.")
    92  	}
    93  
    94  	return self.ListInContextWithSpec(self.orderCtx, "resources/detail", querys, "data")
    95  }
    96  
    97  // https://support.huaweicloud.com/api-bpconsole/zh-cn_topic_0082522029.html
    98  func (self *SOrderManager) RenewPeriodResource(params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
    99  	if self.orderCtx == nil {
   100  		return nil, fmt.Errorf("domainId is emtpy.Use SetDomainId method to set.")
   101  	}
   102  
   103  	return self.CreateInContextWithSpec(self.orderCtx, "resources/renew", params, "order_ids")
   104  }