Skip to content

Commit

Permalink
HARVESTER: SR-IOV polish
Browse files Browse the repository at this point in the history
  • Loading branch information
DaiYuzeng committed Apr 27, 2023
1 parent fdaaf7e commit 0df1b35
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 133 deletions.
9 changes: 7 additions & 2 deletions pkg/harvester/dialog/EnableSriovDevice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mapGetters } from 'vuex';
import { Card } from '@components/Card';
import AsyncButton from '@shell/components/AsyncButton';
import { escapeHtml } from '@shell/utils/string';
import { clone } from '@shell/utils/object';
export default {
name: 'HarvesterEnableSriovDevice',
Expand All @@ -22,7 +23,9 @@ export default {
},
data() {
return { numVFs: 0 };
const numVFs = this.resources[0].spec?.numVFs || 1;
return { numVFs, numVFsHistory: clone(numVFs) };
},
computed: { ...mapGetters({ t: 'i18n/t' }) },
Expand All @@ -36,10 +39,12 @@ export default {
const actionResource = this.resources[0];
try {
this.resources[0].spec.numVFs = this.numVFs;
await actionResource.save();
buttonCb(true);
this.close();
} catch (err) {
this.resources[0].spec.numVFs = this.numVFsHistory;
this.$store.dispatch('growl/fromError', {
title: this.t('generic.notification.title.error', { name: escapeHtml(actionResource.metadata.name) }),
err,
Expand All @@ -62,7 +67,7 @@ export default {
<template #body>
<LabeledInput
v-model.number="resources[0].spec.numVFs"
v-model.number="numVFs"
type="number"
min="0"
required
Expand Down
60 changes: 0 additions & 60 deletions pkg/harvester/formatters/HarvesterNodeName.vue

This file was deleted.

61 changes: 0 additions & 61 deletions pkg/harvester/formatters/SriovNodeName.vue

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { STATE, AGE, SIMPLE_NAME } from '@shell/config/table-headers';
import { NODE } from '@shell/config/types';
import { HCI } from '../types';
import ResourceTable from '@shell/components/ResourceTable';
export default {
Expand Down Expand Up @@ -30,9 +31,9 @@ export default {
const nodeCol = {
name: 'node',
label: 'Node',
value: 'id',
value: 'realNodeName',
sort: ['realNodeName'],
formatter: 'SriovNodeName',
formatter: 'CopyToClipboard',
labelKey: 'tableHeaders.node'
};
Expand Down Expand Up @@ -67,7 +68,7 @@ export default {
return cols;
},
},
}
};
</script>

Expand Down
4 changes: 2 additions & 2 deletions pkg/harvester/list/kubevirt.io.virtualmachine.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export default {
const nodeCol = {
name: 'node',
label: 'Node',
value: 'id',
value: 'realAttachNodeName',
sort: ['realAttachNodeName'],
formatter: 'HarvesterNodeName',
formatter: 'CopyToClipboard',
labelKey: 'tableHeaders.node'
};
Expand Down
23 changes: 18 additions & 5 deletions pkg/harvester/models/devices.harvesterhci.io.sriovnetworkdevice.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import SteveModel from '@shell/plugins/steve/steve-class';
import { escapeHtml } from '@shell/utils/string';
import { colorForState } from '@shell/plugins/dashboard-store/resource-class';
import { NODE } from '@shell/config/types';
import { HCI } from '../types';
import { clone } from '@shell/utils/object';

/**
* Class representing SR-IOV Device resource.
Expand Down Expand Up @@ -63,14 +65,25 @@ export default class SRIOVDevice extends SteveModel {
}

async disableDevice() {
this.spec.numVFs = 0;
await this.save();
const numVFsHistory = clone(this.spec.numVFs);

try {
this.spec.numVFs = 0;
await this.save();
} catch (err) {
this.spec.numVFs = numVFsHistory;
this.$dispatch('growl/fromError', {
title: this.t('generic.notification.title.error', { name: escapeHtml(this.metadata.name) }),
err,
}, { root: true });
}
}

get realNodeName() {
const device = this.$getters['byId'](HCI.SR_IOV, this.id);
const nodeName = device?.spec?.nodeName;
const node = this.$getters['byId'](NODE, nodeName);
const inStore = this.$rootGetters['currentProduct'].inStore;
const nodeName = this.spec?.nodeName;
const nodes = this.$rootGetters[`${ inStore }/all`](NODE);
const node = nodes.find(N => N.id === nodeName);

return node?.nameDisplay || '';
}
Expand Down

0 comments on commit 0df1b35

Please sign in to comment.