feat(xo-server): new API method esxi.listVms
This commit is contained in:
committed by
Julien Fontanet
parent
f5d19fd28a
commit
13837e0bf3
@@ -188,6 +188,35 @@ export default class Esxi extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
async getAllVmMetadata() {
|
||||
const datas = await this.search('VirtualMachine', ['config', 'storage', 'runtime'])
|
||||
|
||||
return Object.keys(datas).map(id => {
|
||||
const { config, storage, runtime } = datas[id]
|
||||
const perDatastoreUsage = Array.isArray(storage.perDatastoreUsage)
|
||||
? storage.perDatastoreUsage
|
||||
: [storage.perDatastoreUsage]
|
||||
return {
|
||||
id,
|
||||
nameLabel: config.name,
|
||||
memory: +config.hardware.memoryMB * 1024 * 1024,
|
||||
nCpus: +config.hardware.numCPU,
|
||||
guestToolsInstalled: false,
|
||||
firmware: config.firmware === 'efi' ? 'uefi' : config.firmware, // bios or uefi
|
||||
powerState: runtime.powerState,
|
||||
storage: perDatastoreUsage.reduce(
|
||||
(prev, curr) => {
|
||||
return {
|
||||
used: prev.used + +curr.committed,
|
||||
free: prev.free + +curr.uncommitted,
|
||||
}
|
||||
},
|
||||
{ used: 0, free: 0 }
|
||||
),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async getTransferableVmMetadata(vmId) {
|
||||
const search = await this.search('VirtualMachine', ['name', 'config', 'storage', 'runtime', 'snapshot'])
|
||||
if (search[vmId] === undefined) {
|
||||
@@ -253,7 +282,7 @@ export default class Esxi extends EventEmitter {
|
||||
return {
|
||||
name_label: config.name,
|
||||
memory: +config.hardware.memoryMB * 1024 * 1024,
|
||||
numCpu: +config.hardware.numCPU,
|
||||
nCpus: +config.hardware.numCPU,
|
||||
guestToolsInstalled: false,
|
||||
firmware: config.firmware === 'efi' ? 'uefi' : config.firmware, // bios or uefi
|
||||
powerState: runtime.powerState,
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
<!--packages-start-->
|
||||
|
||||
- @xen-orchestra/vmware-explorer patch
|
||||
- @xen-orchestra/vmware-explorer minor
|
||||
- @xen-orchestra/backups minor
|
||||
- xo-cli minor
|
||||
- xo-server-auth-oidc minor
|
||||
|
||||
12
packages/xo-server/src/api/esxi.mjs
Normal file
12
packages/xo-server/src/api/esxi.mjs
Normal file
@@ -0,0 +1,12 @@
|
||||
export function listVms({ host, password, sslVerify = true, user }) {
|
||||
return this.connectToEsxiAndList({ host, user, password, sslVerify })
|
||||
}
|
||||
|
||||
listVms.params = {
|
||||
host: { type: 'string' },
|
||||
user: { type: 'string' },
|
||||
password: { type: 'string' },
|
||||
sslVerify: { type: 'boolean', optional: true },
|
||||
}
|
||||
|
||||
listVms.permission = 'admin'
|
||||
@@ -161,6 +161,11 @@ export default class MigrateVm {
|
||||
})
|
||||
}
|
||||
|
||||
async connectToEsxiAndList({ host, user, password, sslVerify }) {
|
||||
const esxi = await this.#connectToEsxi(host, user, password, sslVerify)
|
||||
return esxi.getAllVmMetadata()
|
||||
}
|
||||
|
||||
@decorateWith(deferrable)
|
||||
async migrationfromEsxi(
|
||||
$defer,
|
||||
@@ -173,7 +178,7 @@ export default class MigrateVm {
|
||||
return esxi.getTransferableVmMetadata(vmId)
|
||||
})
|
||||
|
||||
const { disks, firmware, memory, name_label, networks, numCpu, powerState, snapshots } = esxiVmMetadata
|
||||
const { disks, firmware, memory, name_label, networks, nCpus, powerState, snapshots } = esxiVmMetadata
|
||||
const isRunning = powerState !== 'poweredOff'
|
||||
|
||||
const chainsByNodes = await new Task({ name: `build disks and snapshots chains for ${vmId}` }).run(async () => {
|
||||
@@ -194,8 +199,8 @@ export default class MigrateVm {
|
||||
memory_static_min: memory,
|
||||
name_description: 'from esxi',
|
||||
name_label,
|
||||
VCPUs_at_startup: numCpu,
|
||||
VCPUs_max: numCpu,
|
||||
VCPUs_at_startup: nCpus,
|
||||
VCPUs_max: nCpus,
|
||||
})
|
||||
)
|
||||
await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user