keypairs.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/options"
  18. )
  19. type KeypairList struct {
  20. options.BaseListOptions
  21. Scheme string `help:"Scheme of keypair, default is RSA" choices:"RSA|DSA|ECDSA|ED25519"`
  22. }
  23. func (self *KeypairList) Params() (jsonutils.JSONObject, error) {
  24. return options.ListStructToParams(self)
  25. }
  26. type KeypairCreate struct {
  27. NAME string `help:"Name of keypair to be created"`
  28. Scheme string `help:"Scheme of keypair, default is RSA" choices:"RSA|DSA|ECDSA|ED25519" default:"RSA"`
  29. PublicKey string `help:"Publickey of keypair"`
  30. Desc string `help:"Short description of keypair"`
  31. }
  32. func (args *KeypairCreate) Params() (jsonutils.JSONObject, error) {
  33. params := jsonutils.NewDict()
  34. params.Add(jsonutils.NewString(args.NAME), "name")
  35. if len(args.Scheme) > 0 {
  36. params.Add(jsonutils.NewString(args.Scheme), "scheme")
  37. }
  38. if len(args.PublicKey) > 0 {
  39. params.Add(jsonutils.NewString(args.PublicKey), "public_key")
  40. }
  41. if len(args.Desc) > 0 {
  42. params.Add(jsonutils.NewString(args.Desc), "description")
  43. }
  44. return params, nil
  45. }
  46. type KeyPairIdOptions struct {
  47. ID string `help:"ID of keypair"`
  48. }
  49. func (self *KeyPairIdOptions) GetId() string {
  50. return self.ID
  51. }
  52. func (self *KeyPairIdOptions) Params() (jsonutils.JSONObject, error) {
  53. return nil, nil
  54. }
  55. type KeypairUpdate struct {
  56. KeyPairIdOptions
  57. Name string `help:"New name of keypair"`
  58. Desc string `help:"Short description of keypair"`
  59. }
  60. func (args *KeypairUpdate) Params() (jsonutils.JSONObject, error) {
  61. params := jsonutils.NewDict()
  62. if len(args.Name) > 0 {
  63. params.Add(jsonutils.NewString(args.Name), "name")
  64. }
  65. if len(args.Desc) > 0 {
  66. params.Add(jsonutils.NewString(args.Desc), "description")
  67. }
  68. return params, nil
  69. }