mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
parent
f6feddecb4
commit
64a73502ed
2 changed files with 32 additions and 10 deletions
|
@ -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.'
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue