From: Yasin
Date: Mon, 6 Oct 2014 16:08:44 +0000 (+0200)
Subject: tools: dynamically get ple resource hrn and slicename to form a ssh command
X-Git-Tag: myslice-1.2~1^2~16
X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=0026ae2959012d3ebb007f86c38ae63f57083dc8
tools: dynamically get ple resource hrn and slicename to form a ssh command
---
diff --git a/portal/slicetabexperiment.py b/portal/slicetabexperiment.py
index b1020a16..023c2060 100644
--- a/portal/slicetabexperiment.py
+++ b/portal/slicetabexperiment.py
@@ -8,6 +8,8 @@ from django.shortcuts import render
from unfold.loginrequired import FreeAccessView
+from manifold.core.query import Query
+from manifoldapi.manifoldapi import execute_query
from manifoldapi.manifoldresult import ManifoldResult
from ui.topmenu import topmenu_items, the_user
from myslice.configengine import ConfigEngine
@@ -24,5 +26,23 @@ class ExperimentView (FreeAccessView, ThemeView):
split_slicename = slicename.split('.')
ple_slicename = split_slicename[0] + '8' + split_slicename[1] + '_' + split_slicename[2]
- return render_to_response(self.template, { 'theme' : self.theme,'slicename':slicename, 'ple_slicename':ple_slicename, 'username':username }, context_instance=RequestContext(request))
+ query_current_resources = Query.get('slice').select('resource').filter_by('slice_hrn','==',slicename)
+ current_resources = execute_query(request, query_current_resources)
+
+ formatted_resource_list=[]
+ try:
+ for resources in current_resources:
+ list_res = resources['resource']
+ for res in list_res:
+ split_list = res.split('+') # split the resource urn
+ if [s for s in split_list if 'ple' in s]: # search only ple resources
+ res_hrn = split_list[-1] # last element is resource hrn
+ formatted_resource_list.append(res_hrn)
+ except Exception,e:
+ print "Exception in slicetabexperiment.py in ple resource search %s" % e
+
+ print "list of ple resource hrns"
+ print formatted_resource_list
+
+ return render_to_response(self.template, { 'theme' : self.theme,'slicename':slicename, 'ple_slicename':ple_slicename, 'username':username, 'ple_resources':formatted_resource_list }, context_instance=RequestContext(request))
diff --git a/portal/templates/slice-tab-experiment.html b/portal/templates/slice-tab-experiment.html
index b6c7c5c4..9dca1d1b 100644
--- a/portal/templates/slice-tab-experiment.html
+++ b/portal/templates/slice-tab-experiment.html
@@ -8,10 +8,19 @@
PlanetLab Europe resources are accessible directly via SSH. Your SSH public key is deployed automatically
on the reserved nodes. To access your slice on a resource just type the following command:
+ {%if ple_resources%}
- $ ssh {{ple_slicename}}@planetlab-resource.hostname.com
-
- NOTE: Your typical slicename {{slicename}} has been converted to PlanetLab specific format {{ple_slicename}} in order to do SSH.
+ {%for resource in ple_resources %}
+ $ ssh {{ple_slicename}}@{{resource}}
+ {%endfor%}
+
+ {%else%}
+ NOTE: You did not reserve any PLE resources yet. Once reserved, you will get the actual SSH command. A specimen command is given below:
+
+ $ ssh {{ple_slicename}}@planetlab-resource.hostname.com
+
+ {%endif%}
+ NOTE: Your original slicename {{slicename}} has been converted to PlanetLab specific format {{ple_slicename}} in order to do SSH.
Please note that the first '.' is replaced by number 8 and the rest of the dot/s are replaced by underscore/s.
Be aware that after you reserve a PlanetLab Europe resource your slice will be deployed with a delay of about 15 minutes,