Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
Original file line number Diff line number Diff line change
@@ -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');

Expand Down