storage.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. "fmt"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/apis/compute"
  19. "yunion.io/x/onecloud/pkg/mcclient/options"
  20. )
  21. type StorageListOptions struct {
  22. options.BaseListOptions
  23. Share *bool `help:"Share storage list"`
  24. Local *bool `help:"Local storage list"`
  25. Usable *bool `help:"Usable storage list"`
  26. Zone string `help:"List storages in zone" json:"-"`
  27. Region string `help:"List storages in region"`
  28. Schedtag string `help:"filter storage by schedtag"`
  29. HostId string `help:"filter storages which attached the specified host"`
  30. HostSchedtagId string `help:"filter storage by host schedtag"`
  31. ImageId string `help:"filter storage by image"`
  32. IsBaremetal *bool `help:"Baremetal storage list"`
  33. }
  34. func (opts *StorageListOptions) Params() (jsonutils.JSONObject, error) {
  35. return options.ListStructToParams(opts)
  36. }
  37. func (opts *StorageListOptions) GetContextId() string {
  38. return opts.Zone
  39. }
  40. type StorageUpdateOptions struct {
  41. options.BaseUpdateOptions
  42. MediumType string `help:"Medium type" choices:"ssd|rotate"`
  43. RbdRadosMonOpTimeout int64 `help:"ceph rados_mon_op_timeout"`
  44. RbdRadosOsdOpTimeout int64 `help:"ceph rados_osd_op_timeout"`
  45. RbdClientMountTimeout int64 `help:"ceph client_mount_timeout"`
  46. RbdEnableMessengerV2 bool `help:"ceph enable Messenger V2"`
  47. RbdKey string `help:"ceph rbd key"`
  48. Reserved string `help:"Reserved storage space"`
  49. Capacity int `help:"Capacity for storage"`
  50. MasterHost string `help:"slvm storage master host"`
  51. AutoCacheImages *bool `help:"ceph storage auto cache glance images"`
  52. }
  53. func (opts *StorageUpdateOptions) Params() (jsonutils.JSONObject, error) {
  54. return options.StructToParams(opts)
  55. }
  56. type StorageCreateOptions struct {
  57. NAME string `help:"Name of the Storage"`
  58. ZONE string `help:"Zone id of storage"`
  59. Capacity int64 `help:"Capacity of the Storage"`
  60. MediumType string `help:"Medium type" choices:"ssd|rotate" default:"ssd"`
  61. StorageType string `help:"Storage type" choices:"local|nas|vsan|rbd|nfs|gpfs|baremetal|clvm|slvm"`
  62. RbdMonHost string `help:"Ceph mon_host config"`
  63. RbdEnableMessengerV2 bool `help:"ceph enable Messenger V2"`
  64. RbdRadosMonOpTimeout int64 `help:"ceph rados_mon_op_timeout"`
  65. RbdRadosOsdOpTimeout int64 `help:"ceph rados_osd_op_timeout"`
  66. RbdClientMountTimeout int64 `help:"ceph client_mount_timeout"`
  67. RbdKey string `help:"Ceph key config"`
  68. RbdPool string `help:"Ceph Pool Name"`
  69. AutoCacheImages *bool `help:"ceph storage auto cache glance images"`
  70. NfsHost string `help:"NFS host"`
  71. NfsSharedDir string `help:"NFS shared dir"`
  72. ClvmVgName string `help:"clvm vg name"`
  73. SlvmVgName string `help:"slvm vg name"`
  74. Lvmlockd bool `help:"shared lvm storage use lvmlockd"`
  75. MasterHost string `help:"slvm storage master host"`
  76. }
  77. func (opts *StorageCreateOptions) Params() (jsonutils.JSONObject, error) {
  78. if opts.StorageType == "rbd" {
  79. if opts.RbdMonHost == "" || opts.RbdPool == "" {
  80. return nil, fmt.Errorf("Not enough arguments, missing mon_hostor pool")
  81. }
  82. } else if opts.StorageType == "nfs" {
  83. if len(opts.NfsHost) == 0 || len(opts.NfsSharedDir) == 0 {
  84. return nil, fmt.Errorf("Storage type nfs missing conf host or shared dir")
  85. }
  86. } else if opts.StorageType == "clvm" {
  87. if len(opts.ClvmVgName) == 0 {
  88. return nil, fmt.Errorf("Storage type clvm missing conf clvm_vg_name")
  89. }
  90. } else if opts.StorageType == "slvm" {
  91. if len(opts.SlvmVgName) == 0 {
  92. return nil, fmt.Errorf("Storage type slvm missing conf slvm_vg_name")
  93. }
  94. }
  95. return options.StructToParams(opts)
  96. }
  97. type StorageForceDetachHost struct {
  98. options.BaseIdOptions
  99. HOST string `help:"ID or name of host"`
  100. }
  101. func (opts *StorageForceDetachHost) Params() (jsonutils.JSONObject, error) {
  102. return jsonutils.Marshal(map[string]string{"host": opts.HOST}), nil
  103. }
  104. type StorageSetHardwareInfoOptions struct {
  105. options.BaseIdOptions
  106. compute.StorageHardwareInfo
  107. }
  108. func (o *StorageSetHardwareInfoOptions) Params() (jsonutils.JSONObject, error) {
  109. return jsonutils.Marshal(o), nil
  110. }
  111. type StorageSetCommitBoundOptions struct {
  112. options.BaseIdOptions
  113. Cmtbound *float32 `help:"Storage commit bound"`
  114. }
  115. func (o *StorageSetCommitBoundOptions) Params() (jsonutils.JSONObject, error) {
  116. return options.StructToParams(o)
  117. }