yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/client/modules/mod_jobs.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 type SJobManager struct { 27 SResourceManager 28 } 29 30 func NewJobManager(cfg manager.IManagerConfig) *SJobManager { 31 return &SJobManager{SResourceManager: SResourceManager{ 32 SBaseManager: NewBaseManager(cfg), 33 ServiceName: "", 34 Region: cfg.GetRegionId(), 35 ProjectId: cfg.GetProjectId(), 36 version: "v1", 37 Keyword: "", 38 KeywordPlural: "", 39 40 ResourceKeyword: "jobs", 41 }} 42 } 43 44 func (self *SJobManager) Get(id string, querys map[string]string) (jsonutils.JSONObject, error) { 45 processedQuery, err := self.processQueryParam(querys) 46 if err != nil { 47 return nil, err 48 } 49 50 return self.GetInContext(nil, id, processedQuery) 51 } 52 53 func (self *SJobManager) List(querys map[string]string) (*responses.ListResult, error) { 54 processedQuery, err := self.processQueryParam(querys) 55 if err != nil { 56 return nil, err 57 } 58 return self.ListInContext(nil, processedQuery) 59 } 60 61 // 兼容查询不同ServiceName服务的Job做的特殊处理。 62 func (self *SJobManager) processQueryParam(querys map[string]string) (map[string]string, error) { 63 service_type, exists := querys["service_type"] 64 if !exists { 65 return querys, fmt.Errorf("must specific query parameter `service_type`. e.g. ecs|ims|iam") 66 } 67 68 self.ServiceName = ServiceNameType(service_type) 69 delete(querys, "service_type") 70 return querys, nil 71 }