X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fplc%2Fnetwork.py;h=203d321ec95c3695cf3aa8eb732b33274bb5600a;hb=0f3f332624f3737c065694df13dce874202f28ee;hp=9650e4c97c08d43af6fe55e1b8ebb08c7dc83694;hpb=487d8d8af8977271edb60ee453c5969847b12848;p=sfa.git diff --git a/sfa/plc/network.py b/sfa/plc/network.py index 9650e4c9..203d321e 100644 --- a/sfa/plc/network.py +++ b/sfa/plc/network.py @@ -1,13 +1,15 @@ from __future__ import with_statement +import sys import re import socket +from StringIO import StringIO +from lxml import etree +from xmlbuilder import XMLBuilder + +from sfa.util.faults import * +#from sfa.util.sfalogging import sfa_logger from sfa.util.xrn import get_authority from sfa.util.plxrn import hrn_to_pl_slicename, hostname_to_urn -from sfa.util.faults import * -from xmlbuilder import XMLBuilder -from lxml import etree -import sys -from StringIO import StringIO class Sliver: def __init__(self, node): @@ -148,8 +150,8 @@ class Slice: Use with tags that have only one instance """ def get_tag(self, tagname, node = None): - try: - for i in self.slice_tag_ids: + for i in self.slice_tag_ids: + try: tag = self.network.lookupSliceTag(i) if tag.tagname == tagname: if node: @@ -157,10 +159,10 @@ class Slice: return tag elif not tag.node_id: return tag - except InvalidRSpec, e: - # As they're not needed, we ignore some tag types from - # GetSliceTags call. See Slicetag.ignore_tags - pass + except InvalidRSpec, e: + # As they're not needed, we ignore some tag types from + # GetSliceTags call. See Slicetag.ignore_tags + pass return None def get_nodes(self): @@ -183,10 +185,14 @@ class Slice: # Update a slice tag if it exists, else add it def update_tag(self, tagname, value, node = None, role = "user"): + tag = self.get_tag(tagname, node) + if tag and tag.value == value: + return tag + tt = self.network.lookupTagType(tagname) if not tt.permit_update(role): raise InvalidRSpec("permission denied to modify '%s' tag" % tagname) - tag = self.get_tag(tagname, node) + if tag: tag.change(value) else: @@ -343,6 +349,7 @@ class Network: try: val = self.sites[id] except: + self.api.logger.error("Invalid RSpec: site ID %s not found" % id ) raise InvalidRSpec("site ID %s not found" % id) return val @@ -467,6 +474,10 @@ class Network: if not relaxng(tree): error = relaxng.error_log.last_error message = "%s (line %s)" % (error.message, error.line) + self.api.logger.error("failed to validate rspec %r"%message) + self.api.logger.debug("---------- XML input BEG") + self.api.logger.debug(xml) + self.api.logger.debug("---------- XML input END") raise InvalidRSpec(message) self.rspec = rspec @@ -562,8 +573,12 @@ class Network: """ tmp = [] for node in api.plshell.GetNodes(api.plauth, {'peer_id': None}): - t = node['node_id'], Node(self, node) - tmp.append(t) + try: + t = node['node_id'], Node(self, node) + tmp.append(t) + except: + self.api.logger.error("Failed to add node %s (%s) to RSpec" % (node['hostname'], node['node_id'])) + return dict(tmp) def get_ifaces(self, api):