Merge branch 'master' into senslab2
[sfa.git] / sfa / plc / plaggregate.py
index d1272bc..55e6291 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 from sfa.util.xrn import Xrn, hrn_to_urn, urn_to_hrn, urn_to_sliver_id
-from sfa.util.sfatime import epochparse
+from sfa.util.sfatime import utcparse, datetime_to_string
 from sfa.util.sfalogging import logger
 
 from sfa.rspecs.rspec import RSpec
@@ -127,7 +127,8 @@ class PlAggregate:
             # most likely a default/global sliver attribute (node_id == None)
             if tag['node_id'] not in slivers:
                 sliver = Sliver({'sliver_id': urn_to_sliver_id(slice_urn, slice['slice_id'], ""),
-                                 'name': 'plab-vserver',
+                                 'name': slice['name'],
+                                 'type': 'plab-vserver',
                                  'tags': []})
                 slivers[tag['node_id']] = sliver
             slivers[tag['node_id']]['tags'].append(tag)
@@ -135,6 +136,11 @@ class PlAggregate:
         return (slice, slivers)
 
     def get_nodes_and_links(self, slice=None,slivers=[], options={}):
+        # if we are dealing with a slice that has no node just return 
+        # and empty list    
+        if slice is not None and not slice['node_ids']:
+            return ([],[])
+
         filter = {}
         tags_filter = {}
         if slice and 'node_ids' in slice and slice['node_ids']:
@@ -183,10 +189,12 @@ class PlAggregate:
             rspec_node['component_name'] = node['hostname']
             rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn()
             rspec_node['authority_id'] = hrn_to_urn(PlXrn.site_hrn(self.driver.hrn, site['login_base']), 'authority+sa')
-            rspec_node['boot_state'] = node['boot_state']
+            # do not include boot state (<available> element) in the manifest rspec
+            if not slice:     
+                rspec_node['boot_state'] = node['boot_state']
             rspec_node['exclusive'] = 'false'
-            rspec_node['hardware_types']= [HardwareType({'name': 'plab-pc'}),
-                                           HardwareType({'name': 'pc'})]
+            rspec_node['hardware_types'] = [HardwareType({'name': 'plab-pc'}),
+                                            HardwareType({'name': 'pc'})]
             # only doing this because protogeni rspec needs
             # to advertise available initscripts 
             rspec_node['pl_initscripts'] = pl_initscripts.values()
@@ -194,7 +202,7 @@ class PlAggregate:
             # assumes that sites, interfaces and tags have already been prepared.
             site = sites_dict[node['site_id']]
             if site['longitude'] and site['latitude']:  
-                location = Location({'longitude': site['longitude'], 'latitude': site['latitude']})
+                location = Location({'longitude': site['longitude'], 'latitude': site['latitude'], 'country': 'unknown'})
                 rspec_node['location'] = location
             rspec_node['interfaces'] = []
             if_count=0
@@ -219,7 +227,7 @@ class PlAggregate:
                 rspec_node['slivers'] = [sliver]
                 
                 # slivers always provide the ssh service
-                login = Login({'authentication': 'ssh-keys', 'hostname': node['hostname'], 'port':'22'})
+                login = Login({'authentication': 'ssh-keys', 'hostname': node['hostname'], 'port':'22', 'username': sliver['name']})
                 service = Services({'login': login})
                 rspec_node['services'] = [service]
             rspec_nodes.append(rspec_node)
@@ -238,7 +246,7 @@ class PlAggregate:
         slice, slivers = self.get_slice_and_slivers(slice_xrn)
         rspec = RSpec(version=rspec_version, user_options=options)
         if slice and 'expires' in slice:
-            rspec.xml.set('expires',  epochparse(slice['expires']))
+            rspec.xml.set('expires',  datetime_to_string(utcparse(slice['expires'])))
 
         nodes, links = self.get_nodes_and_links(slice, slivers)
         rspec.version.add_nodes(nodes)