tools: dynamically get ple resource hrn and slicename to form a ssh command
authorYasin <mohammed-yasin.rahman@lip6.fr>
Mon, 6 Oct 2014 16:08:44 +0000 (18:08 +0200)
committerYasin <mohammed-yasin.rahman@lip6.fr>
Mon, 6 Oct 2014 16:08:44 +0000 (18:08 +0200)
portal/slicetabexperiment.py
portal/templates/slice-tab-experiment.html

index b1020a1..023c206 100644 (file)
@@ -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))
 
index b6c7c5c..9dca1d1 100644 (file)
@@ -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:
        </p>
+       {%if ple_resources%}
        <p class="command">
-               $ ssh {{ple_slicename}}@planetlab-resource.hostname.com
-       </p>
-       <p><strong>NOTE:</strong> Your typical slicename <b>{{slicename}}</b> has been converted to PlanetLab specific format <b>{{ple_slicename}}</b> in order to do SSH.</p>
+       {%for resource in ple_resources %}
+               $ ssh {{ple_slicename}}@{{resource}}<br>
+       {%endfor%}
+       </p>
+       {%else%}
+               <p><b>NOTE:</b> You did not reserve any PLE resources yet. Once reserved, you will get the actual SSH command. A specimen command is given below:</p>
+               <p class="command">
+               $ ssh {{ple_slicename}}@planetlab-resource.hostname.com<br>
+               </p>
+       {%endif%}
+       <p><strong>NOTE:</strong> Your original slicename <b>{{slicename}}</b> has been converted to PlanetLab specific format <b>{{ple_slicename}}</b> in order to do SSH.</p>
        <p>Please note that the first '.' is replaced by number 8 and the rest of the dot/s are replaced by underscore/s.</p>
        <p>
                Be aware that after you reserve a PlanetLab Europe resource your slice will be deployed with a delay of about 15 minutes,