feat(forklift): UI based on the FIGMA

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
This commit is contained in:
Marcelo Fukumoto
2026-07-07 13:36:44 +02:00
parent 7d8d74ce17
commit 2259910be1
26 changed files with 17508 additions and 2543 deletions
@@ -0,0 +1,556 @@
<script>
import { defineComponent, ref, computed } from 'vue';
import { useStore } from 'vuex';
import { useRoute, useRouter } from 'vue-router';
import Loading from '@shell/components/Loading';
import Masthead from '@shell/components/ResourceList/Masthead';
import AsyncButton from '@shell/components/AsyncButton';
import LabeledSelect from '@shell/components/form/LabeledSelect';
import { RcItemCard } from '@components/RcItemCard';
import { SCHEMA, STORAGE_CLASS, NETWORK_ATTACHMENT } from '@shell/config/types';
import { useI18n } from '@shell/composables/useI18n';
import { HCI } from '../../../../types';
import { PRODUCT_NAME } from '../../../../config/harvester';
import vmData from '../../../../utils/vms.json';
const schema = {
id: HCI.FORKLIFT_NETWORK_MAP,
type: SCHEMA,
attributes: {
kind: HCI.FORKLIFT_NETWORK_MAP,
namespaced: true
},
metadata: { name: HCI.FORKLIFT_NETWORK_MAP },
};
export default defineComponent({
name: 'ForkliftConfigureMappings',
components: {
Loading,
Masthead,
AsyncButton,
LabeledSelect,
RcItemCard,
},
setup() {
const store = useStore();
const route = useRoute();
const router = useRouter();
const { t } = useI18n(store);
const vms = ref([]);
const harvesterNetworks = ref([]);
const storageClasses = ref([]);
const networkEntries = ref([]);
const storageEntries = ref([]);
const errors = ref([]);
const loading = ref(true);
const providerName = computed(() => route.query.provider || 'vsphere');
const namespace = computed(() => route.query.namespace || 'default');
const harvesterNetworkOptions = computed(() => {
const options = [
{ label: 'Pod Networking', value: 'pod' },
{ label: 'Ignored', value: 'ignored' },
];
harvesterNetworks.value.forEach((net) => {
const ns = net.metadata?.namespace || '';
const name = net.metadata?.name || net.id;
const fullName = ns ? `${ ns }/${ name }` : name;
options.push({ label: fullName, value: fullName });
});
return options;
});
const storageClassOptions = computed(() => {
const options = storageClasses.value.map((sc) => ({
label: sc.metadata?.name || sc.id,
value: sc.metadata?.name || sc.id,
}));
if (!options.find((o) => o.value === 'harvester-longhorn')) {
options.unshift({ label: 'harvester-longhorn', value: 'harvester-longhorn' });
}
return options;
});
const allNetworksMapped = computed(() => networkEntries.value.length > 0 && networkEntries.value.every((e) => !!e.target));
const allStorageMapped = computed(() => storageEntries.value.length > 0 && storageEntries.value.every((e) => !!e.target));
const canSave = computed(() => {
return networkEntries.value.length > 0 && storageEntries.value.length > 0 &&
allNetworksMapped.value && allStorageMapped.value;
});
const buildNetworkEntries = () => {
const entries = [];
vms.value.forEach((vm) => {
if (vm.networks && vm.networks.length > 0) {
vm.networks.forEach((net) => {
entries.push({
vmId: vm.id,
vmName: vm.name || vm.id,
name: net.name || 'Unknown',
id: net.id || '',
vlanId: net.vlanId || '',
target: 'pod',
_key: `net-${ vm.id }-${ net.id || net.name }`,
});
});
} else {
entries.push({
vmId: vm.id,
vmName: vm.name || vm.id,
name: 'Default Network',
id: '',
vlanId: '',
target: 'pod',
_key: `net-${ vm.id }-default`,
});
}
});
networkEntries.value = entries;
};
const buildStorageEntries = () => {
const entries = [];
vms.value.forEach((vm) => {
if (vm.disks && vm.disks.length > 0) {
const seen = new Set();
vm.disks.forEach((disk) => {
const ds = disk.datastore;
if (ds && ds.id && !seen.has(ds.id)) {
seen.add(ds.id);
entries.push({
vmId: vm.id,
vmName: vm.name || vm.id,
name: ds.name || 'Unknown',
id: ds.id || '',
type: ds.type || '',
capacity: disk.capacity || 0,
target: 'harvester-longhorn',
_key: `stor-${ vm.id }-${ ds.id }`,
});
}
});
} else {
entries.push({
vmId: vm.id,
vmName: vm.name || vm.id,
name: 'Default Datastore',
id: '',
type: '',
capacity: 0,
target: 'harvester-longhorn',
_key: `stor-${ vm.id }-default`,
});
}
});
storageEntries.value = entries;
};
const formatStorageDetail = (entry) => {
const parts = [];
if (entry.type) {
parts.push(entry.type);
}
if (entry.capacity) {
const gb = entry.capacity / (1024 * 1024 * 1024);
if (gb >= 1024) {
parts.push(`${ (gb / 1024).toFixed(1) } TB`);
} else {
parts.push(`${ Math.round(gb) } GB`);
}
}
return parts.join(' \u2022 ');
};
const cancel = () => {
router.push({
name: `${ PRODUCT_NAME }-c-cluster-forklift`,
params: {
product: route.params.product,
cluster: route.params.cluster,
}
});
};
const saveMappings = async(buttonCb) => {
const inStore = store.getters['currentProduct'].inStore;
const providerRef = {
source: {
apiVersion: 'forklift.konveyor.io/v1beta1',
kind: 'Provider',
name: providerName.value,
namespace: namespace.value,
},
destination: {
apiVersion: 'forklift.konveyor.io/v1beta1',
kind: 'Provider',
name: 'host',
namespace: 'forklift',
},
};
try {
// Create NetworkMap
const networkMapSpec = {
map: networkEntries.value.map((entry) => {
if (entry.target === 'pod') {
return {
source: { name: entry.name, id: entry.id },
destination: { type: 'pod' },
};
}
if (entry.target === 'ignored') {
return {
source: { name: entry.name, id: entry.id },
destination: { type: 'ignored' },
};
}
return {
source: { name: entry.name, id: entry.id },
destination: {
type: 'multus',
name: entry.target,
namespace: namespace.value,
},
};
}),
provider: providerRef,
};
const networkMap = await store.dispatch(`${ inStore }/create`, {
type: HCI.FORKLIFT_NETWORK_MAP,
metadata: {
name: `${ providerName.value }-network-map-${ Math.random().toString(36).substring(2, 7) }`,
namespace: namespace.value,
},
spec: networkMapSpec,
});
await networkMap.save();
// Create StorageMap
const storageMapSpec = {
map: storageEntries.value.map((entry) => ({
source: { name: entry.name, id: entry.id },
destination: { storageClass: entry.target },
})),
provider: providerRef,
};
const storageMap = await store.dispatch(`${ inStore }/create`, {
type: HCI.FORKLIFT_STORAGE_MAP,
metadata: {
name: `${ providerName.value }-storage-map-${ Math.random().toString(36).substring(2, 7) }`,
namespace: namespace.value,
},
spec: storageMapSpec,
});
await storageMap.save();
// Navigate to review page with all mapping data
const networkMappingsData = networkEntries.value.map((entry) => ({
vmId: entry.vmId,
source: entry.name,
target: entry.target === 'pod' ? 'Pod Networking' : entry.target === 'ignored' ? 'Ignored' : entry.target,
}));
const storageMappingsData = storageEntries.value.map((entry) => ({
vmId: entry.vmId,
source: entry.name,
target: entry.target,
}));
router.push({
name: `${ PRODUCT_NAME }-c-cluster-forklift-review-migration`,
params: {
product: route.params.product,
cluster: route.params.cluster,
},
query: {
provider: providerName.value,
namespace: namespace.value,
vms: route.query.vms,
networkMap: networkMap.metadata.name,
storageMap: storageMap.metadata.name,
networkMappings: JSON.stringify(networkMappingsData),
storageMappings: JSON.stringify(storageMappingsData),
}
});
buttonCb(true);
} catch (err) {
errors.value = [err.message || err];
buttonCb(false);
}
};
const init = async() => {
const inStore = store.getters['currentProduct'].inStore;
try {
harvesterNetworks.value = await store.dispatch(`${ inStore }/findAll`, { type: NETWORK_ATTACHMENT });
} catch (e) {
harvesterNetworks.value = [];
}
try {
storageClasses.value = await store.dispatch(`${ inStore }/findAll`, { type: STORAGE_CLASS });
} catch (e) {
storageClasses.value = [];
}
const vmsParam = route.query.vms;
if (vmsParam) {
try {
const vmIds = JSON.parse(vmsParam);
vms.value = vmIds.map((id) => {
const found = vmData.find((vm) => vm.id === id);
return found || {
id, name: id, networks: [], disks: []
};
});
} catch (e) {
vms.value = [];
}
}
buildNetworkEntries();
buildStorageEntries();
loading.value = false;
};
init();
return {
schema,
loading,
networkEntries,
storageEntries,
errors,
harvesterNetworkOptions,
storageClassOptions,
canSave,
t,
formatStorageDetail,
cancel,
saveMappings,
};
},
});
</script>
<template>
<Loading v-if="loading" />
<div
v-else
class="configure-mappings"
>
<Masthead
:schema="schema"
:resource="schema.id"
:type-display="t('harvester.addons.forklift.configureMappings.title')"
:is-creatable="false"
>
<template #subHeader>
<p class="text-muted line-height-20 mmt-5">
{{ t('harvester.addons.forklift.configureMappings.description') }}
</p>
</template>
</Masthead>
<div class="mappings-columns">
<!-- Network Mapping -->
<div class="mapping-column">
<div>
<h3 class="mapping-section-title">
{{ t('harvester.addons.forklift.configureMappings.networkMapping.title') }}
</h3>
<p class="text-muted line-height-20">
{{ t('harvester.addons.forklift.configureMappings.networkMapping.description') }}
</p>
</div>
<RcItemCard
v-for="entry in networkEntries"
:id="entry._key"
:key="entry._key"
:variant="'small'"
:header="{ title: { text: entry.vmId }, statuses: entry.target ? [{ icon: 'icon-notify-tick', color: 'text-success' }] : [] }"
>
<template #item-card-content>
<div class="card-content-row">
<div class="mapping-source">
<span class="source-name">{{ entry.name }}</span>
<span class="source-id text-muted">{{ entry.id }}</span>
<span class="source-detail text-muted">VLAN {{ entry.vlanId || '0' }}</span>
</div>
<div class="mapping-arrow">
→
</div>
<div class="mapping-target">
<LabeledSelect
v-model:value="entry.target"
:options="harvesterNetworkOptions"
:placeholder="t('harvester.addons.forklift.configureMappings.networkMapping.placeholder')"
:searchable="true"
/>
</div>
</div>
</template>
</RcItemCard>
</div>
<!-- Storage Mapping -->
<div class="mapping-column">
<div>
<h3 class="mapping-section-title">
{{ t('harvester.addons.forklift.configureMappings.storageMapping.title') }}
</h3>
<p class="text-muted">
{{ t('harvester.addons.forklift.configureMappings.storageMapping.description') }}
</p>
</div>
<RcItemCard
v-for="entry in storageEntries"
:id="entry._key"
:key="entry._key"
:variant="'small'"
:header="{ title: { text: entry.vmId }, statuses: entry.target ? [{ icon: 'icon-notify-tick', color: 'text-success' }] : [] }"
>
<template #item-card-content>
<div class="card-content-row">
<div class="mapping-source">
<span class="source-name">{{ entry.name }}</span>
<span class="source-id text-muted">{{ entry.id }}</span>
<span
v-if="entry.type || entry.capacity"
class="source-detail text-muted"
>{{ formatStorageDetail(entry) }}</span>
</div>
<div class="mapping-arrow">
→
</div>
<div class="mapping-target">
<LabeledSelect
v-model:value="entry.target"
:options="storageClassOptions"
:placeholder="t('harvester.addons.forklift.configureMappings.storageMapping.placeholder')"
:searchable="true"
/>
</div>
</div>
</template>
</RcItemCard>
</div>
</div>
<div class="actions-footer">
<button
class="btn role-secondary"
@click="cancel"
>
{{ t('generic.cancel') }}
</button>
<AsyncButton
:disabled="!canSave"
:action-label="t('harvester.addons.forklift.configureMappings.save')"
:waiting-label="t('harvester.addons.forklift.configureMappings.save')"
:success-label="t('harvester.addons.forklift.configureMappings.save')"
:error-label="t('harvester.addons.forklift.configureMappings.save')"
@click="saveMappings"
/>
</div>
</div>
</template>
<style lang="scss" scoped>
.configure-mappings {
padding: 20px;
}
.mappings-columns {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 64px;
}
.mapping-column {
display: flex;
gap: 12px;
flex-direction: column;
}
.mapping-section-title {
font-weight: 600;
margin: 0 0 5px 0;
line-height: 28px;
}
.card-content-row {
display: flex;
align-items: center;
gap: 40px;
width: 100%;
}
.mapping-source {
display: flex;
flex-direction: column;
min-width: 160px;
font-size: 14px;
line-height: 20px;
.source-name {
font-weight: 600;
}
}
.mapping-arrow {
color: var(--muted);
font-size: 16px;
flex-shrink: 0;
}
.mapping-target {
flex: 1;
}
.actions-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 30px;
}
.line-height-20 {
line-height: 20px;
}
</style>
@@ -0,0 +1,477 @@
<script>
import { defineComponent, ref, computed } from 'vue';
import { useStore } from 'vuex';
import { useRoute, useRouter } from 'vue-router';
import { LabeledInput } from '@components/Form/LabeledInput';
import { Checkbox } from '@components/Form/Checkbox';
import { Banner } from '@components/Banner';
import Masthead from '@shell/components/ResourceList/Masthead';
import AsyncButton from '@shell/components/AsyncButton';
import { SCHEMA, SECRET } from '@shell/config/types';
import { randomStr } from '@shell/utils/string';
import { useI18n } from '@shell/composables/useI18n';
import { HCI } from '../../../../types';
import { PRODUCT_NAME } from '../../../../config/harvester';
const schema = {
id: HCI.FORKLIFT_PROVIDER,
type: SCHEMA,
attributes: {
kind: HCI.FORKLIFT_PROVIDER,
namespaced: true
},
metadata: { name: HCI.FORKLIFT_PROVIDER },
};
export default defineComponent({
name: 'ForkliftConfigureProvider',
components: {
LabeledInput,
Checkbox,
Banner,
Masthead,
AsyncButton,
},
setup() {
const store = useStore();
const route = useRoute();
const router = useRouter();
const { t } = useI18n(store);
const allSecrets = ref([]);
const providerName = ref('');
const url = ref('');
const username = ref('');
const password = ref('');
const skipTlsVerify = ref(false);
const testResult = ref(null);
const testError = ref(null);
const errors = ref([]);
const createdProvider = ref(null);
const createdSecret = ref(null);
const loading = ref(true);
const isFormValid = computed(() => !!providerName.value && !!url.value && !!username.value && !!password.value);
const cancel = () => {
router.push({
name: `${ PRODUCT_NAME }-c-cluster-forklift`,
params: {
product: route.params.product,
cluster: route.params.cluster,
}
});
};
const testConnection = async(buttonCb) => {
testResult.value = null;
testError.value = null;
if (!providerName.value || !url.value || !username.value || !password.value) {
testError.value = t('harvester.addons.forklift.configureProvider.testMissingFields');
buttonCb(false);
return;
}
const inStore = store.getters['currentProduct'].inStore;
try {
if (createdProvider.value) {
await createdProvider.value.remove();
createdProvider.value = null;
}
if (createdSecret.value) {
await createdSecret.value.remove();
createdSecret.value = null;
}
const namespace = 'default';
const secretName = `${ providerName.value }-creds-${ randomStr(4).toLowerCase() }`;
const newSecret = await store.dispatch(`${ inStore }/create`, {
type: SECRET,
metadata: {
name: secretName,
namespace,
labels: {
createdForProviderType: 'vsphere',
createdForResourceType: 'providers',
}
}
});
newSecret['_type'] = 'Opaque';
newSecret['data'] = {
user: btoa(username.value),
password: btoa(password.value),
insecureSkipVerify: btoa(String(skipTlsVerify.value)),
url: btoa(url.value),
};
await newSecret.save();
createdSecret.value = newSecret;
const provider = await store.dispatch(`${ inStore }/create`, {
type: HCI.FORKLIFT_PROVIDER,
metadata: {
name: providerName.value,
namespace,
},
spec: {
type: 'vsphere',
url: url.value,
secret: {
name: secretName,
namespace,
},
}
});
await provider.save();
createdProvider.value = provider;
const maxAttempts = 15;
let attempts = 0;
let connected = false;
let errorMsg = '';
while (attempts < maxAttempts) {
await new Promise((resolve) => setTimeout(resolve, 2000));
attempts++;
const refreshed = await store.dispatch(`${ inStore }/find`, {
type: HCI.FORKLIFT_PROVIDER,
id: `${ namespace }/${ providerName.value }`,
opt: { force: true }
});
const conditions = refreshed?.status?.conditions || [];
const readyCondition = conditions.find((c) => c.type === 'Ready');
const connectionCondition = conditions.find((c) => c.type === 'ConnectionTestSucceeded');
if (connectionCondition) {
if (connectionCondition.status === 'True') {
connected = true;
break;
} else {
errorMsg = connectionCondition.message || 'Connection failed';
break;
}
}
if (readyCondition) {
if (readyCondition.status === 'True') {
connected = true;
break;
} else if (readyCondition.status === 'False') {
errorMsg = readyCondition.message || 'Provider not ready';
break;
}
}
}
if (connected) {
testResult.value = t('harvester.addons.forklift.configureProvider.testSuccess');
buttonCb(true);
} else {
if (createdProvider.value) {
await createdProvider.value.remove();
createdProvider.value = null;
}
if (createdSecret.value) {
await createdSecret.value.remove();
createdSecret.value = null;
}
testError.value = errorMsg || t('harvester.addons.forklift.configureProvider.testTimeout');
buttonCb(false);
}
} catch (err) {
if (createdProvider.value) {
try {
await createdProvider.value.remove();
} catch (e) {}
createdProvider.value = null;
}
if (createdSecret.value) {
try {
await createdSecret.value.remove();
} catch (e) {}
createdSecret.value = null;
}
testError.value = err.message || t('harvester.addons.forklift.configureProvider.testFailed');
buttonCb(false);
}
};
const saveProvider = async(buttonCb) => {
const inStore = store.getters['currentProduct'].inStore;
errors.value = [];
try {
if (createdProvider.value) {
router.push({
name: `${ PRODUCT_NAME }-c-cluster-forklift-select-vms`,
params: {
product: route.params.product,
cluster: route.params.cluster,
},
query: {
provider: providerName.value,
namespace: createdProvider.value.metadata.namespace,
}
});
return;
}
const namespace = 'default';
const secretName = `${ providerName.value }-creds-${ randomStr(4).toLowerCase() }`;
const newSecret = await store.dispatch(`${ inStore }/create`, {
type: SECRET,
metadata: {
name: secretName,
namespace,
labels: {
createdForProviderType: 'vsphere',
createdForResourceType: 'providers',
}
}
});
newSecret['_type'] = 'Opaque';
newSecret['data'] = {
user: btoa(username.value),
password: btoa(password.value),
insecureSkipVerify: btoa(String(skipTlsVerify.value)),
url: btoa(url.value),
};
await newSecret.save();
const provider = await store.dispatch(`${ inStore }/create`, {
type: HCI.FORKLIFT_PROVIDER,
metadata: {
name: providerName.value,
namespace,
},
spec: {
type: 'vsphere',
url: url.value,
secret: {
name: secretName,
namespace,
},
}
});
await provider.save();
router.push({
name: `${ PRODUCT_NAME }-c-cluster-forklift-select-vms`,
params: {
product: route.params.product,
cluster: route.params.cluster,
},
query: {
provider: providerName.value,
namespace,
}
});
} catch (err) {
errors.value = [err.message || err];
buttonCb(false);
}
};
const init = async() => {
const inStore = store.getters['currentProduct'].inStore;
allSecrets.value = await store.dispatch(`${ inStore }/findAll`, { type: SECRET });
loading.value = false;
};
init();
return {
schema,
allSecrets,
providerName,
url,
username,
password,
skipTlsVerify,
testResult,
testError,
errors,
loading,
isFormValid,
t,
cancel,
testConnection,
saveProvider,
};
},
});
</script>
<template>
<div class="configure-provider">
<Masthead
:schema="schema"
:resource="schema.id"
:type-display="t('harvester.addons.forklift.configureProvider.title')"
:is-creatable="false"
>
<template #subHeader>
<div class="mmt-5">
<p class="text-muted">
{{ t('harvester.addons.forklift.configureProvider.description') }}
</p>
</div>
</template>
</Masthead>
<h3 class="mmt-3 mmb-3 table-title">
<b>{{ t('harvester.addons.forklift.configureProvider.connectionDetails') }}</b>
</h3>
<Banner
class="requirements-banner mt-0 mmb-3"
color="info"
>
<div class="requirements-banner-content">
<span class="requirements-banner-title">{{ t('harvester.addons.forklift.configureProvider.requirementsTitle') }}</span>
<br>
<span>{{ t('harvester.addons.forklift.configureProvider.requirementsText') }}</span>
</div>
</Banner>
<div class="mb-20">
<LabeledInput
v-model:value="providerName"
:label="t('harvester.addons.forklift.configureProvider.name')"
required
/>
</div>
<div class="mb-20">
<LabeledInput
v-model:value="url"
:label="t('harvester.addons.forklift.configureProvider.urlLabel')"
:placeholder="t('harvester.addons.forklift.configureProvider.urlPlaceholder')"
required
/>
<p class="text-muted mt-5">
{{ t('harvester.addons.forklift.configureProvider.urlHint') }}
</p>
</div>
<div class="row mb-20">
<div class="col span-6">
<LabeledInput
v-model:value="username"
:label="t('harvester.addons.forklift.fields.username')"
required
/>
</div>
<div class="col span-6">
<LabeledInput
v-model:value="password"
type="password"
:label="t('harvester.addons.forklift.fields.password')"
required
/>
</div>
</div>
<div class="mb-20">
<Checkbox
v-model:value="skipTlsVerify"
:label="t('harvester.addons.forklift.configureProvider.skipSsl')"
/>
<p class="text-muted ml-20">
{{ t('harvester.addons.forklift.configureProvider.skipSslHint') }}
</p>
</div>
<div class="mb-20">
<AsyncButton
mode="test"
:action-label="t('harvester.addons.forklift.configureProvider.testConnection')"
:waiting-label="t('harvester.addons.forklift.configureProvider.testConnection')"
:success-label="t('harvester.addons.forklift.configureProvider.testConnection')"
:error-label="t('harvester.addons.forklift.configureProvider.testConnection')"
class="btn role-secondary"
@click="testConnection"
/>
</div>
<Banner
v-if="testResult"
color="success"
class="mb-10"
>
{{ testResult }}
</Banner>
<Banner
v-if="testError"
color="error"
class="mb-10"
>
{{ testError }}
</Banner>
<Banner
v-for="(err, i) in errors"
:key="i"
color="error"
class="mb-10"
>
{{ err }}
</Banner>
<div class="provider-actions">
<button
class="btn role-secondary"
@click="cancel"
>
{{ t('generic.cancel') }}
</button>
<AsyncButton
:disabled="!isFormValid"
:action-label="t('harvester.addons.forklift.configureProvider.save')"
:waiting-label="t('harvester.addons.forklift.configureProvider.save')"
:success-label="t('harvester.addons.forklift.configureProvider.save')"
:error-label="t('harvester.addons.forklift.configureProvider.save')"
@click="saveProvider"
/>
</div>
</div>
</template>
<style lang="scss" scoped>
.configure-provider {
padding: 20px;
}
.requirements-banner {
font-weight: 400;
.requirements-banner-title {
font-weight: 600;
}
}
.provider-actions {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 30px;
}
</style>
@@ -0,0 +1,342 @@
<script>
import { defineComponent, ref, computed } from 'vue';
import { useStore } from 'vuex';
import { useRoute } from 'vue-router';
import Loading from '@shell/components/Loading';
import Masthead from '@shell/components/ResourceList/Masthead';
import ResourceTable from '@shell/components/ResourceTable';
import PercentageBar from '@shell/components/PercentageBar';
import MappingsCell from '../../../../components/MappingsCell';
import { SCHEMA } from '@shell/config/types';
import { useI18n } from '@shell/composables/useI18n';
import { HCI } from '../../../../types';
import { PRODUCT_NAME } from '../../../../config/harvester';
import { FORKLIFT_PLAN_VM_COUNT } from '../../../../config/table-headers';
import { STATE, NAME as NAME_COL, AGE } from '@shell/config/table-headers';
const schema = {
id: HCI.FORKLIFT_PLAN,
type: SCHEMA,
attributes: {
kind: HCI.FORKLIFT_PLAN,
namespaced: true
},
metadata: { name: HCI.FORKLIFT_PLAN },
};
export default defineComponent({
name: 'ForkliftMigrationDashboard',
components: {
Loading,
Masthead,
MappingsCell,
PercentageBar,
ResourceTable,
},
setup() {
const store = useStore();
const route = useRoute();
const { t } = useI18n(store);
const loading = ref(true);
const inStore = computed(() => store.getters['currentProduct'].inStore);
const allPlans = computed(() => store.getters[`${ inStore.value }/all`](HCI.FORKLIFT_PLAN));
const allNetworkMaps = computed(() => store.getters[`${ inStore.value }/all`](HCI.FORKLIFT_NETWORK_MAP));
const allStorageMaps = computed(() => store.getters[`${ inStore.value }/all`](HCI.FORKLIFT_STORAGE_MAP));
const rows = computed(() => {
return allPlans.value.map((plan) => {
const netMapName = plan.spec?.map?.network?.name;
const netMapNs = plan.spec?.map?.network?.namespace || plan.metadata.namespace;
const storMapName = plan.spec?.map?.storage?.name;
const storMapNs = plan.spec?.map?.storage?.namespace || plan.metadata.namespace;
const netMap = allNetworkMaps.value.find((m) => m.metadata.name === netMapName && m.metadata.namespace === netMapNs);
const storMap = allStorageMaps.value.find((m) => m.metadata.name === storMapName && m.metadata.namespace === storMapNs);
plan.networkEntries = (netMap?.spec?.map || []).map((e) => `${ e.source?.id || '-' } → ${ e.destination?.type === 'pod' ? 'Pod Network' : (e.destination?.name || '-') }`);
plan.storageEntries = (storMap?.spec?.map || []).map((e) => `${ e.source?.id || '-' } → ${ e.destination?.storageClass || '-' }`);
plan.networkDisplay = plan.networkEntries.join(', ') || '-';
plan.storageDisplay = plan.storageEntries.join(', ') || '-';
plan.vmIdsDisplay = (plan.spec?.vms || []).map((vm) => vm.id || vm.name || '').filter(Boolean).join(', ') || '-';
const vms = plan.status?.migration?.vms || [];
plan.vmProgress = vms.map((vm) => {
const pipeline = vm.pipeline || [];
const totalSteps = pipeline.length;
const completedSteps = pipeline.filter((s) => s.phase === 'Completed').length;
return {
name: vm.id || vm.name || 'Unknown',
steps: pipeline.map((step) => ({
name: step.name || 'Unknown',
progress: step.phase === 'Completed' ? 100 : (step.progress?.completed && step.progress?.total ? Math.round((step.progress.completed / step.progress.total) * 100) : 0),
hasError: !!step.error,
reason: (step.error?.reasons || []).join('; ') || '',
})),
progress: totalSteps > 0 ? Math.round((completedSteps / totalSteps) * 100) : 0,
};
});
let totalSteps = 0;
let completedSteps = 0;
vms.forEach((vm) => {
const pipeline = vm.pipeline || [];
totalSteps += pipeline.length;
completedSteps += pipeline.filter((s) => s.phase === 'Completed').length;
});
plan.progress = totalSteps > 0 ? Math.round((completedSteps / totalSteps) * 100) : 0;
return plan;
});
});
const createLocation = computed(() => ({
name: `${ PRODUCT_NAME }-c-cluster-forklift-configure-provider`,
params: {
product: route.params.product,
cluster: route.params.cluster,
}
}));
const headers = [
{ ...STATE, labelKey: 'harvester.addons.forklift.dashboard.columns.status' },
{
...NAME_COL,
labelKey: 'harvester.addons.forklift.dashboard.columns.plan',
subLabel: 'VM IDs',
},
{ ...FORKLIFT_PLAN_VM_COUNT, width: 105 },
{
name: 'progress',
labelKey: 'harvester.addons.forklift.dashboard.columns.progress',
value: 'progress',
width: 299,
},
{
name: 'mappings',
labelKey: 'harvester.addons.forklift.dashboard.columns.mappings',
value: 'mappingsDisplay',
width: 387,
},
{ ...AGE },
];
const init = async() => {
await Promise.all([
store.dispatch(`${ inStore.value }/findAll`, { type: HCI.FORKLIFT_PLAN }),
store.dispatch(`${ inStore.value }/findAll`, { type: HCI.FORKLIFT_NETWORK_MAP }),
store.dispatch(`${ inStore.value }/findAll`, { type: HCI.FORKLIFT_STORAGE_MAP }),
]);
loading.value = false;
};
init();
return {
schema,
loading,
rows,
createLocation,
headers,
t,
};
},
});
</script>
<template>
<Loading v-if="loading" />
<div v-else>
<Masthead
:schema="schema"
:resource="schema.id"
:type-display="t('harvester.addons.forklift.dashboard.title')"
>
<template #subHeader>
<div class="mmt-5">
<p class="text-muted">
{{ t('harvester.addons.forklift.dashboard.description') }}
</p>
</div>
</template>
<template #createButton>
<router-link
:to="createLocation"
class="btn role-primary"
>
{{ t('harvester.addons.forklift.dashboard.createPlan') }}
</router-link>
</template>
</Masthead>
<ResourceTable
:schema="schema"
:rows="rows"
:headers="headers"
:groupable="false"
:table-actions="false"
:search="false"
key-field="_key"
>
<template #header-left>
<h3 class="table-title m-0">
{{ t('harvester.addons.forklift.dashboard.tableTitle') }}
</h3>
</template>
<template #cell:name="{ row }">
<div class="plan-name-cell">
<div class="plan-name">
{{ row.metadata.name }}
</div>
<div class="plan-vms text-muted">
{{ row.vmIdsDisplay }}
</div>
</div>
</template>
<template #cell:vmCount="{ row }">
{{ (row.spec.vms || []).length }} VMs
</template>
<template #cell:progress="{ row }">
<div
v-if="row.vmProgress && row.vmProgress.length"
class="progress-steps"
>
<div
v-for="vm in row.vmProgress"
:key="vm.name"
class="vm-progress"
>
<div class="vm-name">
{{ vm.name }}
</div>
<div
v-for="step in vm.steps"
:key="step.name"
class="progress-step"
>
<span
class="step-name"
:class="{ 'text-error': step.hasError }"
>
{{ step.name }}
</span>
<PercentageBar
:model-value="step.progress"
:color-stops="step.hasError ? { 0: '--error' } : { 99: '--primary', 100: '--success' }"
preferred-direction="MORE"
class="step-bar"
/>
<span class="step-pct">{{ step.progress }}%</span>
</div>
<div
v-for="step in vm.steps.filter(s => s.hasError)"
:key="`error-${step.name}`"
class="step-error-msg"
>
<span class="text-error">{{ step.reason }}</span>
</div>
</div>
</div>
<span v-else>-</span>
</template>
<template #cell:mappings="{ row }">
<MappingsCell
:network-entries="row.networkEntries"
:storage-entries="row.storageEntries"
/>
</template>
</ResourceTable>
</div>
</template>
<style lang="scss" scoped>
.plan-name-cell {
.plan-name {
font-weight: 600;
line-height: 20px;
}
.plan-vms {
font-size: 12px;
line-height: 20px;
color: var(--muted);
}
}
.progress-steps {
display: flex;
flex-direction: column;
gap: 8px;
}
.vm-progress {
&:not(:last-child) {
padding-bottom: 6px;
border-bottom: 1px solid var(--border);
}
}
.vm-name {
font-weight: 600;
font-size: 12px;
margin-bottom: 4px;
}
.progress-step {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 4px;
padding-right: 13px;
}
.step-error-msg {
margin-top: 4px;
font-size: 12px;
.text-error {
color: var(--error);
}
}
.step-name {
font-size: 12px;
width: 110px;
min-width: 110px;
max-width: 110px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&.text-error {
color: var(--error);
font-weight: 600;
}
}
.step-bar {
flex: 1;
min-width: 80px;
}
.step-pct {
font-size: 12px;
min-width: 35px;
text-align: left;
}
.table-title {
font-weight: 600;
}
</style>
@@ -0,0 +1,544 @@
<script>
import { defineComponent, ref, computed } from 'vue';
import { useStore } from 'vuex';
import { useRoute, useRouter } from 'vue-router';
import Loading from '@shell/components/Loading';
import Masthead from '@shell/components/ResourceList/Masthead';
import AsyncButton from '@shell/components/AsyncButton';
import { Banner } from '@components/Banner';
import { RcItemCard } from '@components/RcItemCard';
import MappingsCell from '../../../../components/MappingsCell';
import { SCHEMA } from '@shell/config/types';
import { useI18n } from '@shell/composables/useI18n';
import { HCI } from '../../../../types';
import { PRODUCT_NAME } from '../../../../config/harvester';
import vmData from '../../../../utils/vms.json';
const schema = {
id: HCI.FORKLIFT_PLAN,
type: SCHEMA,
attributes: {
kind: HCI.FORKLIFT_PLAN,
namespaced: true
},
metadata: { name: HCI.FORKLIFT_PLAN },
};
export default defineComponent({
name: 'ForkliftReviewMigration',
components: {
Loading,
Masthead,
AsyncButton,
Banner,
MappingsCell,
RcItemCard,
},
setup() {
const store = useStore();
const route = useRoute();
const router = useRouter();
const { t } = useI18n(store);
const vms = ref([]);
const networkMappings = ref([]);
const storageMappings = ref([]);
const errors = ref([]);
const loading = ref(true);
const providerName = computed(() => route.query.provider || 'vsphere');
const namespace = computed(() => route.query.namespace || 'default');
const networkMapName = computed(() => route.query.networkMap || '');
const storageMapName = computed(() => route.query.storageMap || '');
const totalVCpu = computed(() => vms.value.reduce((sum, vm) => sum + (vm.cpuCount || vm.numCPU || 0), 0));
const totalMemoryGB = computed(() => {
const totalMB = vms.value.reduce((sum, vm) => sum + (vm.memoryMB || vm.memory || 0), 0);
return Math.round(totalMB / 1024);
});
const totalStorageGB = computed(() => {
let totalBytes = 0;
vms.value.forEach((vm) => {
if (vm.disks && vm.disks.length > 0) {
totalBytes += vm.disks.reduce((sum, d) => sum + (d.capacity || 0), 0);
}
});
return Math.round(totalBytes / (1024 * 1024 * 1024));
});
const vmCards = computed(() => {
return vms.value.map((vm) => {
const cpus = vm.cpuCount || vm.numCPU || 0;
const memMB = vm.memoryMB || vm.memory || 0;
const memGB = memMB ? `${ Math.round(memMB / 1024) } GB` : '-';
let totalDiskBytes = 0;
if (vm.disks && vm.disks.length > 0) {
totalDiskBytes = vm.disks.reduce((sum, d) => sum + (d.capacity || 0), 0);
}
const diskDisplay = totalDiskBytes ? `${ Math.round(totalDiskBytes / (1024 * 1024 * 1024)) } GB` : '-';
const os = vm.guestName || vm.guestOS || vm.os || '-';
const vmNetworkMappings = networkMappings.value.filter((m) => m.vmId === vm.id);
const vmStorageMappings = storageMappings.value.filter((m) => m.vmId === vm.id);
return {
id: vm.id,
name: vm.name || vm.id,
os,
cpus,
memGB,
diskDisplay,
networkMappings: vmNetworkMappings,
storageMappings: vmStorageMappings,
};
});
});
const cancel = () => {
router.push({
name: `${ PRODUCT_NAME }-c-cluster-forklift`,
params: {
product: route.params.product,
cluster: route.params.cluster,
}
});
};
const startMigration = async(buttonCb) => {
const inStore = store.getters['currentProduct'].inStore;
try {
const planName = `${ providerName.value }-plan-${ Math.random().toString(36).substring(2, 7) }`;
const planSpec = {
provider: {
source: {
apiVersion: 'forklift.konveyor.io/v1beta1',
kind: 'Provider',
name: providerName.value,
namespace: namespace.value,
},
destination: {
apiVersion: 'forklift.konveyor.io/v1beta1',
kind: 'Provider',
name: 'host',
namespace: 'forklift',
},
},
map: {
network: {
apiVersion: 'forklift.konveyor.io/v1beta1',
kind: 'NetworkMap',
name: networkMapName.value,
namespace: namespace.value,
},
storage: {
apiVersion: 'forklift.konveyor.io/v1beta1',
kind: 'StorageMap',
name: storageMapName.value,
namespace: namespace.value,
},
},
targetNamespace: namespace.value,
vms: vms.value.map((vm) => ({
id: vm.id,
name: vm.name || vm.id,
})),
warm: false,
};
const plan = await store.dispatch(`${ inStore }/create`, {
type: HCI.FORKLIFT_PLAN,
metadata: {
name: planName,
namespace: namespace.value,
},
spec: planSpec,
});
await plan.save();
const migrationName = `${ planName }-migration-${ Math.random().toString(36).substring(2, 7) }`;
const migration = await store.dispatch(`${ inStore }/create`, {
type: HCI.FORKLIFT_MIGRATION,
metadata: {
name: migrationName,
namespace: namespace.value,
},
spec: {
plan: {
apiVersion: 'forklift.konveyor.io/v1beta1',
kind: 'Plan',
name: planName,
namespace: namespace.value,
},
},
});
await migration.save();
router.push({
name: `${ PRODUCT_NAME }-c-cluster-forklift`,
params: {
product: route.params.product,
cluster: route.params.cluster,
}
});
buttonCb(true);
} catch (err) {
errors.value = [err.message || err];
buttonCb(false);
}
};
const init = async() => {
const vmsParam = route.query.vms;
if (vmsParam) {
try {
const vmIds = JSON.parse(vmsParam);
vms.value = vmIds.map((id) => {
const found = vmData.find((vm) => vm.id === id);
return found || {
id, name: id, networks: [], disks: [], cpuCount: 0, memoryMB: 0, guestName: ''
};
});
} catch (e) {
vms.value = [];
}
}
const networkMappingsParam = route.query.networkMappings;
if (networkMappingsParam) {
try {
networkMappings.value = JSON.parse(networkMappingsParam);
} catch (e) {
networkMappings.value = [];
}
}
const storageMappingsParam = route.query.storageMappings;
if (storageMappingsParam) {
try {
storageMappings.value = JSON.parse(storageMappingsParam);
} catch (e) {
storageMappings.value = [];
}
}
loading.value = false;
};
init();
return {
schema,
loading,
vms,
errors,
providerName,
namespace,
totalVCpu,
totalMemoryGB,
totalStorageGB,
vmCards,
t,
cancel,
startMigration,
};
},
});
</script>
<template>
<Loading v-if="loading" />
<div
v-else
class="review-migration"
>
<Masthead
:schema="schema"
:resource="schema.id"
:type-display="t('harvester.addons.forklift.reviewMigration.title')"
:is-creatable="false"
>
<template #subHeader>
<p class="text-muted mt-5">
{{ t('harvester.addons.forklift.reviewMigration.description') }}
</p>
</template>
</Masthead>
<!-- Migration Details Summary -->
<div class="migration-details">
<h3 class="section-title">
{{ t('harvester.addons.forklift.reviewMigration.migrationDetails') }}
</h3>
<div class="details-grid">
<div class="detail-column">
<div class="detail-item">
<span class="detail-label">{{ t('harvester.addons.forklift.reviewMigration.totalVms') }}</span>
<span class="detail-value detail-value-large">{{ vms.length }}</span>
</div>
</div>
<div class="detail-column">
<div class="detail-item">
<span class="detail-label">{{ t('harvester.addons.forklift.reviewMigration.source') }}</span>
</div>
<div class="detail-item">
<span class="detail-value">{{ providerName }}</span>
</div>
</div>
<div class="detail-column">
<div class="detail-item">
<span class="detail-label">{{ t('harvester.addons.forklift.reviewMigration.targetNamespace') }}</span>
</div>
<div class="detail-item">
<span class="detail-value">{{ namespace }}</span>
</div>
</div>
<div class="detail-column">
<div class="detail-item">
<span class="detail-label">{{ t('harvester.addons.forklift.reviewMigration.vcpu') }}</span>
<span class="detail-value">{{ totalVCpu }}</span>
</div>
<div class="detail-item">
<span class="detail-label">{{ t('harvester.addons.forklift.reviewMigration.memory') }}</span>
<span class="detail-value">{{ totalMemoryGB }} GB</span>
</div>
<div class="detail-item">
<span class="detail-label">{{ t('harvester.addons.forklift.reviewMigration.storage') }}</span>
<span class="detail-value">{{ totalStorageGB }} GB</span>
</div>
</div>
<div class="detail-column grid-column-2">
<div class="detail-item">
<span class="detail-label">{{ t('harvester.addons.forklift.reviewMigration.migrationMode') }}</span>
</div>
<div class="detail-item">
<span class="detail-value">
{{ t('harvester.addons.forklift.reviewMigration.coldMigration') }}
<span
class="ml-10 small-text"
>{{ t('harvester.addons.forklift.reviewMigration.vmsWillShutDown') }}</span>
</span>
</div>
</div>
</div>
</div>
<!-- Virtual Machines -->
<div class="vm-section">
<h3 class="section-title">
{{ t('harvester.addons.forklift.reviewMigration.virtualMachines') }} ({{ vms.length }})
</h3>
<div class="vm-cards-grid">
<RcItemCard
v-for="vm in vmCards"
:id="vm.id"
:key="vm.id"
:variant="'small'"
:header="{ title: { text: vm.name }, statuses: [{ icon: 'icon-notify-tick', color: 'text-success' }] }"
>
<template #item-card-content>
<div class="vm-card-content">
<div class="vm-card-specs">
<span class="vm-os text-muted">{{ vm.os }}</span>
<span class="vm-resources">
<i class="icon icon-dock" />
{{ vm.cpus }} vCPU &bull; {{ vm.memGB }} &bull; {{ vm.diskDisplay }}
</span>
</div>
<MappingsCell
:network-entries="vm.networkMappings.map(m => `${m.source} → ${m.target}`)"
:storage-entries="vm.storageMappings.map(m => `${m.source} → ${m.target}`)"
/>
</div>
</template>
</RcItemCard>
</div>
</div>
<!-- Cold Migration Warning -->
<Banner
color="warning"
class="mt-20"
>
<div>
<span class="banner-title">{{ t('harvester.addons.forklift.reviewMigration.warningTitle') }}</span><br>
{{ t('harvester.addons.forklift.reviewMigration.warningMessage') }}
</div>
</Banner>
<!-- Error banner -->
<Banner
v-for="(err, i) in errors"
:key="i"
color="error"
:label="err"
class="mt-10"
/>
<!-- Actions -->
<div class="actions-footer">
<button
class="btn role-secondary"
@click="cancel"
>
{{ t('generic.cancel') }}
</button>
<AsyncButton
:action-label="t('harvester.addons.forklift.reviewMigration.startMigration')"
:waiting-label="t('harvester.addons.forklift.reviewMigration.startMigration')"
:success-label="t('harvester.addons.forklift.reviewMigration.startMigration')"
:error-label="t('harvester.addons.forklift.reviewMigration.startMigration')"
@click="startMigration"
/>
</div>
</div>
</template>
<style lang="scss" scoped>
.review-migration {
padding: 20px;
}
.section-title {
font-weight: 600;
margin: 0 0 15px 0;
}
.migration-details {
margin-bottom: 30px;
}
.details-grid {
display: grid;
grid-template-columns: minmax(230px, 1fr) 1fr 1fr;
grid-template-rows: 1fr 1fr;
gap: 12px 128px;
width: 747px;
line-height: 20px;
}
.detail-column {
display: flex;
flex-direction: column;
gap: 4px;
&.grid-column-2 {
grid-column: span 2;
}
}
.detail-item {
display: flex;
flex-direction: row;
justify-content: space-between;
.detail-label {
font-size: 14px;
color: var(--muted);
}
.detail-value {
font-weight: 600;
font-size: 14px;
&.detail-value-large {
font-size: 24px;
}
}
}
.vm-section {
margin-top: 30px;
}
.vm-cards-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
gap: 16px;
}
.vm-card-content {
display: flex;
flex-direction: column;
gap: 16px;
line-height: 20px;
}
.vm-card-specs {
display: flex;
flex-direction: row;
gap: 16px;
align-items: center;
.vm-os {
font-size: 14px;
}
.vm-resources {
font-size: 14px;
color: var(--muted);
display: inline-flex;
align-items: center;
gap: 8px;
}
}
.vm-card-mappings {
display: flex;
flex-direction: column;
gap: 4px;
border-top: 1px solid var(--border);
padding-top: 10px;
}
.mapping-line {
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
.icon {
color: var(--muted);
font-size: 14px;
}
}
.small-text {
font-size: 12px;
line-height: 16px;
color: #973C00;
}
.actions-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 30px;
}
.banner-title {
font-weight: 600;
}
</style>
@@ -0,0 +1,518 @@
<script>
import { defineComponent, ref, computed } from 'vue';
import { useStore } from 'vuex';
import { useRoute, useRouter } from 'vue-router';
import Loading from '@shell/components/Loading';
import Masthead from '@shell/components/ResourceList/Masthead';
import SortableTable from '@shell/components/SortableTable';
import { LabeledInput } from '@components/Form/LabeledInput';
import { SCHEMA } from '@shell/config/types';
import { useI18n } from '@shell/composables/useI18n';
import { HCI } from '../../../../types';
import { PRODUCT_NAME } from '../../../../config/harvester';
import vmData from '../../../../utils/vms.json';
const schema = {
id: HCI.FORKLIFT_PROVIDER,
type: SCHEMA,
attributes: {
kind: HCI.FORKLIFT_PROVIDER,
namespaced: true
},
metadata: { name: HCI.FORKLIFT_PROVIDER },
};
export default defineComponent({
name: 'ForkliftSelectVms',
components: {
Loading,
Masthead,
SortableTable,
LabeledInput,
},
setup() {
const store = useStore();
const route = useRoute();
const router = useRouter();
const { t } = useI18n(store);
const allProviders = ref([]);
const provider = ref(null);
const discoveredVMs = ref([]);
const selectedVMs = ref([]);
const manualVMs = ref([]);
const newVmId = ref('');
const tableRows = ref([]);
const loading = ref(true);
const providerName = computed(() => provider.value?.metadata?.name || route.query.provider || '');
const vmCount = computed(() => discoveredVMs.value.length);
const showManualEntry = computed(() => discoveredVMs.value.length === 0);
const selectedCount = computed(() => showManualEntry.value ? manualVMs.value.length : selectedVMs.value.length);
const manualHeaders = [
{
name: 'id',
labelKey: 'harvester.addons.forklift.selectVms.columns.vmId',
value: 'id',
},
];
const headers = [
{
name: 'vmName',
labelKey: 'harvester.addons.forklift.selectVms.columns.vmName',
value: 'vmName',
subLabel: 'Identifier',
},
{
name: 'os',
labelKey: 'harvester.addons.forklift.selectVms.columns.os',
value: 'os',
},
{
name: 'resources',
labelKey: 'harvester.addons.forklift.selectVms.columns.resources',
value: 'resources',
sort: false,
},
{
name: 'powerState',
labelKey: 'harvester.addons.forklift.selectVms.columns.powerState',
value: 'powerState',
},
{
name: 'network',
labelKey: 'harvester.addons.forklift.selectVms.columns.network',
value: 'network',
subLabel: 'Identifier',
},
{
name: 'datastore',
labelKey: 'harvester.addons.forklift.selectVms.columns.datastore',
value: 'datastore',
subLabel: 'Identifier',
},
];
const buildTableRows = () => {
return discoveredVMs.value.map((vm) => {
const cpus = vm.cpuCount || vm.numCPU || '-';
const memMB = vm.memoryMB || vm.memory || 0;
const memGB = memMB ? `${ Math.round(memMB / 1024) } GB` : '-';
let totalDiskBytes = 0;
if (vm.disks && vm.disks.length > 0) {
totalDiskBytes = vm.disks.reduce((sum, d) => sum + (d.capacity || 0), 0);
}
const diskDisplay = totalDiskBytes ? `${ Math.round(totalDiskBytes / (1024 * 1024 * 1024)) } GB` : '-';
const powerState = vm.powerState || vm.status?.phase || '-';
let networks = [];
if (vm.networks && vm.networks.length > 0) {
networks = vm.networks.map((n) => ({
name: n.name || n.id || n,
id: n.id || '',
vlanId: n.vlanId || '',
}));
}
const datastores = [];
if (vm.disks && vm.disks.length > 0) {
const seen = new Set();
vm.disks.forEach((d) => {
const dsId = d.datastore?.id || d.datastore?.name;
if (dsId && !seen.has(dsId)) {
seen.add(dsId);
datastores.push({
name: d.datastore?.name || dsId,
id: d.datastore?.id || '',
type: d.datastore?.type || '',
capacity: d.capacity || 0,
});
}
});
}
return {
_original: vm,
_key: vm.id || vm.vmId || vm.metadata?.name,
vmName: vm.name || vm.metadata?.name || '-',
vmId: vm.id || vm.vmId || vm.metadata?.name || '-',
os: vm.guestName || vm.guestOS || vm.os || '-',
resourcesDisplay: `${ cpus } vCPU`,
resourcesSub: `${ memGB } • ${ diskDisplay }`,
powerState,
powerStateClass: powerState.toLowerCase().includes('on') || powerState.toLowerCase().includes('running') ? 'power-on' : 'power-off',
networks,
network: networks.map((n) => n.name).join(', ') || '-',
datastores,
datastore: datastores.map((d) => d.name).join(', ') || '-',
};
});
};
const addManualVm = () => {
if (!newVmId.value) {
return;
}
manualVMs.value.push({
id: newVmId.value.trim(),
name: newVmId.value.trim(),
_key: `manual-${ newVmId.value.trim() }`,
});
newVmId.value = '';
};
const removeManualVm = (index) => {
manualVMs.value.splice(index, 1);
};
const onSelect = (rows) => {
selectedVMs.value = rows.map((r) => r._original);
};
const cancel = () => {
router.push({
name: `${ PRODUCT_NAME }-c-cluster-forklift`,
params: {
product: route.params.product,
cluster: route.params.cluster,
}
});
};
const saveSelection = () => {
let vmIds;
if (showManualEntry.value) {
vmIds = manualVMs.value.map((vm) => vm.id);
} else {
vmIds = selectedVMs.value.map((vm) => vm.id || vm.vmId || vm.metadata?.name);
}
router.push({
name: `${ PRODUCT_NAME }-c-cluster-forklift-configure-mappings`,
params: {
product: route.params.product,
cluster: route.params.cluster,
},
query: {
provider: providerName.value,
namespace: provider.value?.metadata?.namespace || 'default',
vms: JSON.stringify(vmIds),
}
});
};
const init = async() => {
const inStore = store.getters['currentProduct'].inStore;
allProviders.value = await store.dispatch(`${ inStore }/findAll`, { type: HCI.FORKLIFT_PROVIDER });
const queryProvider = route.query.provider;
const namespace = route.query.namespace || 'default';
if (queryProvider) {
provider.value = allProviders.value.find(
(p) => p.metadata.name === queryProvider && p.metadata.namespace === namespace
);
}
if (provider.value) {
try {
const inventoryType = 'forklift-inventory.konveyor.io.vspherevm';
discoveredVMs.value = await store.dispatch(`${ inStore }/findAll`, { type: inventoryType });
} catch (e) {
discoveredVMs.value = [];
}
}
if (discoveredVMs.value.length === 0) {
discoveredVMs.value = vmData;
}
tableRows.value = buildTableRows();
loading.value = false;
};
init();
return {
schema,
loading,
provider,
providerName,
discoveredVMs,
selectedVMs,
manualVMs,
newVmId,
tableRows,
vmCount,
showManualEntry,
selectedCount,
manualHeaders,
headers,
t,
addManualVm,
removeManualVm,
onSelect,
cancel,
saveSelection,
};
},
});
</script>
<template>
<Loading v-if="loading" />
<div
v-else
>
<Masthead
:schema="schema"
:resource="schema.id"
:type-display="t('harvester.addons.forklift.selectVms.title')"
:is-creatable="false"
>
<template #subHeader>
<p class="text-muted mmt-5">
{{ t('harvester.addons.forklift.selectVms.discovered', { count: vmCount }) }}
<a
v-if="providerName"
class="provider-link"
>{{ providerName }}</a>
<br>
<span class="text-small">{{ t('harvester.addons.forklift.selectVms.lastSynced') }}</span>
</p>
</template>
</Masthead>
<!-- Manual VM entry when no discovered VMs -->
<div v-if="showManualEntry">
<h3 class="m-0 mb-10">
{{ t('harvester.addons.forklift.selectVms.manualEntry.title') }}
</h3>
<p class="text-muted mb-20">
{{ t('harvester.addons.forklift.selectVms.manualEntry.description') }}
</p>
<div class="manual-vm-form">
<div class="row">
<div class="col span-6">
<LabeledInput
v-model:value="newVmId"
:label="t('harvester.addons.forklift.selectVms.manualEntry.vmId')"
:placeholder="t('harvester.addons.forklift.selectVms.manualEntry.vmIdPlaceholder')"
/>
</div>
<div class="col span-2 add-btn-col">
<button
class="btn role-primary"
:disabled="!newVmId"
@click="addManualVm"
>
{{ t('harvester.addons.forklift.selectVms.manualEntry.add') }}
</button>
</div>
</div>
</div>
<SortableTable
:rows="manualVMs"
:headers="manualHeaders"
:search="false"
:table-actions="false"
:row-actions="false"
:groupable="false"
key-field="_key"
class="mt-20"
>
<template #header-left>
<span class="text-muted">{{ manualVMs.length }} {{ t('harvester.addons.forklift.selectVms.manualEntry.added') }}</span>
</template>
<template #cell:id="{ row }">
<div class="manual-vm-row">
<span>{{ row.id }}</span>
<button
class="btn btn-sm role-link"
@click="removeManualVm(manualVMs.indexOf(row))"
>
<i class="icon icon-close" />
</button>
</div>
</template>
</SortableTable>
</div>
<!-- Discovered VMs table -->
<SortableTable
v-else
:rows="tableRows"
:headers="headers"
:search="true"
:table-actions="true"
:row-actions="false"
:groupable="false"
key-field="_key"
@selection="onSelect"
>
<template #header-left>
<div class="vm-table-title">
<h3 class="m-0">
{{ t('harvester.addons.forklift.selectVms.availableVms') }}
</h3>
<span class="text-muted">{{ selectedCount }} {{ t('harvester.addons.forklift.selectVms.selected') }}</span>
</div>
</template>
<template #cell:vmName="{ row }">
<div class="vm-name-cell">
<span class="vm-name">{{ row.vmName }}</span>
<span class="vm-id text-muted">{{ row.vmId }}</span>
</div>
</template>
<template #cell:resources="{ row }">
<span>{{ row.resourcesDisplay }}</span><br>
<span class="text-muted">{{ row.resourcesSub }}</span>
</template>
<template #cell:powerState="{ row }">
<span
class="power-badge"
:class="row.powerStateClass"
>{{ row.powerState }}</span>
</template>
<template #cell:network="{ row }">
<div>
<div
v-for="(net, i) in row.networks"
:key="i"
:class="{ 'mt-4': i > 0 }"
>
<span>{{ net.name }}</span><br>
<span class="text-muted">{{ net.id }}</span>
</div>
</div>
</template>
<template #cell:datastore="{ row }">
<div>
<div
v-for="(ds, i) in row.datastores"
:key="i"
:class="{ 'mt-4': i > 0 }"
>
<span>{{ ds.name }}</span><br>
<span class="text-muted">{{ ds.id }}</span>
</div>
</div>
</template>
</SortableTable>
<div class="actions-footer">
<button
class="btn role-secondary"
@click="cancel"
>
{{ t('generic.cancel') }}
</button>
<button
class="btn role-primary"
:disabled="selectedCount === 0"
@click="saveSelection"
>
{{ t('harvester.addons.forklift.selectVms.saveSelection') }}
</button>
</div>
</div>
</template>
<style lang="scss" scoped>
.provider-link {
color: var(--primary);
font-weight: 600;
}
.vm-table-title {
h4 {
margin: 0;
font-weight: 600;
}
.text-muted {
font-size: 13px;
}
}
.vm-name-cell {
display: flex;
flex-direction: column;
.vm-name {
font-weight: 600;
line-height: 20px;
}
.vm-id {
font-size: 12px;
line-height: 20px;
}
}
.power-badge {
display: inline-block;
padding: 2px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: 600;
&.power-on {
background-color: #d4edda;
color: #155724;
}
&.power-off {
background-color: #fff3cd;
color: #856404;
}
}
.manual-vm-form {
.add-btn-col {
display: flex;
align-items: flex-end;
}
}
.manual-vm-row {
display: flex;
align-items: center;
justify-content: space-between;
}
.multi-line-cell {
display: flex;
flex-direction: column;
line-height: 20px;
}
.mt-4 {
margin-top: 4px;
}
.actions-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 30px;
}
</style>