xen-orchestra/@xen-orchestra/xapi/vif.mjs
Julien Fontanet c3e0308ad0 chore(xapi): convert to ESM
BREAKING CHANGE
2023-07-10 16:45:31 +02:00

53 lines
1.2 KiB
JavaScript

import isVmRunning from './_isVmRunning.mjs'
export default class Vif {
async create(
{
currently_attached = true,
device,
ipv4_allowed,
ipv6_allowed,
locking_mode,
MTU,
network,
other_config = {},
qos_algorithm_params = {},
qos_algorithm_type = '',
VM,
},
{
// duplicated MAC addresses can lead to issues,
// therefore it should be passed explicitely
MAC = '',
} = {}
) {
const [powerState, ...rest] = await Promise.all([
this.getField('VM', VM, 'power_state'),
device ?? (await this.call('VM.get_allowed_VIF_devices', VM))[0],
MTU ?? (await this.getField('network', network, 'MTU')),
])
;[device, MTU] = rest
const vifRef = await this.call('VIF.create', {
currently_attached: powerState === 'Suspended' ? currently_attached : undefined,
device,
ipv4_allowed,
ipv6_allowed,
locking_mode,
MAC,
MTU,
network,
other_config,
qos_algorithm_params,
qos_algorithm_type,
VM,
})
if (currently_attached && isVmRunning(powerState)) {
await this.callAsync('VIF.plug', vifRef)
}
return vifRef
}
}