host.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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/apis/baremetal"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type HostListOptions struct {
  21. Schedtag string `help:"List hosts in schedtag"`
  22. Zone string `help:"List hosts in zone"`
  23. Region string `help:"List hosts in region"`
  24. Wire string `help:"List hosts in wire"`
  25. Image string `help:"List hosts cached images" json:"cachedimage"`
  26. Storage string `help:"List hosts attached to storages"`
  27. Baremetal string `help:"List hosts that is managed by baremetal system" choices:"true|false"`
  28. Empty bool `help:"show empty host" json:"-"`
  29. Occupied bool `help:"show occupid host" json:"-"`
  30. Enabled bool `help:"Show enabled host only" json:"-"`
  31. Disabled bool `help:"Show disabled host only" json:"-"`
  32. HostType string `help:"Host type filter" choices:"baremetal|hypervisor|esxi|container|hyperv|aliyun|azure|qcloud|aws|huawei|ucloud|google|ctyun"`
  33. AnyMac string `help:"Mac matches one of the host's interface"`
  34. AnyIp []string `help:"IP matches one of the host's interface"`
  35. HostStorageType []string `help:"List host in host_storage_type"`
  36. IsBaremetal *bool `help:"filter host list by is_baremetal=true|false"`
  37. ResourceType string `help:"Resource type" choices:"shared|prepaid|dedicated"`
  38. Usable *bool `help:"List all zones that is usable"`
  39. Hypervisor string `help:"filter hosts by hypervisor"`
  40. StorageNotAttached bool `help:"List hosts not attach specified storage"`
  41. Uuid string `help:"find host with given system uuid"`
  42. CdromBoot *bool `help:"filter hosts list by cdrom_boot=true|false"`
  43. Sn string `help:"find host by sn"`
  44. OrderByServerCount string `help:"Order by server count" choices:"desc|asc"`
  45. OrderByStorage string `help:"Order by host storage" choices:"desc|asc"`
  46. OrderByStorageCommitRate string `help:"Order by host storage commite rate" choices:"desc|asc"`
  47. OrderByCpuCommitRate string `help:"Order by host cpu commit rate" choices:"desc|asc"`
  48. OrderByMemCommitRate string `help:"Order by host meme commit rate" choices:"desc|asc"`
  49. OrderByStorageUsed string `help:"Order by storage used" choices:"desc|asc"`
  50. OrderByCpuCommit string `help:"Order by cpu commit" choices:"desc|asc"`
  51. OrderByMemCommit string `help:"Order by mem commit" choices:"desc|asc"`
  52. OrderByCpuUsage string `help:"Order by cpu usage" choices:"desc|asc"`
  53. OrderByMemUsage string `help:"Order by mem usage" choices:"desc|asc"`
  54. OrderByStorageUsage string `help:"Order by storage usage" choices:"desc|asc"`
  55. OrderByVirtualMemUsage string `help:"Order by virtual mem usage" choices:"desc|asc"`
  56. OrderByVirtualCpuUsage string `help:"Order by virtual cpu usage" choices:"desc|asc"`
  57. OrderByVirtualStorageUsage string `help:"Order by virtual storage usage" choices:"desc|asc"`
  58. HideCpuTopoInfo *bool `help:"Host list will remove cpu_info and topology info from sysinfo and metadata"`
  59. AccessIp []string `help:"Access ip address"`
  60. IpmiIp []string `help:"Ipmi ip address"`
  61. PublicIp []string `help:"Public ip address"`
  62. options.BaseListOptions
  63. }
  64. func (opts *HostListOptions) Params() (jsonutils.JSONObject, error) {
  65. params, err := options.ListStructToParams(opts)
  66. if err != nil {
  67. return nil, err
  68. }
  69. if opts.Empty {
  70. params.Add(jsonutils.JSONTrue, "is_empty")
  71. } else if opts.Occupied {
  72. params.Add(jsonutils.JSONFalse, "is_empty")
  73. }
  74. if opts.Enabled {
  75. params.Add(jsonutils.NewInt(1), "enabled")
  76. } else if opts.Disabled {
  77. params.Add(jsonutils.NewInt(0), "enabled")
  78. }
  79. if len(opts.Uuid) > 0 {
  80. params.Add(jsonutils.NewString(opts.Uuid), "uuid")
  81. }
  82. if len(opts.Sn) > 0 {
  83. params.Add(jsonutils.NewString(opts.Sn), "sn")
  84. }
  85. return params, nil
  86. }
  87. type HostShowOptions struct {
  88. options.BaseShowOptions
  89. ShowMetadata bool `help:"Show host metadata in details"`
  90. ShowNicInfo bool `help:"Show host nic_info in details"`
  91. ShowSysInfo bool `help:"Show host sys_info in details"`
  92. ShowAll bool `help:"Show all of host details" short-token:"a"`
  93. }
  94. func (o *HostShowOptions) Params() (jsonutils.JSONObject, error) {
  95. // NOTE: host show only request with base options
  96. return jsonutils.Marshal(o.BaseShowOptions), nil
  97. }
  98. type HostReserveCpusOptions struct {
  99. options.BaseIdsOptions
  100. Cpus string
  101. Mems string
  102. DisableSchedLoadBalance bool
  103. ProcessesPrefix []string `help:"Processes prefix bind reserved cpus"`
  104. }
  105. func (o *HostReserveCpusOptions) Params() (jsonutils.JSONObject, error) {
  106. return jsonutils.Marshal(o), nil
  107. }
  108. type HostAutoMigrateOnHostDownOptions struct {
  109. options.BaseIdsOptions
  110. AutoMigrateOnHostDown string `help:"Auto migrate on host down" choices:"enable|disable" default:"disable"`
  111. AutoMigrateOnHostShutdown string `help:"Auto migrate on host shutdown" choices:"enable|disable" default:"disable"`
  112. }
  113. func (o *HostAutoMigrateOnHostDownOptions) Params() (jsonutils.JSONObject, error) {
  114. return options.StructToParams(o)
  115. }
  116. type HostSetCommitBoundOptions struct {
  117. options.BaseIdsOptions
  118. CpuCmtbound *float32 `help:"Cpu commit bound"`
  119. MemCmtbound *float32 `help:"Mem commit bound"`
  120. }
  121. func (o *HostSetCommitBoundOptions) Params() (jsonutils.JSONObject, error) {
  122. return options.StructToParams(o)
  123. }
  124. type HostSetHostFilesOptions struct {
  125. options.BaseIdsOptions
  126. HostFiles []string `help:"Host files"`
  127. }
  128. func (o *HostSetHostFilesOptions) Params() (jsonutils.JSONObject, error) {
  129. return jsonutils.Marshal(o), nil
  130. }
  131. type HostStatusStatisticsOptions struct {
  132. HostListOptions
  133. options.StatusStatisticsOptions
  134. }
  135. type HostValidateIPMI struct {
  136. IP string `json:"ip" help:"IPMI ip address"`
  137. USERNAME string `json:"username" help:"IPMI username"`
  138. PASSWORD string `json:"password" help:"IPMI password"`
  139. }
  140. func (h HostValidateIPMI) Params() (jsonutils.JSONObject, error) {
  141. return jsonutils.Marshal(baremetal.ValidateIPMIRequest{
  142. Ip: h.IP,
  143. Username: h.USERNAME,
  144. Password: h.PASSWORD,
  145. }), nil
  146. }
  147. type HostIsolatedDeviceNumaStatsOptions struct {
  148. options.BaseIdOptions
  149. DevType string `json:"dev_type"`
  150. }
  151. func (o *HostIsolatedDeviceNumaStatsOptions) Params() (jsonutils.JSONObject, error) {
  152. return jsonutils.Marshal(o), nil
  153. }
  154. type HostUpdateOptions struct {
  155. options.BaseIdOptions
  156. Name string `help:"New name of the host"`
  157. Description *string `help:"New Description of the host"`
  158. MemReserved *string `help:"Memory reserved"`
  159. CpuReserved *int64 `help:"CPU reserved"`
  160. HostType *string `help:"Change host type, CAUTION!!!!" choices:"hypervisor|kubelet|esxi|baremetal"`
  161. CpuCount *int
  162. NodeCount *int8
  163. CpuDesc *string
  164. MemSize *int
  165. StorageSize *int64
  166. // AccessIp string `help:"Change access ip, CAUTION!!!!"`
  167. AccessMac *string `help:"Change baremetal access MAC, CAUTION!!!!"`
  168. Uuid *string `help:"Change baremetal UUID, CAUTION!!!!"`
  169. EnableNumaAllocate string `help:"Host enable numa allocate" choices:"True|False"`
  170. IpmiUsername *string `help:"IPMI user"`
  171. IpmiPassword *string `help:"IPMI password"`
  172. IpmiIpAddr *string `help:"IPMI ip_addr"`
  173. Sn *string `help:"serial number"`
  174. Hostname *string `help:"update host name"`
  175. PublicIp *string `help:"public_ip"`
  176. NoPublicIp *bool `help:"clear public ip"`
  177. }
  178. func (opts *HostUpdateOptions) Params() (jsonutils.JSONObject, error) {
  179. v := jsonutils.Marshal(opts).(*jsonutils.JSONDict)
  180. if opts.NoPublicIp != nil && *opts.NoPublicIp {
  181. v.Set("public_ip", jsonutils.NewString(""))
  182. v.Remove("no_public_ip")
  183. }
  184. if len(opts.EnableNumaAllocate) > 0 {
  185. enableNumaAllocate := false
  186. if opts.EnableNumaAllocate == "True" {
  187. enableNumaAllocate = true
  188. }
  189. v.Set("enable_numa_allocate", jsonutils.NewBool(enableNumaAllocate))
  190. }
  191. v.Remove("id")
  192. return v, nil
  193. }