X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=sfa%2Fplc%2Fnetwork.py;h=e97565c77f79b5b8d71dd184481ca5908cf8b910;hb=2b3c0c7ebe7c55afb14e3ea3aed10f8b1abe01e7;hp=2a3e6ba2b08e463cfa38bb030925b5559226c752;hpb=4a5af967fc43fb39c796bd6e281b495f5bdcf905;p=sfa.git diff --git a/sfa/plc/network.py b/sfa/plc/network.py index 2a3e6ba2..e97565c7 100644 --- a/sfa/plc/network.py +++ b/sfa/plc/network.py @@ -1,13 +1,14 @@ 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 InvalidRSpec 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): @@ -183,10 +184,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: @@ -277,12 +282,11 @@ class Slicetag: def write(self, api): if self.was_added(): - api.plshell.AddSliceTag(api.plauth, self.slice_id, - self.tagname, self.value, self.node_id) + api.driver.AddSliceTag(self.slice_id, self.tagname, self.value, self.node_id) elif self.was_changed(): - api.plshell.UpdateSliceTag(api.plauth, self.id, self.value) + api.driver.UpdateSliceTag(self.id, self.value) elif self.was_deleted(): - api.plshell.DeleteSliceTag(api.plauth, self.id) + api.driver.DeleteSliceTag(self.id) class TagType: @@ -343,6 +347,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 +472,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 @@ -550,7 +559,7 @@ class Network: Create a dictionary of site objects keyed by site ID """ tmp = [] - for site in api.plshell.GetSites(api.plauth, {'peer_id': None}): + for site in api.driver.GetSites({'peer_id': None}): t = site['site_id'], Site(self, site) tmp.append(t) return dict(tmp) @@ -561,9 +570,13 @@ class Network: Create a dictionary of node objects keyed by node ID """ tmp = [] - for node in api.plshell.GetNodes(api.plauth, {'peer_id': None}): - t = node['node_id'], Node(self, node) - tmp.append(t) + for node in api.driver.GetNodes({'peer_id': None}): + 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): @@ -571,7 +584,7 @@ class Network: Create a dictionary of node objects keyed by node ID """ tmp = [] - for iface in api.plshell.GetInterfaces(api.plauth): + for iface in api.driver.GetInterfaces(): t = iface['interface_id'], Iface(self, iface) tmp.append(t) return dict(tmp) @@ -581,7 +594,7 @@ class Network: Create a dictionary of slicetag objects keyed by slice tag ID """ tmp = [] - for tag in api.plshell.GetSliceTags(api.plauth, {'~tagname':Slicetag.ignore_tags}, Slicetag.filter_fields): + for tag in api.driver.GetSliceTags({'~tagname':Slicetag.ignore_tags}, Slicetag.filter_fields): t = tag['slice_tag_id'], Slicetag(tag) tmp.append(t) return dict(tmp) @@ -591,7 +604,7 @@ class Network: Create a list of tagtype obects keyed by tag name """ tmp = [] - for tag in api.plshell.GetTagTypes(api.plauth, {'~tagname':TagType.ignore_tags}): + for tag in api.driver.GetTagTypes({'~tagname':TagType.ignore_tags}): t = tag['tagname'], TagType(tag) tmp.append(t) return dict(tmp) @@ -601,7 +614,7 @@ class Network: Return a Slice object for a single slice """ slicename = hrn_to_pl_slicename(hrn) - slice = api.plshell.GetSlices(api.plauth, [slicename]) + slice = api.driver.GetSlices([slicename]) if len(slice): self.slice = Slice(self, slicename, slice[0]) return self.slice