Make sure we just the "instance" kwarg in cloud.action.

Fixes #29602
This commit is contained in:
rallytime 2016-01-27 16:45:07 -07:00
parent f6feddecb4
commit 64a73502ed
2 changed files with 32 additions and 10 deletions

View file

@ -469,16 +469,28 @@ class CloudClient(object):
)
'''
mapper = salt.cloud.Map(self._opts_defaults(action=fun, names=names))
if instance:
if names:
raise SaltCloudConfigError(
'Please specify either a list of \'names\' or a single '
'\'instance\', but not both.'
)
names = [instance]
if names and not provider:
self.opts['action'] = fun
return mapper.do_action(names, kwargs)
if provider:
if provider and not names:
return mapper.do_function(provider, fun, kwargs)
else:
# This should not be called without either an instance or a
# provider.
# provider. If both an instance/list of names and a provider
# are given, then we also need to exit. We can only have one
# or the other.
raise SaltCloudConfigError(
'Either an instance or a provider must be specified.'
'Either an instance (or list of names) or a provider must be '
'specified, but not both.'
)

View file

@ -6,13 +6,18 @@ The Salt Cloud Runner
This runner wraps the functionality of salt cloud making salt cloud routines
available to all internal apis via the runner system
'''
from __future__ import absolute_import
# Import python libs
from __future__ import absolute_import
import logging
import os
# Import Salt libs
import salt.cloud
from salt.exceptions import SaltCloudConfigError
# Get logging started
log = logging.getLogger(__name__)
def _get_client():
@ -136,12 +141,17 @@ def action(*args, **kwargs):
salt-run cloud.actions start my-salt-vm
'''
client = _get_client()
info = client.action(args[0],
kwargs.get('cloudmap', None),
args[1:],
kwargs.get('provider', None),
kwargs.get('instance', None),
kwargs)
try:
info = client.action(args[0],
kwargs.get('cloudmap', None),
args[1:],
kwargs.get('provider', None),
kwargs.get('instance', None),
kwargs)
except SaltCloudConfigError as err:
log.error(err)
return {}
return info