rules.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 cloudnet
  15. import (
  16. "yunion.io/x/onecloud/pkg/mcclient"
  17. modules "yunion.io/x/onecloud/pkg/mcclient/modules/cloudnet"
  18. base_options "yunion.io/x/onecloud/pkg/mcclient/options"
  19. options "yunion.io/x/onecloud/pkg/mcclient/options/cloudnet"
  20. )
  21. func init() {
  22. R(&options.RuleCreateOptions{}, "router-rule-create", "Create router rule", func(s *mcclient.ClientSession, opts *options.RuleCreateOptions) error {
  23. params, err := base_options.StructToParams(opts)
  24. if err != nil {
  25. return err
  26. }
  27. router, err := modules.Rules.Create(s, params)
  28. if err != nil {
  29. return err
  30. }
  31. printObject(router)
  32. return nil
  33. })
  34. R(&options.RuleGetOptions{}, "router-rule-show", "Show router rule", func(s *mcclient.ClientSession, opts *options.RuleGetOptions) error {
  35. router, err := modules.Rules.Get(s, opts.ID, nil)
  36. if err != nil {
  37. return err
  38. }
  39. printObject(router)
  40. return nil
  41. })
  42. R(&options.RuleListOptions{}, "router-rule-list", "List router rules", func(s *mcclient.ClientSession, opts *options.RuleListOptions) error {
  43. params, err := base_options.ListStructToParams(opts)
  44. if err != nil {
  45. return err
  46. }
  47. result, err := modules.Rules.List(s, params)
  48. if err != nil {
  49. return err
  50. }
  51. printList(result, modules.Rules.GetColumns(s))
  52. return nil
  53. })
  54. R(&options.RuleUpdateOptions{}, "router-rule-update", "Update router rule", func(s *mcclient.ClientSession, opts *options.RuleUpdateOptions) error {
  55. params, err := base_options.StructToParams(opts)
  56. router, err := modules.Rules.Update(s, opts.ID, params)
  57. if err != nil {
  58. return err
  59. }
  60. printObject(router)
  61. return nil
  62. })
  63. R(&options.RuleDeleteOptions{}, "router-rule-delete", "Delete router rule", func(s *mcclient.ClientSession, opts *options.RuleDeleteOptions) error {
  64. router, err := modules.Rules.Delete(s, opts.ID, nil)
  65. if err != nil {
  66. return err
  67. }
  68. printObject(router)
  69. return nil
  70. })
  71. }