resource reservation work in progress
authorCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Tue, 4 Mar 2014 20:27:05 +0000 (21:27 +0100)
committerCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Tue, 4 Mar 2014 20:27:05 +0000 (21:27 +0100)
portal/sliceresourceview.py
portal/static/js/myslice.js
portal/static/js/onelab_slice-resource-view.js
portal/templates/onelab/onelab_slice-resource-view.html
rest/__init__.py
rest/update.py

index e66de0a..3c1e5b5 100644 (file)
@@ -20,4 +20,8 @@ class SliceResourceView (LoginRequiredView, ThemeView):
     template_name = "slice-resource-view.html"
     
     def get(self, request, slicename):
-        return render_to_response(self.template, {"slice": slicename, "theme": self.theme, "username": request.user, "section":"resources"}, context_instance=RequestContext(request))
+        if request.GET.get('message') : 
+            msg = "Successfully updated Slice"
+        else :
+            msg = None
+        return render_to_response(self.template, {"msg" : msg, "slice": slicename, "theme": self.theme, "username": request.user, "section":"resources"}, context_instance=RequestContext(request))
index e1a6de1..a67e314 100644 (file)
@@ -3,7 +3,9 @@
  */
 
 var myslice = {
+       slice: null,
     pending: [],
+    reserved: [],
     
     add: function(resource) {
        if (!this.has(resource)) {
@@ -39,6 +41,41 @@ var myslice = {
        if (!this.pending) {
                this.pending = [];
        }
+    },
+    
+    apply: function() {
+       $('div#loading').show();
+       this.pending = [];
+       this.save();
+       setTimeout(function(){
+               $('div#loading').hide();
+               window.location.href = '/resources/' + this.slice + '?message=true';
+               },6000);
+       
+        
+
+       // $.post("/rest/slice/", { 'fields': ['resource','slice_hrn'], 'filters': { 'slice_hrn' : this.slice  } }, function(data) {
+               // console.log(data);
+               // resources = [];
+               // reserved = [];
+               // update = [];
+               // if ('resource' in data[0]) {
+                       // $.each(data[0].resource, function(idx, r) {
+                               // resources.push(r.urn);
+                       // });
+               // }
+               // //myslice.pending
+               // console.log(myslice.pending);
+               // console.log(resources);
+               // $.each(resources.concat(myslice.pending), function(idx, v) {
+                       // update.push({ 'resource': v });
+               // });
+               // console.log(update);
+               // $.post("/update/slice/", { 'filters': { 'slice_hrn' : myslice.slice  }, 'params' : update }, function(data) {
+                       // console.log(data);
+               // });
+       // });
+       //console.log(this.slice);
     }
     
 };
index 52850a3..28b1a4e 100644 (file)
@@ -10,16 +10,26 @@ $(document).ready(function() {
         }
     });
     
-    $.get("/rest/platform", function(data) {
+    $.get("/rest/network", function(data) {
                var list = '<div class="list-group-item sl-platfrom"><span class="list-group-item-heading">Testbeds</span></div>';
                for(i=0; i<data.length;i++) {
-                       list += '<a href="#" class="list-group-item sl-platfrom" data-platform="'+data[i].platform+'"><span class="list-group-item-heading">'+data[i].platform_longname+'</span><p class="list-group-item-text">'+data[i].platform+'</p></a>';
+                       list += '<a href="#" class="list-group-item sl-platfrom" data-platform="'+data[i].network_hrn+'"><span class="list-group-item-heading">'+data[i].network_longname+'</span><p class="list-group-item-text">'+data[i].network_hrn+'</p></a>';
                }
                $('#select-platform').html(list);
        }).done(function() {
                
        });
        
+       $('button#ApplyPendind').click(function() {
+               myslice.apply();
+               // $.each(myslice.pending, function(k, p) {
+                       // console.log(p);
+               // });
+               // $.post("/update/slice", {}, function() {
+//                     
+               // });
+       });
+       
    //google.maps.event.addDomListener(window, 'load', initialize);
 });
 
@@ -47,7 +57,7 @@ function mapInit() {
                    });
                        var infowindow = new google.maps.InfoWindow();
 
-                   google.maps.event.addListener(marker, 'click', (function(marker, i) {
+                       google.maps.event.addListener(marker, 'click', (function(marker, i) {
                        return function() {
                          infowindow.setContent(data[i].hostname);
                          infowindow.open(map, marker);
index 1fcecf9..d6682d2 100644 (file)
@@ -3,6 +3,9 @@
 {% block head %}
 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC1RUj824JAiHRVqgc2CSIg4CpKHhh84Lw&sensor=false"></script>
 <script src="{{ STATIC_URL }}js/onelab_slice-resource-view.js"></script>
+<script>
+       myslice.slice = "{{ slice }}";
+</script>
 {% endblock %}
 
 {% block content %}
                                <li><a href="">Reserved</a></li>
                                <li><a href="">Pending<span class="badge" id="badge-pending" style="display:none;"></span></a></li>
                                <li>
-                                       <button type="button" class="btn btn-primary apply">Apply</button>
+                                       <button type="button" class="btn btn-primary apply" id="ApplyPendind">Apply</button>
                                        <button type="button" class="btn btn-default clear">Clear</button>
                                </li>
+                               <li>
+                                       <div id="loading" style="display:none;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading" /></div>
+                               </li>
                        </ul>
                </div>
+               <div class="row">
+                       {% if msg %}
+                       <div class="col-md-12"><p class="alert-success">{{ msg }}</p></div>
+                       {% endif %}
+               </div>
                <div class="row">
                        <ul class="nav nav-tabs nav-resources">
                          <li class="active"><a data-panel="resources" href="#">Resources</a></li>
index 8b78fa3..bdf3ee0 100644 (file)
@@ -27,7 +27,7 @@ class ObjectRequest(object):
         self.type = object_type
         self.name = object_name
         self.fields = []
-        self.params = {}
+        self.params = []
         self.filters = {}
         self.options = None
 
@@ -114,9 +114,12 @@ class ObjectRequest(object):
     def update(self):
         query = Query.update(self.type)
         query = self.applyFilters(query, True)
-
+        print ">>>>>",self.params
+        
         if self.params :
-            query.set(self.params)
+            query.set({ 'resource' : self.params})
+#             for param in self.params :
+                
         else:
             raise Exception, "Params are required for update"
         
index 9657976..b1a8875 100644 (file)
@@ -24,15 +24,23 @@ def dispatch(request, object_type, object_name):
         #return error('only post request is supported')
         req_items = request.GET
     for el in req_items.items():
+        
+        print "#===============>",o.params
         if el[0].startswith('filters'):
             o.filters[el[0][8:-1]] = el[1]
         elif el[0].startswith('params'):
-            o.params[el[0][7:-1]] = el[1]
+            print "#======>", el[0]
+            print "#======>", el[0][7:8]
+            print "#======>", el[0][10:-1]
+            print "#======>", el[1]
+            o.params.append({ el[0][10:-1] : el[1] })
+            
+            
         elif el[0].startswith('fields'):
             o.fields=req_items.getlist('fields[]')
         elif el[0].startswith('options'):
             o.options = req_items.getlist('options[]')
-
+    
     try:
         response = o.update()