#NEWLINE# def run( self , vms , persistence = 'Persistent' , disk_type = 'flat' , capacity_gb = 1 , datastore = None , datastore_cluster = None , device_name = None , disk_path = '' , storage_format = 'Thin' ) : #NEWLINE# #INDENT# persistence = persistence . lower ( ) #NEWLINE# disk_type = disk_type . lower ( ) #NEWLINE# storage_format = storage_format . lower ( ) #NEWLINE# si = self . si #NEWLINE# si_content = si . RetrieveContent ( ) #NEWLINE# vm_objs = [ vim . VirtualMachine ( moid , stub = si . _stub ) for moid in vms ] #NEWLINE# [ vm_obj . name for vm_obj in vm_objs ] #NEWLINE# datastore_obj = None #NEWLINE# if datastore : #NEWLINE# #INDENT# datastore_obj = vim . Datastore ( datastore , stub = si . _stub ) #NEWLINE# datastore_obj . name #NEWLINE# #UNINDENT# result = [ ] #NEWLINE# if datastore_cluster : #NEWLINE# #INDENT# ds_clust_obj = vim . StoragePod ( datastore_cluster , stub = si . _stub ) #NEWLINE# ds_clust_obj . name #NEWLINE# srm = si_content . storageResourceManager #NEWLINE# for vm in vm_objs : #NEWLINE# #INDENT# vm_reconfig_spec = NewHardDisk . get_vm_reconfig_spec ( vm , datastore_obj , disk_type , storage_format , persistence , disk_path , device_name , capacity_gb ) #NEWLINE# storage_placement_spec = NewHardDisk . get_storage_placement_spec ( ds_clust_obj , vm , vm_reconfig_spec ) #NEWLINE# datastores = srm . RecommendDatastores ( storageSpec = storage_placement_spec ) #NEWLINE# if ( not datastores . recommendations ) : #NEWLINE# #INDENT# sys . stderr . write ( ( 'Skipping %s as there is no datastore recommendation' % vm . obj . _GetMoId ( ) ) ) #NEWLINE# #UNINDENT# add_disk_task = srm . ApplyStorageDrsRecommendation_Task ( datastores . recommendations [ 0 ] . key ) #NEWLINE# successfully_added_disk = self . _wait_for_task ( add_disk_task ) #NEWLINE# result . append ( { #NEWLINE# #INDENT# 'vm_moid' : vm . _GetMoId ( ) , #NEWLINE# 'success' : successfully_added_disk , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for vm in vm_objs : #NEWLINE# #INDENT# vm_reconfig_spec = NewHardDisk . get_vm_reconfig_spec ( vm , datastore_obj , storage_placement_spec , storage_format , persistence , disk_path , device_name , capacity_gb ) #NEWLINE# add_disk_task = vm . ReconfigVM_Task ( spec = vm_reconfig_spec ) #NEWLINE# successfully_added_disk = self . _wait_for_task ( add_disk_task ) #NEWLINE# result . append ( { #NEWLINE# #INDENT# 'vm_moid' : vm . _GetMoId ( ) , #NEWLINE# 'success' : successfully_added_disk , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# return result