diff --git a/pkg/multicloud/cloudpods/cloudpods.go b/pkg/multicloud/cloudpods/cloudpods.go index 6de5c50cfc..6f8ea577e8 100644 --- a/pkg/multicloud/cloudpods/cloudpods.go +++ b/pkg/multicloud/cloudpods/cloudpods.go @@ -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) diff --git a/pkg/multicloud/cloudpods/shell/secgroup.go b/pkg/multicloud/cloudpods/shell/secgroup.go new file mode 100644 index 0000000000..e9ac3c3844 --- /dev/null +++ b/pkg/multicloud/cloudpods/shell/secgroup.go @@ -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 + }) + +}