yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/client/modules/mod_disks.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 "yunion.io/x/jsonutils" 19 "yunion.io/x/log" 20 21 "yunion.io/x/cloudmux/pkg/multicloud/huawei/client/manager" 22 "yunion.io/x/cloudmux/pkg/multicloud/huawei/client/responses" 23 ) 24 25 type SDiskManager struct { 26 SResourceManager 27 } 28 29 func NewDiskManager(cfg manager.IManagerConfig) *SDiskManager { 30 return &SDiskManager{SResourceManager: SResourceManager{ 31 SBaseManager: NewBaseManager(cfg), 32 ServiceName: ServiceNameEVS, 33 Region: cfg.GetRegionId(), 34 ProjectId: cfg.GetProjectId(), 35 version: "v2", 36 Keyword: "volume", 37 KeywordPlural: "volumes", 38 39 ResourceKeyword: "cloudvolumes", 40 }} 41 } 42 43 func (self *SDiskManager) List(querys map[string]string) (*responses.ListResult, error) { 44 return self.ListInContextWithSpec(nil, "detail", querys, self.KeywordPlural) 45 } 46 47 // https://support.huaweicloud.com/api-evs/evs_04_2003.html 48 func (self *SDiskManager) AsyncCreate(params jsonutils.JSONObject) (string, error) { 49 origin_version := self.version 50 self.version = "v2.1" 51 defer func() { self.version = origin_version }() 52 53 ret, err := self.CreateInContextWithSpec(nil, "", params, "") 54 if err != nil { 55 log.Debugf("AsyncCreate %s", err) 56 return "", err 57 } 58 59 log.Debugf("AsyncCreate result %s", ret.String()) 60 // 按需机器 61 jobId, err := ret.GetString("job_id") 62 if err == nil { 63 return jobId, nil 64 } 65 66 // 包年包月机器 67 return ret.GetString("order_id") 68 } 69 70 // https://support.huaweicloud.com/api-evs/evs_04_2003.html 71 func (self *SDiskManager) GetDiskTypes() (*responses.ListResult, error) { 72 originKeyword := self.ResourceKeyword 73 self.ResourceKeyword = "" 74 defer func() { self.ResourceKeyword = originKeyword }() 75 return self.ListInContextWithSpec(self.ctx, "types", nil, "volume_types") 76 }