Merge pull request #36188 from rallytime/merge-2016.3

[2016.3] Merge forward from 2015.8 to 2016.3
This commit is contained in:
Nicole Thomas 2016-09-09 12:59:20 -06:00 committed by GitHub
commit f035121291
3 changed files with 114 additions and 31 deletions

View File

@ -24,6 +24,21 @@ Set up the cloud configuration at ``/etc/salt/cloud.providers`` or
password: JHGhgsayu32jsa
driver: opennebula
This driver supports accessing new VM instances via DNS entry instead
of IP address. To enable this feature, in the provider or profile file
add `fqdn_base` with a value matching the base of your fully-qualified
domain name. Example:
.. code-block:: yaml
my-opennebula-config:
[...]
fqdn_base: <my.basedomain.com>
[...]
The driver will prepend the hostname to the fqdn_base and do a DNS lookup
to find the IP of the new VM.
.. note:
Whenever ``data`` is provided as a kwarg to a function and the
@ -744,6 +759,27 @@ def get_template_id(kwargs=None, call=None):
return ret
def get_template(vm_):
r'''
Return the template id for a VM.
.. versionadded:: Carbon
vm\_
The VM dictionary for which to obtain a template.
'''
vm_template = str(config.get_cloud_config_value(
'template', vm_, __opts__, search_global=False
))
try:
return list_templates()[vm_template]['id']
except KeyError:
raise SaltCloudNotFound(
'The specified template, \'{0}\', could not be found.'.format(vm_template)
)
def get_vm_id(kwargs=None, call=None):
'''
Returns a virtual machine's ID from the given virtual machine's name.
@ -823,11 +859,27 @@ def create(vm_):
vm\_
The dictionary use to create a VM.
CLI Example:
Optional vm_ dict options for overwriting template:
.. code-block:: bash
region_id
Optional - OpenNebula Zone ID
salt-cloud -p my-opennebula-profile vm_name
memory
Optional - In MB
cpu
Optional - Percent of host CPU to allocate
vcpu
Optional - Amount of vCPUs to allocate
CLI Example:
.. code-block:: bash
salt-cloud -p my-opennebula-profile vm_name
salt-cloud -p my-opennebula-profile vm_name memory=16384 cpu=2.5 vcpu=16
'''
try:
@ -848,20 +900,23 @@ def create(vm_):
'event',
'starting create',
'salt/cloud/{0}/creating'.format(vm_['name']),
{
args={
'name': vm_['name'],
'profile': vm_['profile'],
'provider': vm_['driver'],
},
sock_dir=__opts__['sock_dir'],
transport=__opts__['transport']
)
log.info('Creating Cloud VM {0}'.format(vm_['name']))
kwargs = {
'name': vm_['name'],
'image_id': get_image(vm_),
'template_id': get_template(vm_),
'region_id': get_location(vm_),
}
if 'template' in vm_:
kwargs['image_id'] = get_template_id({'name': vm_['template']})
private_networking = config.get_cloud_config_value(
'private_networking', vm_, __opts__, search_global=False, default=None
@ -872,20 +927,41 @@ def create(vm_):
'event',
'requesting instance',
'salt/cloud/{0}/requesting'.format(vm_['name']),
{'kwargs': kwargs},
args={'kwargs': kwargs},
sock_dir=__opts__['sock_dir'],
)
region = ''
if kwargs['region_id'] is not None:
region = 'SCHED_REQUIREMENTS="ID={0}"'.format(kwargs['region_id'])
template = []
if kwargs.get('region_id'):
template.append('SCHED_REQUIREMENTS="ID={0}"'.format(kwargs.get('region_id')))
if vm_.get('memory'):
template.append('MEMORY={0}'.format(vm_.get('memory')))
if vm_.get('cpu'):
template.append('CPU={0}'.format(vm_.get('cpu')))
if vm_.get('vcpu'):
template.append('VCPU={0}'.format(vm_.get('vcpu')))
template_args = "\n".join(template)
try:
server, user, password = _get_xml_rpc()
auth = ':'.join([user, password])
server.one.template.instantiate(auth,
int(kwargs['image_id']),
cret = server.one.template.instantiate(auth,
int(kwargs['template_id']),
kwargs['name'],
False,
region)
template_args)
if not cret[0]:
log.error(
'Error creating {0} on OpenNebula\n\n'
'The following error was returned when trying to '
'instantiate the template: {1}'.format(
vm_['name'],
cret[1]
),
# Show the traceback if the debug logging level is enabled
exc_info_on_loglevel=logging.DEBUG
)
return False
except Exception as exc:
log.error(
'Error creating {0} on OpenNebula\n\n'
@ -899,6 +975,10 @@ def create(vm_):
)
return False
fqdn = vm_.get('fqdn_base')
if fqdn is not None:
fqdn = '{0}.{1}'.format(vm_['name'], fqdn)
def __query_node_data(vm_name):
node_data = show_instance(vm_name, call='action')
if not node_data:
@ -937,10 +1017,15 @@ def create(vm_):
)
)
try:
private_ip = data['private_ips'][0]
except KeyError:
private_ip = data['template']['nic']['ip']
if fqdn:
vm_['ssh_host'] = fqdn
private_ip = '0.0.0.0'
else:
try:
private_ip = data['private_ips'][0]
except KeyError:
private_ip = data['template']['nic']['ip']
vm_['ssh_host'] = private_ip
ssh_username = config.get_cloud_config_value(
'ssh_username', vm_, __opts__, default='root'
@ -948,7 +1033,6 @@ def create(vm_):
vm_['username'] = ssh_username
vm_['key_filename'] = key_filename
vm_['ssh_host'] = private_ip
ret = __utils__['cloud.bootstrap'](vm_, __opts__)
@ -971,11 +1055,12 @@ def create(vm_):
'event',
'created instance',
'salt/cloud/{0}/created'.format(vm_['name']),
{
args={
'name': vm_['name'],
'profile': vm_['profile'],
'provider': vm_['driver'],
},
sock_dir=__opts__['sock_dir'],
)
return ret
@ -1008,7 +1093,8 @@ def destroy(name, call=None):
'event',
'destroying instance',
'salt/cloud/{0}/destroying'.format(name),
{'name': name},
args={'name': name},
sock_dir=__opts__['sock_dir'],
)
server, user, password = _get_xml_rpc()
@ -1021,7 +1107,8 @@ def destroy(name, call=None):
'event',
'destroyed instance',
'salt/cloud/{0}/destroyed'.format(name),
{'name': name},
args={'name': name},
sock_dir=__opts__['sock_dir'],
)
if __opts__.get('update_cachedir', False) is True:
@ -4333,8 +4420,7 @@ def _list_nodes(full=False):
for nic in vm.find('TEMPLATE').findall('NIC'):
try:
private_ips.append(nic.find('IP').text)
except AttributeError:
# There is no private IP; skip it
except Exception:
pass
vms[name]['id'] = vm.find('ID').text

View File

@ -12,7 +12,6 @@ A module to manage software on Windows
# Import python libs
from __future__ import absolute_import
import errno
import os
import locale
import logging
@ -28,7 +27,7 @@ except ImportError:
# pylint: enable=import-error
# Import salt libs
from salt.exceptions import CommandExecutionError, SaltRenderError
from salt.exceptions import SaltRenderError
import salt.utils
import salt.syspaths
from salt.exceptions import MinionError
@ -1061,6 +1060,9 @@ def get_repo_data(saltenv='base'):
# return __context__['winrepo.data']
repocache_dir = _get_local_repo_dir(saltenv=saltenv)
winrepo = 'winrepo.p'
if not os.path.exists(os.path.join(repocache_dir, winrepo)):
log.debug('No winrepo.p cache file. Refresh pkg db now.')
refresh_db(saltenv=saltenv)
try:
with salt.utils.fopen(
os.path.join(repocache_dir, winrepo), 'rb') as repofile:
@ -1071,12 +1073,6 @@ def get_repo_data(saltenv='base'):
log.exception(exc)
return {}
except IOError as exc:
if exc.errno == errno.ENOENT:
# File doesn't exist
raise CommandExecutionError(
'Windows repo cache doesn\'t exist, pkg.refresh_db likely '
'needed'
)
log.error('Not able to read repo file')
log.exception(exc)
return {}

View File

@ -487,7 +487,8 @@ def image_present(name,
load=None,
force=False,
insecure_registry=False,
client_timeout=CLIENT_TIMEOUT):
client_timeout=CLIENT_TIMEOUT,
**kwargs):
'''
Ensure that an image is present. The image can either be pulled from a
Docker registry, built from a Dockerfile, or loaded from a saved image.