+
+ """
+ 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 = """<?xml version="1.0"?>
+<RSpec xmlns="http://www.planet-lab.org/sfa/rspec/" name="vini">
+ <Capacity>
+ <NetSpec name="physical_topology">"""
+
+ for site in self.getSites():
+ if not (site.public and site.enabled):
+ continue
+
+ xml += """
+ <SiteSpec name="%s"> """ % site.name
+
+ for node in site.get_sitenodes(self.nodes):
+ if not node.tag:
+ continue
+
+ xml += """
+ <NodeSpec name="%s">
+ <hostname>%s</hostname>
+ <bw>%s</bw>
+ </NodeSpec>""" % (node.tag, node.hostname, format_tc_rate(node.bps))
+ xml += """
+ </SiteSpec>"""
+
+ for link in self.sitelinks:
+ xml += """
+ <SiteLinkSpec>
+ <endpoint>%s</endpoint>
+ <endpoint>%s</endpoint>
+ <bw>%s</bw>
+ </SiteLinkSpec>""" % (link.end1.name, link.end2.name, format_tc_rate(link.bps))
+
+
+ if hrn:
+ name = hrn
+ else:
+ name = 'default_topology'
+ xml += """
+ </NetSpec>
+ </Capacity>
+ <Request>
+ <NetSpec name="%s">""" % name
+
+ if hrn:
+ for link in self.nodelinks:
+ xml += """
+ <LinkSpec>
+ <endpoint>%s</endpoint>
+ <endpoint>%s</endpoint>
+ <bw>%s</bw>
+ </LinkSpec>""" % (link.end1.tag, link.end2.tag, format_tc_rate(link.bps))
+ else:
+ xml += default_topo_xml
+
+ xml += """
+ </NetSpec>
+ </Request>
+</RSpec>"""
+
+ # Remove all leading whitespace and newlines
+ lines = xml.split("\n")
+ noblanks = ""
+ for line in lines:
+ noblanks += line.strip()
+ return noblanks