From 8e3ec6fcee6d8423970f5ca4f1d04157639f1f2d Mon Sep 17 00:00:00 2001 From: vichansson Date: Tue, 10 Sep 2024 17:44:49 +0300 Subject: [PATCH] B OpenNebula/one#6716: Correct instances amount when instantiate (#3223) * Now instantiates the correct number of instances specified for a service ServiceTemplate * Default number of instances set to 1 Signed-off-by: Victor Hansson (cherry picked from commit 212aa91a3c59a5a9fa351d1be6fbd9e3d0f10a33) --- .../InstantiateForm/Steps/General/schema.js | 4 +++- .../InstantiateForm/Steps/index.js | 1 + .../containers/ServiceTemplates/Instantiate.js | 15 +++++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/General/schema.js b/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/General/schema.js index 71474a76d7..6f65f34444 100644 --- a/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/General/schema.js +++ b/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/General/schema.js @@ -36,7 +36,9 @@ const INSTANCE_FIELD = { name: 'INSTANCES', label: T.NumberOfInstances, type: INPUT_TYPES.TEXT, - validation: number().required(), + validation: number() + .required() + .default(() => 1), fieldProps: { type: 'number', }, diff --git a/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/index.js b/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/index.js index dfec7d01dd..ce85cf7867 100644 --- a/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/index.js +++ b/src/fireedge/src/client/components/Forms/ServiceTemplate/InstantiateForm/Steps/index.js @@ -120,6 +120,7 @@ const Steps = createSteps([General, UserInputs, Network, Charter], { ), })), name: generalData?.NAME, + instances: generalData?.INSTANCES, } return formatTemplate diff --git a/src/fireedge/src/client/containers/ServiceTemplates/Instantiate.js b/src/fireedge/src/client/containers/ServiceTemplates/Instantiate.js index d8a67a38bf..bd2ff231fd 100644 --- a/src/fireedge/src/client/containers/ServiceTemplates/Instantiate.js +++ b/src/fireedge/src/client/containers/ServiceTemplates/Instantiate.js @@ -62,11 +62,18 @@ function CreateServiceTemplate() { useGetDatastoresQuery(undefined, { refetchOnMountOrArgChange: false }) const onSubmit = async (jsonTemplate) => { + const { instances = 1 } = jsonTemplate + try { - await instantiate({ - id: templateId, - template: jsonTemplate, - }).unwrap() + await Promise.all( + Array.from({ length: instances }, async () => + instantiate({ + id: templateId, + template: jsonTemplate, + }).unwrap() + ) + ) + history.push(PATH.INSTANCE.SERVICES.LIST) enqueueSuccess(T.SuccessServiceTemplateInitiated, [templateId, NAME]) } catch {}