<s> from openflow . optin_manager . sfa . util . xrn import Xrn <EOL> from openflow . optin_manager . sfa . util . xml import XmlElement <EOL> from openflow . optin_manager . sfa . rspecs . elements . element import Element <EOL> from openflow . optin_manager . sfa . rspecs . elements . sliver import Sliver <EOL> from openflow . optin_manager . sfa . rspecs . elements . versions . sfav1PLTag import SFAv1PLTag <EOL> from sfa . planetlab . plxrn import PlXrn <EOL> class SFAv1Sliver : <EOL> @ staticmethod <EOL> def add_slivers ( xml , slivers ) : <EOL> if not slivers : <EOL> return <EOL> if not isinstance ( slivers , list ) : <EOL> slivers = [ slivers ] <EOL> for sliver in slivers : <EOL> sliver_elem = xml . add_instance ( '<STR_LIT>' , sliver , [ '<STR_LIT:name>' ] ) <EOL> tags = sliver . get ( '<STR_LIT>' , [ ] ) <EOL> if tags : <EOL> for tag in tags : <EOL> SFAv1Sliver . add_sliver_attribute ( sliver_elem , tag [ '<STR_LIT>' ] , tag [ '<STR_LIT:value>' ] ) <EOL> @ staticmethod <EOL> def add_sliver_attribute ( xml , name , value ) : <EOL> elem = xml . add_element ( name ) <EOL> elem . set_text ( value ) <EOL> @ staticmethod <EOL> def get_sliver_attributes ( xml ) : <EOL> attribs = [ ] <EOL> for elem in xml . iterchildren ( ) : <EOL> if elem . tag not in Sliver . fields : <EOL> xml_element = XmlElement ( elem , xml . namespaces ) <EOL> instance = Element ( fields = xml_element , element = elem ) <EOL> instance [ '<STR_LIT:name>' ] = elem . tag <EOL> instance [ '<STR_LIT:value>' ] = elem . text <EOL> attribs . append ( instance ) <EOL> return attribs <EOL> @ staticmethod <EOL> def get_slivers ( xml , filter = { } ) : <EOL> xpath = '<STR_LIT>' <EOL> sliver_elems = xml . xpath ( xpath ) <EOL> slivers = [ ] <EOL> for sliver_elem in sliver_elems : <EOL> sliver = Sliver ( sliver_elem . attrib , sliver_elem ) <EOL> if '<STR_LIT>' in xml . attrib : <EOL> sliver [ '<STR_LIT>' ] = xml . attrib [ '<STR_LIT>' ] <EOL> sliver [ '<STR_LIT>' ] = SFAv1Sliver . get_sliver_attributes ( sliver_elem ) <EOL> slivers . append ( sliver ) <EOL> return slivers </s>
