diff --git a/src/api/vm.coffee b/src/api/vm.coffee index 6d65dd360..c25f51023 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -915,6 +915,39 @@ setBootOrder.resolve = { } exports.setBootOrder = setBootOrder +#--------------------------------------------------------------------- + +getCloudInitConfig = $coroutine ({template}) -> + return yield @getXAPI(template).getCloudInitConfig(template._xapiId) + +getCloudInitConfig.params = { + template: { type: 'string' } +} + +getCloudInitConfig.resolve = { + template: ['template', 'VM-template', 'administrate'], +} +exports.getCloudInitConfig = getCloudInitConfig + +#--------------------------------------------------------------------- + +createCloudInitConfigDrive = $coroutine ({vm, sr, config}) -> + xapi = @getXAPI vm + yield xapi.createCloudInitConfigDrive(vm._xapiId, sr._xapiId, config) + return true + +createCloudInitConfigDrive.params = { + vm: { type: 'string' }, + sr: { type: 'string' }, + config: { type: 'string' } +} + +createCloudInitConfigDrive.resolve = { + vm: ['vm', 'VM', 'administrate'], + sr: [ 'sr', 'SR', 'operate' ] +} +exports.createCloudInitConfigDrive = createCloudInitConfigDrive + #===================================================================== Object.defineProperty(exports, '__esModule', { diff --git a/src/xapi.js b/src/xapi.js index 11d630346..28fd77fd2 100644 --- a/src/xapi.js +++ b/src/xapi.js @@ -1309,7 +1309,7 @@ export default class Xapi extends XapiBase { async _doDockerAction (vmId, action, containerId) { const vm = this.getObject(vmId) - const host = vm.$resident_on + const host = vm.$resident_on || this.pool.$master return await this.call('host.call_plugin', host.$ref, 'xscontainer', action, { vmuuid: vm.uuid, @@ -1345,6 +1345,28 @@ export default class Xapi extends XapiBase { await this._doDockerAction(vmId, 'unpause', containerId) } + async getCloudInitConfig (templateId) { + const template = this.getObject(templateId) + const host = this.pool.$master + + let config = await this.call('host.call_plugin', host.$ref, 'xscontainer', 'get_config_drive_default', { + templateuuid: template.uuid + }) + return config.slice(4) // FIXME remove the "True" string on the begining + } + + async createCloudInitConfigDrive (vmId, srId, config) { + const vm = this.getObject(vmId) + const host = this.pool.$master + const sr = this.getObject(srId) + + await this.call('host.call_plugin', host.$ref, 'xscontainer', 'create_config_drive', { + vmuuid: vm.uuid, + sruuid: sr.uuid, + configuration: config + }) + } + // ================================================================= }