mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #10222 from gtmanfred/develop
[salt.cloud] clear salt mine on delete
This commit is contained in:
commit
e9b0d4380d
@ -460,11 +460,12 @@ def create(vm_):
|
|||||||
'salt/cloud/{0}/requesting'.format(vm_['name']),
|
'salt/cloud/{0}/requesting'.format(vm_['name']),
|
||||||
{'kwargs': {'name': kwargs['name'],
|
{'kwargs': {'name': kwargs['name'],
|
||||||
'image': kwargs['image'].name,
|
'image': kwargs['image'].name,
|
||||||
'size': kwargs['size'].name}},
|
'size': kwargs['size'].name,
|
||||||
|
'profile': vm_['profile']}}
|
||||||
)
|
)
|
||||||
|
|
||||||
kwargs['ex_metadata'] = config.get_cloud_config_value(
|
kwargs['ex_metadata'] = config.get_cloud_config_value(
|
||||||
'metadata', vm_, __opts__, default={}, search_global=False
|
'metadata', vm_, __opts__, default={'profile': vm_['profile']}, search_global=False
|
||||||
)
|
)
|
||||||
if not isinstance(kwargs['ex_metadata'], dict):
|
if not isinstance(kwargs['ex_metadata'], dict):
|
||||||
raise SaltCloudConfigError(
|
raise SaltCloudConfigError(
|
||||||
|
@ -24,6 +24,7 @@ from libcloud.compute.deployment import (
|
|||||||
# Import salt libs
|
# Import salt libs
|
||||||
import salt._compat
|
import salt._compat
|
||||||
import salt.utils.event
|
import salt.utils.event
|
||||||
|
import salt.client
|
||||||
|
|
||||||
# Import salt cloud libs
|
# Import salt cloud libs
|
||||||
import salt.utils.cloud
|
import salt.utils.cloud
|
||||||
@ -346,8 +347,22 @@ def destroy(name, conn=None, call=None):
|
|||||||
conn = get_conn() # pylint: disable=E0602
|
conn = get_conn() # pylint: disable=E0602
|
||||||
|
|
||||||
node = get_node(conn, name)
|
node = get_node(conn, name)
|
||||||
|
profiles = get_configured_provider()['profiles']
|
||||||
if node is None:
|
if node is None:
|
||||||
log.error('Unable to find the VM {0}'.format(name))
|
log.error('Unable to find the VM {0}'.format(name))
|
||||||
|
profile = None
|
||||||
|
if 'metadata' in node.extra and 'profile' in node.extra['metadata']:
|
||||||
|
profile = node.extra['metadata']['profile']
|
||||||
|
flush_mine_on_destroy = False
|
||||||
|
if profile is not None and profile in profiles:
|
||||||
|
if 'flush_mine_on_destroy' in profiles[profile]:
|
||||||
|
flush_mine_on_destroy = profiles[profile]['flush_mine_on_destroy']
|
||||||
|
if flush_mine_on_destroy:
|
||||||
|
log.info('Clearing Salt Mine: {0}'.format(name))
|
||||||
|
client = salt.client.LocalClient(__opts__['conf_file'])
|
||||||
|
minions = client.cmd(name, 'mine.flush')
|
||||||
|
|
||||||
|
log.info('Clearing Salt Mine: {0}, {1}'.format(name, flush_mine_on_destroy))
|
||||||
log.info('Destroying VM: {0}'.format(name))
|
log.info('Destroying VM: {0}'.format(name))
|
||||||
ret = conn.destroy_node(node)
|
ret = conn.destroy_node(node)
|
||||||
if ret:
|
if ret:
|
||||||
|
Loading…
Reference in New Issue
Block a user