<s> from vt_manager . communication . sfa . util . sfalogging import logger <EOL> from vt_manager . communication . sfa . util . xml import XpathFilter <EOL> from vt_manager . communication . sfa . util . xrn import Xrn <EOL> from vt_manager . communication . sfa . rspecs . elements . element import Element <EOL> from vt_manager . communication . sfa . rspecs . elements . node import Node <EOL> from vt_manager . communication . sfa . rspecs . elements . sliver import Sliver <EOL> from vt_manager . communication . sfa . rspecs . elements . location import Location <EOL> from vt_manager . communication . sfa . rspecs . elements . hardware_type import HardwareType <EOL> from vt_manager . communication . sfa . rspecs . elements . disk_image import DiskImage <EOL> from vt_manager . communication . sfa . rspecs . elements . interface import Interface <EOL> from vt_manager . communication . sfa . rspecs . elements . bwlimit import BWlimit <EOL> from vt_manager . communication . sfa . rspecs . elements . pltag import PLTag <EOL> from vt_manager . communication . sfa . rspecs . elements . versions . sfav1Sliver import SFAv1Sliver <EOL> from vt_manager . communication . sfa . rspecs . elements . versions . sfav1PLTag import SFAv1PLTag <EOL> from vt_manager . communication . sfa . rspecs . elements . versions . pgv2Services import PGv2Services <EOL> from vt_manager . communication . sfa . rspecs . elements . lease import Lease <EOL> from sfa . planetlab . plxrn import xrn_to_hostname <EOL> class SFAv1Lease : <EOL> @ staticmethod <EOL> def add_leases ( xml , leases ) : <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 ( leases ) > <NUM_LIT:0> : <EOL> network_urn = Xrn ( leases [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) . get_authority_urn ( ) . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> network_elem = xml . add_element ( '<STR_LIT>' , name = network_urn ) <EOL> else : <EOL> network_elem = xml <EOL> grouped_leases = [ ] <EOL> while leases : <EOL> slice_id = leases [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> start_time = leases [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> duration = leases [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> group = [ ] <EOL> for lease in leases : <EOL> if slice_id == lease [ '<STR_LIT>' ] and start_time == lease [ '<STR_LIT>' ] and duration == lease [ '<STR_LIT>' ] : <EOL> group . append ( lease ) <EOL> grouped_leases . append ( group ) <EOL> for lease1 in group : <EOL> leases . remove ( lease1 ) <EOL> lease_elems = [ ] <EOL> for lease in grouped_leases : <EOL> lease_fields = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> lease_elem = network_elem . add_instance ( '<STR_LIT>' , lease [ <NUM_LIT:0> ] , lease_fields ) <EOL> lease_elems . append ( lease_elem ) <EOL> for node in lease : <EOL> lease_elem . add_instance ( '<STR_LIT>' , node , [ '<STR_LIT>' ] ) <EOL> @ staticmethod <EOL> def get_leases ( xml , filter = { } ) : <EOL> xpath = '<STR_LIT>' % ( XpathFilter . xpath ( filter ) , XpathFilter . xpath ( filter ) ) <EOL> lease_elems = xml . xpath ( xpath ) <EOL> return SFAv1Lease . get_lease_objs ( lease_elems ) <EOL> @ staticmethod <EOL> def get_lease_objs ( lease_elems ) : <EOL> leases = [ ] <EOL> for lease_elem in lease_elems : <EOL> node_elems = lease_elem . xpath ( '<STR_LIT>' ) <EOL> for node_elem in node_elems : <EOL> lease = Lease ( lease_elem . attrib , lease_elem ) <EOL> lease [ '<STR_LIT>' ] = lease_elem . attrib [ '<STR_LIT>' ] <EOL> lease [ '<STR_LIT>' ] = lease_elem . attrib [ '<STR_LIT>' ] <EOL> lease [ '<STR_LIT>' ] = lease_elem . attrib [ '<STR_LIT>' ] <EOL> lease [ '<STR_LIT>' ] = node_elem . attrib [ '<STR_LIT>' ] <EOL> leases . append ( lease ) <EOL> return leases </s>
