3 from StringIO import StringIO
4 from sfa.rspecs.rspec import RSpec
5 from sfa.util.xrn import *
6 from sfa.util.plxrn import hostname_to_urn
7 from sfa.util.config import Config
11 header = '<?xml version="1.0"?>\n'
12 namespaces = {'rspecv2':'http://www.protogeni.net/resources/rspec/0.2',
13 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
15 schemas = {'xsi': 'http://www.protogeni.net/resources/rspec/0.2 http://www.protogeni.net/resources/rspec/0.2/ad.xsd'
19 def create(self, type="advertisement"):
21 for namespace in self.namespaces:
23 if namespace not in 'rspecv2':
24 xmlns = xmlns + ":" + namespace
25 self.xml.set(xmlns, self.namespaces[namespace])
26 for schema in self.schemas:
27 self.xml.set(schema+":schemaLocation", self.schemas[schema])
29 def get_network(self):
31 nodes = self.xml.xpath('//rspecv2:node[@component_manager_uuid][1]', self.namespaces)
33 network = nodes[0].get('component_manager_uuid')
36 def get_networks(self):
37 networks = self.xml.xpath('//rspecv2:node[@component_manager_uuid]/@component_manager_uuid')
40 def get_node_elements(self):
41 nodes = self.xml.xpath('//rspecv2:node', self.namespaces)
44 def get_nodes(self, network=None):
45 return self.xml.xpath('//rspecv2:node[@component_uuid]/@component_uuid', self.namespaces)
47 def get_nodes_with_slivers(self, network=None):
49 return self.xml.xpath('//node[@component_manager_uuid="%s"][sliver_type]/@component_uuid' % network, self.namespaces)
51 return self.xml.xpath('//node[sliver_type]/@component_uuid' % network, self.namespaces)
53 def get_nodes_without_slivers(self, network=None):
56 def add_nodes(self, nodes, check_for_dupes=False):
57 if not isinstance(nodes, list):
61 if check_for_dupes and \
62 self.xml.xpath('//rspecv2:node[@component_uuid="%s"]' % urn, self.namespaces):
66 node_tag = etree.SubElement(self.xml, 'node')
67 node_type_tag = etree.SubElement(node_tag, 'node_type', type_name='pcvm', type_slots='100')
68 available_tag = etree.SubElement(node_tag, 'available').text = 'true'
69 exclusive_tag = etree.SubElement(node_tag, 'exclusive').text = 'false'
70 location_tag = etree.SubElement(node_tag, 'location')
71 interface_tag = etree.SubElement(node_tag, 'interface')
74 def add_slivers(self, slivers, check_for_dupes=False):
77 def add_links(self, links, check_for_dupes=False):
81 if __name__ == '__main__':