update get_rspec() to accept creds, and options params
[sfa.git] / sfa / managers / aggregate_manager_pl.py
index c80e02b..da5c337 100644 (file)
@@ -76,15 +76,15 @@ def __get_registry_objects(slice_xrn, creds, users):
 
         site = {}
         site['site_id'] = 0
-        site['name'] = 'geni.%s' % hrn_auth
+        site['name'] = 'geni.%s' % hrn_auth[:20]
         site['enabled'] = True
         site['max_slices'] = 100
 
         # Note:
         # Is it okay if this login base is the same as one already at this myplc site?
         # Do we need uniqueness?  Should use hrn_auth instead of just the leaf perhaps?
-        site['login_base'] = get_leaf(hrn_auth)
-        site['abbreviated_name'] = hrn
+        site['login_base'] = hrn_auth[:20]
+        site['abbreviated_name'] = hrn_auth[:20]
         site['max_slivers'] = 1000
         reg_objects['site'] = site
 
@@ -165,18 +165,20 @@ def create_slice(api, slice_xrn, creds, rspec, users):
 
     # add nodes from rspec
     added_nodes = list(set(request).difference(current))
-    
-    if peer:
-        api.plshell.UnBindObjectFromPeer(api.plauth, 'slice', slice.id, peer)
 
-    api.plshell.AddSliceToNodes(user_plauth, slice.name, added_nodes) 
-    api.plshell.DeleteSliceFromNodes(user_plauth, slice.name, deleted_nodes)
+    try:
+        if peer:
+            api.plshell.UnBindObjectFromPeer(api.plauth, 'slice', slice.id, peer)
+
+        api.plshell.AddSliceToNodes(user_plauth, slice.name, added_nodes) 
+        api.plshell.DeleteSliceFromNodes(user_plauth, slice.name, deleted_nodes)
 
-    network.updateSliceTags()
+        network.updateSliceTags()
 
-    if peer:
-        api.plshell.BindObjectToPeer(api.plauth, 'slice', slice.id, peer, 
-                                     slice.peer_id)
+    finally:
+        if peer:
+            api.plshell.BindObjectToPeer(api.plauth, 'slice', slice.id, peer, 
+                                         slice.peer_id)
 
     # print network.toxml()
     return True
@@ -236,11 +238,13 @@ def delete_slice(api, xrn, creds):
 
     # determine if this is a peer slice
     peer = peers.get_peer(api, hrn)
-    if peer:
-        api.plshell.UnBindObjectFromPeer(api.plauth, 'slice', slice['slice_id'], peer)
-    api.plshell.DeleteSliceFromNodes(api.plauth, slicename, slice['node_ids'])
-    if peer:
-        api.plshell.BindObjectToPeer(api.plauth, 'slice', slice['slice_id'], peer, slice['peer_slice_id'])
+    try:
+        if peer:
+            api.plshell.UnBindObjectFromPeer(api.plauth, 'slice', slice['slice_id'], peer)
+        api.plshell.DeleteSliceFromNodes(api.plauth, slicename, slice['node_ids'])
+    finally:
+        if peer:
+            api.plshell.BindObjectToPeer(api.plauth, 'slice', slice['slice_id'], peer, slice['peer_slice_id'])
     return 1
 
 def get_slices(api, creds):
@@ -266,13 +270,11 @@ def get_rspec(api, creds, options):
     xrn = options.get('geni_slice_urn', None)
     hrn, type = urn_to_hrn(xrn)
 
-    """
     # look in cache first
     if api.cache and not xrn:
         rspec = api.cache.get('nodes')
         if rspec:
             return rspec 
-    """
 
     registry = api.registries[api.hrn]
     credential = api.getCredential()
@@ -287,11 +289,10 @@ def get_rspec(api, creds, options):
 
     rspec = network.toxml()
 
-    """
     # cache the result
     if api.cache and not xrn:
         api.cache.add('nodes', rspec)
-    """
+    
     return rspec