diff --git a/tdp/cli/commands/plan/dag.py b/tdp/cli/commands/plan/dag.py index ebeb6d5c..ad2b80c0 100644 --- a/tdp/cli/commands/plan/dag.py +++ b/tdp/cli/commands/plan/dag.py @@ -86,7 +86,7 @@ def dag( from tdp.cli.utils import print_deployment, validate_plan_creation from tdp.core.dag import Dag from tdp.core.models import DeploymentModel - from tdp.core.models.enums import FilterTypeEnum + from tdp.core.models.enums import DeploymentStateEnum, FilterTypeEnum from tdp.dao import Dao filter_type = None @@ -136,6 +136,7 @@ def dag( with Dao(db_engine, commit_on_exit=True) as dao: if last_deployment := dao.get_last_deployment(): validate_plan_creation(last_deployment.state, force) - deployment.id = last_deployment.id + if last_deployment.state is DeploymentStateEnum.PLANNED: + deployment.id = last_deployment.id dao.session.merge(deployment) click.echo("Deployment plan successfully created.") diff --git a/tdp/cli/commands/plan/import_file.py b/tdp/cli/commands/plan/import_file.py index a5307467..5db5e8ac 100644 --- a/tdp/cli/commands/plan/import_file.py +++ b/tdp/cli/commands/plan/import_file.py @@ -33,6 +33,7 @@ def import_file( from tdp.cli.utils import parse_file, validate_plan_creation from tdp.core.models.deployment_model import DeploymentModel + from tdp.core.models.enums import DeploymentStateEnum from tdp.dao import Dao with Dao(db_engine, commit_on_exit=True) as dao: @@ -47,8 +48,8 @@ def import_file( ) if last_deployment := dao.get_last_deployment(): validate_plan_creation(last_deployment.state, force) - # if a planned deployment is present, update it - deployment.id = last_deployment.id + if last_deployment.state is DeploymentStateEnum.PLANNED: + deployment.id = last_deployment.id dao.session.merge(deployment) dao.session.commit() click.echo("Deployment plan successfully imported.") diff --git a/tdp/cli/commands/plan/ops.py b/tdp/cli/commands/plan/ops.py index 6e416b41..b2be51e8 100644 --- a/tdp/cli/commands/plan/ops.py +++ b/tdp/cli/commands/plan/ops.py @@ -52,6 +52,7 @@ def ops( from tdp.cli.utils import print_deployment, validate_plan_creation from tdp.core.models import DeploymentModel + from tdp.core.models.enums import DeploymentStateEnum from tdp.dao import Dao click.echo( @@ -66,6 +67,7 @@ def ops( with Dao(db_engine, commit_on_exit=True) as dao: if last_deployment := dao.get_last_deployment(): validate_plan_creation(last_deployment.state, force) - deployment.id = last_deployment.id + if last_deployment.state is DeploymentStateEnum.PLANNED: + deployment.id = last_deployment.id dao.session.merge(deployment) click.echo("Deployment plan successfully created.") diff --git a/tdp/cli/commands/plan/reconfigure.py b/tdp/cli/commands/plan/reconfigure.py index ddb34e71..df1fecc0 100644 --- a/tdp/cli/commands/plan/reconfigure.py +++ b/tdp/cli/commands/plan/reconfigure.py @@ -38,6 +38,7 @@ def reconfigure( from tdp.cli.utils import print_deployment, validate_plan_creation from tdp.core.models import DeploymentModel + from tdp.core.models.enums import DeploymentStateEnum from tdp.dao import Dao click.echo("Creating a deployment plan to reconfigure services.") @@ -54,6 +55,7 @@ def reconfigure( return if last_deployment := dao.get_last_deployment(): validate_plan_creation(last_deployment.state, force) - deployment.id = last_deployment.id + if last_deployment.state is DeploymentStateEnum.PLANNED: + deployment.id = last_deployment.id dao.session.merge(deployment) click.echo("Deployment plan successfully created.") diff --git a/tdp/cli/commands/plan/resume.py b/tdp/cli/commands/plan/resume.py index 6a78b141..3e99f697 100644 --- a/tdp/cli/commands/plan/resume.py +++ b/tdp/cli/commands/plan/resume.py @@ -30,6 +30,7 @@ def resume( from tdp.cli.utils import print_deployment, validate_plan_creation from tdp.core.models import DeploymentModel + from tdp.core.models.enums import DeploymentStateEnum from tdp.dao import Dao with Dao(db_engine, commit_on_exit=True) as dao: @@ -51,6 +52,7 @@ def resume( return if last_deployment := dao.get_last_deployment(): validate_plan_creation(last_deployment.state) - deployment.id = last_deployment.id + if last_deployment.state is DeploymentStateEnum.PLANNED: + deployment.id = last_deployment.id dao.session.merge(deployment) click.echo("Deployment plan successfully created.")