clean up
[sfa.git] / sfa / planetlab / plaggregate.py
index 17ca1d6..d85043e 100644 (file)
@@ -248,9 +248,10 @@ class PlAggregate:
                          'type': 'plab-vserver',
                          'tags': []})
         rspec_node['sliver_id'] = rspec_sliver['sliver_id']
-        rspec_node['client_id'] = sliver_allocations[sliver['urn']].client_id
-        if sliver_allocations[sliver['urn']].component_id:
-            rspec_node['component_id'] = sliver_allocations[sliver['urn']].component_id
+        if sliver['urn'] in sliver_allocations:
+            rspec_node['client_id'] = sliver_allocations[sliver['urn']].client_id
+            if sliver_allocations[sliver['urn']].component_id:
+                rspec_node['component_id'] = sliver_allocations[sliver['urn']].component_id
         rspec_node['slivers'] = [rspec_sliver]
 
         # slivers always provide the ssh service
@@ -310,6 +311,9 @@ class PlAggregate:
                     op_status = 'geni_unknown'
             else:
                 allocation_status = 'geni_unallocated'    
+        else:
+            allocation_status = 'geni_unallocated'
+            op_status = 'geni_failed'
         # required fields
         geni_sliver = {'geni_sliver_urn': rspec_node['sliver_id'],
                        'geni_expires': rspec_node['expires'],
@@ -346,8 +350,7 @@ class PlAggregate:
             site_id=lease['site_id']
             site=sites_dict[site_id]
 
-            rspec_lease['lease_id'] = lease['lease_id']
-            rspec_lease['component_id'] = PlXrn(self.driver.hrn, hostname=lease['hostname']).urn
+            rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], lease['hostname'])
             slice_hrn = slicename_to_hrn(self.driver.hrn, lease['name'])
             slice_urn = hrn_to_urn(slice_hrn, 'slice')
             rspec_lease['slice_id'] = slice_urn
@@ -390,6 +393,11 @@ class PlAggregate:
             # add links
             links = self.get_links(sites, nodes_dict, interfaces)        
             rspec.version.add_links(links)
+
+        if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'resources':
+           leases = self.get_leases()
+           rspec.version.add_leases(leases)
+
         return rspec.toxml()
 
     def describe(self, urns, version=None, options={}):