webconsole.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 options
  15. import (
  16. "time"
  17. "yunion.io/x/jsonutils"
  18. )
  19. type WebConsoleOptions struct {
  20. WebconsoleUrl string `help:"Frontend webconsole url" short-token:"w" default:"$WEBCONSOLE_URL"`
  21. }
  22. type PodBaseOptions struct {
  23. WebConsoleOptions
  24. NAME string `help:"Name of k8s pod to connect"`
  25. Namespace string `help:"Namespace of this pod"`
  26. Container string `help:"Container in this pod"`
  27. Cluster string `default:"$K8S_CLUSTER|default" help:"Kubernetes cluster name"`
  28. }
  29. func (opt *PodBaseOptions) Params() (*jsonutils.JSONDict, error) {
  30. return StructToParams(opt)
  31. }
  32. type PodShellOptions struct {
  33. PodBaseOptions
  34. }
  35. type PodLogOptoins struct {
  36. PodBaseOptions
  37. Since string `help:"Only return logs newer than a relative duration like 5s, 2m or 3h"`
  38. }
  39. func (opt *PodLogOptoins) Params() (*jsonutils.JSONDict, error) {
  40. params, err := opt.PodBaseOptions.Params()
  41. if err != nil {
  42. return nil, err
  43. }
  44. if opt.Since != "" {
  45. _, err = time.ParseDuration(opt.Since)
  46. if err != nil {
  47. return nil, err
  48. }
  49. params.Add(jsonutils.NewString(opt.Since), "since")
  50. }
  51. return params, nil
  52. }
  53. type WebConsoleBaremetalOptions struct {
  54. WebConsoleOptions
  55. ID string `help:"Baremetal host id or name"`
  56. }
  57. func (opt *WebConsoleBaremetalOptions) Params() (*jsonutils.JSONDict, error) {
  58. return StructToParams(opt)
  59. }
  60. type WebConsoleSshOptions struct {
  61. WebConsoleOptions
  62. ID string `help:"ID of server" json:"-"`
  63. Ip string `help:"IP to connect if multiple IPs on server"`
  64. Port int `help:"Remote server port"`
  65. Username string `help:"Remote server username"`
  66. KeepUsername bool `help:"Keep remove username"`
  67. Password string `help:"Remote server password"`
  68. ResourceType string `help:"Resource Type" choices:"host|server"`
  69. }
  70. func (opt *WebConsoleSshOptions) Params() (*jsonutils.JSONDict, error) {
  71. data, err := StructToParams(opt)
  72. if err != nil {
  73. return nil, err
  74. }
  75. params := jsonutils.NewDict()
  76. params.Set("webconsole", data)
  77. return params, nil
  78. }
  79. type WebConsoleServerOptions struct {
  80. WebConsoleOptions
  81. ID string `help:"Server id or name"`
  82. }
  83. type WebConsoleServerRdpOptions struct {
  84. WebConsoleOptions
  85. ID string `help:"Server id or name"`
  86. Host *string
  87. Port *int
  88. Username *string
  89. Password *string
  90. Width *int
  91. Height *int
  92. Dpi *int
  93. }
  94. type WebConsoleContainerExecOptions struct {
  95. WebConsoleOptions
  96. ID string `help:"Container id or name"`
  97. }