feat(xo-server/createCloudInit): support network config (#3997)

* feat(xo-server/createCloudInit): support network config

See #3872

* Update index.js
This commit is contained in:
Julien Fontanet 2019-03-01 09:50:37 +01:00 committed by GitHub
parent 944dad6e36
commit 7c5d90fe40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View File

@ -1461,14 +1461,25 @@ getCloudInitConfig.resolve = {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
export async function createCloudInitConfigDrive({ vm, sr, config, coreos }) { export async function createCloudInitConfigDrive({
config,
coreos,
networkConfig,
sr,
vm,
}) {
const xapi = this.getXapi(vm) const xapi = this.getXapi(vm)
if (coreos) { if (coreos) {
// CoreOS is a special CloudConfig drive created by XS plugin // CoreOS is a special CloudConfig drive created by XS plugin
await xapi.createCoreOsCloudInitConfigDrive(vm._xapiId, sr._xapiId, config) await xapi.createCoreOsCloudInitConfigDrive(vm._xapiId, sr._xapiId, config)
} else { } else {
// use generic Cloud Init drive // use generic Cloud Init drive
await xapi.createCloudInitConfigDrive(vm._xapiId, sr._xapiId, config) await xapi.createCloudInitConfigDrive(
vm._xapiId,
sr._xapiId,
config,
networkConfig
)
} }
} }
@ -1476,6 +1487,7 @@ createCloudInitConfigDrive.params = {
vm: { type: 'string' }, vm: { type: 'string' },
sr: { type: 'string' }, sr: { type: 'string' },
config: { type: 'string' }, config: { type: 'string' },
networkConfig: { type: 'string', optional: true },
} }
createCloudInitConfigDrive.resolve = { createCloudInitConfigDrive.resolve = {

View File

@ -2361,8 +2361,16 @@ export default class Xapi extends XapiBase {
} }
// Generic Config Drive // Generic Config Drive
//
// https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
@deferrable @deferrable
async createCloudInitConfigDrive($defer, vmId, srId, config) { async createCloudInitConfigDrive(
$defer,
vmId,
srId,
userConfig,
networkConfig
) {
const vm = this.getObject(vmId) const vm = this.getObject(vmId)
const sr = this.getObject(srId) const sr = this.getObject(srId)
@ -2380,7 +2388,9 @@ export default class Xapi extends XapiBase {
await Promise.all([ await Promise.all([
fs.writeFile('meta-data', 'instance-id: ' + vm.uuid + '\n'), fs.writeFile('meta-data', 'instance-id: ' + vm.uuid + '\n'),
fs.writeFile('user-data', config), fs.writeFile('user-data', userConfig),
networkConfig !== undefined &&
fs.writeFile('network-config', networkConfig),
]) ])
// ignore errors, I (JFT) don't understand why they are emitted // ignore errors, I (JFT) don't understand why they are emitted