fix(VM): support old ipv4 protocol (#5098)
See xoa-support#2540
Indroduced by 7f64cd1801
This commit is contained in:
parent
52020abde8
commit
619f2ef119
@ -305,12 +305,22 @@ const TRANSFORMS = {
|
||||
}
|
||||
})
|
||||
|
||||
const networks = guestMetrics?.networks ?? {}
|
||||
|
||||
// Merge old ipv4 protocol with the new protocol
|
||||
// See: https://github.com/xapi-project/xen-api/blob/324bc6ee6664dd915c0bbe57185f1d6243d9ed7e/ocaml/xapi/xapi_guest_agent.ml#L59-L81
|
||||
const addresses = {}
|
||||
for (const key in networks) {
|
||||
const [, i] = /^(\d+)\/ip$/.exec(key) ?? []
|
||||
addresses[i !== undefined ? `${i}/ipv4/0` : key] = networks[key]
|
||||
}
|
||||
|
||||
const vm = {
|
||||
// type is redefined after for controllers/, templates &
|
||||
// snapshots.
|
||||
type: 'VM',
|
||||
|
||||
addresses: (guestMetrics && guestMetrics.networks) || null,
|
||||
addresses,
|
||||
affinityHost: link(obj, 'affinity'),
|
||||
auto_poweron: otherConfig.auto_poweron === 'true',
|
||||
bios_strings: obj.bios_strings,
|
||||
|
@ -541,22 +541,16 @@ export default class TabNetwork extends BaseComponent {
|
||||
_getIpsByDevice = createSelector(
|
||||
() => this.props.vm.addresses,
|
||||
addresses => {
|
||||
if (addresses === null) {
|
||||
return {}
|
||||
}
|
||||
// VM_guest_metrics.networks seems to always have 3 fields (ip, ipv4 and ipv6) for each interface
|
||||
// http://xenbits.xenproject.org/docs/4.12-testing/misc/xenstore-paths.html#attrvifdevidipv4index-ipv4_address-w
|
||||
// https://github.com/xapi-project/xen-api/blob/d650621ba7b64a82aeb77deca787acb059636eaf/ocaml/xapi/xapi_guest_agent.ml#L76-L79
|
||||
const ipsByDevice = {}
|
||||
Object.entries(addresses).forEach(([key, address]) => {
|
||||
const [device, type] = key.split('/')
|
||||
// The ip and ipv4 fields have the same address.
|
||||
if (type !== 'ip') {
|
||||
if (ipsByDevice[device] === undefined) {
|
||||
ipsByDevice[device] = []
|
||||
}
|
||||
ipsByDevice[device].push(address)
|
||||
const device = key.split('/')[0]
|
||||
if (ipsByDevice[device] === undefined) {
|
||||
ipsByDevice[device] = []
|
||||
}
|
||||
ipsByDevice[device].push(address)
|
||||
})
|
||||
return ipsByDevice
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user