namespace module is gone, plxrn provides PL-specific translations
[sfa.git] / sfa / managers / aggregate_manager_pl.py
index ae4215a..0c70dda 100644 (file)
@@ -1,16 +1,16 @@
-### $Id: slices.py 15842 2009-11-22 09:56:13Z anil $
-### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/plc/slices.py $
-
 import datetime
 import time
 import traceback
 import sys
 import re
 from types import StringTypes
-from sfa.util.namespace import *
+from dateutil.parser import parse
+
+from sfa.util.faults import *
+from sfa.util.xrn import get_authority, hrn_to_urn, urn_to_hrn
+from sfa.util.plxrn import slicename_to_hrn, hrn_to_pl_slicename
 from sfa.util.rspec import *
 from sfa.util.specdict import *
-from sfa.util.faults import *
 from sfa.util.record import SfaRecord
 from sfa.util.policy import Policy
 from sfa.util.record import *
@@ -58,7 +58,7 @@ def __get_registry_objects(slice_xrn, creds, users):
         reg_objects['site'] = site
 
         slice = {}
-        slice['expires'] = int(time.mktime(Credential(string=creds[0]).get_lifetime().timetuple()))
+        slice['expires'] = int(time.mktime(Credential(string=creds[0]).get_expiration().timetuple()))
         slice['hrn'] = hrn
         slice['name'] = hrn_to_pl_slicename(hrn)
         slice['url'] = hrn
@@ -70,7 +70,7 @@ def __get_registry_objects(slice_xrn, creds, users):
         for user in users:
             user['key_ids'] = []
             hrn, _ = urn_to_hrn(user['urn'])
-            user['email'] = hrn + "@geni.net"
+            user['email'] = hrn_to_pl_slicename(hrn) + "@geni.net"
             user['first_name'] = hrn
             user['last_name'] = hrn
             reg_objects['users'][user['email']] = user
@@ -90,10 +90,41 @@ def get_version():
     return version
 
 def slice_status(api, slice_xrn, creds):
+    hrn, type = urn_to_hrn(slice_xrn)
+    # find out where this slice is currently running
+    api.logger.info(hrn)
+    slicename = hrn_to_pl_slicename(hrn)
+    
+    slices = api.plshell.GetSlices(api.plauth, [slicename], ['node_ids','person_ids','name','expires'])
+    if len(slices) == 0:        
+        raise Exception("Slice %s not found (used %s as slicename internally)" % slice_xrn, slicename)
+    slice = slices[0]
+    
+    nodes = api.plshell.GetNodes(api.plauth, slice['node_ids'],
+                                    ['hostname', 'boot_state', 'last_contact'])
+    api.logger.info(slice)
+    api.logger.info(nodes)
+    
     result = {}
     result['geni_urn'] = slice_xrn
     result['geni_status'] = 'unknown'
-    result['geni_resources'] = {}
+    result['pl_login'] = slice['name']
+    result['pl_expires'] = slice['expires']
+    
+    resources = []
+    
+    for node in nodes:
+        res = {}
+        res['pl_hostname'] = node['hostname']
+        res['pl_boot_state'] = node['boot_state']
+        res['pl_last_contact'] = node['last_contact']
+        res['geni_urn'] = ''
+        res['geni_status'] = 'unknown'
+        res['geni_error'] = ''
+
+        resources.append(res)
+        
+    result['geni_resources'] = resources
     return result
 
 def create_slice(api, slice_xrn, creds, rspec, users):
@@ -151,15 +182,16 @@ def create_slice(api, slice_xrn, creds, rspec, users):
     return True
 
 
-def renew_slice(api, xrn, creds, exipration_time):
+def renew_slice(api, xrn, creds, expiration_time):
     hrn, type = urn_to_hrn(xrn)
     slicename = hrn_to_pl_slicename(hrn)
     slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id'])
     if not slices:
         raise RecordNotFound(hrn)
     slice = slices[0]
-    slice['expires'] = expiration_time
-    api.plshell.UpdateSlice(api.plauth, slice['slice_id'], slice)
+    requested_time = parse(expiration_time)
+    record = {'expires': int(time.mktime(requested_time.timetuple()))}
+    api.plshell.UpdateSlice(api.plauth, slice['slice_id'], record)
     return 1         
 
 def start_slice(api, xrn, creds):
@@ -234,7 +266,7 @@ def get_slices(api, creds):
     
 def get_rspec(api, creds, options):
     # get slice's hrn from options
-    xrn = options.get('geni_slice_urn', None)
+    xrn = options.get('geni_slice_urn', '')
     hrn, type = urn_to_hrn(xrn)
 
     # look in cache first