serversecgroups.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. package compute
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/pkg/util/printutils"
  18. "yunion.io/x/onecloud/pkg/mcclient"
  19. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  20. "yunion.io/x/onecloud/pkg/mcclient/options"
  21. )
  22. func init() {
  23. type ServerSecgroupListOptions struct {
  24. options.BaseListOptions
  25. Server string `help:"ID or Name of Server"`
  26. Secgroup string `help:"Secgroup ID or name"`
  27. }
  28. R(&ServerSecgroupListOptions{}, "server-secgroup-list", "List server secgroup pairs", func(s *mcclient.ClientSession, args *ServerSecgroupListOptions) error {
  29. var params *jsonutils.JSONDict
  30. {
  31. var err error
  32. params, err = args.BaseListOptions.Params()
  33. if err != nil {
  34. return err
  35. }
  36. }
  37. var result *printutils.ListResult
  38. var err error
  39. if len(args.Server) > 0 {
  40. result, err = modules.Serversecgroups.ListDescendent(s, args.Server, params)
  41. } else if len(args.Secgroup) > 0 {
  42. result, err = modules.Serversecgroups.ListDescendent2(s, args.Secgroup, params)
  43. } else {
  44. result, err = modules.Serversecgroups.List(s, params)
  45. }
  46. if err != nil {
  47. return err
  48. }
  49. printList(result, modules.Serversecgroups.GetColumns(s))
  50. return nil
  51. })
  52. type ServerSecgroupDetailOptions struct {
  53. SERVER string `help:"ID or Name of Server"`
  54. SECGROUP string `help:"ID or Name of Security Group"`
  55. }
  56. R(&ServerSecgroupDetailOptions{}, "server-secgroup-show", "Show server security group details", func(s *mcclient.ClientSession, args *ServerSecgroupDetailOptions) error {
  57. query := jsonutils.NewDict()
  58. result, err := modules.Serversecgroups.Get(s, args.SERVER, args.SECGROUP, query)
  59. if err != nil {
  60. return err
  61. }
  62. printObject(result)
  63. return nil
  64. })
  65. }