Skip to content

Commit

Permalink
remove server code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajaa-BARHTAOUI committed Feb 21, 2023
1 parent e3edc46 commit de4ffc0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 80 deletions.
83 changes: 21 additions & 62 deletions @xen-orchestra/vmware-explorer/esxi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,41 +124,29 @@ export default class Esxi extends EventEmitter {
objectSet: [objectSpec],
}

let token
result = await this.#exec('RetrievePropertiesEx', {
_this: propertyCollector,
specSet: [propertyFilterSpec],
options: { attributes: { type: 'RetrieveOptions' } },
})

const objects = {}
do {
if (token !== undefined) {
result = await this.#exec('ContinueRetrievePropertiesEx', {
_this: propertyCollector,
token,
})
} else {
result = await this.#exec('RetrievePropertiesEx', {
_this: propertyCollector,
specSet: [propertyFilterSpec],
options: { attributes: { type: 'RetrieveOptions' } },
})
}
const returnObj = Array.isArray(result.returnval.objects) ? result.returnval.objects : [result.returnval.objects]

const returnObj = Array.isArray(result.returnval.objects) ? result.returnval.objects : [result.returnval.objects]
returnObj.forEach(({ obj, propSet }) => {
objects[obj.$value] = {}
propSet = Array.isArray(propSet) ? propSet : [propSet]
propSet.forEach(({ name, val }) => {
// don't care about the type for now
delete val.attributes
// a scalar value : simplify it
if (val.$value) {
objects[obj.$value][name] = val.$value
} else {
objects[obj.$value][name] = val
}
})
returnObj.forEach(({ obj, propSet }) => {
objects[obj.$value] = {}
propSet = Array.isArray(propSet) ? propSet : [propSet]
propSet.forEach(({ name, val }) => {
// don't care about the type for now
delete val.attributes
// a scalar value : simplify it
if (val.$value) {
objects[obj.$value][name] = val.$value
} else {
objects[obj.$value][name] = val
}
})

token = result.returnval.token
} while (token)

})
return objects
}

Expand Down Expand Up @@ -188,35 +176,6 @@ 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) {
Expand Down Expand Up @@ -282,7 +241,7 @@ export default class Esxi extends EventEmitter {
return {
name_label: config.name,
memory: +config.hardware.memoryMB * 1024 * 1024,
nCpus: +config.hardware.numCPU,
numCpu: +config.hardware.numCPU,
guestToolsInstalled: false,
firmware: config.firmware === 'efi' ? 'uefi' : config.firmware, // bios or uefi
powerState: runtime.powerState,
Expand Down
10 changes: 0 additions & 10 deletions packages/xo-server/src/api/esxi.mjs

This file was deleted.

11 changes: 3 additions & 8 deletions packages/xo-server/src/xo-mixins/migrate-vm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ 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,
Expand All @@ -176,7 +171,7 @@ export default class MigrateVm {
return esxi.getTransferableVmMetadata(vmId)
})

const { disks, firmware, memory, name_label, networks, nCpus, powerState, snapshots } = esxiVmMetadata
const { disks, firmware, memory, name_label, networks, numCpu, powerState, snapshots } = esxiVmMetadata
const isRunning = powerState !== 'poweredOff'

const chainsByNodes = await new Task({ name: `build disks and snapshots chains for ${vmId}` }).run(async () => {
Expand All @@ -197,8 +192,8 @@ export default class MigrateVm {
memory_static_min: memory,
name_description: 'from esxi',
name_label,
VCPUs_at_startup: nCpus,
VCPUs_max: nCpus,
VCPUs_at_startup: numCpu,
VCPUs_max: numCpu,
})
)
await Promise.all([
Expand Down

0 comments on commit de4ffc0

Please sign in to comment.