#NEWLINE# @ require_enabled #NEWLINE# def save_instance( self , instance ) : #NEWLINE# #INDENT# metadata_update = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( 'numberCores' in instance . changed_fields ) : #NEWLINE# #INDENT# metadata_update [ 'cpu_cores' ] = str ( instance . numberCores ) #NEWLINE# #UNINDENT# for tag in instance . slice . tags . all ( ) : #NEWLINE# #INDENT# if tag . name . startswith ( 'sysctl-' ) : #NEWLINE# #INDENT# metadata_update [ tag . name ] = tag . value #NEWLINE# #UNINDENT# #UNINDENT# if ( not instance . instance_id ) : #NEWLINE# #INDENT# nics = self . get_requested_networks ( instance . slice ) #NEWLINE# for nic in nics : #NEWLINE# #INDENT# if ( not nic . get ( 'net-id' , None ) ) : #NEWLINE# #INDENT# instance . save ( ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# slice_memberships = SliceMembership . objects . filter ( slice = instance . slice ) #NEWLINE# pubkeys = [ sm . user . public_key for sm in slice_memberships if sm . user . public_key ] #NEWLINE# pubkeys . append ( instance . creator . public_key ) #NEWLINE# instance = self . driver . spawn_instance ( name = instance . name , key_name = instance . creator . keyname , image_id = instance . image . image_id , hostname = instance . node . name , pubkeys = pubkeys , nics = nics , metadata = metadata_update ) #NEWLINE# instance . instance_id = instance . id #NEWLINE# instance . instance_name = getattr ( instance , 'OS-EXT-SRV-ATTR:instance_name' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if nics : #NEWLINE# #INDENT# self . driver . update_instance_metadata ( instance . instance_id , metadata_update ) #NEWLINE# #UNINDENT# #UNINDENT# instance . save ( ) #NEWLINE# instance . enacted = datetime . now ( ) #NEWLINE# instance . save ( update_fields = [ 'enacted' ] )