Skip to content

Commit

Permalink
feat(xo-server/PIF): add XO tasks for PIF.reconfigureIp
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuRA committed Dec 26, 2023
1 parent e609fc4 commit f60e24e
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions packages/xo-server/src/api/pif.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import filter from 'lodash/filter.js'
import find from 'lodash/find.js'
import { Task } from '@xen-orchestra/mixins/Tasks.mjs'

import { IPV4_CONFIG_MODES, IPV6_CONFIG_MODES } from '../xapi/index.mjs'

Expand Down Expand Up @@ -74,18 +75,33 @@ connect.resolve = {
// Reconfigure IP

export async function reconfigureIp({ pif, mode, ip = '', netmask = '', gateway = '', dns = '', ipv6, ipv6Mode }) {
const xapi = this.getXapi(pif)

if ((ipv6 !== '' && pif.ipv6?.[0] !== ipv6) || (ipv6Mode !== undefined && ipv6Mode !== pif.ipv6Mode)) {
await xapi.call('PIF.reconfigure_ipv6', pif._xapiRef, ipv6Mode, ipv6, gateway, dns)
}

if (mode !== undefined && mode !== pif.mode) {
await xapi.call('PIF.reconfigure_ip', pif._xapiRef, mode, ip, netmask, gateway, dns)
}
if (pif.management) {
await xapi.call('host.management_reconfigure', pif._xapiRef)
}
const task = this.tasks.create({
name: `reconfigure ip of: ${pif.device}`,
objectId: pif.uuid,
type: 'xo:pif:reconfigureIp',
})
await task.run(async () => {
const xapi = this.getXapi(pif)

if ((ipv6 !== '' && pif.ipv6?.[0] !== ipv6) || (ipv6Mode !== undefined && ipv6Mode !== pif.ipv6Mode)) {
await Task.run(
{ properties: { name: 'reconfigure IPv6', mode: ipv6Mode, ipv6, gateway, dns, objectId: pif.uuid } },
() => xapi.call('PIF.reconfigure_ipv6', pif._xapiRef, ipv6Mode, ipv6, gateway, dns)
)
}

if (mode !== undefined && mode !== pif.mode) {
await Task.run(
{ properties: { name: 'reconfigure IPv4', mode, ip, netmask, gateway, dns, objectId: pif.uuid } },
() => xapi.call('PIF.reconfigure_ip', pif._xapiRef, mode, ip, netmask, gateway, dns)
)
}
if (pif.management) {
await Task.run({ properties: { name: 'reconfigure PIF management', objectId: pif.uuid } }, () =>
xapi.call('host.management_reconfigure', pif._xapiRef)
)
}
})
}

reconfigureIp.params = {
Expand Down

0 comments on commit f60e24e

Please sign in to comment.