mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2025-12-13 21:21:44 +00:00
Split passthrough to usb and pci components
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
parent
b26da699d3
commit
8a229d56d1
@ -6,7 +6,7 @@ import { escapeHtml } from '@shell/utils/string';
|
|||||||
import { HCI } from '../types';
|
import { HCI } from '../types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'HarvesterEnablePassthrough',
|
name: 'HarvesterEnablePciPassthrough',
|
||||||
|
|
||||||
emits: ['close'],
|
emits: ['close'],
|
||||||
|
|
||||||
114
pkg/harvester/dialog/EnableUSBPassthrough.vue
Normal file
114
pkg/harvester/dialog/EnableUSBPassthrough.vue
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
<script>
|
||||||
|
import { HCI } from '../types';
|
||||||
|
import { mapGetters } from 'vuex';
|
||||||
|
import { Card } from '@components/Card';
|
||||||
|
import AsyncButton from '@shell/components/AsyncButton';
|
||||||
|
import { escapeHtml } from '@shell/utils/string';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'HarvesterEnableUSBPassthrough',
|
||||||
|
|
||||||
|
components: {
|
||||||
|
AsyncButton,
|
||||||
|
Card,
|
||||||
|
},
|
||||||
|
|
||||||
|
props: {
|
||||||
|
resources: {
|
||||||
|
type: Array,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: { ...mapGetters({ t: 'i18n/t' }) },
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
close() {
|
||||||
|
this.$emit('close');
|
||||||
|
},
|
||||||
|
|
||||||
|
async save(buttonCb) {
|
||||||
|
// isSingleProduct == this is a standalone Harvester cluster
|
||||||
|
const isSingleProduct = this.$store.getters['isSingleProduct'];
|
||||||
|
let userName = 'admin';
|
||||||
|
|
||||||
|
// if this is imported Harvester, there may be users other than 'admin
|
||||||
|
if (!isSingleProduct) {
|
||||||
|
const user = this.$store.getters['auth/v3User'];
|
||||||
|
|
||||||
|
userName = user?.username || user?.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < this.resources.length; i++) {
|
||||||
|
const actionResource = this.resources[i];
|
||||||
|
const inStore = this.$store.getters['currentProduct'].inStore;
|
||||||
|
const pt = await this.$store.dispatch(`${ inStore }/create`, {
|
||||||
|
type: HCI.USB_CLAIM,
|
||||||
|
metadata: {
|
||||||
|
name: actionResource.metadata.name,
|
||||||
|
ownerReferences: [{
|
||||||
|
apiVersion: 'devices.harvesterhci.io/v1beta1',
|
||||||
|
kind: 'USBDevice',
|
||||||
|
name: actionResource.metadata.name,
|
||||||
|
uid: actionResource.metadata.uid,
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
pciAddress: actionResource.status.pciAddress,
|
||||||
|
nodeName: actionResource.status.nodeName,
|
||||||
|
userName
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
try {
|
||||||
|
await pt.save();
|
||||||
|
buttonCb(true);
|
||||||
|
this.close();
|
||||||
|
} catch (err) {
|
||||||
|
this.$store.dispatch('growl/fromError', {
|
||||||
|
title: this.t('harvester.usb.claimError', { name: escapeHtml(actionResource.metadata.name) }),
|
||||||
|
err,
|
||||||
|
}, { root: true });
|
||||||
|
buttonCb(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Card :show-highlight-border="false">
|
||||||
|
<h4
|
||||||
|
slot="title"
|
||||||
|
v-clean-html="t('promptRemove.title')"
|
||||||
|
class="text-default-text"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div slot="actions" class="actions">
|
||||||
|
<div class="buttons">
|
||||||
|
<button class="btn role-secondary mr-10" @click="close">
|
||||||
|
{{ t('generic.cancel') }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<AsyncButton mode="enable" @click="save" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.actions {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -135,7 +135,7 @@ export default class PCIDevice extends SteveModel {
|
|||||||
enablePassthroughBulk(resources = this) {
|
enablePassthroughBulk(resources = this) {
|
||||||
this.$dispatch('promptModal', {
|
this.$dispatch('promptModal', {
|
||||||
resources,
|
resources,
|
||||||
component: 'EnablePassthrough'
|
component: 'EnablePciPassthrough'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -135,7 +135,7 @@ export default class USBDevice extends SteveModel {
|
|||||||
enablePassthroughBulk(resources = this) {
|
enablePassthroughBulk(resources = this) {
|
||||||
this.$dispatch('promptModal', {
|
this.$dispatch('promptModal', {
|
||||||
resources,
|
resources,
|
||||||
component: 'EnablePassthrough'
|
component: 'EnableUSBPassthrough'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user