Skip to content

Commit

Permalink
fix: use string as vm id, improves comments, improve progress counter
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Mar 13, 2023
1 parent 131cdee commit 76ec35d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@
- xo-server-auth-oidc minor
- xo-web minor


<!--packages-end-->
43 changes: 27 additions & 16 deletions packages/xo-server/src/api/vm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,11 @@ importFromEsxi.params = {
vm: { type: 'string' },
}

/**
* on success: returns an object, the keys are the esxi id, and the values are the created vm uuid
* On error: throw an error. If stopOnError is false, continue when an error occurs, throws an error at the end with a 'succeeded'
* property listing the VM properly imported and a 'errors' property with all the errors collected
*/
export async function importMultipleFromEsxi({
concurrency = 2,
host,
Expand All @@ -1354,22 +1359,25 @@ export async function importMultipleFromEsxi({
vms,
async vm => {
await new Task({ name: `importing vm ${vm}` }).run(async () => {
const vmUuid = await this.migrationfromEsxi({
host,
user,
password,
sslVerify,
thin,
vm,
sr,
network,
stopSource,
})
result[vm] = vmUuid
try {
const vmUuid = await this.migrationfromEsxi({
host,
user,
password,
sslVerify,
thin,
vm,
sr,
network,
stopSource,
})
result[vm] = vmUuid
} finally {
done++
Task.set('done', done)
Task.set('progress', Math.round((done * 100) / vms.length))
}
})
done++
Task.set('done', done)
Task.set('progress', Math.round((done * 100) / vms.length))
},
{
concurrency,
Expand All @@ -1389,19 +1397,22 @@ export async function importMultipleFromEsxi({
}

importMultipleFromEsxi.params = {
// number of VM import in parallel (during each import, the disks are imported in parallel)
concurrency: { type: 'number', optional: true },
host: { type: 'string' },
network: { type: 'string' },
password: { type: 'string' },
sr: { type: 'string' },
sslVerify: { type: 'boolean', optional: true },
stopSource: { type: 'boolean', optional: true },
// stop on the first error , default true . Warning, change the response format
stopOnError: { type: 'boolean', optional: true },
thin: { type: 'boolean', optional: true },
user: { type: 'string' },
// vm id to be imported, if used from cli use this syntax : vms=json:'["2","9","18"]'
vms: {
items: {
type: 'number',
type: 'string',
},
minItems: 1,
type: 'array',
Expand Down

0 comments on commit 76ec35d

Please sign in to comment.