1 from sfa.util.xrn import Xrn
2 from sfa.util.xml import XmlElement
4 from sfa.rspecs.elements.element import Element
5 from sfa.rspecs.elements.port import Port
10 def add_portrs(xml, ports):
11 raise Exception, "not implemented yet"
14 if not isinstance(ports, list):
17 port_elem = xml.add_instance('port', port, ['name'])
18 tags = port.get('tags', [])
21 Ofeliav1Port.add_port_attribute(port_elem, tag['tagname'], tag['value'])
24 def add_port_attribute(xml, name, value):
25 raise Exception, "not implemented yet"
26 elem = xml.add_element(name)
30 def get_port_attributes(xml):
32 for elem in xml.iterchildren():
33 if elem.tag not in Port.fields:
34 xml_element = XmlElement(elem, xml.namespaces)
35 instance = Element(fields=xml_element, element=elem)
36 instance['name'] = elem.tag
37 instance['value'] = elem.text
38 attribs.append(instance)
42 def get_ports(xml, filter={}):
43 xpath = './openflow:port | ./port'
44 port_elems = xml.xpath(xpath)
46 for port_elem in port_elems:
47 port = Port(port_elem.attrib,port_elem)
48 #if 'component_id' in xml.attrib:
49 # port['component_id'] = xml.attrib['component_id']
50 #port['tags'] = Ofeliav1Port.get_port_attributes(port_elem)