#NEWLINE# def destroy( name , conn = None , call = None ) : #NEWLINE# #INDENT# '\n    Delete a single VM\n    ' #NEWLINE# if ( call == 'function' ) : #NEWLINE# #INDENT# raise SaltCloudSystemExit ( 'The destroy action must be called with -d, --destroy, -a or --action.' ) #NEWLINE# #UNINDENT# salt . utils . cloud . fire_event ( 'event' , 'destroying instance' , 'salt/cloud/{0}/destroying' . format ( name ) , { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# #UNINDENT# } , transport = __opts__ [ 'transport' ] ) #NEWLINE# if ( not conn ) : #NEWLINE# #INDENT# conn = get_conn ( ) #NEWLINE# #UNINDENT# node = get_node ( conn , name ) #NEWLINE# profiles = get_configured_provider ( ) [ 'profiles' ] #NEWLINE# if ( node is None ) : #NEWLINE# #INDENT# log . error ( 'Unable to find the VM {0}' . format ( name ) ) #NEWLINE# #UNINDENT# profile = None #NEWLINE# if ( ( 'metadata' in node . extra ) and ( 'profile' in node . extra [ 'metadata' ] ) ) : #NEWLINE# #INDENT# profile = node . extra [ 'metadata' ] [ 'profile' ] #NEWLINE# #UNINDENT# flush_mine_on_destroy = False #NEWLINE# if ( profile and ( profile in profiles ) and ( 'flush_mine_on_destroy' in profiles [ profile ] ) ) : #NEWLINE# #INDENT# flush_mine_on_destroy = profiles [ profile ] [ 'flush_mine_on_destroy' ] #NEWLINE# #UNINDENT# if flush_mine_on_destroy : #NEWLINE# #INDENT# log . info ( 'Clearing Salt Mine: {0}' . format ( name ) ) #NEWLINE# mopts_ = salt . config . DEFAULT_MINION_OPTS #NEWLINE# conf_path = '/' . join ( __opts__ [ 'conf_file' ] . split ( '/' ) [ : ( - 1 ) ] ) #NEWLINE# mopts_ . update ( salt . config . minion_config ( os . path . join ( conf_path , 'minion' ) ) ) #NEWLINE# client = salt . client . get_local_client ( mopts_ ) #NEWLINE# minions = client . cmd ( name , 'mine.flush' ) #NEWLINE# #UNINDENT# log . info ( 'Clearing Salt Mine: {0}, {1}' . format ( name , flush_mine_on_destroy ) ) #NEWLINE# log . info ( 'Destroying VM: {0}' . format ( name ) ) #NEWLINE# ret = conn . destroy_node ( node ) #NEWLINE# if ret : #NEWLINE# #INDENT# log . info ( 'Destroyed VM: {0}' . format ( name ) ) #NEWLINE# salt . utils . cloud . fire_event ( 'event' , 'destroyed instance' , 'salt/cloud/{0}/destroyed' . format ( name ) , { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# #UNINDENT# } , transport = __opts__ [ 'transport' ] ) #NEWLINE# if ( __opts__ [ 'delete_sshkeys' ] is True ) : #NEWLINE# #INDENT# public_ips = getattr ( node , __opts__ . get ( 'ssh_interface' , 'public_ips' ) ) #NEWLINE# if public_ips : #NEWLINE# #INDENT# salt . utils . cloud . remove_sshkey ( public_ips [ 0 ] ) #NEWLINE# #UNINDENT# private_ips = getattr ( node , __opts__ . get ( 'ssh_interface' , 'private_ips' ) ) #NEWLINE# if private_ips : #NEWLINE# #INDENT# salt . utils . cloud . remove_sshkey ( private_ips [ 0 ] ) #NEWLINE# #UNINDENT# #UNINDENT# if ( __opts__ . get ( 'update_cachedir' , False ) is True ) : #NEWLINE# #INDENT# salt . utils . cloud . delete_minion_cachedir ( name , __active_provider_name__ . split ( ':' ) [ 0 ] , __opts__ ) #NEWLINE# #UNINDENT# return True #NEWLINE# #UNINDENT# log . error ( 'Failed to Destroy VM: {0}' . format ( name ) ) #NEWLINE# return False