Skip to content

Commit

Permalink
Merge pull request #625 from yaacov/add-name-namespace-to-ocp-plan
Browse files Browse the repository at this point in the history
Add namespace and name to openshift plan
  • Loading branch information
yaacov authored Jul 27, 2023
2 parents 36f68c9 + bbdb09f commit a2fd2f1
Showing 1 changed file with 52 additions and 6 deletions.
58 changes: 52 additions & 6 deletions packages/legacy/src/Plans/components/Wizard/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,57 @@ interface IHookRef {
instance: PlanHookInstance;
}

function genrateNodesByVmID(data, kind) {
const result = {};

const traverse = (nodes) => {
for (const node of nodes) {
if (node.kind === kind) {
result[node.object.id] = node.object;
}

if (node.children) {
traverse(node.children);
}
}
};

traverse(data);

return result;
}

function getNameNamespaceByID(id, nodes) {
const { name, namepace } = nodes[id];

return { name, namepace };
}

function getVmsListForPlan(hooksRef: IHookRef[], forms) {
let result = [];
const type = forms.general.values.sourceProvider?.type;
const vmTree = forms.filterVMs.values.selectedTreeNodes;
const vmNodes = genrateNodesByVmID(vmTree, 'VM');

if (type === 'openshift') {
result = hooksRef
? forms.selectVMs.values.selectedVMIds.map((id) => ({
...getNameNamespaceByID(id, vmNodes),
hooks: hooksRef.map((hookRef) => ({ hook: hookRef.ref, step: hookRef.instance.step })),
}))
: forms.selectVMs.values.selectedVMIds.map((id) => getNameNamespaceByID(id, vmNodes));
} else {
result = hooksRef
? forms.selectVMs.values.selectedVMIds.map((id) => ({
id,
hooks: hooksRef.map((hookRef) => ({ hook: hookRef.ref, step: hookRef.instance.step })),
}))
: forms.selectVMs.values.selectedVMIds.map((id) => ({ id }));
}

return result;
}

export const generatePlan = (
forms: PlanWizardFormState,
networkMappingRef: INameNamespaceRef,
Expand Down Expand Up @@ -567,12 +618,7 @@ export const generatePlan = (
network: networkMappingRef,
storage: storageMappingRef,
},
vms: hooksRef
? forms.selectVMs.values.selectedVMIds.map((id) => ({
id,
hooks: hooksRef.map((hookRef) => ({ hook: hookRef.ref, step: hookRef.instance.step })),
}))
: forms.selectVMs.values.selectedVMIds.map((id) => ({ id })),
vms: getVmsListForPlan(hooksRef, forms),
warm: forms.type.values.type === 'Warm',
},
});
Expand Down

0 comments on commit a2fd2f1

Please sign in to comment.