X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Frspecs%2Faggregates%2Fvini%2Futils.py;h=c3118877757e535eb22f7b72dbf707b5dd93b1af;hb=73b163a7ea35209e0675a7c7cef367946928a96f;hp=94e64bf79c6d8d8b65838cc6ebc3910ba93cd84c;hpb=cbfcd01963fd69149937551f9d225ec825554384;p=sfa.git diff --git a/sfa/rspecs/aggregates/vini/utils.py b/sfa/rspecs/aggregates/vini/utils.py index 94e64bf7..c3118877 100644 --- a/sfa/rspecs/aggregates/vini/utils.py +++ b/sfa/rspecs/aggregates/vini/utils.py @@ -1,5 +1,6 @@ import re import socket +from sfa.util.faults import * from sfa.rspecs.aggregates.vini.topology import * default_topo_xml = """ @@ -218,6 +219,7 @@ class Site: self.name = site['abbreviated_name'].replace(" ", "_") self.tag = site['login_base'] self.public = site['is_public'] + self.enabled = site['enabled'] self.links = set() def get_sitenodes(self, nodes): @@ -469,7 +471,17 @@ class Topology: tags.append(self.tags[t]) return tags - def nodeTopoFromRspec(self, rspec): + def lookupSiteLink(self, node1, node2): + site1 = self.sites[node1.site_id] + site2 = self.sites[node2.site_id] + for link in self.sitelinks: + if site1 == link.end1 and site2 == link.end2: + return link + if site2 == link.end1 and site1 == link.end2: + return link + return None + + def nodeTopoFromRSpec(self, rspec): if self.nodelinks: raise Error("virtual topology already present") @@ -478,7 +490,7 @@ class Topology: for node in self.getNodes(): nodedict[node.tag] = node - linkspecs = rspecdict['Rspec']['Request'][0]['NetSpec'][0]['LinkSpec'] + linkspecs = rspecdict['RSpec']['Request'][0]['NetSpec'][0]['LinkSpec'] for l in linkspecs: n1 = nodedict[l['endpoint'][0]] n2 = nodedict[l['endpoint'][1]] @@ -523,14 +535,37 @@ class Topology: tag.delete() tag.write(self.api) + """ + Check the requested topology against the available topology and capacity + """ + def verifyNodeTopo(self, hrn, topo, maxbw): + maxbps = get_tc_rate(maxbw) + for link in self.nodelinks: + if link.bps <= 0: + raise GeniInvalidArgument(bw, "BW") + if link.bps > maxbps: + raise PermissionError(" %s requested %s but max BW is %s" % + (hrn, format_tc_rate(link.bps), maxbw)) + + n1 = link.end1 + n2 = link.end2 + sitelink = self.lookupSiteLink(n1, n2) + if not sitelink: + raise PermissionError("%s: nodes %s and %s not adjacent" % (hrn, n1.tag, n2.tag)) + if sitelink.bps < link.bps: + raise PermissionError("%s: insufficient capacity between %s and %s" % (hrn, n1.tag, n2.tag)) + + """ + Produce XML directly from the topology specification. + """ def toxml(self, hrn = None): xml = """ - + """ for site in self.getSites(): - if not site.public: + if not (site.public and site.enabled): continue xml += """ @@ -581,7 +616,7 @@ class Topology: xml += """ -""" +""" # Remove all leading whitespace and newlines lines = xml.split("\n")