Skip to content

Commit

Permalink
Added deployment status reset functionality (indigo-dc#27)
Browse files Browse the repository at this point in the history
* - Added deployment status reset functionality
- Fixed missing check on "input" field in tosca parameters.yml

* updated deployments.html
  • Loading branch information
mperniola authored Dec 6, 2024
1 parent 18c01a1 commit 189f95f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
18 changes: 16 additions & 2 deletions app/deployments/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,20 @@ def depdel(depid=None):

return redirect(url_for(SHOW_DEPLOYMENTS_ROUTE))

@deployments_bp.route("/<depid>/reset")
@auth.authorized_with_valid_token
def depreset(depid=None):
access_token = iam.token["access_token"]

dep = dbhelpers.get_deployment(depid)
if dep is not None and dep.status == "DELETE_IN_PROGRESS":
try:
app.orchestrator.patch(access_token, depid, "DELETE_FAILED")
except Exception as e:
flash(str(e), "danger")

return redirect(url_for(SHOW_DEPLOYMENTS_ROUTE))


@deployments_bp.route("/depupdate/<depid>")
@auth.authorized_with_valid_token
Expand Down Expand Up @@ -1009,7 +1023,7 @@ def configure_post():
def prepare_configure_form(selected_tosca, tosca_info, steps):
access_token = iam.token["access_token"]
if selected_tosca:
template = copy.deepcopy(tosca_info[selected_tosca])
template = copy.deepcopy(tosca_info[os.path.normpath(selected_tosca)])
# Manage eventual overrides
for k, v in list(template["inputs"].items()):
if "group_overrides" in v and session["active_usergroup"] in v["group_overrides"]:
Expand Down Expand Up @@ -1612,7 +1626,7 @@ def createdep():
tosca_info, _, _ = tosca.get()
access_token = iam.token["access_token"]
# validate input
request_template = request.args.get("template")
request_template = os.path.normpath(request.args.get("template"))
if request_template not in tosca_info.keys():
raise ValueError("Template path invalid (not found in current configuration")

Expand Down
12 changes: 9 additions & 3 deletions app/deployments/templates/deployments.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,15 @@
<a class="dropdown-item" href="{{ url_for('deployments_bp.lockdeployment', depid=deployment.uuid) }}">
<span class="fas fa-lock mr-2"></span>Lock
</a>
<a class="dropdown-item" style="color: red;" href="#delete_confirm_{{deployment.uuid}}" data-toggle="modal" data-backdrop="static" data-keyboard="false" data-target="#delete_confirm_{{deployment.uuid}}">
<span class="fas fa-trash-alt mr-2"></span>Delete
</a>
{% if deployment.status == 'DELETE_IN_PROGRESS' %}
<a class="dropdown-item" href="{{ url_for('deployments_bp.depreset', depid=deployment.uuid) }}">
<span class="fas fa-undo-alt mr-2"></span>Reset Status
</a>
{% else %}
<a class="dropdown-item" style="color: red;" href="#delete_confirm_{{deployment.uuid}}" data-toggle="modal" data-backdrop="static" data-keyboard="false" data-target="#delete_confirm_{{deployment.uuid}}">
<span class="fas fa-trash-alt mr-2"></span>Delete
</a>
{% endif %}
{% else %}
<a class="dropdown-item" href="{{ url_for('deployments_bp.unlockdeployment', depid=deployment.uuid) }}">
<span class="fas fa-lock-open mr-2"></span>Unlock
Expand Down
13 changes: 13 additions & 0 deletions app/lib/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,16 @@ def delete(self, access_token, deployment_uuid):
raise Exception(
"Error deleting deployment {}: {}".format(deployment_uuid, response.text)
)

def patch(self, access_token, deployment_uuid, status):
headers = {
"Content-Type": "application/json",
"Authorization": "bearer %s" % access_token,
}
url = self.orchestrator_url + "/deployments/" + deployment_uuid
payload = {"status": status}
response = requests.patch(url, timeout=self.timeout, json=payload, headers=headers)
if not response.status_code == 204:
raise Exception(
"Error patching deployment {}: {}".format(deployment_uuid, response.text)
)
11 changes: 6 additions & 5 deletions app/lib/tosca_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ def extracttoscainfo(self, template, tosca):
pars_data = yaml.full_load(
io.StringIO(tosca_info["parameters_file"])
)
pars_inputs = pars_data["inputs"]
tosca_info["inputs"] = {
**tosca_inputs,
**pars_inputs,
}
if "inputs" in pars_data:
pars_inputs = pars_data["inputs"]
tosca_info["inputs"] = {
**tosca_inputs,
**pars_inputs,
}
if "outputs" in pars_data:
pars_outputs = pars_data["outputs"]
tosca_info["outputs"] = {
Expand Down

0 comments on commit 189f95f

Please sign in to comment.