guests.go 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582
  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. "time"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/pkg/errors"
  20. "yunion.io/x/onecloud/pkg/apis"
  21. "yunion.io/x/onecloud/pkg/apis/billing"
  22. billing_api "yunion.io/x/onecloud/pkg/apis/billing"
  23. "yunion.io/x/onecloud/pkg/apis/host"
  24. imageapi "yunion.io/x/onecloud/pkg/apis/image"
  25. "yunion.io/x/onecloud/pkg/httperrors"
  26. )
  27. type ServerListInput struct {
  28. apis.VirtualResourceListInput
  29. apis.ExternalizedResourceBaseListInput
  30. apis.DeletePreventableResourceBaseListInput
  31. apis.MultiArchResourceBaseListInput
  32. HostFilterListInput
  33. NetworkFilterListInput `yunion-ambiguous-prefix:"vpc_"`
  34. billing.BillingResourceListInput
  35. GroupFilterListInput
  36. SecgroupFilterListInput
  37. //DiskFilterListInput `yunion-ambiguous-prefix:"storage_"`
  38. ScalingGroupFilterListInput
  39. // 只列出裸金属主机
  40. Baremetal *bool `json:"baremetal"`
  41. // 只列出透传了 GPU 的主机
  42. Gpu *bool `json:"gpu"`
  43. // 只列出透传了 USB 的主机
  44. Usb *bool `json:"usb"`
  45. // 自定义 PCI 设备类型
  46. CustomDevType string `json:"custom_dev_type"`
  47. // 通用虚拟机
  48. Normal *bool `json:"normal"`
  49. // 只列出还有备份机的主机
  50. Backup *bool `json:"bakcup"`
  51. // 列出指定类型的主机
  52. // enum: ["normal","gpu","usb","backup"]
  53. ServerType []string `json:"server_type"`
  54. // 列出管理安全组为指定安全组的主机
  55. AdminSecgroup string `json:"admin_security"`
  56. // 列出Hypervisor为指定值的主机
  57. // enum: ["kvm","esxi","baremetal","aliyun","azure","aws","huawei","ucloud","zstack","openstack","google","ctyun","cloudpods","ecloud","jdcloud","remotefile"]
  58. Hypervisor []string `json:"hypervisor"`
  59. // 列出绑定了弹性IP(EIP)的主机
  60. WithEip *bool `json:"with_eip"`
  61. // 列出未绑定弹性IP(EIP)的主机
  62. WithoutEip *bool `json:"without_eip"`
  63. // 列出可绑定弹性IP的主机
  64. EipAssociable *bool `json:"eip_associable"`
  65. // 列出操作系统为指定值的主机
  66. // enum: ["linux","windows","vmware"]
  67. OsType []string `json:"os_type"`
  68. // 操作系统发行版
  69. OsDist []string `json:"os_dist"`
  70. // 对列表结果按照磁盘大小进行排序
  71. // enum: ["asc","desc"]
  72. OrderByDisk string `json:"order_by_disk"`
  73. OrderByIp string `json:"order_by_ip"`
  74. // 根据ip查找机器
  75. // swagger:ignore
  76. IpAddr string `json:"ip_addr" yunion-deprecated-by:"ip_addrs"`
  77. // 根据多个ip查找机器
  78. IpAddrs []string `json:"ip_addrs"`
  79. // 列出可以挂载指定EIP的主机
  80. UsableServerForEip string `json:"usable_server_for_eip"`
  81. // 列出可以挂载磁盘的主机
  82. AttachableServersForDisk string `json:"attachable_servers_for_disk"`
  83. // Deprecated
  84. // 列出可以挂载磁盘的主机
  85. // swagger:ignore
  86. Disk string `json:"disk" yunion-deprecated-by:"attachable_servers_for_disk"`
  87. // 按主机资源类型进行排序
  88. // enum: ["shared","prepaid","dedicated"]
  89. ResourceType string `json:"resource_type"`
  90. // 返回该宿主机上的所有虚拟机,包括备份机
  91. GetAllGuestsOnHost string `json:"get_all_guests_on_host"`
  92. // 根据宿主机 SN 过滤
  93. // HostSn string `json:"host_sn"`
  94. VcpuCount []int `json:"vcpu_count"`
  95. VmemSize []int `json:"vmem_size"`
  96. BootOrder []string `json:"boot_order"`
  97. Vga []string `json:"vga"`
  98. Vdi []string `json:"vdi"`
  99. Machine []string `json:"machine"`
  100. Bios []string `json:"bios"`
  101. SrcIpCheck *bool `json:"src_ip_check"`
  102. SrcMacCheck *bool `json:"src_mac_check"`
  103. InstanceType []string `json:"instance_type"`
  104. // 根据镜像发行版排序
  105. OrderByOsDist string `json:"order_by_os_dist"`
  106. SnapshotpolicyId string `json:"snapshotpolicy_id"`
  107. // 是否调度到宿主机上
  108. WithHost *bool `json:"with_host"`
  109. // 根据是否绑定快照策略过滤
  110. BindingSnapshotpolicy *bool `json:"binding_snapshotpolicy"`
  111. // 根据虚机关联的磁盘是否绑定快照策略过滤
  112. BindingDisksSnapshotpolicy *bool `json:"binding_disks_snapshotpolicy"`
  113. }
  114. // 主机快照策略绑定/设置接口入参
  115. type ServerSnapshotpolicyInput struct {
  116. // 快照策略ID
  117. SnapshotpolicyId string `json:"snapshotpolicy_id"`
  118. }
  119. func (input *ServerListInput) AfterUnmarshal() {
  120. if input.Baremetal != nil && *input.Baremetal {
  121. input.Hypervisor = append(input.Hypervisor, HYPERVISOR_BAREMETAL)
  122. }
  123. }
  124. type ServerRebuildRootInput struct {
  125. apis.Meta
  126. // swagger:ignore
  127. Image string `json:"image" yunion-deprecated-by:"image_id"`
  128. // 关机且停机不收费情况下不允许重装系统
  129. // 镜像 id
  130. // required: true
  131. ImageId string `json:"image_id"`
  132. // swagger:ignore
  133. // Keypair string `json:"keypair" yunion-deprecated-by:"keypair_id"`
  134. // 秘钥Id
  135. // KeypairId string `json:"keypair_id"`
  136. // ResetPassword *bool `json:"reset_password"`
  137. // Password string `json:"password"`
  138. AutoStart *bool `json:"auto_start"`
  139. AllDisks *bool `json:"all_disks"`
  140. ServerDeployInputBase
  141. }
  142. type ServerResumeInput struct {
  143. apis.Meta
  144. }
  145. type ServerDetails struct {
  146. apis.VirtualResourceDetails
  147. apis.EncryptedResourceDetails
  148. SGuest
  149. HostResourceInfo
  150. // details
  151. // 网络概要
  152. Networks string `json:"networks"`
  153. // 磁盘概要
  154. Disks string `json:"disks"`
  155. // 主机快照策略数量
  156. SnapshotpolicyCount int `json:"snapshotpolicy_count"`
  157. // 磁盘快照策略数量
  158. DisksSnapshotpolicyCount int `json:"disks_snapshotpolicy_count"`
  159. // 磁盘详情
  160. DisksInfo []GuestDiskInfo `json:"disks_info"`
  161. // 虚拟机Ip列表
  162. VirtualIps string `json:"virtual_ips"`
  163. // 安全组规则
  164. SecurityRules string `json:"security_rules"`
  165. // 操作系统名称
  166. OsName string `json:"os_name"`
  167. // 系统管理员可见的安全组规则
  168. AdminSecurityRules string `json:"admin_security_rules"`
  169. // common
  170. IsPrepaidRecycle bool `json:"is_prepaid_recycle"`
  171. // 主备机信息
  172. BackupInfo
  173. // 是否可以回收
  174. CanRecycle bool `json:"can_recycle"`
  175. // 自动释放时间
  176. AutoDeleteAt time.Time `json:"auto_delete_at"`
  177. // 磁盘数量
  178. DiskCount int `json:"disk_count"`
  179. // 是否支持ISO启动
  180. CdromSupport bool `json:"cdrom_support"`
  181. //是否支持Floppy启动
  182. FloppySupport bool `json:"floppy_support"`
  183. // 磁盘大小
  184. // example:30720
  185. DiskSizeMb int64 `json:"disk"`
  186. // IP地址列表字符串
  187. // example: 10.165.2.1,172.16.8.1
  188. IPs string `json:"ips"`
  189. // VIP
  190. Vip string `json:"vip"`
  191. // VIP's eip
  192. VipEip string `json:"vip_eip"`
  193. // mac地址信息
  194. Macs string `json:"macs"`
  195. // 网卡信息
  196. Nics []GuestnetworkShortDesc `json:"nics"`
  197. // 附属IP
  198. SubIPs []string `json:"sub_ips"`
  199. // 归属VPC
  200. Vpc string `json:"vpc"`
  201. // 归属VPC ID
  202. VpcId string `json:"vpc_id"`
  203. // Vpc外网访问模式
  204. VpcExternalAccessMode string `json:"vpc_external_access_mode"`
  205. // 关联安全组列表
  206. Secgroups []apis.StandaloneShortDesc `json:"secgroups"`
  207. // 关联主安全组
  208. Secgroup string `json:"secgroup"`
  209. // 网卡级别安全组
  210. NetworkSecgroups []GuestnetworkSecgroupShortDesc `json:"network_secgroups"`
  211. // 浮动IP
  212. Eip string `json:"eip"`
  213. // 浮动IP类型
  214. EipMode string `json:"eip_mode"`
  215. // 密钥对
  216. Keypair string `json:"keypair"`
  217. // 直通设备(GPU)列表
  218. IsolatedDevices []SIsolatedDevice `json:"isolated_devices"`
  219. // 是否支持GPU
  220. IsGpu bool `json:"is_gpu"`
  221. GpuModel string `json:"gpu_model"`
  222. GpuCount string `json:"gpu_count"`
  223. // Cdrom信息
  224. Cdrom []Cdrom `json:"cdrom"`
  225. //Floppy信息
  226. Floppy []Floppy `json:"floppy"`
  227. // 主机在伸缩组中的状态
  228. ScalingStatus string `json:"scaling_status"`
  229. // 伸缩组id
  230. ScalingGroupId string `json:"scaling_group_id"`
  231. // 监控上报URL
  232. MonitorUrl string `json:"monitor_url"`
  233. // 容器描述信息
  234. Containers []*PodContainerDesc `json:"containers"`
  235. }
  236. type BackupInfo struct {
  237. // 备份主机所在宿主机名称
  238. BackupHostName string `json:"backup_host_name"`
  239. // 备份主机所在宿主机状态
  240. BackupHostStatus string `json:"backup_host_status"`
  241. // 主备机同步状态
  242. BackupGuestSyncStatus string `json:"backup_guest_sync_status"`
  243. }
  244. type PodContainerDesc struct {
  245. Id string `json:"id"`
  246. Name string `json:"name"`
  247. Image string `json:"image"`
  248. Status string `json:"status"`
  249. }
  250. type Floppy struct {
  251. Ordinal int `json:"ordinal"`
  252. Detail string `json:"detail"`
  253. }
  254. type Cdrom struct {
  255. Ordinal int `json:"ordinal"`
  256. Detail string `json:"detail"`
  257. Name string `json:"name"`
  258. BootIndex int8 `json:"boot_index"`
  259. }
  260. type IMetricResource interface {
  261. GetMetricTags() map[string]string
  262. }
  263. func AppendMetricTags(ret map[string]string, res ...IMetricResource) map[string]string {
  264. if ret == nil {
  265. ret = map[string]string{}
  266. }
  267. for _, r := range res {
  268. for k, v := range r.GetMetricTags() {
  269. ret[k] = v
  270. }
  271. }
  272. return ret
  273. }
  274. func (self ServerDetails) GetMetricTags() map[string]string {
  275. ret := map[string]string{
  276. "id": self.Id,
  277. "res_type": "guest",
  278. "is_vm": "true",
  279. "paltform": self.Hypervisor,
  280. "host": self.Host,
  281. "host_id": self.HostId,
  282. "ips": self.IPs,
  283. "vm_ip": self.IPs,
  284. "vm_id": self.Id,
  285. "vm_name": self.Name,
  286. "zone": self.Zone,
  287. "zone_id": self.ZoneId,
  288. "zone_ext_id": self.ZoneExtId,
  289. "os_type": self.OsType,
  290. "status": self.Status,
  291. "cloudregion": self.Cloudregion,
  292. "cloudregion_id": self.CloudregionId,
  293. "region_ext_id": self.RegionExtId,
  294. "tenant": self.Project,
  295. "tenant_id": self.ProjectId,
  296. "brand": self.Brand,
  297. "vm_scaling_group_id": self.ScalingGroupId,
  298. "domain_id": self.DomainId,
  299. "project_domain": self.ProjectDomain,
  300. "account": self.Account,
  301. "account_id": self.AccountId,
  302. "external_id": self.ExternalId,
  303. }
  304. if len(self.HostAccessIp) > 0 {
  305. ret["host_ip"] = self.HostAccessIp
  306. }
  307. return AppendMetricTags(ret, self.MetadataResourceInfo, self.ProjectizedResourceInfo)
  308. }
  309. func (self ServerDetails) GetMetricPairs() map[string]string {
  310. ret := map[string]string{
  311. "vcpu_count": fmt.Sprintf("%d", self.VcpuCount),
  312. "vmem_size": fmt.Sprintf("%d", self.VmemSize),
  313. "disk": fmt.Sprintf("%d", self.DiskSizeMb),
  314. }
  315. return ret
  316. }
  317. // GuestDiskInfo describe the information of disk on the guest.
  318. type GuestDiskInfo struct {
  319. Id string `json:"id"`
  320. Name string `json:"name"`
  321. FsFormat string `json:"fs,omitempty"`
  322. DiskType string `json:"disk_type"`
  323. Index int8 `json:"index"`
  324. BootIndex int8 `json:"boot_index"`
  325. SizeMb int `json:"size"`
  326. DiskFormat string `json:"disk_format"`
  327. Driver string `json:"driver"`
  328. CacheMode string `json:"cache_mode"`
  329. AioMode string `json:"aio_mode"`
  330. AutoReset bool `json:"auto_reset"`
  331. MediumType string `json:"medium_type"`
  332. StorageType string `json:"storage_type"`
  333. Iops int `json:"iops"`
  334. Throughput int `json:"throughput"`
  335. Bps int `json:"bps"`
  336. ImageId string `json:"image_id,omitempty"`
  337. Image string `json:"image,omitemtpy"`
  338. StorageId string `json:"storage_id"`
  339. Preallocation string `json:"preallocation"`
  340. }
  341. func (self GuestDiskInfo) ShortDesc() string {
  342. fs := ""
  343. if len(self.ImageId) > 0 {
  344. fs = "root"
  345. } else if len(self.FsFormat) > 0 {
  346. fs = self.FsFormat
  347. } else {
  348. fs = "none"
  349. }
  350. return fmt.Sprintf("disk%d:%dM/%s/%s/%s/%s/%s", self.Index, self.SizeMb,
  351. self.DiskFormat, self.Driver, self.CacheMode, self.AioMode, fs)
  352. }
  353. type GuestJointResourceDetails struct {
  354. apis.VirtualJointResourceBaseDetails
  355. // 云主机名称
  356. Guest string `json:"guest"`
  357. // 云主机名称
  358. Server string `json:"server"`
  359. }
  360. type GuestJointsListInput struct {
  361. apis.VirtualJointResourceBaseListInput
  362. ServerFilterListInput
  363. }
  364. type GuestResourceInfo struct {
  365. // 虚拟机名称
  366. Guest string `json:"guest"`
  367. // 虚拟机状态
  368. GuestStatus string `json:"guest_status"`
  369. // 宿主机ID
  370. HostId string `json:"host_id"`
  371. HostResourceInfo
  372. }
  373. type ServerResourceInput struct {
  374. // 主机(ID或Name)
  375. ServerId string `json:"server_id"`
  376. // swagger:ignore
  377. // Deprecated
  378. // Filter by guest Id
  379. Server string `json:"server" yunion-deprecated-by:"server_id"`
  380. // swagger:ignore
  381. // Deprecated
  382. // Filter by guest Id
  383. Guest string `json:"guest" yunion-deprecated-by:"server_id"`
  384. // swagger:ignore
  385. // Deprecated
  386. // Filter by guest Id
  387. GuestId string `json:"guest_id" yunion-deprecated-by:"server_id"`
  388. }
  389. type ServerFilterListInput struct {
  390. HostFilterListInput
  391. ServerResourceInput
  392. // 以主机名称排序
  393. OrderByServer string `json:"order_by_server"`
  394. }
  395. type GuestJointBaseUpdateInput struct {
  396. apis.VirtualJointResourceBaseUpdateInput
  397. }
  398. type GuestPublicipToEipInput struct {
  399. // 转换完成后是否自动启动
  400. // default: false
  401. AutoStart bool `json:"auto_start"`
  402. }
  403. type GuestAutoRenewInput struct {
  404. // 设置自动续费
  405. // default: false
  406. // 自动续费分为本地和云上两种模式
  407. // 若公有云本身支持自动续费功能, 则使用云上设置
  408. // 若公有云本身不支持自动续费, 则在本地周期(默认三小时)检查快过期虚拟机并进行续费,续费周期根据设置,请避免使用特殊的计费周期,避免续费失败
  409. AutoRenew bool `json:"auto_renew"`
  410. // 续费周期
  411. // example: 1Y, 1M, 1W
  412. // default: 1M
  413. // 腾讯云仅支持1M
  414. // 阿里云支持 1, 2, 3Y, 1, 2, 3, 6, 12M, 1, 2, 3, 4W
  415. Duration string `json:"duration"`
  416. }
  417. type ConvertToKvmInput struct {
  418. apis.Meta
  419. // target hypervisor
  420. TargetHypervisor string `json:"target_hypervisor"`
  421. // 指定转换的宿主机
  422. PreferHost string `json:"prefer_host"`
  423. // dest guest network configs
  424. Networks []*NetworkConfig `json:"networks"`
  425. // deploy telegraf after convert
  426. DeployTelegraf bool `json:"deploy_telegraf"`
  427. }
  428. type BatchConvertToKvmCheckInput struct {
  429. GuestIds []string `json:"guest_ids"`
  430. }
  431. type GuestSaveToTemplateInput struct {
  432. // The name of guest template
  433. Name string `json:"name"`
  434. // The generate name of guest template
  435. GenerateName string `json:"generate_name"`
  436. }
  437. type GuestSyncFixNicsInput struct {
  438. // 需要修正的IP地址列表
  439. Ip []string `json:"ip"`
  440. }
  441. type GuestMigrateInput struct {
  442. // swagger:ignore
  443. PreferHost string `json:"prefer_host" yunion-deprecated-by:"prefer_host_id"`
  444. PreferHostId string `json:"prefer_host_id"`
  445. AutoStart bool `json:"auto_start"`
  446. IsRescueMode bool `json:"rescue_mode"`
  447. }
  448. type GuestLiveMigrateInput struct {
  449. // swagger:ignore
  450. PreferHost string `json:"prefer_host" yunion-deprecated-by:"prefer_host_id"`
  451. // 指定期望的迁移目标宿主机
  452. PreferHostId string `json:"prefer_host_id"`
  453. // 是否跳过CPU检查,默认要做CPU检查
  454. SkipCpuCheck *bool `json:"skip_cpu_check"`
  455. // 是否跳过kernel检查
  456. SkipKernelCheck *bool `json:"skip_kernel_check"`
  457. // 是否启用 tls
  458. EnableTLS *bool `json:"enable_tls"`
  459. // 迁移带宽限制
  460. MaxBandwidthMb *int64 `json:"max_bandwidth_mb"`
  461. // 快速完成,内存同步一定周期后调整 downtime
  462. QuicklyFinish *bool `json:"quickly_finish"`
  463. KeepDestGuestOnFailed *bool `json:"keep_dest_guest_on_failed"`
  464. }
  465. type GuestSetSecgroupInput struct {
  466. // 安全组Id列表
  467. // 实例必须处于运行,休眠或者关机状态
  468. //
  469. //
  470. // | 平台 | 最多绑定安全组数量 |
  471. // |-------------|------------------- |
  472. // | Azure | 1 |
  473. // | VMware | 不支持安全组 |
  474. // | Baremetal | 不支持安全组 |
  475. // | ZStack | 1 |
  476. // | 其他 | 5 |
  477. SecgroupIds []string `json:"secgroup_ids"`
  478. }
  479. type GuestSetNetworkSecgroupInput struct {
  480. // 安全组Id列表
  481. // 实例必须处于运行,休眠或者关机状态
  482. SecgroupIds []string `json:"secgroup_ids"`
  483. // 虚机网卡 index 或者 mac 地址
  484. NetworkIndex *int `json:"network_index"`
  485. MacAddr string `json:"mac_addr"`
  486. }
  487. type GuestRevokeSecgroupInput struct {
  488. // 安全组Id列表
  489. // 实例必须处于运行,休眠或者关机状态
  490. SecgroupIds []string `json:"secgroup_ids"`
  491. }
  492. type GuestRevokeNetworkSecgroupInput struct {
  493. // 安全组Id列表
  494. // 实例必须处于运行,休眠或者关机状态
  495. SecgroupIds []string `json:"secgroup_ids"`
  496. // 虚机网卡 index 或者 mac 地址
  497. NetworkIndex *int `json:"network_index"`
  498. MacAddr string `json:"mac_addr"`
  499. }
  500. type GuestAssignSecgroupInput struct {
  501. // 安全组Id
  502. // 实例必须处于运行,休眠或者关机状态
  503. SecgroupId string `json:"secgroup_id"`
  504. // swagger:ignore
  505. // Deprecated
  506. Secgrp string `json:"secgrp" yunion-deprecated-by:"secgroup_id"`
  507. // swagger:ignore
  508. // Deprecated
  509. Secgroup string `json:"secgroup" yunion-deprecated-by:"secgroup_id"`
  510. }
  511. type GuestAddSecgroupInput struct {
  512. // 安全组Id列表
  513. // 实例必须处于运行,休眠或者关机状态
  514. //
  515. //
  516. // | 平台 | 最多绑定安全组数量 |
  517. // |-------------|------------------- |
  518. // | Azure | 1 |
  519. // | VMware | 不支持安全组 |
  520. // | Baremetal | 不支持安全组 |
  521. // | ZStack | 1 |
  522. // | 其他 | 5 |
  523. SecgroupIds []string `json:"secgroup_ids"`
  524. }
  525. type GuestNetworkAddSecgroupInput struct {
  526. SecgroupIds []string `json:"secgroup_ids"`
  527. NetworkIndex *int `json:"network_index"`
  528. }
  529. type ServerRemoteUpdateInput struct {
  530. // 是否覆盖替换所有标签
  531. ReplaceTags *bool `json:"replace_tags" help:"replace all remote tags"`
  532. }
  533. type ServerAssociateEipInput struct {
  534. // swagger:ignore
  535. // Deprecated
  536. Eip string `json:"eip" yunion-deprecated-by:"eip_id"`
  537. // 弹性公网IP的ID
  538. EipId string `json:"eip_id"`
  539. // 弹性IP映射的内网IP地址,可选
  540. IpAddr string `json:"ip_addr"`
  541. }
  542. type ServerCreateEipInput struct {
  543. // 计费方式,traffic or bandwidth
  544. ChargeType billing_api.TNetChargeType `json:"charge_type"`
  545. // Bandwidth
  546. Bandwidth int64 `json:"bandwidth"`
  547. // bgp_type
  548. BgpType string `json:"bgp_type"`
  549. // auto_dellocate
  550. AutoDellocate *bool `json:"auto_dellocate"`
  551. // 弹性IP映射的内网IP地址,可选
  552. IpAddr string `json:"ip_addr"`
  553. }
  554. type ServerDissociateEipInput struct {
  555. // 是否自动释放
  556. AudoDelete *bool `json:"auto_delete"`
  557. }
  558. type ServerResetInput struct {
  559. InstanceSnapshot string `json:"instance_snapshot"`
  560. // 自动启动
  561. AutoStart *bool `json:"auto_start"`
  562. // 恢复内存
  563. WithMemory bool `json:"with_memory"`
  564. }
  565. type ServerStopInput struct {
  566. // 是否强制关机
  567. IsForce bool `json:"is_force"`
  568. // 关机等待时间,如果是强制关机,则等待时间为0,如果不设置,默认为30秒
  569. TimeoutSecs int `json:"timeout_secs"`
  570. // 是否关机停止计费, 若平台不支持停止计费,此参数无作用
  571. // 若包年包月机器关机设置此参数,则先转换计费模式到按量计费,再关机不收费
  572. // 目前仅阿里云,腾讯云此参数生效
  573. StopCharging bool `json:"stop_charging"`
  574. }
  575. type ServerSaveImageInput struct {
  576. // 镜像名称
  577. Name string `json:"name"`
  578. GenerateName string `json:"generate_name"`
  579. Notes string `json:"notes"`
  580. IsPublic *bool `json:"is_public"`
  581. // 镜像格式
  582. Format string `json:"format"`
  583. // 保存镜像后是否自动启动,若实例状态为运行中,则会先关闭实例
  584. // 公有云若支持开机保存镜像,此参数则不生效
  585. // default: false
  586. AutoStart bool `json:"auto_start"`
  587. // swagger:ignore
  588. Restart bool `json:"restart"`
  589. // swagger:ignore
  590. OsType string `json:"os_type"`
  591. // swagger:ignore
  592. OsArch string `json:"os_arch"`
  593. // swagger:ignore
  594. ImageId string `json:"image_id"`
  595. }
  596. type ServerSaveGuestImageInput struct {
  597. imageapi.GuestImageCreateInputBase
  598. // 保存镜像后是否自动启动
  599. AutoStart *bool `json:"auto_start"`
  600. }
  601. type ServerDeleteInput struct {
  602. // 是否越过回收站直接删除
  603. // default: false
  604. OverridePendingDelete bool `json:"override_pending_delete"`
  605. // 是否仅删除本地资源
  606. // default: false
  607. Purge bool `json:"purge"`
  608. // 是否删除快照
  609. // default: false
  610. DeleteSnapshots bool `json:"delete_snapshots"`
  611. // 是否删除关联的EIP
  612. // default: false
  613. DeleteEip bool `json:"delete_eip"`
  614. // 是否删除关联的数据盘
  615. // default: false
  616. DeleteDisks bool `json:"delete_disks"`
  617. }
  618. type ServerDetachnetworkInput struct {
  619. // 是否保留IP地址(ip地址会进入到预留ip)
  620. Reserve bool `json:"reserve"`
  621. // 通过IP子网地址, 优先级最高
  622. NetId string `json:"net_id"`
  623. // 通过IP解绑网卡, 优先级高于mac
  624. IpAddr string `json:"ip_addr"`
  625. // 通过IP6 addr解绑网卡, 优先级高于mac
  626. Ip6Addr string `json:"ip6_addr"`
  627. // 通过Mac解绑网卡, 优先级低于ip_addr
  628. Mac string `json:"mac"`
  629. // 解绑后不立即同步配置
  630. DisableSyncConfig *bool `json:"disable_sync_config"`
  631. // 强制卸载,无论虚拟机的状态,仅更新数据库
  632. Force *bool `json:"force"`
  633. }
  634. func (input ServerDetachnetworkInput) IsForce() bool {
  635. return input.Force != nil && *input.Force
  636. }
  637. type ServerSetNetworkNumQueuesInput struct {
  638. // 虚机网卡 mac addr
  639. MacAddr string `json:"mac_addr"`
  640. // 网卡队列数
  641. NumQueues int `json:"num_queues"`
  642. }
  643. type ServerMigrateForecastInput struct {
  644. PreferHostId string `json:"prefer_host_id"`
  645. // Deprecated
  646. // swagger:ignore
  647. PreferHost string `json:"prefer_host" yunion-deprecated-by:"prefer_host_id"`
  648. LiveMigrate bool `json:"live_migrate"`
  649. SkipCpuCheck bool `json:"skip_cpu_check"`
  650. SkipKernelCheck bool `json:"skip_kernel_check"`
  651. ConvertToKvm bool `json:"convert_to_kvm"`
  652. IsRescueMode bool `json:"is_rescue_mode"`
  653. ResetCpuNumaPin bool `json:"reset_cpu_numa_pin"`
  654. }
  655. type ServerResizeDiskInput struct {
  656. // swagger:ignore
  657. Disk string `json:"disk" yunion-deprecated-by:"disk_id"`
  658. // 磁盘Id
  659. DiskId string `json:"disk_id"`
  660. DiskResizeInput
  661. }
  662. type ServerMigrateNetworkInput struct {
  663. // Source network Id
  664. Src string `json:"src"`
  665. // Destination network Id
  666. Dest string `json:"dest"`
  667. }
  668. type ServerDeployInput struct {
  669. apis.Meta
  670. ServerDeployInputBase
  671. // 部署完成后是否自动启动
  672. // 若虚拟机重置密码后需要重启生效,并且当前虚拟机状态为running, 此参数默认为true
  673. // 若虚拟机状态为ready, 指定此参数后,部署完成后,虚拟机会自动启动
  674. AutoStart bool `json:"auto_start"`
  675. }
  676. type ServerDeployInputBase struct {
  677. // swagger:ignore
  678. Keypair string `json:"keypair" yunion-deprecated-by:"keypair_id"`
  679. // 秘钥Id
  680. KeypairId string `json:"keypair_id"`
  681. // 清理指定公钥
  682. // 若指定的秘钥Id和虚拟机的秘钥Id不相同, 则清理旧的公钥
  683. DeletePublicKey string `json:"delete_public_key"`
  684. // 解绑当前虚拟机秘钥, 并清理公钥信息
  685. DeleteKeypair bool `json:"__delete_keypair__"`
  686. // 生成随机密码, 优先级低于password
  687. ResetPassword bool `json:"reset_password"`
  688. // 重置指定密码
  689. Password string `json:"password"`
  690. // 用户自定义启动脚本
  691. // 支持 #cloud-config yaml 格式及shell脚本
  692. // 支持特殊user data平台: Aliyun, Qcloud, Azure, Apsara, Ucloud
  693. // required: false
  694. UserData string `json:"user_data"`
  695. // swagger:ignore
  696. LoginAccount string `json:"login_account"`
  697. // swagger:ignore
  698. Restart bool `json:"restart"`
  699. // swagger:ignore
  700. DeployConfigs []*DeployConfig `json:"deploy_configs"`
  701. // swagger:ignore
  702. DeployTelegraf bool `json:"deploy_telegraf"`
  703. }
  704. type ServerUserDataInput struct {
  705. UserData string `json:"user_data"`
  706. }
  707. type ServerAttachDiskInput struct {
  708. DiskId string `json:"disk_id"`
  709. BootIndex *int8 `json:"boot_index"`
  710. }
  711. type ServerDetachDiskInput struct {
  712. // 磁盘Id,若磁盘未挂载在虚拟机上,不返回错误
  713. DiskId string `json:"disk_id"`
  714. // 是否保留磁盘
  715. // default: false
  716. KeepDisk bool `json:"keep_disk"`
  717. }
  718. type ServerChangeConfigInput struct {
  719. // 关机且停机不收费情况下不允许调整配置
  720. // 实例类型, 优先级高于vcpu_count和vmem_size
  721. InstanceType string `json:"instance_type"`
  722. // swagger:ignore
  723. Sku string `json:"sku" yunion-deprecated-by:"instance_type"`
  724. // swagger:ignore
  725. Flavor string `json:"flavor" yunion-deprecated-by:"instance_type"`
  726. // cpu卡槽数
  727. // vmware 若开机调整配置时,需要保证调整前及调整后 vcpu_count / cpu_sockets 保持不变
  728. // vmware开机调整配置同样需要注意 https://kb.vmware.com/s/article/2008405
  729. CpuSockets *int `json:"cpu_sockets"`
  730. // cpu大小
  731. VcpuCount *int `json:"vcpu_count"`
  732. // 任务分配CPU大小
  733. ExtraCpuCount *int `json:"extra_cpu_count"`
  734. // 内存大小, 1024M, 1G
  735. VmemSize string `json:"vmem_size"`
  736. // 调整完配置后是否自动启动
  737. AutoStart bool `json:"auto_start"`
  738. // disks start from index 1, i.e. cannot change size of system disk(1st disk)
  739. Disks []DiskConfig `json:"disks"`
  740. SetTrafficLimits []ServerNicTrafficLimit `json:"set_traffic_limits"`
  741. ResetTrafficLimits []ServerNicTrafficLimit `json:"reset_traffic_limits"`
  742. }
  743. type ServerUpdateInput struct {
  744. apis.VirtualResourceBaseUpdateInput
  745. HostnameInput
  746. // 删除保护开关
  747. DisableDelete *bool `json:"disable_delete"`
  748. // 启动顺序
  749. BootOrder *string `json:"boot_order"`
  750. // 关机执行操作
  751. ShutdownBehavior *string `json:"shutdown_behavior"`
  752. Vga *string `json:"vga"`
  753. Vdi *string `json:"vdi"`
  754. Machine *string `json:"machine"`
  755. Bios *string `json:"bios"`
  756. SrcIpCheck *bool `json:"src_ip_check"`
  757. SrcMacCheck *bool `json:"src_mac_check"`
  758. SshPort int `json:"ssh_port"`
  759. // swagger:ignore
  760. ProgressMbps float32 `json:"progress_mbps"`
  761. }
  762. type GuestJsonDesc struct {
  763. Name string `json:"name"`
  764. Hostname string `json:"hostname"`
  765. Description string `json:"description"`
  766. UUID string `json:"uuid"`
  767. Mem int `json:"mem"`
  768. CpuSockets int `json:"cpu_sockets"`
  769. Cpu int `json:"cpu"`
  770. Vga string `json:"vga"`
  771. Vdi string `json:"vdi"`
  772. Machine string `json:"machine"`
  773. Bios string `json:"bios"`
  774. BootOrder string `json:"boot_order"`
  775. SrcIpCheck bool `json:"src_ip_check"`
  776. SrcMacCheck bool `json:"src_mac_check"`
  777. IsMaster *bool `json:"is_master"`
  778. IsSlave *bool `json:"is_slave"`
  779. IsVolatileHost bool `json:"is_volatile_host"`
  780. HostId string `json:"host_id"`
  781. // 宿主机管理IP
  782. HostAccessIp string `json:"host_access_ip"`
  783. // 宿主机公网IP(如果有)
  784. HostEIP string `json:"host_eip"`
  785. IsolatedDevices []*IsolatedDeviceJsonDesc `json:"isolated_devices"`
  786. CpuNumaPin []SCpuNumaPin `json:"cpu_numa_pin"`
  787. Domain string `json:"domain"`
  788. Nics []*GuestnetworkJsonDesc `json:"nics"`
  789. Disks []*GuestdiskJsonDesc `json:"disks"`
  790. Cdrom *GuestcdromJsonDesc `json:"cdrom"`
  791. Cdroms []*GuestcdromJsonDesc `json:"cdroms"`
  792. Floppys []*GuestfloppyJsonDesc `json:"floppys"`
  793. Tenant string `json:"tenant"`
  794. TenantId string `json:"tenant_id"`
  795. DomainId string `json:"domain_id"`
  796. ProjectDomain string `json:"project_domain"`
  797. Keypair string `json:"keypair"`
  798. Pubkey string `json:"pubkey"`
  799. NetworkRoles []string `json:"network_roles"`
  800. Secgroups []*SecgroupJsonDesc `json:"secgroups"`
  801. SecurityRules string `json:"security_rules"`
  802. AdminSecurityRules string `json:"admin_security_rules"`
  803. NicSecgroups []*GuestnetworkSecgroupDesc `json:"nic_secgroups"`
  804. ExtraOptions jsonutils.JSONObject `json:"extra_options"`
  805. Kvm string `json:"kvm"`
  806. Zone string `json:"zone"`
  807. ZoneId string `json:"zone_id"`
  808. OsName string `json:"os_name"`
  809. Metadata map[string]string `json:"metadata"`
  810. UserData string `json:"user_data"`
  811. PendingDeleted bool `json:"pending_deleted"`
  812. ScalingGroupId string `json:"scaling_group_id"`
  813. // baremetal
  814. DiskConfig jsonutils.JSONObject `json:"disk_config"`
  815. NicsStandby []*GuestnetworkJsonDesc `json:"nics_standby"`
  816. // esxi
  817. InstanceSnapshotInfo struct {
  818. InstanceSnapshotId string `json:"instance_snapshot_id"`
  819. InstanceId string `json:"instance_id"`
  820. } `json:"instance_snapshot_info"`
  821. EnableEsxiSwap bool `json:"enable_esxi_swap"`
  822. EncryptKeyId string `json:"encrypt_key_id,omitempty"`
  823. IsDaemon bool `json:"is_daemon"`
  824. LightMode bool `json:"light_mode"`
  825. Hypervisor string `json:"hypervisor"`
  826. Containers []*host.ContainerDesc `json:"containers"`
  827. }
  828. type SVCpuPin struct {
  829. Vcpu int `json:"vcpu"`
  830. Pcpu int `json:"pcpu"`
  831. }
  832. type SCpuNumaPin struct {
  833. SizeMB *int `json:"size_mb"`
  834. NodeId int `json:"node_id"`
  835. VcpuPin []SVCpuPin `json:"vcpu_pin"`
  836. ExtraCpuCount int `json:"extra_cpu_count"`
  837. }
  838. type ServerSetBootIndexInput struct {
  839. // key index, value boot_index
  840. Disks map[string]int8 `json:"disks"`
  841. // key ordinal, value boot_index
  842. Cdroms map[string]int8 `json:"cdroms"`
  843. }
  844. type ServerSetDiskIoThrottleInput struct {
  845. // key disk id, value bps
  846. Bps map[string]int `json:"bps"`
  847. // key disk id, value iops
  848. IOPS map[string]int `json:"iops"`
  849. }
  850. type ServerChangeStorageInput struct {
  851. TargetStorageId string `json:"target_storage_id"`
  852. KeepOriginDisk bool `json:"keep_origin_disk"`
  853. }
  854. type ServerChangeStorageInternalInput struct {
  855. ServerChangeStorageInput
  856. Disks []string `json:"disks"`
  857. GuestRunning bool `json:"guest_running"`
  858. DiskCount int `json:"disk_count"`
  859. }
  860. type ServerChangeDiskStorageInput struct {
  861. DiskId string `json:"disk_id"`
  862. TargetStorageId string `json:"target_storage_id"`
  863. KeepOriginDisk bool `json:"keep_origin_disk"`
  864. }
  865. type ServerChangeDiskStorageInternalInput struct {
  866. ServerChangeDiskStorageInput
  867. StorageId string `json:"storage_id"`
  868. TargetDiskId string `json:"target_disk_id"`
  869. DiskFormat string `json:"disk_format"`
  870. GuestRunning bool `json:"guest_running"`
  871. TargetDiskDesc *GuestdiskJsonDesc `json:"target_disk_desc"`
  872. // clone progress
  873. CompletedDiskCount int `json:"completed_disk_count"`
  874. CloneDiskCount int `json:"disk_count"`
  875. }
  876. type ServerCopyDiskToStorageInput struct {
  877. KeepOriginDisk bool `json:"keep_origin_disk"`
  878. GuestRunning bool `json:"guest_running"`
  879. CompletedDiskCount int `json:"completed_disk_count"`
  880. CloneDiskCount int `json:"disk_count"`
  881. }
  882. type ServerSetExtraOptionInput struct {
  883. Key string `json:"key"`
  884. Value string `json:"value"`
  885. }
  886. func (o ServerSetExtraOptionInput) Validate() error {
  887. if len(o.Key) == 0 {
  888. return errors.Wrap(httperrors.ErrBadRequest, "empty key")
  889. }
  890. if len(o.Value) == 0 {
  891. return errors.Wrap(httperrors.ErrBadRequest, "empty value")
  892. }
  893. return nil
  894. }
  895. type ServerDelExtraOptionInput struct {
  896. Key string `json:"key"`
  897. Value string `json:"value"`
  898. }
  899. func (o ServerDelExtraOptionInput) Validate() error {
  900. if len(o.Key) == 0 {
  901. return errors.Wrap(httperrors.ErrBadRequest, "empty key")
  902. }
  903. return nil
  904. }
  905. type ServerSnapshotAndCloneInput struct {
  906. ServerCreateSnapshotParams
  907. // number of cloned servers
  908. // 数量
  909. Count *int `json:"count"`
  910. // Whether auto start the cloned server
  911. // 是否自动启动
  912. AutoStart *bool `json:"auto_start"`
  913. // Whether delete instance snapshot automatically
  914. // 是否自动删除主机快照
  915. AutoDeleteInstanceSnapshot *bool `json:"auto_delete_instance_snapshot"`
  916. // ignore
  917. InstanceSnapshotId string `json:"instance_snapshot_id"`
  918. // Perfer clone destination host
  919. // 指定期望的迁移目标宿主机
  920. PreferHostId string `json:"prefer_host_id"`
  921. }
  922. type ServerInstanceSnapshot struct {
  923. ServerCreateSnapshotParams
  924. WithMemory bool `json:"with_memory"`
  925. }
  926. type ServerCreateSnapshotParams struct {
  927. Name string `json:"name"`
  928. GenerateName string `json:"generate_name"`
  929. }
  930. type ServerCPUSetInput struct {
  931. // Specifies the CPUs that tasks in this cgroup are permitted to access.
  932. CPUS []int `json:"cpus"`
  933. }
  934. type ServerCPUSetResp struct{}
  935. type ServerCPUSetRemoveInput struct{}
  936. type ServerCPUSetRemoveResp struct {
  937. Done bool `json:"done"`
  938. Error string `json:"error"`
  939. }
  940. type ServerGetCPUSetCoresInput struct{}
  941. type ServerGetCPUSetCoresResp struct {
  942. PinnedCores []int `json:"pinned_cores"`
  943. HostCores []int `json:"host_cores"`
  944. HostUsedCores []int `json:"host_used_cores"`
  945. }
  946. type ServerGetNumaInfoInput struct{}
  947. type ServerGetNumaInfoResp struct {
  948. CpuNumaPin jsonutils.JSONObject `json:"cpu_numa_pin"`
  949. IsolatedDevicesNumaNode []int8 `json:"isolated_devices_numa_node"`
  950. }
  951. type ServerGetHardwareInfoInput struct{}
  952. type ServerHardwareInfoMotherboard struct {
  953. Manufacturer string `json:"manufacturer"`
  954. Model string `json:"model"`
  955. OemName string `json:"oem_name"`
  956. SN string `json:"sn"`
  957. Version string `json:"version"`
  958. }
  959. type ServerHardwareInfoCPU struct {
  960. Model string `json:"model"`
  961. Count int `json:"count"`
  962. }
  963. type ServerHardwareInfoMemory struct {
  964. SizeMB int `json:"size_mb"`
  965. }
  966. type ServerHardwareInfoDisk struct {
  967. Id string `json:"id"`
  968. StorageId string `json:"storage_id"`
  969. Model string `json:"model"`
  970. SizeMB int `json:"size_mb"`
  971. // Disk's backend bandwidth. The unit is MB/s
  972. Bandwidth float64 `json:"bandwidth"`
  973. }
  974. type ServerHardwareInfoGPUPCIEInfo struct {
  975. Throughput string `json:"pcie_throughput"`
  976. LaneWidth int `json:"pcie_lane_width"`
  977. }
  978. type ServerHardwareInfoGPU struct {
  979. *IsolatedDeviceModelHardwareInfo
  980. // isolate device id
  981. Id string `json:"id"`
  982. // GPU model name
  983. Model string `json:"model"`
  984. // PCIE information
  985. PCIEInfo *IsolatedDevicePCIEInfo `json:"pcie_info"`
  986. }
  987. type ServerGetHardwareInfoResp struct {
  988. Motherboard *ServerHardwareInfoMotherboard `json:"motherboard"`
  989. CPU *ServerHardwareInfoCPU `json:"cpu"`
  990. Memory *ServerHardwareInfoMemory `json:"memory"`
  991. Disks []*ServerHardwareInfoDisk `json:"disk"`
  992. GPUs []*ServerHardwareInfoGPU `json:"gpu"`
  993. }
  994. type ServerMonitorInput struct {
  995. COMMAND string `json:"command"`
  996. QMP bool `json:"qmp"`
  997. }
  998. type ServerQemuInfo struct {
  999. Version string `json:"version"`
  1000. Cmdline string `json:"cmdline"`
  1001. }
  1002. type IPAddress struct {
  1003. IPAddress string `json:"ip-address"`
  1004. IPAddressType string `json:"ip-address-type"`
  1005. Prefix int `json:"prefix"`
  1006. }
  1007. type IfnameDetail struct {
  1008. HardwareAddress string `json:"hardware-address"`
  1009. IPAddresses []IPAddress `json:"ip-addresses"`
  1010. Name string `json:"name"`
  1011. Statistics struct {
  1012. RxBytes int `json:"rx-bytes"`
  1013. RxDropped int `json:"rx-dropped"`
  1014. RxErrs int `json:"rx-errs"`
  1015. RxPackets int `json:"rx-packets"`
  1016. TxBytes int `json:"tx-bytes"`
  1017. TxDropped int `json:"tx-dropped"`
  1018. TxErrs int `json:"tx-errs"`
  1019. TxPackets int `json:"tx-packets"`
  1020. } `json:"statistics"`
  1021. }
  1022. type ServerQgaSetPasswordInput struct {
  1023. Username string `json:"username"`
  1024. Password string `json:"password"`
  1025. }
  1026. type ServerQgaGuestInfoTaskInput struct {
  1027. }
  1028. type ServerQgaSetNetworkInput struct {
  1029. ServerQgaTimeoutInput
  1030. Device string `json:"device"`
  1031. Ipmask string `json:"ipmask"`
  1032. Gateway string `json:"gateway"`
  1033. Ip6mask string `json:"ip6mask"`
  1034. Gateway6 string `json:"gateway6"`
  1035. }
  1036. type ServerQgaGetNetworkInput struct {
  1037. }
  1038. type ServerQgaTimeoutInput struct {
  1039. // qga execute timeout second
  1040. Timeout int `json:"timeout"`
  1041. }
  1042. type ServerQgaCommandInput struct {
  1043. ServerQgaTimeoutInput
  1044. Command string `json:"command"`
  1045. }
  1046. type ServerSetPasswordInput struct {
  1047. Username string `json:"username"`
  1048. Password string `json:"password"`
  1049. // deploy params
  1050. ResetPassword bool `json:"reset_password"`
  1051. AutoStart bool `json:"auto_start"`
  1052. }
  1053. type ServerInsertVfdInput struct {
  1054. FloppyOrdinal int64 `json:"floppy_ordinal"`
  1055. ImageId string `json:"image_id"`
  1056. }
  1057. type ServerEjectVfdInput struct {
  1058. FloppyOrdinal int64 `json:"floppy_ordinal"`
  1059. ImageId string `json:"image_id"`
  1060. }
  1061. type ServerSetLiveMigrateParamsInput struct {
  1062. MaxBandwidthMB *int64
  1063. DowntimeLimitMS *int64
  1064. }
  1065. type ServerNicTrafficLimit struct {
  1066. Mac string `json:"mac"`
  1067. RxTrafficLimit *int64 `json:"rx_traffic_limit"`
  1068. TxTrafficLimit *int64 `json:"tx_traffic_limit"`
  1069. BillingType billing_api.TBillingType `json:"billing_type"`
  1070. ChargeType billing_api.TNetChargeType `json:"charge_type"`
  1071. }
  1072. func (input ServerNicTrafficLimit) Validate(billingType billing_api.TBillingType, chargeType billing_api.TNetChargeType, txLimit, rxLimit int64) (ServerNicTrafficLimit, bool, error) {
  1073. var billingChange bool
  1074. if len(input.BillingType) > 0 && input.BillingType != billingType {
  1075. billingChange = true
  1076. billingType = input.BillingType
  1077. }
  1078. if len(input.ChargeType) > 0 && input.ChargeType != chargeType {
  1079. billingChange = true
  1080. chargeType = input.ChargeType
  1081. }
  1082. if billingChange {
  1083. if len(input.BillingType) == 0 {
  1084. input.BillingType = billingType
  1085. }
  1086. if len(input.ChargeType) == 0 {
  1087. input.ChargeType = chargeType
  1088. }
  1089. }
  1090. if billingType == billing_api.BILLING_TYPE_POSTPAID && chargeType == billing_api.NET_CHARGE_TYPE_BY_TRAFFIC {
  1091. if txLimit > 0 {
  1092. txLimit = 0
  1093. input.TxTrafficLimit = &txLimit
  1094. } else {
  1095. input.TxTrafficLimit = nil
  1096. }
  1097. if rxLimit > 0 {
  1098. rxLimit = 0
  1099. input.RxTrafficLimit = &rxLimit
  1100. } else {
  1101. input.RxTrafficLimit = nil
  1102. }
  1103. } else if billingType == billing_api.BILLING_TYPE_POSTPAID && chargeType == billing_api.NET_CHARGE_TYPE_BY_BANDWIDTH {
  1104. return input, billingChange, errors.Wrapf(httperrors.ErrNotImplemented, "billing type %s and charge type %s are not supported", input.BillingType, input.ChargeType)
  1105. } else if billingType == billing_api.BILLING_TYPE_PREPAID && chargeType == billing_api.NET_CHARGE_TYPE_BY_TRAFFIC {
  1106. if txLimit == 0 && input.TxTrafficLimit == nil {
  1107. return input, billingChange, errors.Wrapf(httperrors.ErrBadRequest, "tx traffic limit is required")
  1108. }
  1109. if rxLimit == 0 && input.RxTrafficLimit == nil {
  1110. return input, billingChange, errors.Wrapf(httperrors.ErrBadRequest, "rx traffic limit is required")
  1111. }
  1112. if input.TxTrafficLimit != nil && *input.TxTrafficLimit <= 0 {
  1113. return input, billingChange, errors.Wrapf(httperrors.ErrBadRequest, "tx traffic limit must be greater than 0")
  1114. }
  1115. if input.RxTrafficLimit != nil && *input.RxTrafficLimit <= 0 {
  1116. return input, billingChange, errors.Wrapf(httperrors.ErrBadRequest, "rx traffic limit must be greater than 0")
  1117. }
  1118. } else if billingType == billing_api.BILLING_TYPE_PREPAID && chargeType == billing_api.NET_CHARGE_TYPE_BY_BANDWIDTH {
  1119. if txLimit > 0 {
  1120. txLimit = 0
  1121. input.TxTrafficLimit = &txLimit
  1122. } else {
  1123. input.TxTrafficLimit = nil
  1124. }
  1125. if rxLimit > 0 {
  1126. rxLimit = 0
  1127. input.RxTrafficLimit = &rxLimit
  1128. } else {
  1129. input.RxTrafficLimit = nil
  1130. }
  1131. } else {
  1132. return input, billingChange, errors.Wrapf(httperrors.ErrBadRequest, "invalid billing type %s and charge type %s", input.BillingType, input.ChargeType)
  1133. }
  1134. return input, billingChange, nil
  1135. }
  1136. type GuestAddSubIpsInfo struct {
  1137. Count int `json:"count"`
  1138. SubIps []string `json:"sub_ips"`
  1139. Reserved bool `json:"reserved"`
  1140. AllocDir IPAllocationDirection `json:"alloc_dir"`
  1141. }
  1142. type GuestAddSubIpsInput struct {
  1143. ServerNetworkInfo
  1144. GuestAddSubIpsInfo
  1145. }
  1146. type GuestUpdateSubIpsInput struct {
  1147. GuestAddSubIpsInput
  1148. RemoveSubIps []string `json:"remove_sub_ips"`
  1149. }
  1150. type NetworkAddrConf struct {
  1151. Id string `json:"id"`
  1152. Type string `json:"type"`
  1153. IpAddr string `json:"ip_addr"`
  1154. Masklen int `json:"masklen"`
  1155. Gateway string `json:"gateway"`
  1156. }
  1157. type ServerLoginInfoInput struct {
  1158. PrivateKey string `json:"private_key"`
  1159. }
  1160. type ServerLoginInfoOutput struct {
  1161. Username string `json:"username"`
  1162. Updated string `json:"updated"`
  1163. LoginKey string `json:"login_key"`
  1164. Keypair string `json:"keypair"`
  1165. Password string `json:"password"`
  1166. }
  1167. type GuestPerformStartInput struct {
  1168. // 指定启动虚拟机的Qemu版本,可选值:2.12.1, 4.2.0
  1169. // 仅适用于KVM虚拟机
  1170. QemuVersion string `json:"qemu_version"`
  1171. // 按量机器自动转换为包年包月
  1172. AutoPrepaid bool `json:"auto_prepaid"`
  1173. }
  1174. type ServerSetOSInfoInput struct {
  1175. // OS type, e.g.: Linux, Windows
  1176. Type string `json:"type" help:"OS type, e.g.: Linux, Windows"`
  1177. // OS distribution, e.g.: CentOS, Ubuntu, Windows Server 2016 Datacenter
  1178. Distribution string `json:"distribution" help:"OS distribution, e.g.: CentOS, Ubuntu, Windows Server 2016 Datacenter"`
  1179. // OS version, e.g: 7.9, 22.04, 6.3
  1180. Version string `json:"version" help:"OS version, e.g.: 7.9, 22.04, 6.3"`
  1181. Arch string `json:"arch" help:"OS arch, e.g.: x86_64, aarch64"`
  1182. }
  1183. type ServerNetworkInfo struct {
  1184. Index int `json:"index"`
  1185. Mac string `json:"mac"`
  1186. IpAddr string `json:"ip_addr"`
  1187. Ip6Addr string `json:"ip6_addr"`
  1188. }
  1189. type ServerChangeIpaddrInput struct {
  1190. ServerNetworkInfo
  1191. NetDesc string `json:"net_desc"`
  1192. NetConf *NetworkConfig `json:"net_conf"`
  1193. Reserve *bool `json:"reserve"`
  1194. RestartNetwork *bool `json:"restart_network"`
  1195. }
  1196. type ServerChangeBandwidthInput struct {
  1197. ServerNetworkInfo
  1198. Bandwidth int `json:"bandwidth"`
  1199. NoSync *bool `json:"no_sync"`
  1200. }
  1201. type ServerChangeConfigSpecs struct {
  1202. CpuSockets int `json:"cpu_sockets"`
  1203. VcpuCount int `json:"vcpu_count"`
  1204. ExtraCpuCount int `json:"extra_cpu_count"`
  1205. VmemSize int `json:"vmem_size"`
  1206. InstanceType string `json:"instance_type"`
  1207. }
  1208. type DiskResizeSpec struct {
  1209. DiskId string `json:"disk_id"`
  1210. SizeMb int `json:"size_mb"`
  1211. OldSizeMb int `json:"old_size_mb"`
  1212. }
  1213. type ServerChangeConfigSettings struct {
  1214. Old ServerChangeConfigSpecs `json:"old"`
  1215. ServerChangeConfigSpecs
  1216. InstanceTypeFamily string `json:"instance_type_family"`
  1217. // disks to resize
  1218. Resize []*DiskResizeSpec `json:"resize"`
  1219. // disks to create
  1220. Create []*DiskConfig `json:"create"`
  1221. AutoStart bool `json:"auto_start"`
  1222. GuestOnline bool `json:"guest_online"`
  1223. // 设置虚拟网卡的流量上限
  1224. SetTrafficLimits []ServerNicTrafficLimit `json:"set_traffic_limits"`
  1225. // 重置虚拟网卡的流量上限,并且将网卡的流量归零
  1226. ResetTrafficLimits []ServerNicTrafficLimit `json:"reset_traffic_limits"`
  1227. SchedDesc jsonutils.JSONObject `json:"sched_desc"`
  1228. }
  1229. func (conf ServerChangeConfigSettings) CpuChanged() bool {
  1230. return conf.VcpuCount != conf.Old.VcpuCount
  1231. }
  1232. func (conf ServerChangeConfigSettings) AddedCpu() int {
  1233. addCpu := conf.VcpuCount - conf.Old.VcpuCount
  1234. if addCpu < 0 {
  1235. addCpu = 0
  1236. }
  1237. return addCpu
  1238. }
  1239. func (conf ServerChangeConfigSettings) ExtraCpuChanged() bool {
  1240. return conf.ExtraCpuCount != conf.Old.ExtraCpuCount
  1241. }
  1242. func (conf ServerChangeConfigSettings) AddedExtraCpu() int {
  1243. addCpu := conf.ExtraCpuCount - conf.Old.ExtraCpuCount
  1244. if addCpu < 0 {
  1245. addCpu = 0
  1246. }
  1247. return addCpu
  1248. }
  1249. func (conf ServerChangeConfigSettings) MemChanged() bool {
  1250. return conf.VmemSize != conf.Old.VmemSize
  1251. }
  1252. func (conf ServerChangeConfigSettings) InstanceTypeChanged() bool {
  1253. return len(conf.InstanceType) > 0 && conf.InstanceType != conf.Old.InstanceType
  1254. }
  1255. func (conf ServerChangeConfigSettings) AddedMem() int {
  1256. addMem := conf.VmemSize - conf.Old.VmemSize
  1257. if addMem < 0 {
  1258. addMem = 0
  1259. }
  1260. return addMem
  1261. }
  1262. func (conf ServerChangeConfigSettings) AddedDisk() int {
  1263. var size int
  1264. for _, resize := range conf.Resize {
  1265. size += resize.SizeMb - resize.OldSizeMb
  1266. }
  1267. for _, create := range conf.Create {
  1268. size += create.SizeMb
  1269. }
  1270. return size
  1271. }
  1272. type ServerReleasedIsolatedDevice struct {
  1273. DevType string `json:"dev_type"`
  1274. Model string `json:"model"`
  1275. }
  1276. type ServerChangeBillingTypeInput struct {
  1277. // 仅在虚拟机开机或关机状态下调用
  1278. // enmu: [postpaid, prepaid]
  1279. // required: true
  1280. BillingType billing_api.TBillingType `json:"billing_type"`
  1281. }
  1282. type ServerPerformStatusInput struct {
  1283. apis.PerformStatusInput
  1284. Containers map[string]*ContainerPerformStatusInput `json:"containers"`
  1285. }
  1286. type ServerModificationType struct {
  1287. Name string `json:"name"`
  1288. }
  1289. type ServerModificationTypesOutput struct {
  1290. ModificationTypes []ServerModificationType `json:"modification_types"`
  1291. }