#NEWLINE# def get_as_elem( self , slice = None ) : #NEWLINE# #INDENT# '\n        Get the PlanetLabNetwork as ElementTree element so it can be added\n        to the RSpec and dumped as XML.\n        \n        @keyword slice: Optional. Slice for which we are producing this RSpec.\n            Specifying the slice will set the <sliver /> tag for PlanetLab\n            nodes that are part of the slice.\n        @type slice: L{expedient.clearinghouse.slice.models.Slice}.\n        @return: the NetSpec element\n        @rtype: C{xml.etree.ElementTree.Element}\n        ' #NEWLINE# netspec = et . Element ( 'NetSpec' , dict ( name = self . name ) ) #NEWLINE# if slice : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# sliver = slice . sliver_set . get ( resource__pk = self . pk ) #NEWLINE# net_sliver = sliver . as_leaf_class ( ) #NEWLINE# ( stime , duration ) = get_start_duration ( net_sliver . start_time , net_sliver . end_time ) #NEWLINE# netspec [ 'start_time' ] = ( '%s' % stime ) #NEWLINE# netspec [ 'duration' ] = ( '%s' % duration ) #NEWLINE# #UNINDENT# except Sliver . DoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# for rsc_type in [ 'node' ] : #NEWLINE# #INDENT# if slice : #NEWLINE# #INDENT# filter_key = ( 'planetlab%s__network' % rsc_type ) #NEWLINE# rsc_ids = slice . resource_set . filter ( ** { #NEWLINE# #INDENT# filter_key : self , #NEWLINE# #UNINDENT# } ) . values_list ( 'pk' , flat = True ) #NEWLINE# sliver_info_tuples = slice . sliver_set . filter ( resource__pk__in = rsc_ids ) . values_list ( 'resource_id' , 'start_time' , 'end_time' ) #NEWLINE# sliver_info = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for t in sliver_info_tuples : #NEWLINE# #INDENT# sliver_info [ t [ 0 ] ] = t [ 1 : ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# rsc_ids = [ ] #NEWLINE# sliver_info = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# rsc_set_elem = et . SubElement ( rsc_ids , ( '%ss' % rsc_type ) ) #NEWLINE# for rsc in getattr ( self , ( '%ss' % rsc_type ) ) . all ( ) : #NEWLINE# #INDENT# rsc_elem = rsc . get_as_elem ( ) #NEWLINE# if ( rsc . pk in rsc_ids ) : #NEWLINE# #INDENT# et . SubElement ( rsc_elem , 'sliver' ) #NEWLINE# ( stime , duration ) = get_start_duration ( * sliver_info_tuples [ rsc . pk ] ) #NEWLINE# rsc_elem [ 'start_time' ] = ( '%s' % stime ) #NEWLINE# rsc_elem [ 'duration' ] = ( '%s' % duration ) #NEWLINE# #UNINDENT# rsc_set_elem . append ( rsc_elem ) #NEWLINE# #UNINDENT# #UNINDENT# return netspec