From fd20678290a7331546a750fb9a0a611705c3f40c Mon Sep 17 00:00:00 2001 From: Radoslaw Szwajkowski Date: Mon, 18 Sep 2023 22:25:19 +0200 Subject: [PATCH] Create a wrapper with providerType prop for all provider specific Resource types Add an optional providerType property to implement narrowing (discriminated union). The property is populated only for VMs with a dedicated hook. Signed-off-by: Radoslaw Szwajkowski --- .../ProviderVirtualMachinesList.tsx | 34 ++---------- .../VirtualMachines/utils/useInventoryVms.tsx | 54 +++++++++++++++++++ .../mocks/src/definitions/basic/disks.mock.ts | 5 ++ .../src/definitions/basic/namespaces.mock.ts | 5 ++ .../src/definitions/basic/networks.mock.ts | 16 ++++++ .../src/definitions/basic/nicProfiles.mock.ts | 5 ++ .../src/definitions/basic/storages.mock.ts | 21 ++++++++ .../mocks/src/definitions/basic/vms.mock.ts | 14 +++++ .../src/types/provider/openshift/Namespace.ts | 4 +- .../openshift/NetworkAttachmentDefinition.ts | 4 +- .../types/provider/openshift/StorageClass.ts | 4 +- .../types/provider/openshift/TypedResource.ts | 6 +++ .../types/src/types/provider/openshift/VM.ts | 4 +- .../src/types/provider/openstack/Network.ts | 4 +- .../types/provider/openstack/TypedResource.ts | 6 +++ .../types/src/types/provider/openstack/VM.ts | 4 +- .../types/provider/openstack/VolumeType.ts | 4 +- .../types/src/types/provider/ova/Network.ts | 4 +- .../src/types/provider/ova/TypedResource.ts | 6 +++ packages/types/src/types/provider/ova/VM.ts | 4 +- .../types/src/types/provider/ovirt/Cluster.ts | 4 +- .../types/src/types/provider/ovirt/Disk.ts | 4 +- .../src/types/provider/ovirt/DiskProfile.ts | 4 +- .../types/src/types/provider/ovirt/Host.ts | 4 +- .../types/src/types/provider/ovirt/Network.ts | 4 +- .../src/types/provider/ovirt/NicProfile.ts | 4 +- .../src/types/provider/ovirt/StorageDomain.ts | 4 +- .../src/types/provider/ovirt/TypedResource.ts | 6 +++ packages/types/src/types/provider/ovirt/VM.ts | 4 +- .../src/types/provider/vsphere/DataStore.ts | 4 +- .../src/types/provider/vsphere/Network.ts | 4 +- .../types/provider/vsphere/TypedResource.ts | 6 +++ .../types/src/types/provider/vsphere/VM.ts | 4 +- 33 files changed, 193 insertions(+), 71 deletions(-) create mode 100644 packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx create mode 100644 packages/types/src/types/provider/openshift/TypedResource.ts create mode 100644 packages/types/src/types/provider/openstack/TypedResource.ts create mode 100644 packages/types/src/types/provider/ova/TypedResource.ts create mode 100644 packages/types/src/types/provider/ovirt/TypedResource.ts create mode 100644 packages/types/src/types/provider/vsphere/TypedResource.ts diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx index 89873b365..d43c047bc 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx @@ -1,14 +1,13 @@ import React, { useState } from 'react'; import { RouteComponentProps } from 'react-router-dom'; import StandardPage from 'src/components/page/StandardPage'; -import { useProviderInventory, UseProviderInventoryParams } from 'src/modules/Providers/hooks'; import { ProviderData } from 'src/modules/Providers/utils'; import { useForkliftTranslation } from 'src/utils/i18n'; import { loadUserSettings, ResourceFieldFactory, RowProps } from '@kubev2v/common'; import { ProviderVirtualMachine } from '@kubev2v/types'; -import { getHighestPriorityConcern } from '../utils'; +import { useInventoryVms } from '../utils/useInventoryVms'; export interface VmData { vm: ProviderVirtualMachine; @@ -39,34 +38,7 @@ export const ProviderVirtualMachinesList: React.FC loadUserSettings({ pageId })); - const { provider, inventory } = obj; - const { namespace } = provider.metadata; - - const largeInventory = inventory?.vmCount > 1000; - const customTimeoutAndInterval = largeInventory ? 250000 : undefined; - const validProvider = loaded && !loadError && provider; - - const inventoryOptions: UseProviderInventoryParams = { - provider: validProvider, - subPath: 'vms?detail=4', - fetchTimeout: customTimeoutAndInterval, - interval: customTimeoutAndInterval, - }; - - const { - inventory: vms, - loading, - error, - } = useProviderInventory(inventoryOptions); - - const vmData: VmData[] = - !loading && !error && Array.isArray(vms) - ? vms.map((vm) => ({ - vm, - name: vm.name, - concerns: getHighestPriorityConcern(vm), - })) - : []; + const [vmData, loading] = useInventoryVms(obj, loaded, loadError); return ( @@ -74,7 +46,7 @@ export const ProviderVirtualMachinesList: React.FC diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx new file mode 100644 index 000000000..75bd72197 --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/useInventoryVms.tsx @@ -0,0 +1,54 @@ +import { useProviderInventory, UseProviderInventoryParams } from 'src/modules/Providers/hooks'; +import { ProviderData } from 'src/modules/Providers/utils'; + +import { ProviderVirtualMachine } from '@kubev2v/types'; + +import { VmData } from '../components'; + +import { getHighestPriorityConcern } from './helpers'; + +/** + * A hook for retrieving VMs from the inventory. + * Adds providerType property to each VM. + * + * @param providerData provider that is the source of the data + * @param providerLoaded loading status of the parent provider + * @param providerLoadError load error of the parent provider (if any) + * @returns {Array} tuple containing: the data, loading status and load error (if any) + */ +export const useInventoryVms = ( + { provider, inventory }: ProviderData, + providerLoaded: boolean, + providerLoadError: unknown, +): [VmData[], boolean, Error] => { + const largeInventory = inventory?.vmCount > 1000; + const customTimeoutAndInterval = largeInventory ? 250000 : undefined; + const validProvider = providerLoaded && !providerLoadError && provider; + + const inventoryOptions: UseProviderInventoryParams = { + provider: validProvider, + subPath: 'vms?detail=4', + fetchTimeout: customTimeoutAndInterval, + interval: customTimeoutAndInterval, + }; + + const { + inventory: vms, + loading, + error, + } = useProviderInventory(inventoryOptions); + + const vmData: VmData[] = + !loading && !error && Array.isArray(vms) + ? vms.map((vm) => ({ + vm: { + ...vm, + providerType: provider?.spec?.type, + } as ProviderVirtualMachine, + name: vm.name, + concerns: getHighestPriorityConcern(vm), + })) + : []; + + return [vmData, loading, error]; +}; diff --git a/packages/mocks/src/definitions/basic/disks.mock.ts b/packages/mocks/src/definitions/basic/disks.mock.ts index a22746155..16e8c8006 100644 --- a/packages/mocks/src/definitions/basic/disks.mock.ts +++ b/packages/mocks/src/definitions/basic/disks.mock.ts @@ -70,6 +70,7 @@ export const MOCK_DISKS: { [uid in OvirtProviderIDs]: OVirtDisk[] } = { actualSize: 134217728, storageType: 'image', status: 'ok', + providerType: 'ovirt', }, ], [OVIRT_02_UID]: [ @@ -85,6 +86,7 @@ export const MOCK_DISKS: { [uid in OvirtProviderIDs]: OVirtDisk[] } = { actualSize: 0, storageType: 'image', status: 'ok', + providerType: 'ovirt', }, ], [OVIRT_INSECURE_UID]: [ @@ -101,6 +103,7 @@ export const MOCK_DISKS: { [uid in OvirtProviderIDs]: OVirtDisk[] } = { actualSize: 2501120, storageType: 'image', status: 'ok', + providerType: 'ovirt', }, ], [OVIRT_03_UID]: [ @@ -117,6 +120,7 @@ export const MOCK_DISKS: { [uid in OvirtProviderIDs]: OVirtDisk[] } = { actualSize: 2501120, storageType: 'image', status: 'locked', + providerType: 'ovirt', }, { id: disk5DaId, @@ -131,6 +135,7 @@ export const MOCK_DISKS: { [uid in OvirtProviderIDs]: OVirtDisk[] } = { actualSize: 0, storageType: 'image', status: 'ok', + providerType: 'ovirt', }, ], }; diff --git a/packages/mocks/src/definitions/basic/namespaces.mock.ts b/packages/mocks/src/definitions/basic/namespaces.mock.ts index 53000d4ae..beaba015d 100644 --- a/packages/mocks/src/definitions/basic/namespaces.mock.ts +++ b/packages/mocks/src/definitions/basic/namespaces.mock.ts @@ -19,6 +19,7 @@ export const MOCK_OPENSHIFT_NAMESPACES: { [uid in OpenshiftProviderIDs]: OpenShi name: NAMESPACE_MIGRATION, selfLink: `providers/openshift/${OPENSHIFT_HOST_UID}/namespaces/11a0375f-f33e-489b-812a-d9a0929388ae`, object: { kind: 'Namespace', apiVersion: 'v1' }, + providerType: 'openshift', }, { uid: '68d88b58-22f4-49ba-8665-74f4256aa617', @@ -27,6 +28,7 @@ export const MOCK_OPENSHIFT_NAMESPACES: { [uid in OpenshiftProviderIDs]: OpenShi name: NAMESPACE_FORKLIFT, selfLink: `providers/openshift/${OPENSHIFT_HOST_UID}/namespaces/68d88b58-22f4-49ba-8665-74f4256aa617`, object: { kind: 'Namespace', apiVersion: 'v1' }, + providerType: 'openshift', }, ], [OPENSHIFT_01_UID]: [ @@ -37,6 +39,7 @@ export const MOCK_OPENSHIFT_NAMESPACES: { [uid in OpenshiftProviderIDs]: OpenShi name: 'example-namespace-1', selfLink: `providers/openshift/${OPENSHIFT_01_UID}/namespaces/338c69a1-bee1-40a9-af33-e83b0ec3cb99`, object: { kind: 'Namespace', apiVersion: 'v1' }, + providerType: 'openshift', }, ], [OPENSHIFT_02_UID]: [ @@ -47,6 +50,7 @@ export const MOCK_OPENSHIFT_NAMESPACES: { [uid in OpenshiftProviderIDs]: OpenShi name: 'example-namespace-2', selfLink: `providers/openshift/${OPENSHIFT_02_UID}/namespaces/287d34b7-763f-4065-ba3a-2b7d6440baf6`, object: { kind: 'Namespace', apiVersion: 'v1' }, + providerType: 'openshift', }, ], [OPENSHIFT_03_UID]: [ @@ -57,6 +61,7 @@ export const MOCK_OPENSHIFT_NAMESPACES: { [uid in OpenshiftProviderIDs]: OpenShi name: 'example-namespace-3', selfLink: `providers/openshift/${OPENSHIFT_03_UID}/namespaces/c4f375bb-39dc-4276-913e-0d4c43691d2f`, object: { kind: 'Namespace', apiVersion: 'v1' }, + providerType: 'openshift', }, ], }; diff --git a/packages/mocks/src/definitions/basic/networks.mock.ts b/packages/mocks/src/definitions/basic/networks.mock.ts index aa3b26c10..9d1f9d416 100644 --- a/packages/mocks/src/definitions/basic/networks.mock.ts +++ b/packages/mocks/src/definitions/basic/networks.mock.ts @@ -31,6 +31,7 @@ export const MOCK_VMWARE_NETWORKS: { [uid in VmwareProviderIDs]: VSphereNetwork[ variant: '', host: [], parent: null, + providerType: 'vsphere', }, { id: '2', @@ -41,6 +42,7 @@ export const MOCK_VMWARE_NETWORKS: { [uid in VmwareProviderIDs]: VSphereNetwork[ variant: '', host: [], parent: null, + providerType: 'vsphere', }, ], [VMWARE_02_UID]: [ @@ -53,6 +55,7 @@ export const MOCK_VMWARE_NETWORKS: { [uid in VmwareProviderIDs]: VSphereNetwork[ variant: '', host: [], parent: null, + providerType: 'vsphere', }, ], [VMWARE_03_UID]: [ @@ -65,6 +68,7 @@ export const MOCK_VMWARE_NETWORKS: { [uid in VmwareProviderIDs]: VSphereNetwork[ variant: '', host: [], parent: null, + providerType: 'vsphere', }, { id: '5', @@ -75,6 +79,7 @@ export const MOCK_VMWARE_NETWORKS: { [uid in VmwareProviderIDs]: VSphereNetwork[ variant: '', host: [], parent: null, + providerType: 'vsphere', }, ], }; @@ -92,6 +97,7 @@ export const MOCK_RHV_NETWORKS: { [uid in OvirtProviderIDs]: OVirtNetwork[] } = vlan: '', usages: [], nicProfiles: [], + providerType: 'ovirt', }, { id: '8b6f4200-cba6-4579-8edd-ea08b7ddd97b', @@ -103,6 +109,7 @@ export const MOCK_RHV_NETWORKS: { [uid in OvirtProviderIDs]: OVirtNetwork[] } = vlan: '', usages: [], nicProfiles: [], + providerType: 'ovirt', }, { id: '0189c310-19e6-41e3-97b1-33894562b5fb', @@ -114,6 +121,7 @@ export const MOCK_RHV_NETWORKS: { [uid in OvirtProviderIDs]: OVirtNetwork[] } = vlan: '', usages: [], nicProfiles: [], + providerType: 'ovirt', }, ], [OVIRT_02_UID]: [ @@ -128,6 +136,7 @@ export const MOCK_RHV_NETWORKS: { [uid in OvirtProviderIDs]: OVirtNetwork[] } = vlan: '', usages: [], nicProfiles: [], + providerType: 'ovirt', }, ], [OVIRT_03_UID]: [ @@ -142,6 +151,7 @@ export const MOCK_RHV_NETWORKS: { [uid in OvirtProviderIDs]: OVirtNetwork[] } = vlan: '', usages: [], nicProfiles: [], + providerType: 'ovirt', }, ], [OVIRT_INSECURE_UID]: [ @@ -156,6 +166,7 @@ export const MOCK_RHV_NETWORKS: { [uid in OvirtProviderIDs]: OVirtNetwork[] } = vlan: '', usages: [], nicProfiles: [], + providerType: 'ovirt', }, ], }; @@ -180,6 +191,7 @@ export const MOCK_OPENSHIFT_NETWORKS: { name: 'example-network-1', }, }, + providerType: 'openshift', }, { uid: '8b6f4200-cba6-4579-8edd-ea08b7ddd97b', @@ -197,6 +209,7 @@ export const MOCK_OPENSHIFT_NETWORKS: { name: 'example-network-2', }, }, + providerType: 'openshift', }, ], [OPENSHIFT_01_UID]: [ @@ -215,6 +228,7 @@ export const MOCK_OPENSHIFT_NETWORKS: { name: 'ocp-network-1', }, }, + providerType: 'openshift', }, ], [OPENSHIFT_02_UID]: [ @@ -234,6 +248,7 @@ export const MOCK_OPENSHIFT_NETWORKS: { resourceVersion: '1', }, }, + providerType: 'openshift', }, ], [OPENSHIFT_03_UID]: [ @@ -253,6 +268,7 @@ export const MOCK_OPENSHIFT_NETWORKS: { name: 'ocp-network-3', }, }, + providerType: 'openshift', }, ], }; diff --git a/packages/mocks/src/definitions/basic/nicProfiles.mock.ts b/packages/mocks/src/definitions/basic/nicProfiles.mock.ts index 7efca4ea3..c495f0823 100644 --- a/packages/mocks/src/definitions/basic/nicProfiles.mock.ts +++ b/packages/mocks/src/definitions/basic/nicProfiles.mock.ts @@ -85,6 +85,7 @@ export const MOCK_NIC_PROFILES: { [uid in OvirtProviderIDs]: OVirtNicProfile[] } qos: '', properties: [], passThrough: false, + providerType: 'ovirt', }, { id: np2Id, @@ -97,6 +98,7 @@ export const MOCK_NIC_PROFILES: { [uid in OvirtProviderIDs]: OVirtNicProfile[] } qos: 'e00fb4fb-e88e-4245-9b68-077db776d74c', properties: [], passThrough: false, + providerType: 'ovirt', }, ], [OVIRT_02_UID]: [ @@ -111,6 +113,7 @@ export const MOCK_NIC_PROFILES: { [uid in OvirtProviderIDs]: OVirtNicProfile[] } qos: '', properties: [], passThrough: false, + providerType: 'ovirt', }, ], [OVIRT_03_UID]: [ @@ -125,6 +128,7 @@ export const MOCK_NIC_PROFILES: { [uid in OvirtProviderIDs]: OVirtNicProfile[] } qos: '', properties: [], passThrough: false, + providerType: 'ovirt', }, ], [OVIRT_INSECURE_UID]: [ @@ -139,6 +143,7 @@ export const MOCK_NIC_PROFILES: { [uid in OvirtProviderIDs]: OVirtNicProfile[] } qos: '', properties: [], passThrough: false, + providerType: 'ovirt', }, ], }; diff --git a/packages/mocks/src/definitions/basic/storages.mock.ts b/packages/mocks/src/definitions/basic/storages.mock.ts index b9d0f744f..46e02cbbd 100644 --- a/packages/mocks/src/definitions/basic/storages.mock.ts +++ b/packages/mocks/src/definitions/basic/storages.mock.ts @@ -44,6 +44,7 @@ export const MOCK_VMWARE_DATASTORES: { [uid in VmwareProviderIDs]: VSphereDataSt capacity: 0, free: 0, maintenance: '', + providerType: 'vsphere', }, { id: '2', @@ -59,6 +60,7 @@ export const MOCK_VMWARE_DATASTORES: { [uid in VmwareProviderIDs]: VSphereDataSt capacity: 0, free: 0, maintenance: '', + providerType: 'vsphere', }, ], [VMWARE_02_UID]: [ @@ -76,6 +78,7 @@ export const MOCK_VMWARE_DATASTORES: { [uid in VmwareProviderIDs]: VSphereDataSt capacity: 0, free: 0, maintenance: '', + providerType: 'vsphere', }, ], [VMWARE_03_UID]: [ @@ -93,6 +96,7 @@ export const MOCK_VMWARE_DATASTORES: { [uid in VmwareProviderIDs]: VSphereDataSt capacity: 0, free: 0, maintenance: '', + providerType: 'vsphere', }, { id: '5', @@ -108,6 +112,7 @@ export const MOCK_VMWARE_DATASTORES: { [uid in VmwareProviderIDs]: VSphereDataSt capacity: 0, free: 0, maintenance: '', + providerType: 'vsphere', }, ], }; @@ -125,6 +130,7 @@ export const MOCK_RHV_STORAGE_DOMAINS: { [uid in OvirtProviderIDs]: OVirtStorage type: '', capacity: 0, storage: { type: '' }, + providerType: 'ovirt', }, { id: '2', @@ -137,6 +143,7 @@ export const MOCK_RHV_STORAGE_DOMAINS: { [uid in OvirtProviderIDs]: OVirtStorage type: '', capacity: 0, storage: { type: '' }, + providerType: 'ovirt', }, ], [OVIRT_02_UID]: [ @@ -151,6 +158,7 @@ export const MOCK_RHV_STORAGE_DOMAINS: { [uid in OvirtProviderIDs]: OVirtStorage type: '', capacity: 0, storage: { type: '' }, + providerType: 'ovirt', }, ], [OVIRT_03_UID]: [ @@ -165,6 +173,7 @@ export const MOCK_RHV_STORAGE_DOMAINS: { [uid in OvirtProviderIDs]: OVirtStorage type: '', capacity: 0, storage: { type: '' }, + providerType: 'ovirt', }, ], [OVIRT_INSECURE_UID]: [ @@ -179,6 +188,7 @@ export const MOCK_RHV_STORAGE_DOMAINS: { [uid in OvirtProviderIDs]: OVirtStorage type: '', capacity: 0, storage: { type: '' }, + providerType: 'ovirt', }, ], }; @@ -195,6 +205,7 @@ export const MOCK_OPENSTACK_VOLUME_TYPES: { [uid in OpenstackProviderIDs]: Opens isPublic: true, qosSpecsID: '', publicAccess: true, + providerType: 'openstack', }, { id: '2', @@ -205,6 +216,7 @@ export const MOCK_OPENSTACK_VOLUME_TYPES: { [uid in OpenstackProviderIDs]: Opens isPublic: true, qosSpecsID: '', publicAccess: true, + providerType: 'openstack', }, { id: '3', @@ -215,6 +227,7 @@ export const MOCK_OPENSTACK_VOLUME_TYPES: { [uid in OpenstackProviderIDs]: Opens isPublic: true, qosSpecsID: '', publicAccess: true, + providerType: 'openstack', }, ], [OPENSTACK_02_UID]: [ @@ -227,6 +240,7 @@ export const MOCK_OPENSTACK_VOLUME_TYPES: { [uid in OpenstackProviderIDs]: Opens isPublic: true, qosSpecsID: '', publicAccess: true, + providerType: 'openstack', }, { id: '5', @@ -237,6 +251,7 @@ export const MOCK_OPENSTACK_VOLUME_TYPES: { [uid in OpenstackProviderIDs]: Opens isPublic: true, qosSpecsID: '', publicAccess: true, + providerType: 'openstack', }, ], }; @@ -263,6 +278,7 @@ export const MOCK_OPENSHIFT_STORAGE_CLASS: { }, }, }, + providerType: 'openshift', }, { uid: 'uid-1', @@ -278,6 +294,7 @@ export const MOCK_OPENSHIFT_STORAGE_CLASS: { name: 'large', }, }, + providerType: 'openshift', }, { uid: 'uid-2', @@ -293,6 +310,7 @@ export const MOCK_OPENSHIFT_STORAGE_CLASS: { name: 'small', }, }, + providerType: 'openshift', }, ], [OPENSHIFT_01_UID]: [ @@ -313,6 +331,7 @@ export const MOCK_OPENSHIFT_STORAGE_CLASS: { }, }, }, + providerType: 'openshift', }, ], [OPENSHIFT_02_UID]: [ @@ -333,6 +352,7 @@ export const MOCK_OPENSHIFT_STORAGE_CLASS: { }, }, }, + providerType: 'openshift', }, ], [OPENSHIFT_03_UID]: [ @@ -353,6 +373,7 @@ export const MOCK_OPENSHIFT_STORAGE_CLASS: { }, }, }, + providerType: 'openshift', }, ], }; diff --git a/packages/mocks/src/definitions/basic/vms.mock.ts b/packages/mocks/src/definitions/basic/vms.mock.ts index 666e33ad6..81c91e856 100644 --- a/packages/mocks/src/definitions/basic/vms.mock.ts +++ b/packages/mocks/src/definitions/basic/vms.mock.ts @@ -69,6 +69,7 @@ const vm1: VSphereVM = { isTemplate: false, host: 'esx12.v2v.example.com', parent: null, + providerType: 'vsphere', }; export const MOCK_VMWARE_VMS: { [uid in VmwareProviderIDs]: VSphereVM[] } = { @@ -105,6 +106,7 @@ export const MOCK_VMWARE_VMS: { [uid in VmwareProviderIDs]: VSphereVM[] } = { isTemplate: false, host: 'esx12.v2v.example.com', parent: null, + providerType: 'vsphere', }, { id: 'vm-1008', @@ -139,6 +141,7 @@ export const MOCK_VMWARE_VMS: { [uid in VmwareProviderIDs]: VSphereVM[] } = { isTemplate: false, host: 'esx13.v2v.example.com', parent: null, + providerType: 'vsphere', }, { id: 'vm-2686', @@ -162,6 +165,7 @@ export const MOCK_VMWARE_VMS: { [uid in VmwareProviderIDs]: VSphereVM[] } = { isTemplate: false, host: 'esx13.v2v.example.com', parent: null, + providerType: 'vsphere', }, ], [VMWARE_02_UID]: [], @@ -188,6 +192,7 @@ export const MOCK_VMWARE_VMS: { [uid in VmwareProviderIDs]: VSphereVM[] } = { isTemplate: false, host: '', parent: null, + providerType: 'vsphere', }, { id: 'vm-431', @@ -222,6 +227,7 @@ export const MOCK_VMWARE_VMS: { [uid in VmwareProviderIDs]: VSphereVM[] } = { isTemplate: false, host: '', parent: null, + providerType: 'vsphere', }, ], }; @@ -241,6 +247,7 @@ export const MOCK_RHV_VMS: { [uid in OvirtProviderIDs]: OVirtVM[] } = { concerns: [], cluster: 'main', host: 'host.example.com', + providerType: 'ovirt', }, { id: '2a66a719-440c-4544-9da0-692d14338b12', @@ -255,6 +262,7 @@ export const MOCK_RHV_VMS: { [uid in OvirtProviderIDs]: OVirtVM[] } = { concerns: [], cluster: 'main', host: 'host.example.com', + providerType: 'ovirt', }, { id: '64333a40-ffbb-4c28-add7-5560bdf082fb', @@ -269,6 +277,7 @@ export const MOCK_RHV_VMS: { [uid in OvirtProviderIDs]: OVirtVM[] } = { concerns: [], cluster: 'main', host: 'host-2.example.com', + providerType: 'ovirt', }, { id: '6f9de857-ef39-43b7-8853-af982286dc59', @@ -283,6 +292,7 @@ export const MOCK_RHV_VMS: { [uid in OvirtProviderIDs]: OVirtVM[] } = { concerns: [], cluster: 'main', host: 'host-2.example.com', + providerType: 'ovirt', }, ], [OVIRT_02_UID]: [ @@ -299,6 +309,7 @@ export const MOCK_RHV_VMS: { [uid in OvirtProviderIDs]: OVirtVM[] } = { concerns: [], cluster: '', host: '', + providerType: 'ovirt', }, ], [OVIRT_03_UID]: [ @@ -315,6 +326,7 @@ export const MOCK_RHV_VMS: { [uid in OvirtProviderIDs]: OVirtVM[] } = { concerns: [], cluster: '', host: '', + providerType: 'ovirt', }, { id: 'be55c259-2415-448d-841e-f4b9d743242e', @@ -329,6 +341,7 @@ export const MOCK_RHV_VMS: { [uid in OvirtProviderIDs]: OVirtVM[] } = { concerns: [], cluster: '', host: '', + providerType: 'ovirt', }, ], [OVIRT_INSECURE_UID]: [ @@ -345,6 +358,7 @@ export const MOCK_RHV_VMS: { [uid in OvirtProviderIDs]: OVirtVM[] } = { concerns: [], cluster: '', host: '', + providerType: 'ovirt', }, ], }; diff --git a/packages/types/src/types/provider/openshift/Namespace.ts b/packages/types/src/types/provider/openshift/Namespace.ts index 4b45e3666..797353d56 100644 --- a/packages/types/src/types/provider/openshift/Namespace.ts +++ b/packages/types/src/types/provider/openshift/Namespace.ts @@ -1,9 +1,9 @@ import { V1Namespace } from '../../k8s/V1Namespace'; -import { OpenshiftResource } from './Resource'; +import { TypedOpenshiftResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ocp/namespace.go -export interface OpenShiftNamespace extends OpenshiftResource { +export interface OpenShiftNamespace extends TypedOpenshiftResource { // Object core.Namespace `json:"object"` object: V1Namespace; } diff --git a/packages/types/src/types/provider/openshift/NetworkAttachmentDefinition.ts b/packages/types/src/types/provider/openshift/NetworkAttachmentDefinition.ts index 75d2b0683..33a484141 100644 --- a/packages/types/src/types/provider/openshift/NetworkAttachmentDefinition.ts +++ b/packages/types/src/types/provider/openshift/NetworkAttachmentDefinition.ts @@ -1,9 +1,9 @@ import { V1NetworkAttachmentDefinition } from '../../k8s/V1NetworkAttachmentDefinition'; -import { OpenshiftResource } from './Resource'; +import { TypedOpenshiftResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ocp/netattachdefinition.go -export interface OpenShiftNetworkAttachmentDefinition extends OpenshiftResource { +export interface OpenShiftNetworkAttachmentDefinition extends TypedOpenshiftResource { // Object net.NetworkAttachmentDefinition `json:"object"` object: V1NetworkAttachmentDefinition; } diff --git a/packages/types/src/types/provider/openshift/StorageClass.ts b/packages/types/src/types/provider/openshift/StorageClass.ts index 551b00740..73c01bf14 100644 --- a/packages/types/src/types/provider/openshift/StorageClass.ts +++ b/packages/types/src/types/provider/openshift/StorageClass.ts @@ -1,9 +1,9 @@ import { IoK8sApiStorageV1StorageClass } from '../../k8s/IoK8sApiStorageV1StorageClass'; -import { OpenshiftResource } from './Resource'; +import { TypedOpenshiftResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ocp/storageclass.go -export interface OpenShiftStorageClass extends OpenshiftResource { +export interface OpenShiftStorageClass extends TypedOpenshiftResource { // Object storage.StorageClass `json:"object"` object: IoK8sApiStorageV1StorageClass; } diff --git a/packages/types/src/types/provider/openshift/TypedResource.ts b/packages/types/src/types/provider/openshift/TypedResource.ts new file mode 100644 index 000000000..5dcb00c8e --- /dev/null +++ b/packages/types/src/types/provider/openshift/TypedResource.ts @@ -0,0 +1,6 @@ +import { OpenshiftResource } from './Resource'; + +export interface TypedOpenshiftResource extends OpenshiftResource { + // prop added by the UI to implement narrowing (discriminated union) + providerType: 'openshift'; +} diff --git a/packages/types/src/types/provider/openshift/VM.ts b/packages/types/src/types/provider/openshift/VM.ts index c0fb0302f..d70b431c8 100644 --- a/packages/types/src/types/provider/openshift/VM.ts +++ b/packages/types/src/types/provider/openshift/VM.ts @@ -1,10 +1,10 @@ import { V1VirtualMachine } from '../../k8s/V1VirtualMachine'; import { Concern } from '../base'; -import { OpenshiftResource } from './Resource'; +import { TypedOpenshiftResource } from './TypedResource'; // https://github.com/kubev2v/forklift/blob/main/pkg/controller/provider/web/ocp/vm.go -export interface OpenshiftVM extends OpenshiftResource { +export interface OpenshiftVM extends TypedOpenshiftResource { concerns: Concern[]; object: V1VirtualMachine; } diff --git a/packages/types/src/types/provider/openstack/Network.ts b/packages/types/src/types/provider/openstack/Network.ts index 058a91194..6a6e223d6 100644 --- a/packages/types/src/types/provider/openstack/Network.ts +++ b/packages/types/src/types/provider/openstack/Network.ts @@ -1,7 +1,7 @@ -import { OpenstackResource } from './Resource'; +import { TypedOpenstackResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/openstack/network.go -export interface OpenstackNetwork extends OpenstackResource { +export interface OpenstackNetwork extends TypedOpenstackResource { // Description string `json:"description"` description: string; // AdminStateUp bool `json:"adminStateUp"` diff --git a/packages/types/src/types/provider/openstack/TypedResource.ts b/packages/types/src/types/provider/openstack/TypedResource.ts new file mode 100644 index 000000000..bf4e120bf --- /dev/null +++ b/packages/types/src/types/provider/openstack/TypedResource.ts @@ -0,0 +1,6 @@ +import { OpenstackResource } from './Resource'; + +export interface TypedOpenstackResource extends OpenstackResource { + // prop added by the UI to implement narrowing (discriminated union) + providerType: 'openstack'; +} diff --git a/packages/types/src/types/provider/openstack/VM.ts b/packages/types/src/types/provider/openstack/VM.ts index f7665813c..32f83996e 100644 --- a/packages/types/src/types/provider/openstack/VM.ts +++ b/packages/types/src/types/provider/openstack/VM.ts @@ -1,9 +1,9 @@ import { Concern } from '../base/model'; -import { OpenstackResource } from './Resource'; +import { TypedOpenstackResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/openstack/vm.go -export interface OpenstackVM extends OpenstackResource { +export interface OpenstackVM extends TypedOpenstackResource { // TenantID string `json:"tenantID"` tenantID: string; // 'ACTIVE' | 'SHUTOFF' | 'PAUSED' | 'SHELVED_OFFLOADED' | 'SUSPENDED' diff --git a/packages/types/src/types/provider/openstack/VolumeType.ts b/packages/types/src/types/provider/openstack/VolumeType.ts index 1b41987b7..3615f9e44 100644 --- a/packages/types/src/types/provider/openstack/VolumeType.ts +++ b/packages/types/src/types/provider/openstack/VolumeType.ts @@ -1,7 +1,7 @@ -import { OpenstackResource } from './Resource'; +import { TypedOpenstackResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/openstack/volumetype.go -export interface OpenstackVolumeType extends OpenstackResource { +export interface OpenstackVolumeType extends TypedOpenstackResource { // Description string `json:"description"` description: string; // ExtraSpecs map[string]string `json:"extraSpecs,omitempty"` diff --git a/packages/types/src/types/provider/ova/Network.ts b/packages/types/src/types/provider/ova/Network.ts index 29abbe631..b05b4d5d9 100644 --- a/packages/types/src/types/provider/ova/Network.ts +++ b/packages/types/src/types/provider/ova/Network.ts @@ -1,6 +1,6 @@ -import { OvaResource } from './Resource'; +import { TypedOvaResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ova/network.go -export interface OvaNetwork extends OvaResource { +export interface OvaNetwork extends TypedOvaResource { Description?: string; } diff --git a/packages/types/src/types/provider/ova/TypedResource.ts b/packages/types/src/types/provider/ova/TypedResource.ts new file mode 100644 index 000000000..3bce1b662 --- /dev/null +++ b/packages/types/src/types/provider/ova/TypedResource.ts @@ -0,0 +1,6 @@ +import { OvaResource } from './Resource'; + +export interface TypedOvaResource extends OvaResource { + // prop added by the UI to implement narrowing (discriminated union) + providerType: 'ova'; +} diff --git a/packages/types/src/types/provider/ova/VM.ts b/packages/types/src/types/provider/ova/VM.ts index dcf979b19..5b0982661 100644 --- a/packages/types/src/types/provider/ova/VM.ts +++ b/packages/types/src/types/provider/ova/VM.ts @@ -1,10 +1,10 @@ import { Concern } from '../base/model'; import { OvaNetwork } from './Network'; -import { OvaResource } from './Resource'; +import { TypedOvaResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ova/vm.go -export interface OvaVM extends OvaResource { +export interface OvaVM extends TypedOvaResource { OvaPath: string; RevisionValidated: number; PolicyVersion: number; diff --git a/packages/types/src/types/provider/ovirt/Cluster.ts b/packages/types/src/types/provider/ovirt/Cluster.ts index 68c6dd312..22faa6586 100644 --- a/packages/types/src/types/provider/ovirt/Cluster.ts +++ b/packages/types/src/types/provider/ovirt/Cluster.ts @@ -1,7 +1,7 @@ -import { OVirtResource } from './Resource'; +import { TypedOVirtResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ovirt/cluster.go -export interface OVirtCluster extends OVirtResource { +export interface OVirtCluster extends TypedOVirtResource { // DataCenter string `json:"dataCenter"` dataCenter: string; // HaReservation bool `json:"haReservation"` diff --git a/packages/types/src/types/provider/ovirt/Disk.ts b/packages/types/src/types/provider/ovirt/Disk.ts index c51eb4a29..c9e1c77a5 100644 --- a/packages/types/src/types/provider/ovirt/Disk.ts +++ b/packages/types/src/types/provider/ovirt/Disk.ts @@ -1,7 +1,7 @@ -import { OVirtResource } from './Resource'; +import { TypedOVirtResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ovirt/disk.go -export interface OVirtDisk extends OVirtResource { +export interface OVirtDisk extends TypedOVirtResource { // Shared bool `json:"shared"` shared: boolean; // StorageDomain string `json:"storageDomain"` diff --git a/packages/types/src/types/provider/ovirt/DiskProfile.ts b/packages/types/src/types/provider/ovirt/DiskProfile.ts index 81ab7787c..37f8a5bbb 100644 --- a/packages/types/src/types/provider/ovirt/DiskProfile.ts +++ b/packages/types/src/types/provider/ovirt/DiskProfile.ts @@ -1,7 +1,7 @@ -import { OVirtResource } from './Resource'; +import { TypedOVirtResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ovirt/diskprofile.go -export interface OVirtDiskProfile extends OVirtResource { +export interface OVirtDiskProfile extends TypedOVirtResource { // StorageDomain string `json:"storageDomain"` storageDomain: string; // QoS string `json:"qos"` diff --git a/packages/types/src/types/provider/ovirt/Host.ts b/packages/types/src/types/provider/ovirt/Host.ts index 286a0fa5f..13bc3b4be 100644 --- a/packages/types/src/types/provider/ovirt/Host.ts +++ b/packages/types/src/types/provider/ovirt/Host.ts @@ -1,8 +1,8 @@ import { OVirtHostNIC, OVirtNetworkAttachment } from './model'; -import { OVirtResource } from './Resource'; +import { TypedOVirtResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ovirt/host.go -export interface OVirtHost extends OVirtResource { +export interface OVirtHost extends TypedOVirtResource { // Cluster string `json:"cluster"` cluster: string; // Status string `json:"status"` diff --git a/packages/types/src/types/provider/ovirt/Network.ts b/packages/types/src/types/provider/ovirt/Network.ts index f65c02767..5ebaf36f8 100644 --- a/packages/types/src/types/provider/ovirt/Network.ts +++ b/packages/types/src/types/provider/ovirt/Network.ts @@ -1,7 +1,7 @@ -import { OVirtResource } from './Resource'; +import { TypedOVirtResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ovirt/network.go -export interface OVirtNetwork extends OVirtResource { +export interface OVirtNetwork extends TypedOVirtResource { // DataCenter string `json:"dataCenter"` dataCenter: string; // VLan string `json:"vlan"` diff --git a/packages/types/src/types/provider/ovirt/NicProfile.ts b/packages/types/src/types/provider/ovirt/NicProfile.ts index 70cf3a7a6..ff1d3f9d9 100644 --- a/packages/types/src/types/provider/ovirt/NicProfile.ts +++ b/packages/types/src/types/provider/ovirt/NicProfile.ts @@ -1,8 +1,8 @@ import { OVirtProperty } from './model'; -import { OVirtResource } from './Resource'; +import { TypedOVirtResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ovirt/nicprofile.go -export interface OVirtNicProfile extends OVirtResource { +export interface OVirtNicProfile extends TypedOVirtResource { // Network string `json:"network"` network: string; // NetworkFilter string `json:"networkFilter"` diff --git a/packages/types/src/types/provider/ovirt/StorageDomain.ts b/packages/types/src/types/provider/ovirt/StorageDomain.ts index 5366ddcee..f33192cc9 100644 --- a/packages/types/src/types/provider/ovirt/StorageDomain.ts +++ b/packages/types/src/types/provider/ovirt/StorageDomain.ts @@ -1,7 +1,7 @@ -import { OVirtResource } from './Resource'; +import { TypedOVirtResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ovirt/storage.go -export interface OVirtStorageDomain extends OVirtResource { +export interface OVirtStorageDomain extends TypedOVirtResource { // DataCenter string `json:"dataCenter"` dataCenter: string; // Type string `json:"type"` diff --git a/packages/types/src/types/provider/ovirt/TypedResource.ts b/packages/types/src/types/provider/ovirt/TypedResource.ts new file mode 100644 index 000000000..0b317db6f --- /dev/null +++ b/packages/types/src/types/provider/ovirt/TypedResource.ts @@ -0,0 +1,6 @@ +import { OVirtResource } from './Resource'; + +export interface TypedOVirtResource extends OVirtResource { + // prop added by the UI to implement narrowing (discriminated union) + providerType: 'ovirt'; +} diff --git a/packages/types/src/types/provider/ovirt/VM.ts b/packages/types/src/types/provider/ovirt/VM.ts index 5a594ae6a..3f1e0d884 100644 --- a/packages/types/src/types/provider/ovirt/VM.ts +++ b/packages/types/src/types/provider/ovirt/VM.ts @@ -1,10 +1,10 @@ import { Concern } from '../base/model'; import { OVirtDiskAttachment, OVirtNIC } from './model'; -import { OVirtResource } from './Resource'; +import { TypedOVirtResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/ovirt/vm.go -export interface OVirtVM extends OVirtResource { +export interface OVirtVM extends TypedOVirtResource { // Cluster string `json:"cluster"` cluster: string; // 'up' | 'down' diff --git a/packages/types/src/types/provider/vsphere/DataStore.ts b/packages/types/src/types/provider/vsphere/DataStore.ts index 6c32b5ccc..14a40762a 100644 --- a/packages/types/src/types/provider/vsphere/DataStore.ts +++ b/packages/types/src/types/provider/vsphere/DataStore.ts @@ -1,7 +1,7 @@ -import { VSphereResource } from './Resource'; +import { TypedVSphereResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/vsphere/datastore.go -export interface VSphereDataStore extends VSphereResource { +export interface VSphereDataStore extends TypedVSphereResource { // Type string `json:"type"` type: string; // Capacity int64 `json:"capacity"` diff --git a/packages/types/src/types/provider/vsphere/Network.ts b/packages/types/src/types/provider/vsphere/Network.ts index 0c4ba36b8..7f539291e 100644 --- a/packages/types/src/types/provider/vsphere/Network.ts +++ b/packages/types/src/types/provider/vsphere/Network.ts @@ -1,10 +1,10 @@ import { Ref } from '../base/model'; import { VSphereDVSHost } from './model'; -import { VSphereResource } from './Resource'; +import { TypedVSphereResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/vsphere/network.go -export interface VSphereNetwork extends VSphereResource { +export interface VSphereNetwork extends TypedVSphereResource { // Variant string `json:"variant"` variant: string; // DVSwitch *model.Ref `json:"dvSwitch,omitempty"` diff --git a/packages/types/src/types/provider/vsphere/TypedResource.ts b/packages/types/src/types/provider/vsphere/TypedResource.ts new file mode 100644 index 000000000..252cd7572 --- /dev/null +++ b/packages/types/src/types/provider/vsphere/TypedResource.ts @@ -0,0 +1,6 @@ +import { VSphereResource } from './Resource'; + +export interface TypedVSphereResource extends VSphereResource { + // prop added by the UI to implement narrowing (discriminated union) + providerType: 'vsphere'; +} diff --git a/packages/types/src/types/provider/vsphere/VM.ts b/packages/types/src/types/provider/vsphere/VM.ts index a446579ff..f72bf076f 100644 --- a/packages/types/src/types/provider/vsphere/VM.ts +++ b/packages/types/src/types/provider/vsphere/VM.ts @@ -1,10 +1,10 @@ import { Concern, Ref } from '../base/model'; import { VSphereDisk } from './model'; -import { VSphereResource } from './Resource'; +import { TypedVSphereResource } from './TypedResource'; // https://github.com/kubev2v/forklift/tree/main/pkg/controller/provider/web/vsphere/vm.go -export interface VSphereVM extends VSphereResource { +export interface VSphereVM extends TypedVSphereResource { // RevisionValidated int64 `json:"revisionValidated"` revisionValidated: number; // IsTemplate bool `json:"isTemplate"`