diff --git a/shell/models/__tests__/rke-machine.cattle.io.vmwarevspheremachinetemplate.test.ts b/shell/models/__tests__/rke-machine.cattle.io.vmwarevspheremachinetemplate.test.ts new file mode 100644 index 0000000000..1466ad8a0e --- /dev/null +++ b/shell/models/__tests__/rke-machine.cattle.io.vmwarevspheremachinetemplate.test.ts @@ -0,0 +1,23 @@ +import VmwarevsphereMachineTemplate from '@shell/models/rke-machine.cattle.io.vmwarevspheremachinetemplate'; + +describe('class VmwarevsphereMachineTemplate', () => { + describe('providerLocation', () => { + it.each([ + ['/DC1/host/ClusterA/Resources', 'ClusterA'], + ['/DC1/host/ClusterA/Resources/PoolX', 'ClusterA'], + ['/DC1/host/esxi01/Resources', 'esxi01'], + ['/DC1/vm/FolderA', null], + [undefined, null], + ])('should derive provider location from pool path %p', (pool: string | undefined, expected: string | null) => { + const machineTemplate = new VmwarevsphereMachineTemplate({ + spec: { + template: { + spec: { pool } + } + } + }); + + expect(machineTemplate.providerLocation).toStrictEqual(expected); + }); + }); +}); diff --git a/shell/models/rke-machine.cattle.io.vmwarevspheremachinetemplate.js b/shell/models/rke-machine.cattle.io.vmwarevspheremachinetemplate.js index 1e2c67b5ed..471e8b5e45 100644 --- a/shell/models/rke-machine.cattle.io.vmwarevspheremachinetemplate.js +++ b/shell/models/rke-machine.cattle.io.vmwarevspheremachinetemplate.js @@ -1,11 +1,20 @@ import { formatSi } from '@shell/utils/units'; import MachineTemplate from './rke-machine.cattle.io.machinetemplate'; +const POOL_LOCATION_MATCHER = /\/host\/([^/]+)\/Resources(?:\/|$)/; + export default class VmwarevsphereMachineTemplate extends MachineTemplate { get provider() { return 'vmwarevsphere'; } + get providerLocation() { + const pool = this.spec?.template?.spec?.pool; + const match = pool?.match(POOL_LOCATION_MATCHER); + + return match?.[1] || null; + } + get providerSize() { const size = formatSi(this.spec.template.spec.memorySize * 1048576, 1024, 'iB');