diff --git a/src/api/pif.js b/src/api/pif.js index 517abd27d..9f58e5f65 100644 --- a/src/api/pif.js +++ b/src/api/pif.js @@ -76,3 +76,18 @@ reconfigureIp.params = { reconfigureIp.resolve = { pif: ['id', 'PIF', 'administrate'] } + +// =================================================================== + +export async function editPif ({ pif, vlan }) { + await this.getXapi(pif).editPif(pif._xapiId, { vlan }) +} + +editPif.params = { + id: { type: 'string' }, + vlan: { type: ['integer', 'string'] } +} + +editPif.resolve = { + pif: ['id', 'PIF', 'administrate'] +} diff --git a/src/xapi/index.js b/src/xapi/index.js index 5bcf0a220..69549a84a 100644 --- a/src/xapi/index.js +++ b/src/xapi/index.js @@ -1874,6 +1874,29 @@ export default class Xapi extends XapiBase { return this._getOrWaitObject(networkRef) } + async editPif ( + pifId, + { vlan } + ) { + const pif = this.getObject(pifId) + const physPif = find(this.objects.all, obj => ( + obj.$type === 'pif' && + (obj.physical || obj.bond_master_of) && + obj.$pool === pif.$pool && + obj.device === pif.device + )) + + if (!physPif) { + throw new Error('PIF not found') + } + + await this.call('VLAN.destroy', pif.VLAN_master_of) + const pifs = await this.call('pool.create_VLAN_from_PIF', physPif.$ref, pif.network, asInteger(vlan)) + if (!pif.currently_attached) { + forEach(pifs, pifRef => this.call('PIF.unplug', pifRef)::pCatch(noop)) + } + } + async createBondedNetwork ({ bondMode, mac,