<s> from foam . sfa . util . sfalogging import logger <EOL> from foam . sfa . util . xml import XpathFilter <EOL> from foam . sfa . util . xrn import Xrn <EOL> from foam . sfa . rspecs . elements . element import Element <EOL> from foam . sfa . rspecs . elements . node import Node <EOL> from foam . sfa . rspecs . elements . sliver import Sliver <EOL> from foam . sfa . rspecs . elements . location import Location <EOL> from foam . sfa . rspecs . elements . hardware_type import HardwareType <EOL> from foam . sfa . rspecs . elements . disk_image import DiskImage <EOL> from foam . sfa . rspecs . elements . interface import Interface <EOL> from foam . sfa . rspecs . elements . bwlimit import BWlimit <EOL> from foam . sfa . rspecs . elements . pltag import PLTag <EOL> from foam . sfa . rspecs . elements . versions . nitosv1Sliver import NITOSv1Sliver <EOL> from foam . sfa . rspecs . elements . versions . nitosv1PLTag import NITOSv1PLTag <EOL> from foam . sfa . rspecs . elements . versions . pgv2Services import PGv2Services <EOL> from foam . sfa . rspecs . elements . lease import Lease <EOL> from foam . sfa . rspecs . elements . spectrum import Spectrum <EOL> from foam . sfa . rspecs . elements . channel import Channel <EOL> class NITOSv1Channel : <EOL> @ staticmethod <EOL> def add_channels ( xml , channels ) : <EOL> network_elems = xml . xpath ( '<STR_LIT>' ) <EOL> if len ( network_elems ) > <NUM_LIT:0> : <EOL> network_elem = network_elems [ <NUM_LIT:0> ] <EOL> elif len ( channels ) > <NUM_LIT:0> : <EOL> network_urn = "<STR_LIT>" <EOL> network_elem = xml . add_element ( '<STR_LIT>' , name = network_urn ) <EOL> else : <EOL> network_elem = xml <EOL> spectrum_elem = network_elem . add_instance ( '<STR_LIT>' , [ ] ) <EOL> channel_elems = [ ] <EOL> for channel in channels : <EOL> channel_fields = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> channel_elem = spectrum_elem . add_instance ( '<STR_LIT>' , channel , channel_fields ) <EOL> channel_elems . append ( channel_elem ) <EOL> @ staticmethod <EOL> def get_channels ( xml , filter = { } ) : <EOL> xpath = '<STR_LIT>' % ( XpathFilter . xpath ( filter ) , XpathFilter . xpath ( filter ) ) <EOL> channel_elems = xml . xpath ( xpath ) <EOL> return NITOSv1Channel . get_channel_objs ( channel_elems ) <EOL> @ staticmethod <EOL> def get_channel_objs ( channel_elems ) : <EOL> channels = [ ] <EOL> for channel_elem in channel_elems : <EOL> channel = Channel ( channel_elem . attrib , channel_elem ) <EOL> channel [ '<STR_LIT>' ] = channel_elem . attrib [ '<STR_LIT>' ] <EOL> channel [ '<STR_LIT>' ] = channel_elem . attrib [ '<STR_LIT>' ] <EOL> channel [ '<STR_LIT>' ] = channel_elem . attrib [ '<STR_LIT>' ] <EOL> channels . append ( channel ) <EOL> return channels </s>
