Skip to content

Commit 797fc5c

Browse files
authored
Merge pull request #393 from grycap/devel
Change set infra name
2 parents 42a907d + 6553ed0 commit 797fc5c

4 files changed

Lines changed: 32 additions & 6 deletions

File tree

app/__init__.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from functools import wraps
4242
from urllib.parse import urlparse
4343
from radl import radl_parse
44-
from radl.radl import deploy
44+
from radl.radl import deploy, description
4545
from flask_apscheduler import APScheduler
4646
from flask_wtf.csrf import CSRFProtect
4747

@@ -463,7 +463,9 @@ def showinfrastructures():
463463
except Exception as ex:
464464
app.logger.exception("Error getting user credentials: %s" % ex, "error")
465465
creds = []
466-
infra_data["site"] = utils.get_site_info_from_radl(radl_json, creds)
466+
site_info = utils.get_site_info_from_radl(radl_json, creds)
467+
if site_info:
468+
infra_data["site"] = site_info
467469
try:
468470
infra.write_infra(inf_id, infra_data)
469471
except Exception as se:
@@ -1231,6 +1233,21 @@ def manage_inf(infid=None, op=None):
12311233
try:
12321234
infra_data = infra.get_infra(infid)
12331235
infra_data["name"] = form_data['description']
1236+
1237+
# Set the name in the infrastructure RADL
1238+
response = im.get_inf_property(infid, "radl", auth_data)
1239+
if not response.ok:
1240+
raise Exception(response.text)
1241+
infra_radl = radl_parse.parse_radl(response.text)
1242+
if not infra_radl.description:
1243+
infra_radl.description = description("desc")
1244+
if not infra_radl.description.getValue("name"):
1245+
infra_radl.description.setValue("name", infra_data["name"])
1246+
infra_radl.deploys = []
1247+
response = im.addresource_inf(infid, str(infra_radl), auth_data, context=False)
1248+
if not response.ok:
1249+
raise Exception(response.text)
1250+
12341251
infra.write_infra(infid, infra_data)
12351252
except Exception as uex:
12361253
flash("Error updating infrastructure description: %s" % str(uex), "error")

app/im.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ def create_inf(self, payload, auth_data):
112112
url = "%s/infrastructures?async=1" % self.im_url
113113
return requests.post(url, headers=headers, data=payload, timeout=self.timeout)
114114

115-
def addresource_inf(self, infid, payload, auth_data):
115+
def addresource_inf(self, infid, payload, auth_data, context=None):
116116
headers = {"Authorization": auth_data, "Accept": "application/json"}
117117
url = "%s/infrastructures/%s" % (self.im_url, infid)
118+
if context is False:
119+
url += "?context=0"
118120
return requests.post(url, headers=headers, data=payload, timeout=self.timeout)
119121

120122
def get_cloud_images(self, cloud_id, auth_data):

app/templates/infrastructures.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ <h4 class="font-weight-bold text-primary">My Infrastructures</h4>
158158
{% for infId, infInfo in infrastructures.items() %}
159159
<tr>
160160
<th scope="row">
161-
<a id="desc_{{infId}}_a" href="#" onclick="$('#edit_dest_{{infId}}').modal('show');">
162161
{% if infInfo["name"] != "" %}
163162
{{infInfo["name"]}}
164163
{% else %}
164+
<a id="desc_{{infId}}_a" href="#" onclick="$('#edit_dest_{{infId}}').modal('show');">
165165
N/A
166-
{% endif %}
167166
</a>
167+
{% endif %}
168168
</th>
169169
<th>
170170
{{infId}}
@@ -324,7 +324,7 @@ <h5 class="modal-title" id="outputs_label_{{infId}}">Outputs</h5>
324324
<div class="modal-dialog" role="document">
325325
<div class="modal-content">
326326
<div class="modal-header">
327-
<h5 class="modal-title" id="edit_dest_label_{{infId}}">Edit Infrastructure Name</h5>
327+
<h5 class="modal-title" id="edit_dest_label_{{infId}}">Set Infrastructure Name</h5>
328328
<button type="button" class="close" data-dismiss="modal">&times;</button>
329329
</div>
330330
<div class="modal-body">

app/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,10 @@ def getVOs(session):
749749
def get_site_info_from_radl(radl, creds):
750750
res_site = {}
751751

752+
site_type = None
753+
site_host = None
754+
site_vo = None
755+
752756
# Get provider info from RADL
753757
for elem in radl:
754758
if elem["class"] == "system":
@@ -759,6 +763,9 @@ def get_site_info_from_radl(radl, creds):
759763
site_type = "fedcloud"
760764
break
761765

766+
if not site_type:
767+
return res_site
768+
762769
# Now try to get the corresponding cred
763770
# only for EGI sites
764771
for cred in creds:

0 commit comments

Comments
 (0)