a little nicer wrt pep8
[sfa.git] / sfa / planetlab / topology.py
1 ##
2 # SFA Topology Info
3 #
4 # This module holds topology configuration for SFA. It is implemnted as a
5 # list of site_id tuples
6
7 import os.path
8 import traceback
9 from sfa.util.sfalogging import logger
10
11
12 class Topology(set):
13     """
14     Parse the topology configuration file. 
15     """
16
17     def __init__(self, config_file="/etc/sfa/topology"):
18         set.__init__(self)
19         try:
20             # load the links
21             f = open(config_file, 'r')
22             for line in f:
23                 ignore = line.find('#')
24                 if ignore > -1:
25                     line = line[0:ignore]
26                 tup = line.split()
27                 if len(tup) > 1:
28                     self.add((tup[0], tup[1]))
29         except Exception as e:
30             logger.log_exc(
31                 "Could not find or load the configuration file: %s" % config_file)
32             raise