topology.py moved in sfa/plc/
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 1 Dec 2011 12:01:08 +0000 (13:01 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 1 Dec 2011 12:01:08 +0000 (13:01 +0100)
sfa/importer/sfa-import-plc.py
sfa/managers/aggregate_manager.py
sfa/plc/aggregate.py
sfa/plc/peers.py
sfa/plc/topology.py [moved from sfa/util/topology.py with 74% similarity]

index a991552..d41bbd4 100755 (executable)
@@ -18,10 +18,9 @@ import os
 import getopt
 import sys
 
-from sfa.util.xrn import get_leaf, get_authority
-from sfa.util.plxrn import hostname_to_hrn, slicename_to_hrn, email_to_hrn, hrn_to_pl_slicename
 from sfa.util.config import Config
-from sfa.util.xrn import Xrn
+from sfa.util.xrn import Xrn, get_leaf, get_authority
+from sfa.util.plxrn import hostname_to_hrn, slicename_to_hrn, email_to_hrn, hrn_to_pl_slicename
 
 from sfa.storage.table import SfaTable
 
index 2fbdf3d..c412e17 100644 (file)
@@ -12,6 +12,7 @@ from sfa.util.callids import Callids
 
 from sfa.trust.sfaticket import SfaTicket
 from sfa.trust.credential import Credential
+
 from sfa.rspecs.version_manager import VersionManager
 from sfa.rspecs.rspec import RSpec
 
index 0eff6cc..afdc656 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 from sfa.util.xrn import hrn_to_urn, urn_to_hrn, urn_to_sliver_id
-from sfa.util.plxrn import PlXrn, hostname_to_urn, hrn_to_pl_slicename
+from sfa.util.sfatime import epochparse
 
 from sfa.rspecs.rspec import RSpec
 from sfa.rspecs.elements.hardware_type import HardwareType
@@ -12,10 +12,12 @@ from sfa.rspecs.elements.location import Location
 from sfa.rspecs.elements.interface import Interface
 from sfa.rspecs.elements.services import Services
 from sfa.rspecs.elements.pltag import PLTag
-from sfa.util.topology import Topology
 from sfa.rspecs.version_manager import VersionManager
+
+from sfa.util.plxrn import PlXrn, hostname_to_urn, hrn_to_pl_slicename
 from sfa.plc.vlink import get_tc_rate
-from sfa.util.sfatime import epochparse
+from sfa.plc.topology import Topology
+
 
 class Aggregate:
 
@@ -54,8 +56,8 @@ class Aggregate:
             site1 = sites[site_id1]
             site2 = sites[site_id2]
             # get hrns
-            site1_hrn = self.api.hrn + '.' + site1['login_base']
-            site2_hrn = self.api.hrn + '.' + site2['login_base']
+            site1_hrn = self.api.driver.hrn + '.' + site1['login_base']
+            site2_hrn = self.api.driver.hrn + '.' + site2['login_base']
 
             for s1_node_id in site1['node_ids']:
                 for s2_node_id in site2['node_ids']:
@@ -65,9 +67,9 @@ class Aggregate:
                     node2 = nodes[s2_node_id]
                     # 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_xrn = PlXrn(auth=self.api.driver.hrn, interface='node%s:eth0' % (node1['node_id']))
                     if1_ipv4 = interfaces[node1['interface_ids'][0]]['ip']
-                    if2_xrn = PlXrn(auth=self.api.hrn, interface='node%s:eth0' % (node2['node_id']))
+                    if2_xrn = PlXrn(auth=self.api.driver.hrn, interface='node%s:eth0' % (node2['node_id']))
                     if2_ipv4 = interfaces[node2['interface_ids'][0]]['ip']
 
                     if1 = Interface({'component_id': if1_xrn.urn, 'ipv4': if1_ipv4} )
@@ -78,8 +80,8 @@ class Aggregate:
                     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')
+                    link['component_id'] = PlXrn(auth=self.api.driver.hrn, interface=link['component_name']).get_urn()
+                    link['component_manager_id'] =  hrn_to_urn(self.api.driver.hrn, 'authority+am')
                     links.append(link)
 
         return links
@@ -180,10 +182,10 @@ class Aggregate:
             # xxx how to retrieve site['login_base']
             site_id=node['site_id']
             site=sites_dict[site_id]
-            rspec_node['component_id'] = hostname_to_urn(self.api.hrn, site['login_base'], node['hostname'])
+            rspec_node['component_id'] = hostname_to_urn(self.api.driver.hrn, site['login_base'], node['hostname'])
             rspec_node['component_name'] = node['hostname']
-            rspec_node['component_manager_id'] = self.api.hrn
-            rspec_node['authority_id'] = hrn_to_urn(PlXrn.site_hrn(self.api.hrn, site['login_base']), 'authority+sa')
+            rspec_node['component_manager_id'] = self.api.driver.hrn
+            rspec_node['authority_id'] = hrn_to_urn(PlXrn.site_hrn(self.api.driver.hrn, site['login_base']), 'authority+sa')
             rspec_node['boot_state'] = node['boot_state']
             rspec_node['exclusive'] = 'False'
             rspec_node['hardware_types']= [HardwareType({'name': 'plab-pc'}),
@@ -202,7 +204,8 @@ class Aggregate:
             for if_id in node['interface_ids']:
                 interface = Interface(interfaces[if_id]) 
                 interface['ipv4'] = interface['ip']
-                interface['component_id'] = PlXrn(auth=self.api.hrn, interface='node%s:eth%s' % (node['node_id'], if_count)).get_urn()
+                interface['component_id'] = PlXrn(auth=self.api.driver.hrn, 
+                                                  interface='node%s:eth%s' % (node['node_id'], if_count)).get_urn()
                 rspec_node['interfaces'].append(interface)
                 if_count+=1
 
index b659ea9..f9f80db 100644 (file)
@@ -2,7 +2,7 @@ from sfa.util.xrn import get_authority
 from types import StringTypes
 
 def get_peer(api, hrn):
-    # Becaues of myplc federation,  we first need to determine if this
+    # Because of myplc native federation,  we first need to determine if this
     # slice belongs to out local plc or a myplc peer. We will assume it
     # is a local site, unless we find out otherwise
     peer = None
similarity index 74%
rename from sfa/util/topology.py
rename to sfa/plc/topology.py
index 79482f1..cd6036a 100644 (file)
@@ -15,16 +15,7 @@ class Topology(set):
 
     def __init__(self, config_file = "/etc/sfa/topology"):
         set.__init__(self) 
-        self.config_file = None
-        self.config_path = None
-        self.load(config_file)
-
-    def load(self, config_file):
         try:
-            
-            self.config_file = config_file
-            # path to configuration data
-            self.config_path = os.path.dirname(config_file)
             # load the links
             f = open(config_file, 'r')
             for line in f: