api.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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. "time"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/onecloud/pkg/apis"
  19. billing_api "yunion.io/x/onecloud/pkg/apis/billing"
  20. )
  21. type SchedtagConfig struct {
  22. apis.Meta
  23. // swagger:ignore
  24. Id string `json:"id"`
  25. // 调度策略
  26. // required: 必须使用
  27. // prefer: 尽量使用
  28. // avoid: 避免使用
  29. // exclude: 禁止使用
  30. // enmu: required, prefer, avoid, exclude
  31. Strategy string `json:"strategy"`
  32. // swagger:ignore
  33. Weight int `json:"weight"`
  34. // 资源类型
  35. // hosts: 宿主机
  36. // networks: 网络
  37. // storages: 存储
  38. // enmu: hosts, storages, networks
  39. ResourceType string `json:"resource_type"`
  40. }
  41. type NetworkConfig struct {
  42. apis.Meta
  43. // 网卡序号, 从0开始
  44. // required: true
  45. Index int `json:"index"`
  46. // 子网名称或ID
  47. // required: true
  48. Network string `json:"network"`
  49. // swagger:ignore
  50. Wire string `json:"wire"`
  51. // 内网地址
  52. Exit bool `json:"exit"`
  53. Private bool `json:"private"`
  54. // 网卡MAC地址
  55. // requried: false
  56. Mac string `json:"mac"`
  57. // 如果是批量创建,指定每个网卡MAC地址
  58. // requried: false
  59. Macs []string `json:"macs"`
  60. // 子网内的IPv4地址, 若不指定会按照子网的地址分配策略分配一个IP地址
  61. // required: false
  62. Address string `json:"address"`
  63. // 如果是批量创建,指定每台主机子网内的IPv4地址
  64. // required: false
  65. Addresses []string `json:"addresses"`
  66. // 子网内的IPv6地址
  67. // required: false
  68. Address6 string `json:"address6"`
  69. // 如果是批量创建,指定每台主机子网内的IPv4地址
  70. // required: false
  71. Addresses6 []string `json:"addresses6"`
  72. // 是否要求分配IPv6地址
  73. // required: false
  74. RequireIPv6 bool `json:"require_ipv6"`
  75. // 只分配IPv6地址,禁用IPv4
  76. // required: false
  77. StrictIPv6 bool `json:"strict_ipv6"`
  78. // 驱动方式
  79. // 若指定镜像的网络驱动方式,此参数会被覆盖
  80. Driver string `json:"driver"`
  81. BwLimit int `json:"bw_limit"`
  82. Vip bool `json:"vip"`
  83. Reserved bool `json:"reserved"`
  84. NumQueues int `json:"num_queues"`
  85. RxTrafficLimit int64 `json:"rx_traffic_limit"`
  86. TxTrafficLimit int64 `json:"tx_traffic_limit"`
  87. NetType TNetworkType `json:"net_type"`
  88. IsDefault bool `json:"is_default"`
  89. // sriov nic
  90. SriovDevice *IsolatedDeviceConfig `json:"sriov_device"`
  91. RequireDesignatedIP bool `json:"require_designated_ip"`
  92. RequireTeaming bool `json:"require_teaming"`
  93. TryTeaming bool `json:"try_teaming"`
  94. StandbyPortCount int `json:"standby_port_count"`
  95. StandbyAddrCount int `json:"standby_addr_count"`
  96. PortMappings GuestPortMappings `json:"port_mappings"`
  97. // 计费模式
  98. BillingType billing_api.TBillingType `json:"billing_type"`
  99. // 计量模式
  100. ChargeType billing_api.TNetChargeType `json:"charge_type"`
  101. // swagger:ignore
  102. Project string `json:"project_id"`
  103. // swagger:ignore
  104. Domain string `json:"domain_id"`
  105. Ifname string `json:"ifname"`
  106. Schedtags []*SchedtagConfig `json:"schedtags"`
  107. // network secgroups
  108. Secgroups []string `json:"secgroups"`
  109. }
  110. type AttachNetworkInput struct {
  111. // 添加的网卡的配置
  112. // required: false
  113. Nets []*NetworkConfig `json:"nets"`
  114. // 添加的网卡的配置
  115. // required: false
  116. NetDesc []string `json:"net_desc"`
  117. // 添加后不立即同步配置
  118. DisableSyncConfig *bool `json:"disable_sync_config"`
  119. }
  120. type DiskConfig struct {
  121. apis.Meta
  122. // 挂载到虚拟机的磁盘顺序, -1代表不挂载任何虚拟机
  123. // default: -1
  124. Index int `json:"index"`
  125. BootIndex *int8 `json:"boot_index"`
  126. // 镜像ID,通过镜像创建磁盘,创建虚拟机时第一块磁盘需要指定此参数
  127. // required: false
  128. ImageId string `json:"image_id"`
  129. // 镜像加密key ID
  130. ImageEncryptKeyId string `json:"image_encrypt_key_id"`
  131. // 快照ID,通过快照创建磁盘,此参数必须加上 'snapshot-' 前缀
  132. // example: snapshot-3140cecb-ccc4-4865-abae-3a5ba8c69d9b
  133. // requried: false
  134. SnapshotId string `json:"snapshot_id"`
  135. BackupId string `json:"backup_id"`
  136. // 磁盘类型
  137. // enum: ["sys", "data", "swap"]
  138. DiskType string `json:"disk_type"`
  139. Schedtags []*SchedtagConfig `json:"schedtags"`
  140. // 磁盘大小,单位Mb
  141. // 若创建裸金属服务器是, -1代表自动向后扩展存储
  142. // requried:true
  143. SizeMb int `json:"size"`
  144. // 文件系统,仅kvm支持自动格式化磁盘,私有云和公有云此参数不会生效
  145. // enum: ["swap", "ext2", "ext3", "ext4", "xfs", "ntfs", "fat", "hfsplus"]
  146. // requried: false
  147. Fs string `json:"fs"`
  148. // 文件系统特性
  149. FsFeatures *DiskFsFeatures `json:"fs_features"`
  150. // 关机后自动重置磁盘
  151. // required: false
  152. AutoReset bool `json:"auto_reset"`
  153. // 是否跟随主机删除而自动删除
  154. // 默认跟随主机创建的磁盘为 true
  155. // required: false
  156. AutoDelete *bool `json:"auto_delete,omitempty"`
  157. // 磁盘存储格式
  158. // enum: ["qcow2", "raw", "docker", "iso", "vmdk", "vmdkflatver1", "vmdkflatver2", "vmdkflat", "vmdksparse", "vmdksparsever1", "vmdksparsever2", "vmdksepsparse", "vhd"]
  159. // requried: false
  160. Format string `json:"format"`
  161. // 磁盘驱动方式
  162. // enum: ["virtio", "ide", "scsi", "sata", "pvscsi"]
  163. // requried: false
  164. Driver string `json:"driver"`
  165. // 磁盘缓存模式
  166. // enum: ["writeback", "none", "writethrough"]
  167. // requried: false
  168. Cache string `json:"cache"`
  169. // 挂载点,必须以 '/' 开头,例如 /opt 仅KVM此参数有效
  170. // requried: false
  171. Mountpoint string `json:"mountpoint"`
  172. // 操作系统CPU架构
  173. // required: false
  174. OsArch string `json:"os_arch"`
  175. //后端存储类型,若指定了存储ID,此参数会根据存储设置,若不指定,则作为调度的一个参考
  176. //
  177. //
  178. //
  179. // | 平台 | 存储类型 | 中文 | 数据盘 | 系统盘 | 可否扩容 | 可否单独创建 | 扩容步长 | 说明 |
  180. // |---- | ---- | ---- | ----- | ----- | ------- | ----------- | ------- | ----- |
  181. // |Esxi |local |本地盘 |1-500GB |30~500GB | 是 | 否 | 1G | |
  182. // |Esxi |nas |NAS盘 |30-3072GB |30~500GB | 是 | 否 | 1G | |
  183. // |Esxi |vsan |VSAN盘 |30-3072GB |30~500GB | 是 | 否 | 1G | |
  184. // |KVM |local |本地盘盘 |1-500GB |30~500GB | 是 | 否 | 1G | |
  185. // |KVM |rbd |云硬盘 |1-3072GB |30~500GB | 是 | 是 | 1G | |
  186. // |Azure |standard_lrs |标准 HDD |1-4095GB |30~4095GB | 是 | 是 | 1G | |
  187. // |Azure |standardssd_lrs |标准 SSD |1-4095GB |30~4095GB | 是 | 是 | 1G | |
  188. // |Azure |premium_lrs |高级SSD |1-4095GB |30~4095GB | 是 | 是 | 1G | |
  189. // |AWS |gp2 |通用型SSD |1-16384GB |20~16384GB | 是 | 是 | 1G | |
  190. // |AWS |io1 |预配置 IOPS SSD |4-16384GB |20-16384GB | 是 | 是 | 1G | |
  191. // |AWS |st1 |吞吐优化HDD |500-16384GB |不支持 | 是 | 是 | 1G | |
  192. // |AWS |sc1 |Cold HDD |500-16384GB |不支持 | 是 | 是 | 1G | |
  193. // |AWS |standard |磁介质 |1-1024GB |20-1024GB | 是 | 是 | 1G | |
  194. // |腾讯云 |cloud_ssd |SSD云硬盘 |10-16000GB |50~500GB | 是 | 是 | 10G | |
  195. // |腾讯云 |cloud_basic |普通云硬盘 |10-16000GB |50~500GB | 是 | 是 | 10G | |
  196. // |腾讯云 |cloud_preium |高性能云硬盘 |10-16000GB |50~1024GB | 是 | 是 | 10G | |
  197. // |腾讯云 |local_basic |普通本地盘 |10-1600GB |不支持 | 否 | 否 | | |
  198. // |腾讯云 |local_ssd |SSD本地盘 |10-7000GB |部分区域套餐支持 | 否 | 否 | | |
  199. // |腾讯云 |local_pro |HDD本地盘 |跟随套餐 |部分区域套餐支持 | 否 | 否 | | |
  200. // |华为云或天翼云 |SSD |超高IO云硬盘 |10-32768GB |40~1024GB | 是 | 是 | 1G | |
  201. // |华为云或天翼云 |SAS |高IO云硬盘 |10-32768GB |40~1024GB | 是 | 是 | 1G | |
  202. // |华为云或天翼云 |SATA |普通IO云硬盘 |10-32768GB |40~1024GB | 是 | 是 | 1G | |
  203. // |OpenStack |nova |nova |不支持 |30-500GB | 否 | 否 | | |
  204. // |OpenStack |自定义 |... |无限制 |无限制 | 是 | 是 | 1G | |
  205. // |Ucloud |CLOUD_NORMAL |普通云盘 |20-8000GB |不支持 | 是 | 是 | 1G | |
  206. // |Ucloud |CLOUD_SSD |SSD云盘 |20-4000GB |20-500GB | 是 | 是 | 1G | |
  207. // |Ucloud |LOCAL_NORMAL |普通本地盘 | | | 是 | 是 | 1G | |
  208. // |Ucloud |LOCAL_SSD |SSD本地盘 | | | 是 | 是 | 1G | |
  209. // |Ucloud |EXCLUSIVE_LOCAL_DISK |独享本地盘 | | | 是 | 是 | 1G | |
  210. // |ZStack |localstorage |本地盘 | | | 是 | 是 | 1G | |
  211. // |ZStack |ceph |云硬盘 | | | 是 | 是 | 1G | |
  212. // |Google |local-ssd |本地SSD暂存盘 |375GB |不支持 | 否 | 否 | | 跟随实例创建,一次最多添加8个 |
  213. // |Google |pd-standard |标准永久性磁盘 |10-65536GB |10-65536GB | 是 | 是 | 1G | |
  214. // |Google |pd-ssd |SSD永久性磁盘 |10-65536GB |10-65536GB | 是 | 是 | 1G | |
  215. Backend string `json:"backend"`
  216. //介质类型
  217. //rotate: 机械盘
  218. //ssd: 固态硬盘
  219. //hybird: 混合盘
  220. //emum: [rotate, ssd, hybrid]
  221. //default: hybird
  222. Medium string `json:"medium"`
  223. //swagger:ignore
  224. ImageProperties map[string]string `json:"image_properties"`
  225. //存储ID, 指定存储后,磁盘会在此存储上创建
  226. //存储列表可以参数 storage 列表API
  227. //required: false
  228. Storage string `json:"storage_id"`
  229. //swagger:ignore
  230. DiskId string `json:"disk_id"`
  231. //swagger:ignore
  232. ExistingPath string `json:"existing_path"`
  233. // requried:false
  234. Iops int `json:"iops"`
  235. // 磁盘吞吐量, 仅对aws gp3生效
  236. // 范围: 125-1000
  237. Throughput int `json:"throughput"`
  238. // NVNe device
  239. NVMEDevice *IsolatedDeviceConfig `json:"nvme_device"`
  240. // 预分配策略:
  241. // off: 关闭预分配,默认关闭
  242. // metadata: 精简置备
  243. // falloc: 厚置备延迟置零
  244. // full: 厚置备快速置零
  245. // default: off
  246. Preallocation string `json:"preallocation"`
  247. }
  248. type IsolatedDeviceConfig struct {
  249. Index int `json:"index"`
  250. Id string `json:"id"`
  251. DevType string `json:"dev_type"`
  252. Model string `json:"model"`
  253. Vendor string `json:"vendor"`
  254. NetworkIndex *int `json:"network_index"`
  255. WireId string `json:"wire_id"`
  256. DiskIndex *int8 `json:"disk_index"`
  257. DevicePath string `json:"device_path"`
  258. }
  259. type BaremetalDiskConfig struct {
  260. //Index int `json:"index"`
  261. // disk type
  262. Type string `json:"type"` // ssd / rotate
  263. // raid config
  264. Conf string `json:"conf"` // raid配置
  265. Count int64 `json:"count"` // 连续几块
  266. Range []int64 `json:"range"` // 指定几块
  267. Splits string `json:"splits"`
  268. Size []int64 `json:"size"` //
  269. Adapter *int `json:"adapter,omitempty"`
  270. Driver string `json:"driver"`
  271. Cachedbadbbu *bool `json:"cachedbadbbu,omitempty"`
  272. Strip *int64 `json:"strip,omitempty"`
  273. RA *bool `json:"ra,omitempty"`
  274. WT *bool `json:"wt,omitempty"`
  275. Direct *bool `json:"direct,omitempty"`
  276. SoftRaidIdx *int `json:"soft_raid_idx"`
  277. }
  278. type RootDiskMatcherSizeMBRange struct {
  279. Start int64 `json:"start"`
  280. End int64 `json:"end"`
  281. }
  282. const (
  283. BAREMETAL_SERVER_METATA_ROOT_DISK_MATCHER = "baremetal_root_disk_matcher"
  284. )
  285. type BaremetalRootDiskMatcher struct {
  286. Device string `json:"device"`
  287. SizeMB int64 `json:"size_mb"`
  288. SizeMBRange *RootDiskMatcherSizeMBRange `json:"size_mb_range"`
  289. PCIPath string `json:"pci_path"`
  290. }
  291. type ServerConfigs struct {
  292. // 调度使用指定的云账号
  293. PreferManager string `json:"prefer_manager_id"`
  294. // 调度到指定区域,优先级低于prefer_zone_id
  295. PreferRegion string `json:"prefer_region_id"`
  296. // 调度到指定可用区,优先级低于prefer_host_id
  297. PreferZone string `json:"prefer_zone_id"`
  298. // 调度使用指定二层网络, 优先级低于prefer_host_id
  299. PreferWire string `json:"prefer_wire_id"`
  300. // 调度使用指定宿主机
  301. PreferHost string `json:"prefer_host_id"`
  302. // 主机高可用时,将备机调度到指定宿主机, 此参数仅对KVM生效
  303. PreferBackupHost string `json:"prefer_backup_host"`
  304. // 虚拟化技术或平台
  305. //
  306. //
  307. //
  308. // |hypervisor | 技术或平台 |
  309. // |------- | ---------- |
  310. // |kvm | 本地私有云 |
  311. // |esxi | VMWare |
  312. // |baremetal | 裸金属 |
  313. // |aliyun | 阿里云 |
  314. // |aws | 亚马逊 |
  315. // |qcloud | 腾讯云 |
  316. // |azure | 微软云 |
  317. // |huawei | 华为云 |
  318. // |openstack | OpenStack |
  319. // |ucloud | Ucloud |
  320. // |zstack | ZStack |
  321. // |google | 谷歌云 |
  322. // |ctyun | 天翼云 |
  323. // default: kvm
  324. Hypervisor string `json:"hypervisor"`
  325. // swagger:ignore
  326. Provider string `json:"provider"`
  327. // 包年包月资源池
  328. // swagger:ignore
  329. // emum: shared, prepaid, dedicated
  330. ResourceType string `json:"resource_type"`
  331. // 套餐名称, 此参数优先级高于vcpu_count和vmem_size
  332. // 套餐可以通过 serverskus 列表获取
  333. // esxi, openstack, zstack等私有云都统一使用provider为OneCloud的套餐
  334. // 公有云使用各自的套餐
  335. InstanceType string `json:"instance_type"`
  336. // swagger:ignore
  337. // Deprecated
  338. // alias for InstanceType
  339. Sku string `json:"sku" yunion-deprecated-by:"instance_type"`
  340. // 虚拟机高可用(创建备机)
  341. // default: false
  342. // required: false
  343. Backup bool `json:"backup"`
  344. // 设置为 daemon 虚机
  345. // default: false
  346. // required: false
  347. IsDaemon *bool `json:"is_daemon"`
  348. // swagger:ignore
  349. // 创建虚拟机数量
  350. // default: 1
  351. Count int `json:"count"`
  352. // 磁盘列表,第一块磁盘为系统盘,需要指定image_id
  353. // 若指定主机快照,此参数可以为空
  354. // required: true
  355. Disks []*DiskConfig `json:"disks"`
  356. // 指定主机网络
  357. // required: false
  358. Networks []*NetworkConfig `json:"nets"`
  359. // 调度标签
  360. // required: false
  361. Schedtags []*SchedtagConfig `json:"schedtags"`
  362. // 透传设备列表
  363. // required: false
  364. IsolatedDevices []*IsolatedDeviceConfig `json:"isolated_devices"`
  365. // 裸金属磁盘配置列表
  366. BaremetalDiskConfigs []*BaremetalDiskConfig `json:"baremetal_disk_configs"`
  367. // 裸金属系统盘匹配器
  368. BaremetalRootDiskMatcher *BaremetalRootDiskMatcher `json:"baremetal_root_disk_matcher"`
  369. // 主机组列表, 参数可以是主机组名称或ID,建议使用ID
  370. InstanceGroupIds []string `json:"groups"`
  371. // DEPRECATE
  372. Suggestion bool `json:"suggestion"`
  373. }
  374. func NewServerConfigs() *ServerConfigs {
  375. return &ServerConfigs{
  376. Disks: make([]*DiskConfig, 0),
  377. Networks: make([]*NetworkConfig, 0),
  378. Schedtags: make([]*SchedtagConfig, 0),
  379. IsolatedDevices: make([]*IsolatedDeviceConfig, 0),
  380. BaremetalDiskConfigs: make([]*BaremetalDiskConfig, 0),
  381. InstanceGroupIds: make([]string, 0),
  382. }
  383. }
  384. type DeployConfig struct {
  385. Action string `json:"action"`
  386. Path string `json:"path"`
  387. Content string `json:"content"`
  388. }
  389. // KickstartConfig Kickstart/Autoinstall自动化安装配置
  390. type KickstartConfig struct {
  391. // 配置文件内容 (当用户直接提供配置时使用)
  392. // required: false
  393. Config string `json:"config,omitempty"`
  394. // 配置文件 URL (当配置文件位于外部服务器时使用)
  395. // required: false
  396. ConfigURL string `json:"config_url,omitempty"`
  397. // 操作系统类型 (用于确定内核参数和文件路径)
  398. // enum: ["centos", "rhel", "fedora", "openeuler", "ubuntu"]
  399. // required: true
  400. OSType string `json:"os_type" validate:"required,oneof=centos rhel fedora openeuler ubuntu"`
  401. // 是否启用 (用于临时禁用而不删除配置)
  402. // default: true
  403. // required: false
  404. Enabled *bool `json:"enabled,omitempty"`
  405. // 最大重试次数
  406. // default: 3
  407. // required: false
  408. MaxRetries int `json:"max_retries,omitempty"`
  409. // 安装超时时间 (分钟)
  410. // default: 60
  411. // required: false
  412. TimeoutMinutes int `json:"timeout_minutes,omitempty"`
  413. }
  414. type ServerCreateInput struct {
  415. apis.VirtualResourceCreateInput
  416. DeletePreventableCreateInput
  417. HostnameInput
  418. *ServerConfigs
  419. apis.EncryptedResourceCreateInput
  420. // 虚拟机内存大小,单位Mb,若未指定instance_type,此参数为必传项
  421. VmemSize int `json:"vmem_size"`
  422. EnableMemclean bool `json:"enable_memclean"`
  423. // 虚拟机Cpu大小,若未指定instance_type,此参数为必传项
  424. // default: 1
  425. VcpuCount int `json:"vcpu_count"`
  426. // cpu卡槽数
  427. // 目前仅vmware支持此参数
  428. // default: 1
  429. CpuSockets int `json:"cpu_sockets"`
  430. // 额外分配 cpu 数量
  431. // required: false
  432. ExtraCpuCount int `json:"extra_cpu_count"`
  433. // 用户自定义启动脚本
  434. // 支持 #cloud-config yaml 格式及shell脚本
  435. // 支持特殊user data平台: Aliyun, Qcloud, Azure, Apsara, Ucloud
  436. // required: false
  437. UserData string `json:"user_data"`
  438. // swagger:ignore
  439. // 创建测试数据,不实际创建资源
  440. FakeCreate bool `json:"fake_create"`
  441. // swagger:ignore
  442. // Deprecated
  443. Keypair string `json:"keypair" yunion-deprecated-by:"keypair_id"`
  444. // 秘钥对Id
  445. // required: false
  446. KeypairId string `json:"keypair_id"`
  447. // 密码
  448. // 要求: 密码长度 >= 20, 至少包含一个数字一个小写字母一个大小字母及特殊字符~`!@#$%^&*()-_=+[]{}|:';\",./<>?中的一个
  449. // requried: false
  450. Password string `json:"password"`
  451. // 登录账户
  452. // required: false
  453. LoginAccount string `json:"login_account"`
  454. // 使用ISO光盘启动, 仅KVM平台支持
  455. // required: false
  456. Cdrom string `json:"cdrom"`
  457. CdromBootIndex *int8 `json:"cdrom_boot_index"`
  458. // enum: ["cirros", "vmware", "qxl", "std"]
  459. // default: std
  460. Vga string `json:"vga"`
  461. // 远程连接协议
  462. // enum: ["vnc", "spice"]
  463. // default: vnc
  464. Vdi string `json:"vdi"`
  465. // BIOS类型, 若镜像是Windows,并且支持UEFI,则自动会设置为UEFI
  466. // emulate: BIOS, UEFI
  467. Bios string `json:"bios"`
  468. EnableTpm bool `json:"enable_tpm"`
  469. // Machine类型
  470. // emulate: pc, q35
  471. Machine string `json:"machine"`
  472. // 启动顺序
  473. // c: cdrome
  474. // d: disk
  475. // n: network
  476. // example: cnd
  477. // default: cdn
  478. BootOrder string `json:"boot_order"`
  479. // 启用cloud-init,需要镜像装有cloud-init服务
  480. // default: false
  481. EnableCloudInit bool `json:"enable_cloud_init"`
  482. // 随机密码, 若指定password参数,此参数不生效
  483. // 若值为false并且password为空,则表示保留镜像密码
  484. ResetPassword *bool `json:"reset_password"`
  485. // 关机后执行的操作
  486. // terminate: 关机后自动删除
  487. // enum: ["stop", "terminate", "stop_release_gpu"]
  488. // default: stop
  489. ShutdownBehavior string `json:"shutdown_behavior"`
  490. // 创建后自动启动
  491. // 部分云创建后会自动启动例如: 腾讯云, AWS, OpenStack, ZStack, Ucloud, Huawei, Azure, 天翼云
  492. // default: false
  493. AutoStart bool `json:"auto_start"`
  494. DeployConfigs []*DeployConfig `json:"deploy_configs"`
  495. DeployTelegraf bool `json:"deploy_telegraf"`
  496. // 包年包月时长
  497. //
  498. //
  499. // |平台 |是否支持 |
  500. // |---- |------- |
  501. // |KVM |否 |
  502. // |ESxi |否 |
  503. // |OpenStack |否 |
  504. // |ZStack |否 |
  505. // |Google |否 |
  506. // |Azure |否 |
  507. // |AWS |否 |
  508. // |腾讯云 |是 |
  509. // |Aliyun |是 |
  510. // |Ucloud |是 |
  511. // |Huawei |是 |
  512. // |天翼云 |是 |
  513. Duration string `json:"duration"`
  514. // 是否自动续费
  515. // default: false
  516. AutoRenew bool `json:"auto_renew"`
  517. // swagger:ignore
  518. AutoPrepaidRecycle bool `json:"auto_prepaid_recycle,omitfalse"`
  519. // 弹性公网IP带宽
  520. // 指定此参数后会创建新的弹性公网IP并绑定到新建的虚拟机
  521. // 此参数优先级低于public_ip
  522. EipBw int `json:"eip_bw,omitzero"`
  523. // 弹性公网IP线路类型
  524. EipBgpType string `json:"eip_bgp_type,omitzero"`
  525. // 弹性公网IP计费类型
  526. EipChargeType billing_api.TNetChargeType `json:"eip_charge_type,omitempty"`
  527. // 是否跟随主机删除而自动释放
  528. EipAutoDellocate bool `json:"eip_auto_dellocate,omitempty"`
  529. // 弹性公网IP名称或ID
  530. // 绑定已有弹性公网IP, 此参数会限制虚拟机再谈下公网IP所在的区域创建
  531. // required: false
  532. Eip string `json:"eip,omitempty"`
  533. // 公网IP带宽(单位MB)
  534. // 若指定此参数则忽略eip相关参数
  535. // 私有云不支持此参数
  536. //
  537. //
  538. // |平台 |支持范围 |
  539. // |---- |------- |
  540. // |腾讯云 |按量计费1-100, 包年包月1-200 |
  541. PublicIpBw int `json:"public_ip_bw,omitzero"`
  542. // 公网IP计费类型
  543. // 默认按流量计费
  544. //
  545. //
  546. // |类别 |说明 |
  547. // |---- |------- |
  548. // |traffic |按流量计费|
  549. // |bandwidth |按带宽计费|
  550. PublicIpChargeType billing_api.TNetChargeType `json:"public_ip_charge_type,omitempty"`
  551. // 使用主机快照创建虚拟机, 主机快照不会重置密码及秘钥信息
  552. // 使用主机快照创建的虚拟机将沿用之前的密码秘钥及安全组信息
  553. // required: false
  554. InstanceSnapshotId string `json:"instance_snapshot_id,omitempty"`
  555. // 使用主机备份创建虚拟机, 主机快照不会重置密码及秘钥信息
  556. // 使用主机备份创建的虚拟机将沿用之前的密码秘钥及安全组信息
  557. // required: false
  558. InstanceBackupId string `json:"instance_backup_id,omitempty"`
  559. // 安全组Id, 此参数会和secgroups参数合并
  560. SecgroupId string `json:"secgrp_id"`
  561. // 安全组Id列表
  562. Secgroups []string `json:"secgroups"`
  563. // swagger:ignore
  564. OsType string `json:"os_type"`
  565. // swagger:ignore
  566. OsArch string `json:"os_arch"`
  567. // swagger:ignore
  568. DisableUsbKbd bool `json:"disable_usb_kbd"`
  569. // swagger:ignore
  570. OsProfile jsonutils.JSONObject `json:"__os_profile__"`
  571. // swagger:ignore
  572. BillingType billing_api.TBillingType `json:"billing_type"`
  573. // swagger:ignore
  574. BillingCycle string `json:"billing_cycle"`
  575. // 到期释放时间
  576. ReleaseAt time.Time `json:"release_at"`
  577. // swagger:ignore
  578. // Deprecated
  579. // 此参数等同于 hypervisor=baremetal
  580. Baremetal bool `json:"baremetal"`
  581. // Used to store BaremetalConvertHypervisorTaskId
  582. ParentTaskId string `json:"__parent_task_id,omitempty"`
  583. // 指定系统盘默认存储类型, 如果指定宿主机
  584. // swagger:ignore
  585. DefaultStorageType string `json:"default_storage_type,omitempty"`
  586. // 指定用于新建主机的主机镜像ID
  587. GuestImageID string `json:"guest_image_id"`
  588. // Kickstart/Autoinstall自动化安装配置
  589. // required: false
  590. KickstartConfig *KickstartConfig `json:"kickstart_config,omitempty"`
  591. Pod *PodCreateInput `json:"pod"`
  592. }
  593. func (c *KickstartConfig) IsEnabled() bool {
  594. if c.Enabled != nil && !*c.Enabled {
  595. return false
  596. }
  597. return true
  598. }
  599. // ServerUpdateKickstartStatusInput 更新虚拟机 kickstart 状态的输入
  600. type ServerUpdateKickstartStatusInput struct {
  601. // kickstart 状态
  602. // enum: ["kickstart_pending", "kickstart_installing", "kickstart_completed", "kickstart_failed"]
  603. // required: true
  604. Status string `json:"status" validate:"required,oneof=kickstart_pending kickstart_installing kickstart_completed kickstart_failed"`
  605. // 错误信息(可选)
  606. // required: false
  607. ErrorMessage string `json:"error_message,omitempty"`
  608. }
  609. func (input *ServerCreateInput) AfterUnmarshal() {
  610. if input.Baremetal {
  611. input.Hypervisor = HYPERVISOR_BAREMETAL
  612. }
  613. }
  614. type ServerCloneInput struct {
  615. apis.Meta
  616. Name string `json:"name"`
  617. AutoStart bool `json:"auto_start"`
  618. EipBw int `json:"eip_bw,omitzero"`
  619. EipChargeType string `json:"eip_charge_type,omitempty"`
  620. Eip string `json:"eip,omitempty"`
  621. PreferHostId string `json:"prefer_host_id"`
  622. }
  623. type GuestBatchMigrateRequest struct {
  624. apis.Meta
  625. GuestIds []string `json:"guest_ids"`
  626. PreferHostId string `json:"prefer_host_id"`
  627. // Deprecated
  628. // swagger:ignore
  629. PreferHost string `json:"prefer_host" yunion-deprecated-by:"prefer_host_id"`
  630. SkipCpuCheck bool `json:"skip_cpu_check"`
  631. SkipKernelCheck bool `json:"skip_kernel_check"`
  632. EnableTLS *bool `json:"enable_tls"`
  633. MaxBandwidthMb *int64 `json:"max_bandwidth_mb"`
  634. QuciklyFinish *bool `json:"quickly_finish"`
  635. }
  636. type GuestBatchMigrateParams struct {
  637. Id string `json:"id"`
  638. LiveMigrate bool `json:"live_migrate"`
  639. SkipCpuCheck bool `json:"skip_cpu_check"`
  640. SkipKernelCheck bool `json:"skip_kernel_check"`
  641. EnableTLS *bool `json:"enable_tls"`
  642. RescueMode bool `json:"rescue_mode"`
  643. OldStatus string `json:"old_status"`
  644. MaxBandwidthMb *int64 `json:"max_bandwidth_mb"`
  645. QuciklyFinish *bool `json:"quickly_finish"`
  646. }
  647. type HostLoginInfo struct {
  648. apis.Meta
  649. Username string `json:"username"`
  650. Password string `json:"password"`
  651. Ip string `json:"ip"`
  652. }