fix(region): cloudpods error

This commit is contained in:
ioito
2022-03-15 20:19:58 +08:00
parent ad30742a1c
commit a42fd8ca05
2 changed files with 55 additions and 1 deletions
+9 -1
View File
@@ -16,6 +16,7 @@ package cloudpods
import (
"context"
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
@@ -125,8 +126,15 @@ func (self *SCloudpodsClient) get(manager ModelManager, id string, params map[st
if len(id) == 0 {
return errors.Wrap(cloudprovider.ErrNotFound, "empty id")
}
resp, err := manager.Get(self.s, id, jsonutils.Marshal(params))
body := jsonutils.NewDict()
for k, v := range params {
body.Set(k, jsonutils.NewString(v))
}
resp, err := manager.Get(self.s, id, body)
if err != nil {
if strings.Contains(err.Error(), "NotFoundError") {
return errors.Wrapf(cloudprovider.ErrNotFound, err.Error())
}
return errors.Wrapf(err, "Get(%s)", id)
}
return resp.Unmarshal(retVal)
@@ -0,0 +1,46 @@
// 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 shell
import (
"yunion.io/x/onecloud/pkg/multicloud/cloudpods"
"yunion.io/x/onecloud/pkg/util/shellutils"
)
func init() {
type SecurityGroupListOptions struct {
}
shellutils.R(&SecurityGroupListOptions{}, "security-group-list", "List security-groups", func(cli *cloudpods.SRegion, args *SecurityGroupListOptions) error {
groups, err := cli.GetSecurityGroups()
if err != nil {
return err
}
printList(groups, 0, 0, 0, nil)
return nil
})
type SecurityGroupIdOptions struct {
ID string
}
shellutils.R(&SecurityGroupIdOptions{}, "security-group-show", "Show security group", func(cli *cloudpods.SRegion, args *SecurityGroupIdOptions) error {
group, err := cli.GetSecurityGroup(args.ID)
if err != nil {
return err
}
printObject(group)
return nil
})
}