networkaddress.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/errors"
  18. baseoptions "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type NetworkAddressCreateOptions struct {
  21. ParentType string `help:"object type" choices:"guestnetwork" default:"guestnetwork"`
  22. ParentId string `help:"object id"`
  23. Guest string `help:"guest name or uuid" json:"guest_id"`
  24. GuestnetworkIndex int `help:"guest network interface index"`
  25. Type string `help:"address type" choices:"sub_ip" default:"sub_ip"`
  26. IPAddr string `help:"preferred ip address"`
  27. Count int `help:"create multiple addresses" json:",omitzero"`
  28. }
  29. func (opts *NetworkAddressCreateOptions) Params() (jsonutils.JSONObject, error) {
  30. if opts.Guest != "" {
  31. } else if opts.ParentId != "" {
  32. return nil, errors.Error("do not support directly specifying parent id yet")
  33. } else {
  34. return nil, errors.Error("requires parent spec, try --guest, etc.")
  35. }
  36. return baseoptions.StructToParams(opts)
  37. }
  38. func (opts *NetworkAddressCreateOptions) GetCountParam() int {
  39. return opts.Count
  40. }
  41. type NetworkAddressListOptions struct {
  42. baseoptions.BaseListOptions
  43. Type string
  44. ParentType string
  45. ParentId string
  46. NetworkId string
  47. IpAddr string
  48. GuestId []string
  49. }
  50. func (opts *NetworkAddressListOptions) Params() (jsonutils.JSONObject, error) {
  51. return baseoptions.ListStructToParams(opts)
  52. }
  53. type NetworkAddressIdOptions struct {
  54. ID string
  55. }
  56. func (opts *NetworkAddressIdOptions) GetId() string {
  57. return opts.ID
  58. }
  59. func (opts *NetworkAddressIdOptions) Params() (jsonutils.JSONObject, error) {
  60. return nil, nil
  61. }
  62. type NetworkAddressIdsOptions struct {
  63. ID []string
  64. }
  65. func (opts *NetworkAddressIdsOptions) GetIds() []string {
  66. return opts.ID
  67. }
  68. func (opts *NetworkAddressIdsOptions) Params() (jsonutils.JSONObject, error) {
  69. return nil, nil
  70. }