natstable.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/onecloud/pkg/mcclient"
  18. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  19. "yunion.io/x/onecloud/pkg/mcclient/options"
  20. "yunion.io/x/onecloud/pkg/mcclient/options/compute"
  21. )
  22. func init() {
  23. R(&compute.NatSTableListOptions{}, "snat-list", "List SNAT entries", func(s *mcclient.ClientSession, opts *compute.NatSTableListOptions) error {
  24. params, err := options.ListStructToParams(opts)
  25. if err != nil {
  26. return err
  27. }
  28. result, err := modules.NatSTable.List(s, params)
  29. if err != nil {
  30. return err
  31. }
  32. printList(result, modules.NatSTable.GetColumns(s))
  33. return nil
  34. })
  35. R(&compute.NatSDeleteShowOptions{}, "snat-delete", "Delete a SNAT", func(s *mcclient.ClientSession, args *compute.NatSDeleteShowOptions) error {
  36. results, err := modules.NatSTable.Delete(s, args.ID, nil)
  37. if err != nil {
  38. return err
  39. }
  40. printObject(results)
  41. return nil
  42. })
  43. R(&compute.NatSDeleteShowOptions{}, "snat-show", "Show a SNAT", func(s *mcclient.ClientSession, args *compute.NatSDeleteShowOptions) error {
  44. results, err := modules.NatSTable.Get(s, args.ID, nil)
  45. if err != nil {
  46. return err
  47. }
  48. printObject(results)
  49. return nil
  50. })
  51. R(&compute.NatSCreateOptions{}, "snat-create", "Create a SNAT", func(s *mcclient.ClientSession, args *compute.NatSCreateOptions) error {
  52. params := jsonutils.NewDict()
  53. params.Add(jsonutils.NewString(args.NAME), "name")
  54. params.Add(jsonutils.NewString(args.NATGATEWAYID), "natgateway_id")
  55. params.Add(jsonutils.NewString(args.IP), "ip")
  56. params.Add(jsonutils.NewString(args.EXTERNALIPID), "external_ip_id")
  57. params.Add(jsonutils.NewString(args.SourceCIDR), "source_cidr")
  58. params.Add(jsonutils.NewString(args.NetworkID), "network_id")
  59. result, err := modules.NatSTable.Create(s, params)
  60. if err != nil {
  61. return err
  62. }
  63. printObject(result)
  64. return nil
  65. })
  66. }