#NEWLINE# def generate_configdrive( session , instance , vm_ref , userdevice , network_info , admin_password = None , files = None ) : #NEWLINE# #INDENT# sr_ref = safe_find_sr ( msg ) #NEWLINE# vdi_ref = create_vdi ( session , sr_ref , instance , 'config-2' , 'configdrive' , configdrive . CONFIGDRIVESIZE_BYTES ) #NEWLINE# try : #NEWLINE# #INDENT# with vdi_attached_here ( session , vdi_ref , read_only = False ) as dev : #NEWLINE# #INDENT# extra_md = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if admin_password : #NEWLINE# #INDENT# extra_md [ 'admin_pass' ] = admin_password #NEWLINE# #UNINDENT# inst_md = instance_metadata . InstanceMetadata ( instance , content = files , extra_md = extra_md , network_info = network_info ) #NEWLINE# with configdrive . ConfigDriveBuilder ( instance_md = inst_md ) as cdb : #NEWLINE# #INDENT# with utils . tempdir ( ) as tmp_path : #NEWLINE# #INDENT# tmp_file = os . path . join ( tmp_path , 'configdrive' ) #NEWLINE# cdb . make_drive ( tmp_file ) #NEWLINE# dev_path = utils . make_dev_path ( dev ) #NEWLINE# utils . execute ( 'dd' , ( 'if=%s' % tmp_file ) , ( 'of=%s' % dev_path ) , 'oflag=direct,sync' , run_as_root = True ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# create_vbd ( session , vm_ref , vdi_ref , userdevice , bootable = False , read_only = True ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# with excutils . save_and_reraise_exception ( ) : #NEWLINE# #INDENT# msg = 'Error while generating config drive' #NEWLINE# LOG . debug ( msg , instance = instance , exc_info = True ) #NEWLINE# safe_destroy_vdis ( session , [ vdi_ref ] )