Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespace and name to openshift plan #625

Merged
merged 1 commit into from
Jul 27, 2023
Merged
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
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
Loading