#NEWLINE# def create( vm_ ) : #NEWLINE# #INDENT# '\n    Create a single VM from a data dict\n    ' #NEWLINE# try : #NEWLINE# #INDENT# if ( vm_ [ 'profile' ] and ( config . is_profile_configured ( __opts__ , ( __active_provider_name__ or 'vsphere' ) , vm_ [ 'profile' ] , vm_ = vm_ ) is False ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( 'provider' in vm_ ) : #NEWLINE# #INDENT# vm_ [ 'driver' ] = vm_ . pop ( 'provider' ) #NEWLINE# #UNINDENT# salt . utils . cloud . fire_event ( 'event' , 'starting create' , 'salt/cloud/{0}/creating' . format ( vm_ [ 'name' ] ) , { #NEWLINE# #INDENT# 'name' : vm_ [ 'name' ] , #NEWLINE# 'profile' : vm_ [ 'profile' ] , #NEWLINE# 'provider' : vm_ [ 'driver' ] , #NEWLINE# #UNINDENT# } , transport = __opts__ [ 'transport' ] ) #NEWLINE# log . info ( 'Creating Cloud VM {0}' . format ( vm_ [ 'name' ] ) ) #NEWLINE# conn = get_conn ( ) #NEWLINE# salt . utils . cloud . fire_event ( 'event' , 'requesting instance' , 'salt/cloud/{0}/requesting' . format ( vm_ [ 'name' ] ) , { #NEWLINE# #INDENT# 'kwargs' : vm_ , #NEWLINE# #UNINDENT# } , transport = __opts__ [ 'transport' ] ) #NEWLINE# folder = config . get_cloud_config_value ( 'folder' , vm_ , __opts__ , default = None ) #NEWLINE# resourcepool = config . get_cloud_config_value ( 'resourcepool' , vm_ , __opts__ , default = None ) #NEWLINE# datastore = config . get_cloud_config_value ( 'datastore' , vm_ , __opts__ , default = None ) #NEWLINE# host = config . get_cloud_config_value ( 'host' , vm_ , __opts__ , default = None ) #NEWLINE# template = config . get_cloud_config_value ( 'template' , vm_ , __opts__ , default = False ) #NEWLINE# clone_kwargs = { #NEWLINE# #INDENT# 'name' : vm_ [ 'name' ] , #NEWLINE# 'folder' : template , #NEWLINE# 'resourcepool' : resourcepool , #NEWLINE# 'datastore' : datastore , #NEWLINE# 'host' : host , #NEWLINE# 'template' : template , #NEWLINE# #UNINDENT# } #NEWLINE# log . debug ( 'clone_kwargs are set to {0}' . format ( pprint . pformat ( clone_kwargs ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# template = conn . get_vm_by_name ( vm_ [ 'image' ] ) #NEWLINE# new_instance = template . clone ( ** clone_kwargs ) #NEWLINE# data = new_instance . get_properties ( ) #NEWLINE# #UNINDENT# except Exception as exc : #NEWLINE# #INDENT# log . error ( 'Error creating {0} on vSphere\n\nThe following exception was thrown when trying to run the initial deployment: \n{1}' . format ( vm_ [ 'name' ] , str ( exc ) ) , exc_info_on_loglevel = logging . DEBUG ) #NEWLINE# return False #NEWLINE# #UNINDENT# deploy_kwargs = None #NEWLINE# if ( config . get_cloud_config_value ( 'deploy' , vm_ , __opts__ ) is True ) : #NEWLINE# #INDENT# deploy_kwargs = _deploy ( vm_ ) #NEWLINE# #UNINDENT# ret = show_instance ( name = vm_ [ 'name' ] , call = 'action' ) #NEWLINE# show_deploy_args = config . get_cloud_config_value ( 'show_deploy_args' , vm_ , __opts__ , default = False ) #NEWLINE# if show_deploy_args : #NEWLINE# #INDENT# ret [ 'deploy_kwargs' ] = deploy_kwargs #NEWLINE# #UNINDENT# log . info ( "Created Cloud VM '{0[name]}'" . format ( vm_ ) ) #NEWLINE# log . debug ( "'{0[name]}' VM creation details:\n{1}" . format ( vm_ , pprint . pformat ( ret ) ) ) #NEWLINE# salt . utils . cloud . fire_event ( 'event' , 'created instance' , 'salt/cloud/{0}/created' . format ( vm_ [ 'name' ] ) , { #NEWLINE# #INDENT# 'name' : vm_ [ 'name' ] , #NEWLINE# 'profile' : vm_ [ 'profile' ] , #NEWLINE# 'provider' : vm_ [ 'driver' ] , #NEWLINE# #UNINDENT# } , transport = __opts__ [ 'transport' ] ) #NEWLINE# return ret