diff --git a/src/api/vm.coffee b/src/api/vm.coffee index 276867a25..a7dbfd779 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -884,21 +884,13 @@ exports.attachDisk = attachDisk # FIXME: position should be optional and default to last. createInterface = $coroutine ({vm, network, position, mtu, mac}) -> - xapi = @getXAPI vm - - VIF_ref = $wait xapi.call 'VIF.create', { - VM: vm.ref - network: network.ref - device: position - MTU: mtu ? '1500' - MAC: mac ? '' - other_config: {} - qos_algorithm_type: '' - qos_algorithm_params: {} - } - - return $wait(xapi.call( 'VIF.get_record', VIF_ref)).uuid + vif = $wait @getXAPI(vm).createVirtualInterface(vm.id, network.id, { + mac, + mtu, + position + }) + return vif.$id createInterface.params = { vm: { type: 'string' } diff --git a/src/xapi.js b/src/xapi.js index 743c0e26d..7dabb0575 100644 --- a/src/xapi.js +++ b/src/xapi.js @@ -486,6 +486,30 @@ export default class Xapi extends XapiBase { // ================================================================= + async createVirtualInterface (vmId, networkId, { + mac = '', + mtu = 1500, + position = 0 + } = {}) { + const vm = this.getObject(vmId) + const network = this.getObject(networkId) + + const ref = await this.call('VIF.create', { + device: String(position), + MAC: String(mac), + MTU: String(mtu), + network: network.$ref, + other_config: {}, + qos_algorithm_params: {}, + qos_algorithm_type: '', + VM: vm.$ref + }) + + return await this._getOrWaitObject(ref) + } + + // ================================================================= + async _doDockerAction (vmId, action, containerId) { const vm = this.getObject(vmId) const host = vm.$resident_on diff --git a/src/xo.js b/src/xo.js index c0daa2713..476fbaed3 100644 --- a/src/xo.js +++ b/src/xo.js @@ -312,7 +312,8 @@ export default class Xo extends EventEmitter { $poolId: { enumerable: true, value: pool.$id - } + }, + ref: { value: xapiObject.$ref } }) objects.set(id, xoObject)