mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #44415 from vernondcole/vagrant_cloud_minor_revisions
Vagrant and saltify cloud minor revisions
This commit is contained in:
commit
8e99aeed6a
3 changed files with 61 additions and 41 deletions
|
@ -99,7 +99,8 @@ Profile configuration example:
|
|||
# vagrant_up_timeout: 300 # (seconds) timeout for cmd.run of the "vagrant up" command
|
||||
# vagrant_provider: '' # option for "vagrant up" like: "--provider vmware_fusion"
|
||||
# ssh_host: None # "None" means try to find the routable IP address from "ifconfig"
|
||||
# target_network: None # Expected CIDR address of your bridged network
|
||||
# ssh_username: '' # also required when ssh_host is used.
|
||||
# target_network: None # Expected CIDR address range of your bridged network
|
||||
# force_minion_config: false # Set "true" to re-purpose an existing VM
|
||||
|
||||
The machine can now be created and configured with the following command:
|
||||
|
|
|
@ -258,19 +258,30 @@ def create(vm_):
|
|||
wol_host = config.get_cloud_config_value(
|
||||
'wol_sender_node', vm_, __opts__, default='')
|
||||
if wol_mac and wol_host:
|
||||
log.info('sending wake-on-lan to %s using node %s',
|
||||
wol_mac, wol_host)
|
||||
local = salt.client.LocalClient()
|
||||
if isinstance(wol_mac, six.string_types):
|
||||
wol_mac = [wol_mac] # a smart user may have passed more params
|
||||
ret = local.cmd(wol_host, 'network.wol', wol_mac)
|
||||
log.info('network.wol returned value %s', ret)
|
||||
if ret and ret[wol_host]:
|
||||
sleep_time = config.get_cloud_config_value(
|
||||
'wol_boot_wait', vm_, __opts__, default=30)
|
||||
if sleep_time > 0.0:
|
||||
log.info('delaying %d seconds for boot', sleep_time)
|
||||
time.sleep(sleep_time)
|
||||
good_ping = False
|
||||
ssh_host = config.get_cloud_config_value(
|
||||
'ssh_host', vm_, __opts__, default='')
|
||||
if ssh_host:
|
||||
log.info('trying to ping %s', ssh_host)
|
||||
count = 'n' if salt.utils.platform.is_windows() else 'c'
|
||||
cmd = 'ping -{} 1 {}'.format(count, ssh_host)
|
||||
good_ping = __salt__['cmd.retcode'](cmd) == 0
|
||||
if good_ping:
|
||||
log.info('successful ping.')
|
||||
else:
|
||||
log.info('sending wake-on-lan to %s using node %s',
|
||||
wol_mac, wol_host)
|
||||
local = salt.client.LocalClient()
|
||||
if isinstance(wol_mac, six.string_types):
|
||||
wol_mac = [wol_mac] # a smart user may have passed more params
|
||||
ret = local.cmd(wol_host, 'network.wol', wol_mac)
|
||||
log.info('network.wol returned value %s', ret)
|
||||
if ret and ret[wol_host]:
|
||||
sleep_time = config.get_cloud_config_value(
|
||||
'wol_boot_wait', vm_, __opts__, default=30)
|
||||
if sleep_time > 0.0:
|
||||
log.info('delaying %d seconds for boot', sleep_time)
|
||||
time.sleep(sleep_time)
|
||||
log.info('Provisioning existing machine %s', vm_['name'])
|
||||
ret = __utils__['cloud.bootstrap'](vm_, __opts__)
|
||||
else:
|
||||
|
|
|
@ -30,7 +30,8 @@ if six.PY3:
|
|||
import ipaddress
|
||||
else:
|
||||
import salt.ext.ipaddress as ipaddress
|
||||
from salt.exceptions import SaltCloudException, SaltCloudSystemExit
|
||||
from salt.exceptions import SaltCloudException, SaltCloudSystemExit, \
|
||||
SaltInvocationError
|
||||
|
||||
# Get logging started
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -229,18 +230,22 @@ def create(vm_):
|
|||
kwarg={'network_mask': network_mask,
|
||||
'get_private_key': True})[host]
|
||||
with tempfile.NamedTemporaryFile() as pks:
|
||||
if 'private_key' not in vm_ and ret.get('private_key', False):
|
||||
if 'private_key' not in vm_ and ret and ret.get('private_key', False):
|
||||
pks.write(ret['private_key'])
|
||||
pks.flush()
|
||||
log.debug('wrote private key to %s', pks.name)
|
||||
vm_['key_filename'] = pks.name
|
||||
if 'ssh_host' not in vm_:
|
||||
vm_.setdefault('ssh_username', ret['ssh_username'])
|
||||
if ret.get('ip_address'):
|
||||
vm_['ssh_host'] = ret['ip_address']
|
||||
else: # if probe failed or not used, use Vagrant's reported ssh info
|
||||
vm_['ssh_host'] = ret['ssh_host']
|
||||
vm_.setdefault('ssh_port', ret['ssh_port'])
|
||||
try:
|
||||
vm_.setdefault('ssh_username', ret['ssh_username'])
|
||||
if ret.get('ip_address'):
|
||||
vm_['ssh_host'] = ret['ip_address']
|
||||
else: # if probe failed or not used, use Vagrant's reported ssh info
|
||||
vm_['ssh_host'] = ret['ssh_host']
|
||||
vm_.setdefault('ssh_port', ret['ssh_port'])
|
||||
except (KeyError, TypeError):
|
||||
raise SaltInvocationError(
|
||||
'Insufficient SSH addressing information for {}'.format(name))
|
||||
|
||||
log.info('Provisioning machine %s as node %s using ssh %s',
|
||||
machine, name, vm_['ssh_host'])
|
||||
|
@ -288,29 +293,32 @@ def destroy(name, call=None):
|
|||
transport=opts['transport']
|
||||
)
|
||||
my_info = _get_my_info(name)
|
||||
profile_name = my_info[name]['profile']
|
||||
profile = opts['profiles'][profile_name]
|
||||
host = profile['host']
|
||||
local = salt.client.LocalClient()
|
||||
ret = local.cmd(host, 'vagrant.destroy', [name])
|
||||
if my_info:
|
||||
profile_name = my_info[name]['profile']
|
||||
profile = opts['profiles'][profile_name]
|
||||
host = profile['host']
|
||||
local = salt.client.LocalClient()
|
||||
ret = local.cmd(host, 'vagrant.destroy', [name])
|
||||
|
||||
if ret[host]:
|
||||
__utils__['cloud.fire_event'](
|
||||
'event',
|
||||
'destroyed instance',
|
||||
'salt/cloud/{0}/destroyed'.format(name),
|
||||
args={'name': name},
|
||||
sock_dir=opts['sock_dir'],
|
||||
transport=opts['transport']
|
||||
)
|
||||
if ret[host]:
|
||||
__utils__['cloud.fire_event'](
|
||||
'event',
|
||||
'destroyed instance',
|
||||
'salt/cloud/{0}/destroyed'.format(name),
|
||||
args={'name': name},
|
||||
sock_dir=opts['sock_dir'],
|
||||
transport=opts['transport']
|
||||
)
|
||||
|
||||
if opts.get('update_cachedir', False) is True:
|
||||
__utils__['cloud.delete_minion_cachedir'](
|
||||
name, __active_provider_name__.split(':')[0], opts)
|
||||
if opts.get('update_cachedir', False) is True:
|
||||
__utils__['cloud.delete_minion_cachedir'](
|
||||
name, __active_provider_name__.split(':')[0], opts)
|
||||
|
||||
return {'Destroyed': '{0} was destroyed.'.format(name)}
|
||||
return {'Destroyed': '{0} was destroyed.'.format(name)}
|
||||
else:
|
||||
return {'Error': 'Error destroying {}'.format(name)}
|
||||
else:
|
||||
return {'Error': 'Error destroying {}'.format(name)}
|
||||
return {'Error': 'No response from {}. Cannot destroy.'.format(name)}
|
||||
|
||||
|
||||
# noinspection PyTypeChecker
|
||||
|
|
Loading…
Add table
Reference in a new issue