hostfile.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. "os"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/cmd/climc/shell"
  19. computeapi "yunion.io/x/onecloud/pkg/apis/compute"
  20. "yunion.io/x/onecloud/pkg/mcclient/options"
  21. )
  22. type HostFileListOptions struct {
  23. Type []string `help:"Type of host file"`
  24. options.BaseListOptions
  25. }
  26. func (opts *HostFileListOptions) Params() (jsonutils.JSONObject, error) {
  27. params, err := options.ListStructToParams(opts)
  28. if err != nil {
  29. return nil, err
  30. }
  31. if len(opts.Type) > 0 {
  32. params.Add(jsonutils.NewStringArray(opts.Type), "type")
  33. }
  34. return params, nil
  35. }
  36. type HostFileShowOptions struct {
  37. options.BaseShowOptions
  38. }
  39. func (o *HostFileShowOptions) Params() (jsonutils.JSONObject, error) {
  40. // NOTE: host show only request with base options
  41. return jsonutils.Marshal(o.BaseShowOptions), nil
  42. }
  43. type HostFileUpdateOptions struct {
  44. options.BaseIdOptions
  45. computeapi.HostFileUpdateInput
  46. File string `json:"file"`
  47. }
  48. func (opts *HostFileUpdateOptions) Params() (jsonutils.JSONObject, error) {
  49. if len(opts.File) > 0 {
  50. cont, err := os.ReadFile(opts.File)
  51. if err != nil {
  52. return nil, err
  53. }
  54. opts.Content = string(cont)
  55. }
  56. return jsonutils.Marshal(opts), nil
  57. }
  58. type HostFileCreateOptions struct {
  59. computeapi.HostFileCreateInput
  60. File string `json:"file"`
  61. }
  62. func (opts *HostFileCreateOptions) Params() (jsonutils.JSONObject, error) {
  63. if len(opts.File) > 0 {
  64. cont, err := os.ReadFile(opts.File)
  65. if err != nil {
  66. return nil, err
  67. }
  68. opts.Content = string(cont)
  69. }
  70. return jsonutils.Marshal(opts), nil
  71. }
  72. type HostFileDeleteOptions struct {
  73. options.BaseIdOptions
  74. }
  75. func (opts *HostFileDeleteOptions) Params() (jsonutils.JSONObject, error) {
  76. return jsonutils.Marshal(opts), nil
  77. }
  78. type HostFileEditOptions struct {
  79. options.BaseIdOptions
  80. }
  81. func (opts *HostFileEditOptions) EditType() shell.EditType {
  82. return shell.EditTypeText
  83. }
  84. func (opts *HostFileEditOptions) EditFields() []string {
  85. return []string{"content"}
  86. }