Skip to content

Commit

Permalink
feat(xo-web/health): filter duplicated MAC addresses by running VMs (#…
Browse files Browse the repository at this point in the history
…5917)

See xoa-support#4054
  • Loading branch information
MathieuRA committed Sep 24, 2021
1 parent 216b759 commit 919d118
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Expand Up @@ -9,6 +9,7 @@
- [Backup] Go back to previous page instead of going to the overview after editing a job: keeps current filters and page (PR [#5913](https://github.com/vatesfr/xen-orchestra/pull/5913))
- [Health] Do not take into consideration duplicated MAC addresses from CR VMs (PR [#5916](https://github.com/vatesfr/xen-orchestra/pull/5916))
- [Health] Ability to filter duplicated MAC addresses by running VMs (PR [#5917](https://github.com/vatesfr/xen-orchestra/pull/5917))

### Bug fixes

Expand Down
1 change: 1 addition & 0 deletions packages/xo-web/src/common/intl/messages.js
Expand Up @@ -117,6 +117,7 @@ const messages = {
filterOnlyManaged: 'Managed disks',
filterOnlyOrphaned: 'Orphaned disks',
filterOnlyRegular: 'Normal disks',
filterOnlyRunningVms: 'Running VMs',
filterOnlySnapshots: 'Snapshot disks',
filterOnlyUnmanaged: 'Unmanaged disks',
filterSaveAs: 'Save…',
Expand Down
24 changes: 17 additions & 7 deletions packages/xo-web/src/xo-app/dashboard/health/index.js
Expand Up @@ -80,14 +80,14 @@ const AlarmColPool = connectStore(() => ({
const DUPLICATED_MAC_ADDRESSES_COLUMNS = [
{
name: _('vifMacLabel'),
itemRenderer: macAddress => <pre>{macAddress}</pre>,
sortCriteria: macAddress => macAddress,
itemRenderer: ({ mac }) => <pre>{mac}</pre>,
sortCriteria: ({ mac }) => mac,
},
{
name: _('vifs'),
itemRenderer: (macAddress, { vifsByMac }) => (
itemRenderer: ({ vifs }) => (
<div>
{vifsByMac[macAddress].map(vif => (
{vifs.map(vif => (
<Row key={vif.id}>
<Col>
{_('vifOnVmWithNetwork', {
Expand All @@ -103,6 +103,10 @@ const DUPLICATED_MAC_ADDRESSES_COLUMNS = [
},
]

const DUPLICATED_MAC_ADDRESSES_FILTERS = {
filterOnlyRunningVms: 'nRunningVms:>1',
}

const SR_COLUMNS = [
{
name: _('srName'),
Expand Down Expand Up @@ -532,6 +536,7 @@ const HANDLED_VDI_TYPES = new Set(['system', 'user', 'ephemeral'])
guestToolsVms: getGuestToolsVms,
userSrs: getUserSrs,
vifsByMac: getVifsByMac,
vms: getVms,
}
})
export default class Health extends Component {
Expand Down Expand Up @@ -584,11 +589,16 @@ export default class Health extends Component {
_getDuplicatedMacAddresses = createCollectionWrapper(
createSelector(
() => this._getVifsByMac(),
vifsByMac => {
() => this.props.vms,
(vifsByMac, vms) => {
const duplicatedMacAddresses = []
for (const [macAddress, vifs] of Object.entries(vifsByMac)) {
if (vifs.length > 1) {
duplicatedMacAddresses.push(macAddress)
duplicatedMacAddresses.push({
mac: macAddress,
nRunningVms: vifs.filter(vif => vms[vif.$VM].power_state === 'Running').length,
vifs,
})
}
}
return duplicatedMacAddresses.sort()
Expand Down Expand Up @@ -754,8 +764,8 @@ export default class Health extends Component {
collection={props.areObjectsFetched ? duplicatedMacAddresses : null}
columns={DUPLICATED_MAC_ADDRESSES_COLUMNS}
component={SortedTable}
data-vifsByMac={this.props.vifsByMac}
emptyMessage={_('noDuplicatedMacAddresses')}
filters={DUPLICATED_MAC_ADDRESSES_FILTERS}
stateUrlParam='s_duplicated_mac_addresses'
/>
</CardBlock>
Expand Down

0 comments on commit 919d118

Please sign in to comment.