diff --git a/src/api/vif.js b/src/api/vif.js index a3deb1bee..c7d61a650 100644 --- a/src/api/vif.js +++ b/src/api/vif.js @@ -1,3 +1,4 @@ +// TODO: move into vm and rename to removeInterface async function delete_ ({vif}) { // TODO: check if VIF is attached before await this.getXAPI(vif).call('VIF.destroy', vif.ref) @@ -13,7 +14,7 @@ delete_.resolve = { } // ------------------------------------------------------------------- - +// TODO: move into vm and rename to disconnectInterface export async function disconnect ({vif}) { // TODO: check if VIF is attached before await this.getXAPI(vif).call('VIF.unplug_force', vif.ref) @@ -28,7 +29,7 @@ disconnect.resolve = { } // ------------------------------------------------------------------- - +// TODO: move into vm and rename to connectInterface export async function connect ({vif}) { // TODO: check if VIF is attached before await this.getXAPI(vif).call('VIF.plug', vif.ref) diff --git a/src/xapi.js b/src/xapi.js index 7c0097a20..e3eb2d270 100644 --- a/src/xapi.js +++ b/src/xapi.js @@ -528,7 +528,9 @@ export default class Xapi extends XapiBase { VM: vm.$ref }) - await this.call('VBD.plug', vbdRef) + if (isVmRunning(vm)) { + await this.call('VBD.plug', vbdRef) + } } // ================================================================= @@ -541,7 +543,7 @@ export default class Xapi extends XapiBase { const vm = this.getObject(vmId) const network = this.getObject(networkId) - const ref = await this.call('VIF.create', { + const vifRef = await this.call('VIF.create', { device: String(position), MAC: String(mac), MTU: String(mtu), @@ -552,7 +554,11 @@ export default class Xapi extends XapiBase { VM: vm.$ref }) - return await this._getOrWaitObject(ref) + if (isVmRunning(vm)) { + await this.call('VIF.plug', vifRef) + } + + return await this._getOrWaitObject(vifRef) } // =================================================================