natdtable.go 2.6 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.NatDTableListOptions{}, "dnat-list", "List DNAT entries", func(s *mcclient.ClientSession, opts *compute.NatDTableListOptions) error {
  24. params, err := options.ListStructToParams(opts)
  25. if err != nil {
  26. return err
  27. }
  28. result, err := modules.NatDTable.List(s, params)
  29. if err != nil {
  30. return err
  31. }
  32. printList(result, modules.NatDTable.GetColumns(s))
  33. return nil
  34. })
  35. R(&compute.NatDDeleteShowOptions{}, "dnat-delete", "Delete a DNAT", func(s *mcclient.ClientSession, args *compute.NatDDeleteShowOptions) error {
  36. results, err := modules.NatDTable.Delete(s, args.ID, nil)
  37. if err != nil {
  38. return err
  39. }
  40. printObject(results)
  41. return nil
  42. })
  43. R(&compute.NatDDeleteShowOptions{}, "dnat-show", "Show a DNAT", func(s *mcclient.ClientSession, args *compute.NatDDeleteShowOptions) error {
  44. results, err := modules.NatDTable.Get(s, args.ID, nil)
  45. if err != nil {
  46. return err
  47. }
  48. printObject(results)
  49. return nil
  50. })
  51. R(&compute.NatDCreateOptions{}, "dnat-create", "Create a DNAT", func(s *mcclient.ClientSession, args *compute.NatDCreateOptions) 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.INTERNALIP), "internal_ip")
  56. params.Add(jsonutils.NewString(args.INTERNALPORT), "internal_port")
  57. params.Add(jsonutils.NewString(args.EXTERNALIP), "external_ip")
  58. params.Add(jsonutils.NewString(args.EXTERNALIPID), "external_ip_id")
  59. params.Add(jsonutils.NewString(args.EXTERNALPORT), "external_port")
  60. params.Add(jsonutils.NewString(args.IPPROTOCOL), "ip_protocol")
  61. result, err := modules.NatDTable.Create(s, params)
  62. if err != nil {
  63. return err
  64. }
  65. printObject(result)
  66. return nil
  67. })
  68. }