X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2FrspecHelper.py;h=deaa746ae6ee333f1bec134a397127498bbeb554;hb=57b6a99255d4a88be9c0f910f8524677e34ff4bc;hp=6cac3b3c4c08af2182f3b33a8af6fca94511579d;hpb=010a951595e3120bd7cb10b36d18d04c819c20c6;p=sfa.git diff --git a/sfa/util/rspecHelper.py b/sfa/util/rspecHelper.py index 6cac3b3c..deaa746a 100755 --- a/sfa/util/rspecHelper.py +++ b/sfa/util/rspecHelper.py @@ -7,8 +7,8 @@ from lxml import etree from StringIO import StringIO from optparse import OptionParser -from sfa.util.faults import * -from sfa.util.sfalogging import sfa_logger +from sfa.util.faults import InvalidRSpec +from sfa.util.sfalogging import logger def merge_rspecs(rspecs): """ @@ -24,29 +24,31 @@ def merge_rspecs(rspecs): try: known_networks[network.get('name')]=True except: - sfa_logger().error("merge_rspecs: cannot register network with no name in rspec") + logger.error("merge_rspecs: cannot register network with no name in rspec") pass def is_registered_network (network): try: return network.get('name') in known_networks except: - sfa_logger().error("merge_rspecs: cannot retrieve network with no name in rspec") + logger.error("merge_rspecs: cannot retrieve network with no name in rspec") return False # the resulting tree rspec = None for input_rspec in rspecs: + # ignore empty strings as returned with used call_ids + if not input_rspec: continue try: tree = etree.parse(StringIO(input_rspec)) except etree.XMLSyntaxError: # consider failing silently here - sfa_logger().log_exc("merge_rspecs, parse error") + logger.log_exc("merge_rspecs, parse error") message = str(sys.exc_info()[1]) + ' with ' + input_rspec raise InvalidRSpec(message) root = tree.getroot() if not root.get("type") in ["SFA"]: - sfa_logger().error("merge_rspecs: unexpected type for rspec root, %s"%root.get('type')) + logger.error("merge_rspecs: unexpected type for rspec root, %s"%root.get('type')) continue if rspec == None: # we scan the first input, register all networks @@ -79,20 +81,27 @@ class RSpec: if len(networks) == 1: self.network = networks[0] + # Thierry : need this to locate hostname even if several networks def get_node_element(self, hostname, network=None): - if network == None: + if network == None and self.network: network = self.network - names = self.rspec.iterfind("./network[@name='%s']/site/node/hostname" % network) + if network != None: + names = self.rspec.iterfind("./network[@name='%s']/site/node/hostname" % network) + else: + names = self.rspec.iterfind("./network/site/node/hostname") for name in names: if name.text == hostname: return name.getparent() return None + # Thierry : need this to return all nodes in all networks def get_node_list(self, network=None): - if network == None: + if network == None and self.network: network = self.network - result = self.rspec.xpath("./network[@name='%s']/site/node/hostname/text()" % network) - return result + if network != None: + return self.rspec.xpath("./network[@name='%s']/site/node/hostname/text()" % network) + else: + return self.rspec.xpath("./network/site/node/hostname/text()") def get_network_list(self): return self.rspec.xpath("./network[@name]/@name")