servers.go 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719
  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. "io/ioutil"
  18. "strconv"
  19. "strings"
  20. "yunion.io/x/jsonutils"
  21. "yunion.io/x/pkg/errors"
  22. "yunion.io/x/pkg/util/fileutils"
  23. "yunion.io/x/pkg/util/regutils"
  24. billing_api "yunion.io/x/onecloud/pkg/apis/billing"
  25. "yunion.io/x/onecloud/pkg/apis/cloudcommon/db"
  26. computeapi "yunion.io/x/onecloud/pkg/apis/compute"
  27. schedapi "yunion.io/x/onecloud/pkg/apis/scheduler"
  28. "yunion.io/x/onecloud/pkg/cloudcommon/cmdline"
  29. "yunion.io/x/onecloud/pkg/mcclient/options"
  30. "yunion.io/x/onecloud/pkg/util/cgrouputils/cpuset"
  31. "yunion.io/x/onecloud/pkg/util/fileutils2"
  32. )
  33. var ErrEmtptyUpdate = errors.Error("No valid update data")
  34. type ServerListOptions struct {
  35. Zone string `help:"Zone ID or Name"`
  36. Wire string `help:"Wire ID or Name"`
  37. Network string `help:"Network ID or Name"`
  38. Disk string `help:"Disk ID or Name"`
  39. Host string `help:"Host ID or Name"`
  40. Baremetal *bool `help:"Show baremetal servers"`
  41. Gpu *bool `help:"Show gpu servers"`
  42. Secgroup string `help:"Secgroup ID or Name"`
  43. AdminSecgroup string `help:"AdminSecgroup ID or Name"`
  44. Hypervisor string `help:"Show server of hypervisor" choices:"kvm|esxi|pod|baremetal|aliyun|azure|aws|huawei|ucloud|volcengine|zstack|openstack|google|ctyun|incloudsphere|nutanix|bingocloud|cloudpods|ecloud|jdcloud|remotefile|h3c|hcs|hcso|hcsop|proxmox|ksyun|baidu|cucloud|qingcloud|sangfor|zettakit|uis|cnware"`
  45. Region string `help:"Show servers in cloudregion"`
  46. WithEip *bool `help:"Show Servers with EIP"`
  47. WithoutEip *bool `help:"Show Servers without EIP"`
  48. OsType string `help:"OS Type" choices:"linux|windows|vmware"`
  49. Vpc []string `help:"Vpc id or name"`
  50. UsableServerForEip string `help:"Eip id or name"`
  51. WithoutUserMeta *bool `help:"Show Servers without user metadata"`
  52. EipAssociable *bool `help:"Show Servers can associate with eip"`
  53. HostSn string `help:"Host SN"`
  54. IpAddr string `help:"Fileter by ip"`
  55. IpAddrs []string `help:"Fileter by ips"`
  56. OrderByDisk string `help:"Order by disk size" choices:"asc|desc"`
  57. OrderByOsDist string `help:"Order by os distribution" choices:"asc|desc"`
  58. OrderByHost string `help:"Order by host name" choices:"asc|desc"`
  59. OrderByNetwork string `help:"Order by network name" choices:"asc|desc"`
  60. OrderByIp string `help:"Order by ip" choices:"asc|desc"`
  61. ResourceType string `help:"Resource type" choices:"shared|prepaid|dedicated"`
  62. BillingType string `help:"billing type" choices:"postpaid|prepaid"`
  63. ScalingGroup string `help:"ScalingGroup's id or name'"`
  64. options.BaseListOptions
  65. options.MultiArchListOptions
  66. VpcProvider string `help:"filter by vpc's provider" json:"vpc_provider"`
  67. WithMeta *bool `help:"filter by metadata" negative:"without_meta"`
  68. WithUserMeta *bool `help:"filter by user metadata" negative:"without_user_meta"`
  69. WithHost *bool `help:"filter guest with host or not" negative:"without_host"`
  70. SnapshotpolicyId string `help:"filter guest with snapshotpolicy or not" json:"snapshotpolicy_id"`
  71. BindingDisksSnapshotpolicy *bool `help:"filter guest with disks binding snapshotpolicy or not" negative:"no-binding-disks-snapshotpolicy" json:"binding_disks_snapshotpolicy"`
  72. BindingSnapshotpolicy *bool `help:"filter guest with binding snapshotpolicy or not" negative:"no-binding-snapshotpolicy" json:"binding_snapshotpolicy"`
  73. }
  74. func (o *ServerListOptions) Params() (jsonutils.JSONObject, error) {
  75. return options.ListStructToParams(o)
  76. }
  77. type ServerIdOptions struct {
  78. ID string `help:"ID or name of the server" json:"-"`
  79. }
  80. func (o *ServerIdOptions) GetId() string {
  81. return o.ID
  82. }
  83. func (o *ServerIdOptions) Params() (jsonutils.JSONObject, error) {
  84. return nil, nil
  85. }
  86. type ServerLoginInfoOptions struct {
  87. ID string `help:"ID or name of the server" json:"-"`
  88. Key string `help:"File name of private key, if password is encrypted by key"`
  89. }
  90. type ServerSSHLoginOptions struct {
  91. ServerLoginInfoOptions
  92. Host string `help:"IP address or hostname of the server"`
  93. Port int `help:"SSH service port" default:"22"`
  94. User string `help:"SSH login user"`
  95. Password string `help:"SSH password"`
  96. UseCloudroot bool `help:"SSH login with cloudroot"`
  97. }
  98. type ServerConvertToKvmOptions struct {
  99. ServerIdsOptions
  100. PreferHost string `help:"Perfer host id or name" json:"prefer_host"`
  101. }
  102. func (o *ServerConvertToKvmOptions) Params() (jsonutils.JSONObject, error) {
  103. return options.StructToParams(o)
  104. }
  105. type ServerStartOptions struct {
  106. ServerIdsOptions
  107. QemuVersion string `help:"prefer qemu version" json:"qemu_version"`
  108. AutoPrepaid *bool `help:"Auto convert postpaid to prepaid"`
  109. }
  110. func (o *ServerStartOptions) Params() (jsonutils.JSONObject, error) {
  111. return jsonutils.Marshal(o), nil
  112. }
  113. type ServerIdsOptions struct {
  114. ID []string `help:"ID of servers to operate" metavar:"SERVER" json:"-"`
  115. }
  116. func (o *ServerIdsOptions) GetIds() []string {
  117. return o.ID
  118. }
  119. func (o *ServerIdsOptions) Params() (jsonutils.JSONObject, error) {
  120. return nil, nil
  121. }
  122. type ServerDeleteBackupOptions struct {
  123. ID string `help:"ID of the server" json:"-"`
  124. Purge *bool `help:"Purge Guest Backup" json:"purge"`
  125. }
  126. func (o *ServerDeleteBackupOptions) GetId() string {
  127. return o.ID
  128. }
  129. func (o *ServerDeleteBackupOptions) Params() (jsonutils.JSONObject, error) {
  130. return options.StructToParams(o)
  131. }
  132. type ServerSwitchToBackupOptions struct {
  133. ID string `help:"ID of the server" json:"-"`
  134. AutoStart bool `help:"Start guest after switch to backup" json:"auto_start"`
  135. }
  136. func (o *ServerSwitchToBackupOptions) GetId() string {
  137. return o.ID
  138. }
  139. func (o *ServerSwitchToBackupOptions) Params() (jsonutils.JSONObject, error) {
  140. return options.StructToParams(o)
  141. }
  142. func (o *ServerSwitchToBackupOptions) Description() string {
  143. return "Switch geust master to backup host"
  144. }
  145. type ServerCreateBackupOptions struct {
  146. ID string `help:"ID of the server" json:"-"`
  147. AutoStart bool `help:"Start guest after create backup guest" json:"auto_start"`
  148. }
  149. func (o *ServerCreateBackupOptions) GetId() string {
  150. return o.ID
  151. }
  152. func (o *ServerCreateBackupOptions) Params() (jsonutils.JSONObject, error) {
  153. return options.StructToParams(o)
  154. }
  155. type ServerShowOptions struct {
  156. options.BaseShowOptions `id->help:"ID or name of the server"`
  157. }
  158. func (o *ServerShowOptions) Params() (jsonutils.JSONObject, error) {
  159. return options.StructToParams(o)
  160. }
  161. func (o *ServerShowOptions) GetId() string {
  162. return o.ID
  163. }
  164. type ServerChangeOwnerCandidateDomainsOptions struct {
  165. ServerShowOptions
  166. }
  167. func (o *ServerChangeOwnerCandidateDomainsOptions) Description() string {
  168. return "Get change owner candidate domain list"
  169. }
  170. func ParseServerDeployInfo(info string) (*computeapi.DeployConfig, error) {
  171. sdi := &computeapi.DeployConfig{}
  172. colon := strings.IndexByte(info, ':')
  173. if colon <= 0 {
  174. return nil, fmt.Errorf("malformed deploy info: %s", info)
  175. }
  176. if info[0] == '+' {
  177. sdi.Action = "append"
  178. sdi.Path = info[1:colon]
  179. } else {
  180. sdi.Action = "create"
  181. sdi.Path = info[:colon]
  182. }
  183. nameOrContent := info[colon+1:]
  184. data, err := ioutil.ReadFile(nameOrContent)
  185. if err != nil {
  186. sdi.Content = nameOrContent
  187. } else {
  188. sdi.Content = string(data)
  189. }
  190. return sdi, nil
  191. }
  192. func ParseServerDeployInfoList(list []string) ([]*computeapi.DeployConfig, error) {
  193. ret := make([]*computeapi.DeployConfig, 0)
  194. for _, info := range list {
  195. deployInfo, err := ParseServerDeployInfo(info)
  196. if err != nil {
  197. return nil, err
  198. }
  199. ret = append(ret, deployInfo)
  200. }
  201. return ret, nil
  202. }
  203. type ServerCreateCommonConfig struct {
  204. Manager string `help:"Preferred cloudprovider where virtual server should bd created" json:"prefer_manager"`
  205. Region string `help:"Preferred region where virtual server should be created" json:"prefer_region"`
  206. Zone string `help:"Preferred zone where virtual server should be created" json:"prefer_zone"`
  207. Wire string `help:"Preferred wire where virtual server should be created" json:"prefer_wire"`
  208. Host string `help:"Preferred host where virtual server should be created" json:"prefer_host"`
  209. ResourceType string `help:"Resource type" choices:"shared|prepaid|dedicated"`
  210. Schedtag []string `help:"Schedule policy, key = aggregate name, value = require|exclude|prefer|avoid" metavar:"<KEY:VALUE>"`
  211. Net []string `help:"Network descriptions" metavar:"NETWORK"`
  212. NetPortMapping []string `help:"Network port mapping, e.g. 'index=0,port=80,host_port=8080,protocol=<tcp|udp>,host_port_range=<int>-<int>,remote_ips=x.x.x.x|y.y.y.y'" short-token:"p"`
  213. NetSchedtag []string `help:"Network schedtag description, e.g. '0:<tag>:<strategy>'"`
  214. IsolatedDevice []string `help:"Isolated device model or ID" metavar:"ISOLATED_DEVICE"`
  215. Project string `help:"'Owner project ID or Name" json:"tenant"`
  216. User string `help:"Owner user ID or Name"`
  217. Count int `help:"Create multiple simultaneously" default:"1"`
  218. Disk []string `help:"
  219. Disk descriptions
  220. size: 500M, 10G
  221. auto_delete: true, false
  222. fs: swap, ext2, ext3, ext4, xfs, ntfs, fat, hfsplus
  223. fs_features: casefold
  224. format: qcow2, raw, docker, iso, vmdk, vmdkflatver1, vmdkflatver2, vmdkflat, vmdksparse, vmdksparsever1, vmdksparsever2, vmdksesparse, vhd
  225. driver: virtio, ide, scsi, sata, pvscsi
  226. cache_mod: writeback, none, writethrough
  227. medium: rotate, ssd, hybrid
  228. disk_type: sys, data
  229. mountpoint: /, /opt
  230. storage_type: local, rbd, nas, nfs
  231. snapshot_id: use snapshot-list get snapshot id
  232. disk_id: use disk-list get disk id
  233. storage_id: use storage-list get storage id
  234. image_id: use image-list get image id
  235. for example:
  236. --disk 'image_id=c2be02a4-7ff2-43e6-8a00-a489e04d2d6f,size=10G,driver=ide,storage_type=rbd,auto_delete=true'
  237. --disk 'size=500M'
  238. --disk 'snpahost_id=1ceb8c6d-6571-451d-8957-4bd3a871af85'
  239. " nargs:"+"`
  240. DiskSchedtag []string `help:"Disk schedtag description, e.g. '0:<tag>:<strategy>'"`
  241. }
  242. func (o ServerCreateCommonConfig) Data() (*computeapi.ServerConfigs, error) {
  243. data := &computeapi.ServerConfigs{
  244. PreferManager: o.Manager,
  245. PreferRegion: o.Region,
  246. PreferZone: o.Zone,
  247. PreferWire: o.Wire,
  248. PreferHost: o.Host,
  249. ResourceType: o.ResourceType,
  250. Count: o.Count,
  251. Networks: make([]*computeapi.NetworkConfig, 0),
  252. Disks: make([]*computeapi.DiskConfig, 0),
  253. }
  254. for i, n := range o.Net {
  255. net, err := cmdline.ParseNetworkConfig(n, i)
  256. if err != nil {
  257. return nil, err
  258. }
  259. data.Networks = append(data.Networks, net)
  260. }
  261. if len(o.NetPortMapping) != 0 {
  262. pms, err := cmdline.ParseNetworkConfigPortMappings(o.NetPortMapping)
  263. if err != nil {
  264. return nil, errors.Wrap(err, "parse network port mapping")
  265. }
  266. for idx, _ := range pms {
  267. if idx >= len(data.Networks) {
  268. return nil, errors.Errorf("not found %d network of index", idx)
  269. }
  270. pm := pms[idx]
  271. data.Networks[idx].PortMappings = pm
  272. }
  273. }
  274. for _, ntag := range o.NetSchedtag {
  275. idx, tag, err := cmdline.ParseResourceSchedtagConfig(ntag)
  276. if err != nil {
  277. return nil, fmt.Errorf("ParseDiskSchedtag: %v", err)
  278. }
  279. if idx >= len(data.Networks) {
  280. return nil, fmt.Errorf("Invalid network index: %d", idx)
  281. }
  282. n := data.Networks[idx]
  283. n.Schedtags = append(n.Schedtags, tag)
  284. }
  285. for i, g := range o.IsolatedDevice {
  286. dev, err := cmdline.ParseIsolatedDevice(g, i)
  287. if err != nil {
  288. return nil, err
  289. }
  290. data.IsolatedDevices = append(data.IsolatedDevices, dev)
  291. }
  292. for _, tag := range o.Schedtag {
  293. schedtag, err := cmdline.ParseSchedtagConfig(tag)
  294. if err != nil {
  295. return nil, err
  296. }
  297. data.Schedtags = append(data.Schedtags, schedtag)
  298. }
  299. for i, d := range o.Disk {
  300. disk, err := cmdline.ParseDiskConfig(d, i)
  301. if err != nil {
  302. return nil, err
  303. }
  304. data.Disks = append(data.Disks, disk)
  305. }
  306. for _, dtag := range o.DiskSchedtag {
  307. idx, tag, err := cmdline.ParseResourceSchedtagConfig(dtag)
  308. if err != nil {
  309. return nil, fmt.Errorf("ParseDiskSchedtag: %v", err)
  310. }
  311. if idx >= len(data.Disks) {
  312. return nil, fmt.Errorf("Invalid disk index: %d", idx)
  313. }
  314. d := data.Disks[idx]
  315. d.Schedtags = append(d.Schedtags, tag)
  316. }
  317. return data, nil
  318. }
  319. type ServerConfigs struct {
  320. ServerCreateCommonConfig
  321. Hypervisor string `help:"Hypervisor type" choices:"kvm|pod|esxi|baremetal|container|aliyun|azure|qcloud|aws|huawei|openstack|ucloud|volcengine|zstack|google|ctyun|incloudsphere|bingocloud|cloudpods|ecloud|jdcloud|remotefile|h3c|hcs|hcso|hcsop|proxmox|sangfor|zettakit|uis"`
  322. Backup bool `help:"Create server with backup server"`
  323. BackupHost string `help:"Perfered host where virtual backup server should be created"`
  324. AutoSwitchToBackupOnHostDown bool `help:"Auto switch to backup server on host down"`
  325. Daemon *bool `help:"Set as a daemon server" json:"is_daemon"`
  326. RaidConfig []string `help:"Baremetal raid config" json:"-"`
  327. RootDiskMatcher string `help:"Baremetal root disk matcher, e.g. 'device=/dev/sdb' 'size=900G' 'size_start=800G,size_end=900G'" json:"-"`
  328. }
  329. func (o ServerConfigs) Data() (*computeapi.ServerConfigs, error) {
  330. data, err := o.ServerCreateCommonConfig.Data()
  331. if err != nil {
  332. return nil, err
  333. }
  334. data.Backup = o.Backup
  335. data.PreferBackupHost = o.BackupHost
  336. data.IsDaemon = o.Daemon
  337. data.Hypervisor = o.Hypervisor
  338. if len(o.RaidConfig) > 0 {
  339. // if data.Hypervisor != "baremetal" {
  340. // return nil, fmt.Errorf("RaidConfig is applicable to baremetal ONLY")
  341. // }
  342. for _, conf := range o.RaidConfig {
  343. raidConf, err := cmdline.ParseBaremetalDiskConfig(conf)
  344. if err != nil {
  345. return nil, err
  346. }
  347. data.BaremetalDiskConfigs = append(data.BaremetalDiskConfigs, raidConf)
  348. }
  349. }
  350. if len(o.RootDiskMatcher) > 0 {
  351. matcher, err := cmdline.ParseBaremetalRootDiskMatcher(o.RootDiskMatcher)
  352. if err != nil {
  353. return nil, err
  354. }
  355. data.BaremetalRootDiskMatcher = matcher
  356. }
  357. return data, nil
  358. }
  359. type ServerCloneOptions struct {
  360. SOURCE string `help:"Source server id or name" json:"-"`
  361. TARGET_NAME string `help:"Name of newly server" json:"name"`
  362. AutoStart bool `help:"Auto start server after it is created"`
  363. EipBw int `help:"allocate EIP with bandwidth in MB when server is created" json:"eip_bw,omitzero"`
  364. EipChargeType string `help:"newly allocated EIP charge type" choices:"traffic|bandwidth" json:"eip_charge_type,omitempty"`
  365. Eip string `help:"associate with an existing EIP when server is created" json:"eip,omitempty"`
  366. }
  367. func (o *ServerCloneOptions) GetId() string {
  368. return o.SOURCE
  369. }
  370. func (o *ServerCloneOptions) Params() (jsonutils.JSONObject, error) {
  371. return jsonutils.Marshal(o), nil
  372. }
  373. func (o *ServerCloneOptions) Description() string {
  374. return "Clone a server"
  375. }
  376. type ServerCreateFromInstanceSnapshot struct {
  377. InstaceSnapshotId string `help:"Instace snapshot id or name"`
  378. NAME string `help:"Name of newly server" json:"name"`
  379. AutoStart bool `help:"Auto start server after it is created"`
  380. AllowDelete bool `help:"Unlock server to allow deleting"`
  381. EipBw int `help:"allocate EIP with bandwidth in MB when server is created" json:"eip_bw,omitzero"`
  382. EipChargeType string `help:"newly allocated EIP charge type" choices:"traffic|bandwidth" json:"eip_charge_type,omitempty"`
  383. Eip string `help:"associate with an existing EIP when server is created" json:"eip,omitempty"`
  384. }
  385. type ServerCreateOptions struct {
  386. ServerCreateOptionalOptions
  387. NAME string `help:"Name of server" json:"-"`
  388. }
  389. type ServerCreateOptionalOptions struct {
  390. ServerConfigs
  391. MemSpec string `help:"Memory size Or Instance Type" metavar:"MEMSPEC" json:"-"`
  392. CpuSockets int `help:"Cpu sockets"`
  393. EnableMemclean bool `help:"clean guest memory after guest exit" json:"enable_memclean"`
  394. EnableTpm bool `help:"enable tpm device" json:"enable_tpm"`
  395. Keypair string `help:"SSH Keypair"`
  396. Password string `help:"Default user password"`
  397. LoginAccount string `help:"Guest login account"`
  398. Iso string `help:"ISO image ID" metavar:"IMAGE_ID" json:"cdrom"`
  399. IsoBootIndex *int8 `help:"Iso bootindex" metavar:"IMAGE_BOOT_INDEX" json:"cdrom_boot_index"`
  400. VcpuCount int `help:"#CPU cores of VM server, default 1" default:"1" metavar:"<SERVER_CPU_COUNT>" json:"vcpu_count" token:"ncpu"`
  401. ExtraCpuCount int `help:"Extra allocate cpu count" json:"extra_cpu_count"`
  402. InstanceType string `help:"instance flavor"`
  403. Vga string `help:"VGA driver" choices:"std|vmware|cirrus|qxl|virtio"`
  404. Vdi string `help:"VDI protocool" choices:"vnc|spice"`
  405. Bios string `help:"BIOS" choices:"BIOS|UEFI"`
  406. Machine string `help:"Machine type" choices:"pc|q35"`
  407. Desc string `help:"Description" metavar:"<DESCRIPTION>" json:"description"`
  408. Boot string `help:"Boot device" metavar:"<BOOT_DEVICE>" choices:"disk|cdrom" json:"-"`
  409. EnableCloudInit bool `help:"Enable cloud-init service"`
  410. NoAccountInit *bool `help:"Not reset account password"`
  411. AllowDelete *bool `help:"Unlock server to allow deleting" json:"-"`
  412. ShutdownBehavior string `help:"Behavior after VM server shutdown" metavar:"<SHUTDOWN_BEHAVIOR>" choices:"stop|terminate|stop_release_gpu"`
  413. AutoStart bool `help:"Auto start server after it is created"`
  414. Deploy []string `help:"Specify deploy files in virtual server file system" json:"-"`
  415. DeployTelegraf bool `help:"Deploy telegraf agent if guest os is supported"`
  416. Group []string `help:"Group ID or Name of virtual server"`
  417. System bool `help:"Create a system VM, sysadmin ONLY option" json:"is_system"`
  418. TaskNotify *bool `help:"Setup task notify" json:"-"`
  419. FakeCreate *bool `help:"Fake create server"`
  420. DryRun *bool `help:"Dry run to test scheduler" json:"-"`
  421. UserDataFile string `help:"user_data file path" json:"-"`
  422. InstanceSnapshot string `help:"instance snapshot" json:"instance_snapshot"`
  423. Secgroups []string `help:"secgroups" json:"secgroups"`
  424. OsType string `help:"os type, e.g. Linux, Windows, etc."`
  425. Duration string `help:"valid duration of the server, e.g. 1H, 1D, 1W, 1M, 1Y, ADMIN ONLY option"`
  426. AutoRenew bool `help:"auto renew for prepaid server"`
  427. AutoPrepaidRecycle bool `help:"automatically enable prepaid recycling after server is created successfully" json:"auto_prepaid_recycle,omitfalse"`
  428. // Kickstart related options
  429. KickstartOSType string `help:"Kickstart OS type" choices:"centos|rhel|fedora|openeuler|ubuntu" json:"-"`
  430. KickstartConfigFile string `help:"Kickstart configuration content file" json:"-"`
  431. KickstartConfigURL string `help:"Kickstart configuration URL" json:"-"`
  432. KickstartEnabled *bool `help:"Enable kickstart" json:"-"`
  433. KickstartMaxRetries int `help:"Kickstart max retries" default:"3" json:"-"`
  434. KickstartTimeoutMinutes int `help:"Kickstart timeout in minutes" default:"60" json:"-"`
  435. GenerateName bool `help:"name is generated by pattern" json:"-"`
  436. EipBw int `help:"allocate EIP with bandwidth in MB when server is created" json:"eip_bw,omitzero"`
  437. EipBgpType string `help:"desired BGP type of newly alloated EIP" json:"eip_bgp_type,omitzero"`
  438. EipChargeType string `help:"newly allocated EIP charge type" choices:"traffic|bandwidth" json:"eip_charge_type,omitempty"`
  439. Eip string `help:"associate with an existing EIP when server is created" json:"eip,omitempty"`
  440. PublicIpBw int `help:"associate public ip with bandwidth in MB where server is created" json:"public_ip_bw,omitzero"`
  441. PublicIpChargeType string `help:"newly allocated public ip charge type" choices:"traffic|bandwidth" json:"public_ip_charge_type,omitempty"`
  442. GuestImageID string `help:"create from guest image, need to specify the guest image id"`
  443. EncryptKey string `help:"encryption key"`
  444. Tags []string `help:"tags in the form of key=value"`
  445. }
  446. func (o *ServerCreateOptions) ToScheduleInput() (*schedapi.ScheduleInput, error) {
  447. // so serious error
  448. data := new(schedapi.ServerConfig)
  449. data.ServerConfigs = computeapi.NewServerConfigs()
  450. // only support digit number as for now
  451. memSize, err := strconv.Atoi(o.MemSpec)
  452. if err != nil {
  453. return nil, err
  454. }
  455. data.Memory = memSize
  456. if o.VcpuCount > 0 {
  457. data.Ncpu = o.VcpuCount
  458. }
  459. for i, d := range o.Disk {
  460. disk, err := cmdline.ParseDiskConfig(d, i)
  461. if err != nil {
  462. return nil, err
  463. }
  464. data.Disks = append(data.Disks, disk)
  465. }
  466. for i, n := range o.Net {
  467. net, err := cmdline.ParseNetworkConfig(n, i)
  468. if err != nil {
  469. return nil, err
  470. }
  471. data.Networks = append(data.Networks, net)
  472. }
  473. for i, g := range o.IsolatedDevice {
  474. dev, err := cmdline.ParseIsolatedDevice(g, i)
  475. if err != nil {
  476. return nil, err
  477. }
  478. data.IsolatedDevices = append(data.IsolatedDevices, dev)
  479. }
  480. count := 1
  481. if o.Count > 1 {
  482. count = o.Count
  483. }
  484. input := new(schedapi.ScheduleInput)
  485. data.Count = count
  486. data.InstanceGroupIds = o.Group
  487. input.ServerConfig = *data
  488. if o.DryRun != nil && *o.DryRun {
  489. input.Details = true
  490. }
  491. return input, nil
  492. }
  493. func (opts *ServerCreateOptionalOptions) OptionalParams() (*computeapi.ServerCreateInput, error) {
  494. config, err := opts.ServerConfigs.Data()
  495. if err != nil {
  496. return nil, err
  497. }
  498. params := &computeapi.ServerCreateInput{
  499. ServerConfigs: config,
  500. VcpuCount: opts.VcpuCount,
  501. KeypairId: opts.Keypair,
  502. Password: opts.Password,
  503. LoginAccount: opts.LoginAccount,
  504. Cdrom: opts.Iso,
  505. CdromBootIndex: opts.IsoBootIndex,
  506. Vga: opts.Vga,
  507. Vdi: opts.Vdi,
  508. Bios: opts.Bios,
  509. Machine: opts.Machine,
  510. ShutdownBehavior: opts.ShutdownBehavior,
  511. AutoStart: opts.AutoStart,
  512. Duration: opts.Duration,
  513. AutoRenew: opts.AutoRenew,
  514. AutoPrepaidRecycle: opts.AutoPrepaidRecycle,
  515. EipBw: opts.EipBw,
  516. EipBgpType: opts.EipBgpType,
  517. EipChargeType: billing_api.TNetChargeType(opts.EipChargeType),
  518. PublicIpBw: opts.PublicIpBw,
  519. PublicIpChargeType: billing_api.TNetChargeType(opts.PublicIpChargeType),
  520. Eip: opts.Eip,
  521. EnableCloudInit: opts.EnableCloudInit,
  522. OsType: opts.OsType,
  523. GuestImageID: opts.GuestImageID,
  524. Secgroups: opts.Secgroups,
  525. EnableMemclean: opts.EnableMemclean,
  526. EnableTpm: opts.EnableTpm,
  527. }
  528. params.ProjectId = opts.Project
  529. if opts.FakeCreate != nil {
  530. params.FakeCreate = *opts.FakeCreate
  531. }
  532. if len(opts.EncryptKey) > 0 {
  533. params.EncryptKeyId = &opts.EncryptKey
  534. }
  535. if regutils.MatchSize(opts.MemSpec) {
  536. memSize, err := fileutils.GetSizeMb(opts.MemSpec, 'M', 1024)
  537. if err != nil {
  538. return nil, err
  539. }
  540. params.VmemSize = memSize
  541. } else {
  542. params.InstanceType = opts.InstanceType
  543. }
  544. deployInfos, err := ParseServerDeployInfoList(opts.Deploy)
  545. if err != nil {
  546. return nil, err
  547. }
  548. params.DeployConfigs = deployInfos
  549. params.DeployTelegraf = opts.DeployTelegraf
  550. if len(opts.Boot) > 0 {
  551. if opts.Boot == "disk" {
  552. params.BootOrder = "cdn"
  553. } else {
  554. params.BootOrder = "dcn"
  555. }
  556. }
  557. resetPasswd := false
  558. if opts.NoAccountInit != nil && *opts.NoAccountInit {
  559. params.ResetPassword = &resetPasswd
  560. } else {
  561. params.ResetPassword = nil
  562. }
  563. if len(opts.UserDataFile) > 0 {
  564. userdata, err := ioutil.ReadFile(opts.UserDataFile)
  565. if err != nil {
  566. return nil, err
  567. }
  568. params.UserData = string(userdata)
  569. }
  570. if options.BoolV(opts.AllowDelete) {
  571. disableDelete := false
  572. params.DisableDelete = &disableDelete
  573. }
  574. if options.BoolV(opts.DryRun) {
  575. params.Suggestion = true
  576. }
  577. // group
  578. params.InstanceGroupIds = opts.Group
  579. // set description
  580. params.Description = opts.Desc
  581. params.IsSystem = &opts.System
  582. // if kickstart os type is specified, then kickstart is enabled
  583. if len(opts.KickstartOSType) > 0 {
  584. if opts.KickstartConfigFile == "" && opts.KickstartConfigURL == "" {
  585. return nil, fmt.Errorf("either --kickstart-config or --kickstart-config-url must be provided when --kickstart-os-type is specified")
  586. }
  587. if opts.KickstartConfigFile != "" && opts.KickstartConfigURL != "" {
  588. return nil, fmt.Errorf("--kickstart-config and --kickstart-config-url cannot be both provided, choose one")
  589. }
  590. kickstartConfig := &computeapi.KickstartConfig{
  591. OSType: opts.KickstartOSType,
  592. }
  593. if opts.KickstartConfigFile != "" {
  594. ksconf, err := fileutils2.FileGetContents(opts.KickstartConfigFile)
  595. if err != nil {
  596. return nil, errors.Wrapf(err, "FileGetContents %s", opts.KickstartConfigFile)
  597. }
  598. kickstartConfig.Config = ksconf
  599. }
  600. if opts.KickstartConfigURL != "" {
  601. kickstartConfig.ConfigURL = opts.KickstartConfigURL
  602. }
  603. // setting default value
  604. if opts.KickstartEnabled != nil {
  605. kickstartConfig.Enabled = opts.KickstartEnabled
  606. } else {
  607. enabled := true
  608. kickstartConfig.Enabled = &enabled
  609. }
  610. if opts.KickstartMaxRetries > 0 {
  611. kickstartConfig.MaxRetries = opts.KickstartMaxRetries
  612. } else {
  613. kickstartConfig.MaxRetries = 3
  614. }
  615. if opts.KickstartTimeoutMinutes > 0 {
  616. kickstartConfig.TimeoutMinutes = opts.KickstartTimeoutMinutes
  617. } else {
  618. kickstartConfig.TimeoutMinutes = 60
  619. }
  620. params.KickstartConfig = kickstartConfig
  621. }
  622. return params, nil
  623. }
  624. func (opts *ServerCreateOptions) Params() (*computeapi.ServerCreateInput, error) {
  625. params, err := opts.OptionalParams()
  626. if err != nil {
  627. return nil, err
  628. }
  629. meta := map[string]string{}
  630. for _, v := range opts.Tags {
  631. tag := strings.Split(v, "=")
  632. if len(tag) != 2 {
  633. return nil, fmt.Errorf("invalid tag %s", v)
  634. }
  635. prefix := db.USER_TAG_PREFIX
  636. k, v := prefix+strings.TrimPrefix(tag[0], prefix), tag[1]
  637. meta[k] = v
  638. }
  639. params.Metadata = meta
  640. if opts.GenerateName {
  641. params.GenerateName = opts.NAME
  642. } else {
  643. params.Name = opts.NAME
  644. }
  645. return params, nil
  646. }
  647. type ServerStopOptions struct {
  648. ID []string `help:"ID or Name of server" json:"-"`
  649. Force *bool `help:"Stop server forcefully" json:"is_force"`
  650. StopCharging *bool `help:"Stop charging when server stop"`
  651. }
  652. func (o *ServerStopOptions) GetIds() []string {
  653. return o.ID
  654. }
  655. func (o *ServerStopOptions) Params() (jsonutils.JSONObject, error) {
  656. return options.StructToParams(o)
  657. }
  658. type ServerUpdateOptions struct {
  659. ServerIdsOptions
  660. Name string `help:"New name to change"`
  661. Vmem string `help:"Memory size" json:"vmem_size"`
  662. Ncpu *int `help:"CPU count" json:"vcpu_count"`
  663. Vga string `help:"VGA driver" choices:"std|vmware|cirrus|qxl|virtio"`
  664. Vdi string `help:"VDI protocol" choices:"vnc|spice"`
  665. Bios string `help:"BIOS" choices:"BIOS|UEFI"`
  666. Desc string `help:"Description" json:"description"`
  667. Boot string `help:"Boot device" choices:"disk|cdrom"`
  668. Delete string `help:"Lock server to prevent from deleting" choices:"enable|disable" json:"-"`
  669. ShutdownBehavior string `help:"Behavior after VM server shutdown" choices:"stop|terminate|stop_release_gpu"`
  670. Machine string `help:"Machine type" choices:"q35|pc"`
  671. IsDaemon *bool `help:"Daemon server" negative:"no-daemon"`
  672. PendingDeletedAt string `help:"change pending deleted time"`
  673. Hostname string `help:"host name of server"`
  674. }
  675. func (opts *ServerUpdateOptions) Params() (jsonutils.JSONObject, error) {
  676. params, err := options.StructToParams(opts)
  677. if err != nil {
  678. return nil, err
  679. }
  680. if len(opts.Boot) > 0 {
  681. if opts.Boot == "disk" {
  682. params.Set("boot_order", jsonutils.NewString("cdn"))
  683. } else {
  684. params.Set("boot_order", jsonutils.NewString("dcn"))
  685. }
  686. }
  687. if len(opts.Delete) > 0 {
  688. if opts.Delete == "disable" {
  689. params.Set("disable_delete", jsonutils.JSONTrue)
  690. } else {
  691. params.Set("disable_delete", jsonutils.JSONFalse)
  692. }
  693. }
  694. if params.Size() == 0 {
  695. return nil, ErrEmtptyUpdate
  696. }
  697. return params, nil
  698. }
  699. type ServerDeleteOptions struct {
  700. ServerIdsOptions
  701. OverridePendingDelete *bool `help:"Delete server directly instead of pending delete" short-token:"f"`
  702. DeleteSnapshots *bool `help:"Delete server snapshots"`
  703. DeleteDisks *bool `help:"Delete server disks"`
  704. DeleteEip *bool `help:"Delete eip"`
  705. DeleteBastionServer *bool `help:"Remove from bastion host"`
  706. }
  707. func (o *ServerDeleteOptions) QueryParams() (jsonutils.JSONObject, error) {
  708. return options.StructToParams(o)
  709. }
  710. type ServerCancelDeleteOptions struct {
  711. ServerIdsOptions
  712. }
  713. func (o *ServerCancelDeleteOptions) Description() string {
  714. return "Cancel pending delete servers"
  715. }
  716. type ServerDeployOptions struct {
  717. ServerIdOptions
  718. Keypair string `help:"ssh Keypair used for login" json:"-"`
  719. DeleteKeypair bool `help:"Remove ssh Keypairs" json:"-"`
  720. Deploy []string `help:"Specify deploy files in virtual server file system" json:"-"`
  721. ResetPassword bool `help:"Force reset password"`
  722. Password string `help:"Default user password"`
  723. LoginAccount string `help:"Guest login account"`
  724. AutoStart bool `help:"Auto start server after deployed"`
  725. DeployTelegraf bool `help:"Deploy telegraf if guest os supported"`
  726. }
  727. func (opts *ServerDeployOptions) Params() (jsonutils.JSONObject, error) {
  728. params := new(computeapi.ServerDeployInput)
  729. {
  730. if opts.DeleteKeypair == true {
  731. params.DeleteKeypair = opts.DeleteKeypair
  732. } else if len(opts.Keypair) > 0 {
  733. params.Keypair = opts.Keypair
  734. }
  735. params.AutoStart = opts.AutoStart
  736. params.ResetPassword = opts.ResetPassword
  737. params.Password = opts.Password
  738. params.DeployTelegraf = opts.DeployTelegraf
  739. params.LoginAccount = opts.LoginAccount
  740. }
  741. {
  742. deployInfos, err := ParseServerDeployInfoList(opts.Deploy)
  743. if err != nil {
  744. return nil, err
  745. }
  746. params.DeployConfigs = deployInfos
  747. }
  748. return params.JSON(params), nil
  749. }
  750. func (opts *ServerDeployOptions) Description() string {
  751. return "Deploy hostname and keypair to a stopped virtual server"
  752. }
  753. type ServerSecGroupOptions struct {
  754. ID string `help:"ID or Name of server" metavar:"Guest" json:"-"`
  755. Secgrp string `help:"ID of Security Group" metavar:"Security Group" positional:"true"`
  756. }
  757. func (o *ServerSecGroupOptions) GetId() string {
  758. return o.ID
  759. }
  760. func (o *ServerSecGroupOptions) Params() (jsonutils.JSONObject, error) {
  761. return options.StructToParams(o)
  762. }
  763. type ServerSecGroupsOptions struct {
  764. ID string `help:"ID or Name of server" metavar:"Guest" json:"-"`
  765. SecgroupIds []string `help:"Ids of Security Groups" metavar:"Security Groups" positional:"true"`
  766. }
  767. func (o *ServerSecGroupsOptions) GetId() string {
  768. return o.ID
  769. }
  770. func (opts *ServerSecGroupsOptions) Params() (jsonutils.JSONObject, error) {
  771. return jsonutils.Marshal(map[string][]string{"secgroup_ids": opts.SecgroupIds}), nil
  772. }
  773. type ServerNetworkSecGroupsOptions struct {
  774. ID string `help:"ID or Name of server" metavar:"Guest" json:"-"`
  775. NetworkIndex *int `help:"Guest network index" metavar:"Network Index"`
  776. SecgroupIds []string `help:"Ids of Security Groups" metavar:"Security Groups" positional:"true"`
  777. }
  778. func (o *ServerNetworkSecGroupsOptions) GetId() string {
  779. return o.ID
  780. }
  781. func (opts *ServerNetworkSecGroupsOptions) Params() (jsonutils.JSONObject, error) {
  782. return jsonutils.Marshal(opts), nil
  783. }
  784. type ServerModifySrcCheckOptions struct {
  785. ID string `help:"ID or Name of server" metavar:"Guest" json:"-"`
  786. SrcIpCheck string `help:"Turn on/off src ip check" choices:"on|off"`
  787. SrcMacCheck string `help:"Turn on/off src mac check" choices:"on|off"`
  788. }
  789. func (o *ServerModifySrcCheckOptions) GetId() string {
  790. return o.ID
  791. }
  792. func (o *ServerModifySrcCheckOptions) Params() (jsonutils.JSONObject, error) {
  793. return options.StructToParams(o)
  794. }
  795. func (o *ServerModifySrcCheckOptions) Description() string {
  796. return "Modify src ip, mac check settings"
  797. }
  798. type ServerDisableAutoMergeSnapshot struct {
  799. ServerIdOptions
  800. DisableAutoMergeSnapshot bool `help:"Disable auto merge snapshots"`
  801. }
  802. func (o *ServerDisableAutoMergeSnapshot) Params() (jsonutils.JSONObject, error) {
  803. return options.StructToParams(o)
  804. }
  805. type ServerSendKeyOptions struct {
  806. ID string `help:"ID or Name of server" metavar:"Guest" json:"-"`
  807. KEYS string `help:"Special keys to send, eg. ctrl, alt, f12, shift, etc, separated by \"-\""`
  808. Hold *uint `help:"Hold key for specified milliseconds" json:"duration"`
  809. }
  810. func (o *ServerSendKeyOptions) GetId() string {
  811. return o.ID
  812. }
  813. func (o *ServerSendKeyOptions) Params() (jsonutils.JSONObject, error) {
  814. return options.StructToParams(o)
  815. }
  816. // Kickstart related options
  817. type ServerKickstartConfigOptions struct {
  818. ServerIdOptions
  819. OSType string `help:"Kickstart OS type" choices:"centos|rhel|fedora|openeuler|ubuntu" json:"os_type"`
  820. Config string `help:"Kickstart configuration content" json:"config,omitempty"`
  821. ConfigURL string `help:"Kickstart configuration URL" json:"config_url,omitempty"`
  822. Enabled *bool `help:"Enable kickstart" json:"enabled,omitempty"`
  823. MaxRetries int `help:"Kickstart max retries" default:"3" json:"max_retries,omitempty"`
  824. TimeoutMinutes int `help:"Kickstart timeout in minutes" default:"60" json:"timeout_minutes,omitempty"`
  825. }
  826. func (o *ServerKickstartConfigOptions) Params() (jsonutils.JSONObject, error) {
  827. if o.Config == "" && o.ConfigURL == "" {
  828. return nil, fmt.Errorf("either --config or --config-url must be provided")
  829. }
  830. if o.Config != "" && o.ConfigURL != "" {
  831. return nil, fmt.Errorf("--config and --config-url cannot be both provided, choose one")
  832. }
  833. return options.StructToParams(o)
  834. }
  835. func (o *ServerSendKeyOptions) Description() string {
  836. return "Send keys to server"
  837. }
  838. type ServerKickstartCompleteOptions struct {
  839. ServerIdOptions
  840. Restart bool `help:"Restart the server after marking kickstart as completed" default:"true" json:"restart"`
  841. }
  842. func (o *ServerKickstartCompleteOptions) Params() (jsonutils.JSONObject, error) {
  843. return options.StructToParams(o)
  844. }
  845. type ServerMonitorOptions struct {
  846. ServerIdOptions
  847. Qmp bool `help:"Use qmp protocol, default is hmp"`
  848. COMMAND string `help:"Qemu Monitor command to send"`
  849. }
  850. func (o *ServerMonitorOptions) Params() (jsonutils.JSONObject, error) {
  851. return options.StructToParams(o)
  852. }
  853. type ServerQgaSetPassword struct {
  854. ServerIdOptions
  855. USERNAME string `help:"Which user to set password" json:"username"`
  856. PASSWORD string `help:"Password content" json:"password"`
  857. }
  858. func (o *ServerQgaSetPassword) Params() (jsonutils.JSONObject, error) {
  859. return options.StructToParams(o)
  860. }
  861. type ServerQgaCommand struct {
  862. ServerIdOptions
  863. COMMAND string `help:"qga command"`
  864. Timeout int `help:"qga command execute timeout (s)"`
  865. }
  866. func (o *ServerQgaCommand) Params() (jsonutils.JSONObject, error) {
  867. return options.StructToParams(o)
  868. }
  869. type ServerQgaPing struct {
  870. ServerIdOptions
  871. Timeout int `help:"qga command execute timeout (s)"`
  872. }
  873. func (o *ServerQgaPing) Params() (jsonutils.JSONObject, error) {
  874. return options.StructToParams(o)
  875. }
  876. type ServerQgaGuestInfoTask struct {
  877. ServerIdOptions
  878. }
  879. func (o *ServerQgaGuestInfoTask) Params() (jsonutils.JSONObject, error) {
  880. return options.StructToParams(o)
  881. }
  882. type ServerQgaGetNetwork struct {
  883. ServerIdOptions
  884. }
  885. func (o *ServerQgaGetNetwork) Params() (jsonutils.JSONObject, error) {
  886. return options.StructToParams(o)
  887. }
  888. type ServerSetPasswordOptions struct {
  889. ServerIdOptions
  890. Username string `help:"Which user to set password" json:"username"`
  891. Password string `help:"Password content" json:"password"`
  892. ResetPassword bool `help:"Force reset password"`
  893. AutoStart bool `help:"Auto start server after reset password"`
  894. }
  895. func (o *ServerSetPasswordOptions) Params() (jsonutils.JSONObject, error) {
  896. return options.StructToParams(o)
  897. }
  898. type ServerSetBootIndexOptions struct {
  899. ServerIdOptions
  900. Disks map[string]int8 `help:"Disk index and boot index" json:"disks"`
  901. Cdroms map[string]int8 `help:"Cdrom ordinal and boot index" json:"cdroms"`
  902. }
  903. func (o *ServerSetBootIndexOptions) Params() (jsonutils.JSONObject, error) {
  904. for k, _ := range o.Disks {
  905. if i, e := strconv.Atoi(k); e != nil {
  906. return nil, e
  907. } else if i > 127 {
  908. return nil, fmt.Errorf("disk index grate than 127")
  909. }
  910. }
  911. for k, _ := range o.Cdroms {
  912. if _, e := strconv.Atoi(k); e != nil {
  913. return nil, e
  914. }
  915. }
  916. return options.StructToParams(o)
  917. }
  918. type ServerNicTrafficLimitOptions struct {
  919. ServerIdOptions
  920. MAC string `help:"guest network mac address"`
  921. RxTrafficLimit *int64 `help:" rx traffic limit, unit Byte"`
  922. TxTrafficLimit *int64 `help:" tx traffic limit, unit Byte"`
  923. ChargeType string `help:"nic charge type" choices:"bandwidth|traffic"`
  924. BillingType string `help:"nic billing type" choices:"prepaid|postpaid"`
  925. }
  926. func (o *ServerNicTrafficLimitOptions) Params() (jsonutils.JSONObject, error) {
  927. return options.StructToParams(o)
  928. }
  929. type ServerSaveImageOptions struct {
  930. ServerIdOptions
  931. IMAGE string `help:"Image name" json:"name"`
  932. Public *bool `help:"Make the image public available" json:"is_public"`
  933. Format string `help:"image format" choices:"vmdk|qcow2"`
  934. Notes string `help:"Notes about the image"`
  935. AutoStart *bool `help:"Auto start server after image saved"`
  936. }
  937. func (o *ServerSaveImageOptions) Params() (jsonutils.JSONObject, error) {
  938. return options.StructToParams(o)
  939. }
  940. func (o *ServerSaveImageOptions) Description() string {
  941. return "Save root disk to new image and upload to glance."
  942. }
  943. type ServerSaveGuestImageOptions struct {
  944. ServerIdOptions
  945. IMAGE string `help:"Image name" json:"name"`
  946. AutoStart *bool `help:"Auto start server after image saved"`
  947. }
  948. func (o *ServerSaveGuestImageOptions) Params() (jsonutils.JSONObject, error) {
  949. return options.StructToParams(o)
  950. }
  951. func (o *ServerSaveGuestImageOptions) Description() string {
  952. return "Save root disk and data disks to new images and upload to glance."
  953. }
  954. type ServerChangeOwnerOptions struct {
  955. ID string `help:"Server to change owner" json:"-"`
  956. PROJECT string `help:"Project ID or change" json:"tenant"`
  957. }
  958. func (o *ServerChangeOwnerOptions) GetId() string {
  959. return o.ID
  960. }
  961. func (o *ServerChangeOwnerOptions) Params() (jsonutils.JSONObject, error) {
  962. return options.StructToParams(o)
  963. }
  964. type ServerRebuildRootOptions struct {
  965. ID string `help:"Server to rebuild root" json:"-"`
  966. ImageId string `help:"New root Image template ID" json:"image_id" token:"image"`
  967. Keypair string `help:"ssh Keypair used for login"`
  968. Password string `help:"Default user password"`
  969. LoginAccount string `help:"Guest login account"`
  970. NoAccountInit *bool `help:"Not reset account password"`
  971. AutoStart *bool `help:"Auto start server after it is created"`
  972. AllDisks *bool `help:"Rebuild all disks including data disks"`
  973. UserData string `hlep:"user data scripts"`
  974. }
  975. func (o *ServerRebuildRootOptions) GetId() string {
  976. return o.ID
  977. }
  978. func (o *ServerRebuildRootOptions) Params() (jsonutils.JSONObject, error) {
  979. params, err := options.StructToParams(o)
  980. if err != nil {
  981. return nil, err
  982. }
  983. if o.NoAccountInit != nil && *o.NoAccountInit {
  984. params.Add(jsonutils.JSONFalse, "reset_password")
  985. }
  986. if o.Password != "" {
  987. params.Set("reset_password", jsonutils.JSONTrue)
  988. }
  989. return params, nil
  990. }
  991. func (o *ServerRebuildRootOptions) Description() string {
  992. return "Rebuild VM root image with new template"
  993. }
  994. type ServerChangeConfigOptions struct {
  995. ServerIdOptions
  996. VcpuCount *int `help:"New number of Virtual CPU cores" json:"vcpu_count" token:"ncpu"`
  997. ExtraCpuCount *int `help:"Extra allocate cpu count" json:"extra_cpu_count"`
  998. CpuSockets *int `help:"Cpu sockets"`
  999. VmemSize string `help:"New memory size" json:"vmem_size" token:"vmem"`
  1000. Disk []string `help:"Data disk description, from the 1st data disk to the last one, empty string if no change for this data disk"`
  1001. InstanceType string `help:"Instance Type, e.g. S2.SMALL2 for qcloud"`
  1002. ResetTrafficLimits []string `help:"reset traffic limits, mac,rx,tx"`
  1003. SetTrafficLimits []string `help:"set traffic limits, mac,rx,tx"`
  1004. }
  1005. func (o *ServerChangeConfigOptions) Params() (jsonutils.JSONObject, error) {
  1006. params, err := options.StructToParams(o)
  1007. if err != nil {
  1008. return nil, err
  1009. }
  1010. if len(o.Disk) > 0 {
  1011. params.Remove("disk.0")
  1012. disksConf := make([]*computeapi.DiskConfig, 0)
  1013. for i, d := range o.Disk {
  1014. // params.Set(key, value)
  1015. diskConfig, err := cmdline.ParseDiskConfig(d, i+1)
  1016. if err != nil {
  1017. return nil, err
  1018. }
  1019. disksConf = append(disksConf, diskConfig)
  1020. }
  1021. params.Set("disks", jsonutils.Marshal(disksConf))
  1022. }
  1023. if err != nil {
  1024. return nil, err
  1025. }
  1026. if len(o.ResetTrafficLimits) > 0 {
  1027. // mac,rx_limit,tx_limit
  1028. // ab:bc:cd:ef:ad:fa,12312312,1231233
  1029. resetLimits := []*jsonutils.JSONDict{}
  1030. for i := range o.ResetTrafficLimits {
  1031. resetLimit := jsonutils.NewDict()
  1032. segs := strings.Split(o.ResetTrafficLimits[i], ",")
  1033. if len(segs) != 3 {
  1034. return nil, fmt.Errorf("invalid reset traffic limit input %s", o.ResetTrafficLimits[i])
  1035. }
  1036. resetLimit.Set("mac", jsonutils.NewString(segs[0]))
  1037. rx, err := strconv.Atoi(segs[1])
  1038. if err != nil {
  1039. return nil, fmt.Errorf("invalid reset traffic limit input %s: %s", o.ResetTrafficLimits[i], err)
  1040. }
  1041. resetLimit.Set("rx_traffic_limit", jsonutils.NewInt(int64(rx)))
  1042. tx, err := strconv.Atoi(segs[1])
  1043. if err != nil {
  1044. return nil, fmt.Errorf("invalid reset traffic limit input %s: %s", o.ResetTrafficLimits[i], err)
  1045. }
  1046. resetLimit.Set("tx_traffic_limit", jsonutils.NewInt(int64(tx)))
  1047. resetLimits = append(resetLimits, resetLimit)
  1048. }
  1049. params.Set("reset_traffic_limits", jsonutils.Marshal(resetLimits))
  1050. }
  1051. if len(o.SetTrafficLimits) > 0 {
  1052. // mac,rx_limit,tx_limit
  1053. // ab:bc:cd:ef:ad:fa,12312312,1231233
  1054. setLimits := []*jsonutils.JSONDict{}
  1055. for i := range o.SetTrafficLimits {
  1056. setLimit := jsonutils.NewDict()
  1057. segs := strings.Split(o.SetTrafficLimits[i], ",")
  1058. if len(segs) != 3 {
  1059. return nil, fmt.Errorf("invalid reset traffic limit input %s", o.SetTrafficLimits[i])
  1060. }
  1061. setLimit.Set("mac", jsonutils.NewString(segs[0]))
  1062. rx, err := strconv.Atoi(segs[1])
  1063. if err != nil {
  1064. return nil, fmt.Errorf("invalid reset traffic limit input %s: %s", o.SetTrafficLimits[i], err)
  1065. }
  1066. setLimit.Set("rx_traffic_limit", jsonutils.NewInt(int64(rx)))
  1067. tx, err := strconv.Atoi(segs[1])
  1068. if err != nil {
  1069. return nil, fmt.Errorf("invalid reset traffic limit input %s: %s", o.SetTrafficLimits[i], err)
  1070. }
  1071. setLimit.Set("tx_traffic_limit", jsonutils.NewInt(int64(tx)))
  1072. setLimits = append(setLimits, setLimit)
  1073. }
  1074. params.Set("set_traffic_limits", jsonutils.Marshal(setLimits))
  1075. }
  1076. if params.Size() == 0 {
  1077. return nil, ErrEmtptyUpdate
  1078. }
  1079. return params, nil
  1080. }
  1081. func (o *ServerChangeConfigOptions) Description() string {
  1082. return "Change configuration of VM"
  1083. }
  1084. type ServerResetOptions struct {
  1085. ID []string `help:"ID of servers to operate" metavar:"SERVER" json:"-"`
  1086. Hard *bool `help:"Hard reset or not; default soft" json:"is_hard"`
  1087. }
  1088. func (o *ServerResetOptions) GetIds() []string {
  1089. return o.ID
  1090. }
  1091. func (o *ServerResetOptions) Params() (jsonutils.JSONObject, error) {
  1092. return options.StructToParams(o)
  1093. }
  1094. type ServerRestartOptions struct {
  1095. ID []string `help:"ID of servers to operate" metavar:"SERVER" json:"-"`
  1096. IsForce *bool `help:"Force reset or not; default false" json:"is_force"`
  1097. }
  1098. func (o *ServerRestartOptions) GetIds() []string {
  1099. return o.ID
  1100. }
  1101. func (o *ServerRestartOptions) Params() (jsonutils.JSONObject, error) {
  1102. return options.StructToParams(o)
  1103. }
  1104. type ServerMigrateForecastOptions struct {
  1105. ID string `help:"ID of server" json:"-"`
  1106. PreferHost string `help:"Server migration prefer host id or name" json:"prefer_host"`
  1107. LiveMigrate *bool `help:"Use live migrate"`
  1108. SkipCpuCheck *bool `help:"Skip check CPU mode of the target host" json:"skip_cpu_check"`
  1109. SkipKernelCheck *bool `help:"Skip target kernel version check" json:"skip_kernel_check"`
  1110. }
  1111. func (o *ServerMigrateForecastOptions) GetId() string {
  1112. return o.ID
  1113. }
  1114. func (o *ServerMigrateForecastOptions) Params() (jsonutils.JSONObject, error) {
  1115. return options.StructToParams(o)
  1116. }
  1117. type ServerMigrateOptions struct {
  1118. ID string `help:"ID of server" json:"-"`
  1119. PreferHost string `help:"Server migration prefer host id or name" json:"prefer_host"`
  1120. AutoStart *bool `help:"Server auto start after migrate" json:"auto_start"`
  1121. RescueMode *bool `help:"Migrate server in rescue mode, all disks must reside on shared storage" json:"rescue_mode"`
  1122. }
  1123. func (o *ServerMigrateOptions) GetId() string {
  1124. return o.ID
  1125. }
  1126. func (o *ServerMigrateOptions) Params() (jsonutils.JSONObject, error) {
  1127. return options.StructToParams(o)
  1128. }
  1129. type ServerLiveMigrateOptions struct {
  1130. ID string `help:"ID of server" json:"-"`
  1131. PreferHost string `help:"Server migration prefer host id or name" json:"prefer_host"`
  1132. SkipCpuCheck *bool `help:"Skip check CPU mode of the target host" json:"skip_cpu_check"`
  1133. SkipKernelCheck *bool `help:"Skip target kernel version check" json:"skip_kernel_check"`
  1134. EnableTLS *bool `help:"Enable tls migration" json:"enable_tls"`
  1135. QuicklyFinish *bool `help:"quickly finish, fix downtime after a few rounds of memory synchronization"`
  1136. MaxBandwidthMb *int64 `help:"live migrate downtime, unit MB"`
  1137. KeepDestGuestOnFailed *bool `help:"do not delete dest guest on migrate failed, for debug"`
  1138. }
  1139. func (o *ServerLiveMigrateOptions) GetId() string {
  1140. return o.ID
  1141. }
  1142. func (o *ServerLiveMigrateOptions) Params() (jsonutils.JSONObject, error) {
  1143. return options.StructToParams(o)
  1144. }
  1145. type ServerSetLiveMigrateParamsOptions struct {
  1146. ID string `help:"ID of server" json:"-"`
  1147. MaxBandwidthMB *int64 `help:"live migrate downtime, unit MB"`
  1148. DowntimeLimitMS *int64 `help:"live migrate downtime limit"`
  1149. }
  1150. func (o *ServerSetLiveMigrateParamsOptions) GetId() string {
  1151. return o.ID
  1152. }
  1153. func (o *ServerSetLiveMigrateParamsOptions) Params() (jsonutils.JSONObject, error) {
  1154. return options.StructToParams(o)
  1155. }
  1156. type ServerBatchMetadataOptions struct {
  1157. Guests []string `help:"IDs or names of server" json:"-"`
  1158. TAGS []string `help:"Tags info, eg: hypervisor=aliyun、os_type=Linux、os_version"`
  1159. }
  1160. func (opts *ServerBatchMetadataOptions) Params() (jsonutils.JSONObject, error) {
  1161. params := jsonutils.NewDict()
  1162. if len(opts.Guests) == 0 {
  1163. return nil, fmt.Errorf("missing guest option")
  1164. }
  1165. params.Add(jsonutils.Marshal(opts.Guests), "guests")
  1166. metadata := jsonutils.NewDict()
  1167. for _, tag := range opts.TAGS {
  1168. info := strings.Split(tag, "=")
  1169. if len(info) == 2 {
  1170. if len(info[0]) == 0 {
  1171. return nil, fmt.Errorf("invalidate tag info %s", tag)
  1172. }
  1173. metadata.Add(jsonutils.NewString(info[1]), info[0])
  1174. } else if len(info) == 1 {
  1175. metadata.Add(jsonutils.NewString(info[0]), info[0])
  1176. } else {
  1177. return nil, fmt.Errorf("invalidate tag info %s", tag)
  1178. }
  1179. }
  1180. params.Add(metadata, "metadata")
  1181. return params, nil
  1182. }
  1183. type ServerAssociateEipOptions struct {
  1184. ServerIdOptions
  1185. EIP string `help:"ID or name of EIP to associate"`
  1186. }
  1187. func (o *ServerAssociateEipOptions) Params() (jsonutils.JSONObject, error) {
  1188. params := jsonutils.NewDict()
  1189. params.Add(jsonutils.NewString(o.EIP), "eip")
  1190. return params, nil
  1191. }
  1192. func (o *ServerAssociateEipOptions) Description() string {
  1193. return "Associate a server and an eip"
  1194. }
  1195. type ServerDissociateEipOptions struct {
  1196. ServerIdOptions
  1197. AutoDelete bool `help:"automatically delete the dissociate EIP" json:"auto_delete,omitfalse"`
  1198. }
  1199. func (o *ServerDissociateEipOptions) Params() (jsonutils.JSONObject, error) {
  1200. return options.StructToParams(o)
  1201. }
  1202. func (o *ServerDissociateEipOptions) Description() string {
  1203. return "Dissociate an eip from a server"
  1204. }
  1205. type ServerRenewOptions struct {
  1206. ID string `help:"ID or name of server to renew"`
  1207. DURATION string `help:"Duration of renew, ADMIN only command"`
  1208. }
  1209. func (o *ServerRenewOptions) GetId() string {
  1210. return o.ID
  1211. }
  1212. func (o *ServerRenewOptions) Params() (jsonutils.JSONObject, error) {
  1213. params := jsonutils.NewDict()
  1214. params.Add(jsonutils.NewString(o.DURATION), "duration")
  1215. return params, nil
  1216. }
  1217. type ServerPrepaidRecycleOptions struct {
  1218. ServerIdOptions
  1219. AutoDelete bool `help:"after joining the pool, remove the server automatically"`
  1220. }
  1221. func (o *ServerPrepaidRecycleOptions) Params() (jsonutils.JSONObject, error) {
  1222. params := jsonutils.NewDict()
  1223. if o.AutoDelete {
  1224. params.Add(jsonutils.JSONTrue, "auto_delete")
  1225. }
  1226. return params, nil
  1227. }
  1228. type ServerIoThrottle struct {
  1229. ServerIdOptions
  1230. DiskBps map[string]int `help:"disk bps of throttle, input diskId=BPS" json:"bps"`
  1231. DiskIOPS map[string]int `help:"disk iops of throttle, input diskId=IOPS" json:"iops"`
  1232. }
  1233. func (o *ServerIoThrottle) Params() (jsonutils.JSONObject, error) {
  1234. return jsonutils.Marshal(o), nil
  1235. }
  1236. func (o *ServerIoThrottle) Description() string {
  1237. return "Guest io set throttle"
  1238. }
  1239. type ServerPublicipToEip struct {
  1240. ServerIdOptions
  1241. AutoStart bool `help:"Auto start new guest"`
  1242. }
  1243. func (o *ServerPublicipToEip) Params() (jsonutils.JSONObject, error) {
  1244. params := jsonutils.NewDict()
  1245. params.Set("auto_start", jsonutils.NewBool(o.AutoStart))
  1246. return params, nil
  1247. }
  1248. func (o *ServerPublicipToEip) Description() string {
  1249. return "Convert PublicIp to Eip for server"
  1250. }
  1251. type ServerSetAutoRenew struct {
  1252. ServerIdOptions
  1253. AutoRenew bool `help:"Set server auto renew or manual renew"`
  1254. Duration string `help:"Duration for renew" default:"1M"`
  1255. }
  1256. func (o *ServerSetAutoRenew) Params() (jsonutils.JSONObject, error) {
  1257. params := jsonutils.NewDict()
  1258. params.Set("auto_renew", jsonutils.NewBool(o.AutoRenew))
  1259. params.Set("duration", jsonutils.NewString(o.Duration))
  1260. return params, nil
  1261. }
  1262. func (o *ServerSetAutoRenew) Description() string {
  1263. return "Set autorenew for server"
  1264. }
  1265. type ServerSaveTemplateOptions struct {
  1266. ServerIdOptions
  1267. TemplateName string `help:"The name of guest template"`
  1268. }
  1269. func (o *ServerSaveTemplateOptions) Params() (jsonutils.JSONObject, error) {
  1270. dict := jsonutils.NewDict()
  1271. dict.Set("name", jsonutils.NewString(o.TemplateName))
  1272. return dict, nil
  1273. }
  1274. func (o *ServerSaveTemplateOptions) Description() string {
  1275. return "Save Guest Template of this Server"
  1276. }
  1277. type ServerRemoteUpdateOptions struct {
  1278. ServerIdOptions
  1279. computeapi.ServerRemoteUpdateInput
  1280. }
  1281. type ServerCreateEipOptions struct {
  1282. options.BaseIdOptions
  1283. Bandwidth int `help:"EIP bandwidth in Mbps" default:"5"`
  1284. BgpType *string `help:"desired BGP type"`
  1285. ChargeType *string `help:"bandwidth charge type" choices:"traffic|bandwidth"`
  1286. }
  1287. func (opts *ServerCreateEipOptions) Params() (jsonutils.JSONObject, error) {
  1288. return jsonutils.Marshal(opts), nil
  1289. }
  1290. type ServerMakeSshableOptions struct {
  1291. options.BaseIdOptions
  1292. User string `help:"ssh username for ssh connection" default:"root"`
  1293. PrivateKey string `help:"ssh privatekey for ssh connection"`
  1294. Password string `help:"ssh password for ssh connection"`
  1295. Port int `help:"ssh port for ssh connection"`
  1296. }
  1297. func (opts *ServerMakeSshableOptions) Params() (jsonutils.JSONObject, error) {
  1298. if opts.User == "" {
  1299. return nil, fmt.Errorf("ssh username must be set")
  1300. }
  1301. if opts.PrivateKey == "" && opts.Password == "" {
  1302. return nil, fmt.Errorf("either --private-key or --password must be set")
  1303. }
  1304. return jsonutils.Marshal(opts), nil
  1305. }
  1306. type ServerSetSshportOptions struct {
  1307. options.BaseIdOptions
  1308. Port int `help:"ssh port" default:"22"`
  1309. }
  1310. func (opts *ServerSetSshportOptions) Params() (jsonutils.JSONObject, error) {
  1311. return jsonutils.Marshal(opts), nil
  1312. }
  1313. type ServerHaveAgentOptions struct {
  1314. options.BaseIdOptions
  1315. }
  1316. type ServerMigrateNetworkOptions struct {
  1317. options.BaseIdOptions
  1318. computeapi.ServerMigrateNetworkInput
  1319. }
  1320. func (opts *ServerMigrateNetworkOptions) Params() (jsonutils.JSONObject, error) {
  1321. return jsonutils.Marshal(opts), nil
  1322. }
  1323. type ServerStatusStatisticsOptions struct {
  1324. ServerListOptions
  1325. options.StatusStatisticsOptions
  1326. }
  1327. type ServerProjectStatisticsOptions struct {
  1328. ServerListOptions
  1329. options.ProjectStatisticsOptions
  1330. }
  1331. type ServerDomainStatisticsOptions struct {
  1332. ServerListOptions
  1333. options.DomainStatisticsOptions
  1334. }
  1335. type ServerChangeDiskStorageOptions struct {
  1336. options.BaseIdOptions
  1337. DISKID string `json:"disk_id" help:"Disk id or name"`
  1338. TARGETSTORAGE string `json:"target_storage_id" help:"Target storage id or name"`
  1339. KeepOriginDisk bool `json:"keep_origin_disk" help:"Keep origin disk when changed"`
  1340. }
  1341. func (o *ServerChangeDiskStorageOptions) Params() (jsonutils.JSONObject, error) {
  1342. return jsonutils.Marshal(o), nil
  1343. }
  1344. type ServerChangeStorageOptions struct {
  1345. options.BaseIdOptions
  1346. TARGETSTORAGE string `json:"target_storage_id" help:"Target storage id or name"`
  1347. KeepOriginDisk bool `json:"keep_origin_disk" help:"Keep origin disk when changed"`
  1348. }
  1349. func (o *ServerChangeStorageOptions) Params() (jsonutils.JSONObject, error) {
  1350. return jsonutils.Marshal(o), nil
  1351. }
  1352. type ServerCPUSetOptions struct {
  1353. options.BaseIdOptions
  1354. SETS string `help:"Cgroup cpusets CPUs spec string, e.g. '0-2,16'"`
  1355. }
  1356. func (o *ServerCPUSetOptions) Params() (jsonutils.JSONObject, error) {
  1357. cpus, err := cpuset.Parse(o.SETS)
  1358. if err != nil {
  1359. return nil, errors.Wrap(err, "parse cpuset failed")
  1360. }
  1361. input := &computeapi.ServerCPUSetInput{
  1362. CPUS: cpus.ToSlice(),
  1363. }
  1364. return jsonutils.Marshal(input), nil
  1365. }
  1366. type ServerVncOptions struct {
  1367. ServerIdOptions
  1368. Origin bool
  1369. }
  1370. func (o *ServerVncOptions) Params() (jsonutils.JSONObject, error) {
  1371. return jsonutils.Marshal(o), nil
  1372. }
  1373. type ServerScreenDumpOptions struct {
  1374. ServerIdOptions
  1375. ObjectName string
  1376. }
  1377. func (o *ServerScreenDumpOptions) Params() (jsonutils.JSONObject, error) {
  1378. return jsonutils.Marshal(o), nil
  1379. }
  1380. type ServerSetNetworkNumQueues struct {
  1381. ServerIdOptions
  1382. MacAddr string `help:"server network mac addr"`
  1383. NumQueues int `help:"network num queues"`
  1384. }
  1385. func (o *ServerSetNetworkNumQueues) Params() (jsonutils.JSONObject, error) {
  1386. return jsonutils.Marshal(o), nil
  1387. }
  1388. type ServerIsoOptions struct {
  1389. ServerIdOptions
  1390. Ordinal int `help:"server iso ordinal, default 0"`
  1391. }
  1392. func (o *ServerIsoOptions) Params() (jsonutils.JSONObject, error) {
  1393. return jsonutils.Marshal(o), nil
  1394. }
  1395. type ServerAddSubIpsOptions struct {
  1396. ServerIdOptions
  1397. computeapi.GuestAddSubIpsInput
  1398. }
  1399. func (o *ServerAddSubIpsOptions) Params() (jsonutils.JSONObject, error) {
  1400. return jsonutils.Marshal(o), nil
  1401. }
  1402. type ServerUpdateSubIpsOptions struct {
  1403. ServerIdOptions
  1404. computeapi.GuestUpdateSubIpsInput
  1405. }
  1406. func (o *ServerUpdateSubIpsOptions) Params() (jsonutils.JSONObject, error) {
  1407. return jsonutils.Marshal(o), nil
  1408. }
  1409. type ServerSetOSInfoOptions struct {
  1410. ServerIdsOptions
  1411. computeapi.ServerSetOSInfoInput
  1412. }
  1413. func (o *ServerSetOSInfoOptions) Params() (jsonutils.JSONObject, error) {
  1414. return jsonutils.Marshal(o), nil
  1415. }
  1416. type ServerSetRootDiskMatcher struct {
  1417. ROOTDISKMATCHER string `help:"Baremetal root disk matcher, e.g. 'device=/dev/sdb' 'size=900G' 'size_start=800G,size_end=900G'" json:"-"`
  1418. ServerIdsOptions
  1419. }
  1420. func (o *ServerSetRootDiskMatcher) Params() (jsonutils.JSONObject, error) {
  1421. matcher, err := cmdline.ParseBaremetalRootDiskMatcher(o.ROOTDISKMATCHER)
  1422. if err != nil {
  1423. return nil, err
  1424. }
  1425. return jsonutils.Marshal(matcher), nil
  1426. }
  1427. type ServerSetTpmOptions struct {
  1428. ServerIdsOptions
  1429. EnableTpm bool `help:"Enable tpm device"`
  1430. }
  1431. func (o *ServerSetTpmOptions) Params() (jsonutils.JSONObject, error) {
  1432. return jsonutils.Marshal(o), nil
  1433. }
  1434. type ServerChangeBillingTypeOptions struct {
  1435. ServerIdOptions
  1436. BillingType string `choices:"prepaid|postpaid"`
  1437. }
  1438. func (o *ServerChangeBillingTypeOptions) Params() (jsonutils.JSONObject, error) {
  1439. return jsonutils.Marshal(map[string]string{"billing_type": o.BillingType}), nil
  1440. }