bugfixes
[sfa.git] / sfa / plc / aggregate.py
index 18a5123..c1f008f 100644 (file)
@@ -6,6 +6,7 @@ from sfa.rspecs.rspec import RSpec
 from sfa.rspecs.elements.hardware_type import HardwareType
 from sfa.rspecs.elements.node import Node
 from sfa.rspecs.elements.link import Link
+from sfa.rspecs.elements.sliver import Sliver
 from sfa.rspecs.elements.login import Login
 from sfa.rspecs.elements.location import Location
 from sfa.rspecs.elements.interface import Interface
@@ -39,7 +40,8 @@ class Aggregate:
             iface['interface_id'] = interface['interface_id']
             iface['node_id'] = interface['node_id']
             iface['ipv4'] = interface['ip']
-            iface['bwlimit'] = str(int(interface['bwlimit'])/1000)
+            if interface['bwlimit']:
+                iface['bwlimit'] = str(int(interface['bwlimit'])/1000)
             interfaces[iface['interface_id']] = iface
         return interfaces
 
@@ -59,28 +61,27 @@ class Aggregate:
             # get hrns
             site1_hrn = self.api.hrn + '.' + site1['login_base']
             site2_hrn = self.api.hrn + '.' + site2['login_base']
-            # get the first node
-            node1 = self.nodes[site1['node_ids'][0]]
-            node2 = self.nodes[site2['node_ids'][0]]
-
-            # set interfaces
-            # just get first interface of the first node
-            if1_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (node1['node_id']))
-            if1_ipv4 = self.interfaces[node1['interface_ids'][0]]['ip']
-            if2_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (node2['node_id']))
-            if2_ipv4 = self.interfaces[node2['interface_ids'][0]]['ip']
-
-            if1 = Interface({'component_id': if1_xrn.urn, 'ipv4': if1_ipv4} )
-            if2 = Interface({'component_id': if2_xrn.urn, 'ipv4': if2_ipv4} )
-
-            # set link
-            link = Link({'capacity': '1000000', 'latency': '0', 'packet_loss': '0', 'type': 'ipv4'})
-            link['interface1'] = if1
-            link['interface2'] = if2
-            link['component_name'] = "%s:%s" % (site1['login_base'], site2['login_base'])
-            link['component_id'] = PlXrn(auth=self.api.hrn, interface=link['component_name']).get_urn()
-            link['component_manager_id'] =  hrn_to_urn(self.api.hrn, 'authority+am')
-            links[link['component_name']] = link
+
+            for s1_node in self.nodes[site1['node_ids']]:
+                for s2_node in self.nodes[site2['node_ids']]:
+                    # set interfaces
+                    # just get first interface of the first node
+                    if1_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (s1_node['node_id']))
+                    if1_ipv4 = self.interfaces[node1['interface_ids'][0]]['ip']
+                    if2_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (s2_node['node_id']))
+                    if2_ipv4 = self.interfaces[node2['interface_ids'][0]]['ip']
+
+                    if1 = Interface({'component_id': if1_xrn.urn, 'ipv4': if1_ipv4} )
+                    if2 = Interface({'component_id': if2_xrn.urn, 'ipv4': if2_ipv4} )
+
+                    # set link
+                    link = Link({'capacity': '1000000', 'latency': '0', 'packet_loss': '0', 'type': 'ipv4'})
+                    link['interface1'] = if1
+                    link['interface2'] = if2
+                    link['component_name'] = "%s:%s" % (site1['login_base'], site2['login_base'])
+                    link['component_id'] = PlXrn(auth=self.api.hrn, interface=link['component_name']).get_urn()
+                    link['component_manager_id'] =  hrn_to_urn(self.api.hrn, 'authority+am')
+                    links[link['component_name']] = link
 
         return links
 
@@ -106,7 +107,7 @@ class Aggregate:
         slice = None
         if not slice_xrn:
             return (slice, slivers)
-        slice_urn = hrn_to_urn(slice_xrn)
+        slice_urn = hrn_to_urn(slice_xrn, 'slice')
         slice_hrn, _ = urn_to_hrn(slice_xrn)
         slice_name = hrn_to_pl_slicename(slice_hrn)
         slices = self.api.driver.GetSlices(slice_name)
@@ -178,7 +179,8 @@ class Aggregate:
             rspec_node['authority_id'] = hrn_to_urn(PlXrn.site_hrn(self.api.hrn, site['login_base']), 'authority+sa')
             rspec_node['boot_state'] = node['boot_state']
             rspec_node['exclusive'] = 'False'
-            rspec_node['hardware_types'].append(HardwareType({'name': 'plab-vserver'}))
+            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()
@@ -193,7 +195,7 @@ class Aggregate:
             for if_id in node['interface_ids']:
                 interface = Interface(interfaces[if_id]) 
                 interface['ipv4'] = interface['ipv4']
-                interface['component_id'] = PlXrn(auth=self.api.hrn, interface='node%s:eth%s' % (node['node_id'], if_count))
+                interface['component_id'] = PlXrn(auth=self.api.hrn, interface='node%s:eth%s' % (node['node_id'], if_count)).get_urn()
                 rspec_node['interfaces'].append(interface)
                 if_count+=1
 
@@ -207,9 +209,9 @@ class Aggregate:
                 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'})
                 service = Services({'login': login})
-                rspec_node['services'].append(service)
+                rspec_node['services'] = [service]
             rspec_nodes.append(rspec_node)
         return rspec_nodes
              
@@ -225,9 +227,9 @@ class Aggregate:
 
         slice, slivers = self.get_slice_and_slivers(slice_xrn)
         rspec = RSpec(version=rspec_version, user_options=self.user_options)
-        if slice and 'expiration_date' in slice:
-            rspec.set('expires',  epochparse(slice['expiration_date'])) 
-        rspec.version.add_nodes(self.get_nodes(slice), slivers)
+        if slice and 'expires' in slice:
+            rspec.xml.set('expires',  epochparse(slice['expires'])) 
+        rspec.version.add_nodes(self.get_nodes(slice, slivers))
         rspec.version.add_links(self.get_links(slice))
         
         # add sliver defaults