-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1188 from yaacov/show-host-and-folder-in-vsphere-…
…vms-list 🐾 Add hosts and folders to vSphere vms list
- Loading branch information
Showing
16 changed files
with
140 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
...console-plugin/src/modules/Plans/views/create/components/ProvidersVirtualMachinesList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
...le-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/filters/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @index(['./*', /style/g], f => `export * from '${f.path}';`) | ||
export * from './concernFilter'; | ||
// @endindex |
4 changes: 4 additions & 0 deletions
4
...sole-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/hooks/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// @index(['./*', /style/g], f => `export * from '${f.path}';`) | ||
export * from './useInventoryVms'; | ||
export * from './useVSphereInventoryVms'; | ||
// @endindex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...dules/Providers/views/details/tabs/VirtualMachines/utils/hooks/useVSphereInventoryVms.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useProviderInventory, UseProviderInventoryParams } from 'src/modules/Providers/hooks'; | ||
import { ProviderData } from 'src/modules/Providers/utils'; | ||
|
||
import { ProviderHost, VSphereResource } from '@kubev2v/types'; | ||
|
||
/** | ||
* A hook for retrieving hosts and folders from the inventory. | ||
* | ||
* @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 hosts and folders data | ||
*/ | ||
export const useVSphereInventoryVms = ( | ||
{ provider }: ProviderData, | ||
providerLoaded: boolean, | ||
providerLoadError: unknown, | ||
): [{ [key: string]: ProviderHost }, { [key: string]: VSphereResource }] => { | ||
const validProvider = providerLoaded && !providerLoadError && provider; | ||
|
||
const hostsInventoryOptions: UseProviderInventoryParams = { | ||
provider: validProvider, | ||
subPath: 'hosts?detail=4', | ||
interval: 180000, | ||
}; | ||
|
||
const { inventory: hosts } = useProviderInventory<ProviderHost[]>(hostsInventoryOptions); | ||
|
||
const foldersInventoryOptions: UseProviderInventoryParams = { | ||
provider: validProvider, | ||
subPath: 'folders?detail=4', | ||
interval: 180000, | ||
}; | ||
|
||
const { inventory: folders } = useProviderInventory<VSphereResource[]>(foldersInventoryOptions); | ||
|
||
const foldersDict = convertArrayToDictionary(folders); | ||
const hostsDict = convertArrayToDictionary(hosts); | ||
|
||
return [hostsDict, foldersDict]; | ||
}; | ||
|
||
/** | ||
* Converts an array of Resource objects into a dictionary where the keys are the resource IDs. | ||
* | ||
* @param {T[]} resources - The array of Resource objects to convert. | ||
* @returns {{ [key: string]: T }} - A dictionary with resource IDs as keys and Resource objects as values. | ||
*/ | ||
function convertArrayToDictionary<T>(resources: T[]): { [key: string]: T } { | ||
if (!resources) { | ||
return undefined; | ||
} | ||
|
||
return resources.reduce((dict, resource) => { | ||
dict[resource['id']] = resource; | ||
return dict; | ||
}, {} as { [key: string]: T }); | ||
} |
2 changes: 2 additions & 0 deletions
2
...ft-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// @index(['./*', /style/g], f => `export * from '${f.path}';`) | ||
export * from './filters'; | ||
export * from './helpers'; | ||
export * from './hooks'; | ||
// @endindex |