Skip to content

Commit 25eed2c

Browse files
fix(ui): shorten conversion host labels
1 parent 2402b41 commit 25eed2c

3 files changed

Lines changed: 104 additions & 38 deletions

File tree

ui/src/utils/vmware.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
export const formatKvmConversionHostName = (host, migrationMode, yes, no) => {
19+
const details = host.details || {}
20+
const isSupported = value => value === true || value === 'true'
21+
const hostParts = [host.name]
22+
const capabilityParts = []
23+
24+
if (host.clustername) {
25+
hostParts.push(`[${host.clustername}]`)
26+
}
27+
28+
const virtV2vVersion = details['host.virtv2v.version']
29+
capabilityParts.push(`virt-v2v=${virtV2vVersion || (isSupported(host.instanceconversionsupported) ? yes : no)}`)
30+
31+
if (migrationMode === 'cbt' || migrationMode === 'vddk') {
32+
const vddkSupported = isSupported(details['host.vddk.support'])
33+
const vddkVersion = details['host.vddk.version']
34+
capabilityParts.push(`VDDK=${vddkSupported ? (vddkVersion || yes) : no}`)
35+
}
36+
if (migrationMode === 'cbt') {
37+
capabilityParts.push(`CBT=${isSupported(details['host.vddk.blockcopy.support']) ? yes : no}`)
38+
}
39+
40+
return `${hostParts.join(' ')}${capabilityParts.join(' / ')}`
41+
}

ui/src/views/tools/ImportUnmanagedInstance.vue

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ import MultiNetworkSelection from '@views/compute/wizard/MultiNetworkSelection'
460460
import OsLogo from '@/components/widgets/OsLogo'
461461
import ResourceIcon from '@/components/view/ResourceIcon'
462462
import CheckBoxSelectPair from '@/components/CheckBoxSelectPair'
463+
import { formatKvmConversionHostName } from '@/utils/vmware'
463464
464465
export default {
465466
name: 'ImportUnmanagedInstances',
@@ -1111,47 +1112,13 @@ export default {
11111112
this.kvmHostsForConversion = this.kvmHostsForConversion.filter(host => ['Enabled', 'Disabled'].includes(host.resourcestate))
11121113
// Check if any host has VDDK support
11131114
let hasVddkSupport = false
1114-
this.kvmHostsForConversion.map(host => {
1115-
host.name = host.name + ' [Pod=' + host.podname + '] [Cluster=' + host.clustername + ']'
1116-
if (host.instanceconversionsupported !== null && host.instanceconversionsupported !== undefined && host.instanceconversionsupported) {
1117-
host.name = host.name + ' (' + this.$t('label.supported') + ')'
1118-
} else {
1119-
host.name = host.name + ' (' + this.$t('label.not.supported') + ')'
1120-
}
1121-
if (host.details['host.virtv2v.version']) {
1122-
host.name = host.name + ' (virt-v2v=' + host.details['host.virtv2v.version'] + ')'
1123-
}
1124-
if (host.details['host.ovftool.version']) {
1125-
host.name = host.name + ' (ovftool=' + host.details['host.ovftool.version'] + ')'
1126-
}
1115+
this.kvmHostsForConversion.forEach(host => {
1116+
const details = host.details || {}
11271117
// Check for VDDK support
1128-
if (host.details['host.vddk.support'] === 'true' || host.details['host.vddk.support'] === true) {
1118+
if (details['host.vddk.support'] === 'true' || details['host.vddk.support'] === true) {
11291119
hasVddkSupport = true
11301120
}
1131-
1132-
if (this.form.usevddk) {
1133-
if (host.details['host.vddk.support'] === 'true' || host.details['host.vddk.support'] === true) {
1134-
host.name = host.name + ' (VDDK=' + this.$t('label.supported') + ')'
1135-
} else {
1136-
host.name = host.name + ' (VDDK=' + this.$t('label.not.supported') + ')'
1137-
}
1138-
if (host.details['host.vddk.version']) {
1139-
host.name = host.name + ' (vddk=' + host.details['host.vddk.version'] + ')'
1140-
}
1141-
}
1142-
if (this.form.vmwaremigrationmode === 'cbt') {
1143-
if (host.details['host.vddk.blockcopy.support'] === 'true' || host.details['host.vddk.blockcopy.support'] === true) {
1144-
host.name = host.name + ' (' + this.$t('label.host.vmware.cbt.data.copy.support') + '=' + this.$t('label.supported') + ')'
1145-
} else {
1146-
host.name = host.name + ' (' + this.$t('label.host.vmware.cbt.data.copy.support') + '=' + this.$t('label.not.supported') + ')'
1147-
}
1148-
if (host.details['host.qemu.img.version']) {
1149-
host.name = host.name + ' (qemu-img=' + host.details['host.qemu.img.version'] + ')'
1150-
}
1151-
if (host.details['host.qemu.nbd.version']) {
1152-
host.name = host.name + ' (qemu-nbd=' + host.details['host.qemu.nbd.version'] + ')'
1153-
}
1154-
}
1121+
host.name = this.formatKvmConversionHostName(host)
11551122
})
11561123
11571124
// Enable usevddk by default if at least one host has VDDK support
@@ -1161,6 +1128,13 @@ export default {
11611128
}
11621129
})
11631130
},
1131+
formatKvmConversionHostName (host) {
1132+
return formatKvmConversionHostName(
1133+
host,
1134+
this.form.vmwaremigrationmode,
1135+
this.$t('label.yes'),
1136+
this.$t('label.no'))
1137+
},
11641138
fetchKvmHostsForImporting () {
11651139
getAPI('listHosts', {
11661140
clusterid: this.cluster.id,

ui/tests/unit/utils/vmware.spec.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
import { formatKvmConversionHostName } from '@/utils/vmware'
19+
20+
const host = {
21+
name: 'qa1-vmwarelab-576a1b2a-mix-host2',
22+
podname: 'Pod',
23+
clustername: 'KVM-Cluster',
24+
instanceconversionsupported: true,
25+
details: {
26+
'host.virtv2v.version': '2.7.1rhel=9',
27+
'host.vddk.support': 'true',
28+
'host.vddk.version': '8',
29+
'host.vddk.blockcopy.support': 'true',
30+
'host.qemu.img.version': '7.0.0',
31+
'host.qemu.nbd.version': 'qemu-nbd 7.0.0 (qemu-kvm-7.0.0-13.el9)'
32+
}
33+
}
34+
35+
describe('utils/vmware', () => {
36+
describe('formatKvmConversionHostName()', () => {
37+
it('shows a concise CBT conversion host label', () => {
38+
expect(formatKvmConversionHostName(host, 'cbt', 'Yes', 'No')).toBe(
39+
'qa1-vmwarelab-576a1b2a-mix-host2 [KVM-Cluster] — virt-v2v=2.7.1rhel=9 / VDDK=8 / CBT=Yes')
40+
})
41+
42+
it('does not expose low-level QEMU or Pod details in the selector', () => {
43+
const label = formatKvmConversionHostName(host, 'cbt', 'Yes', 'No')
44+
45+
expect(label).not.toContain('qemu-img')
46+
expect(label).not.toContain('qemu-nbd')
47+
expect(label).not.toContain('Pod')
48+
expect(label).not.toContain('Supported')
49+
})
50+
})
51+
})

0 commit comments

Comments
 (0)