1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
import uuid |
17
|
|
|
|
18
|
|
|
from oslo_config import cfg |
19
|
|
|
|
20
|
|
|
from st2common import log as logging |
21
|
|
|
from st2actions.runners.ssh.paramiko_ssh_runner import RUNNER_COMMAND |
22
|
|
|
from st2actions.runners.ssh.paramiko_ssh_runner import BaseParallelSSHRunner |
23
|
|
|
from st2common.models.system.paramiko_command_action import ParamikoRemoteCommandAction |
24
|
|
|
|
25
|
|
|
__all__ = [ |
26
|
|
|
'get_runner', |
27
|
|
|
|
28
|
|
|
'ParamikoRemoteCommandRunner' |
29
|
|
|
] |
30
|
|
|
|
31
|
|
|
LOG = logging.getLogger(__name__) |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
def get_runner(): |
35
|
|
|
return ParamikoRemoteCommandRunner(str(uuid.uuid4())) |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
class ParamikoRemoteCommandRunner(BaseParallelSSHRunner): |
39
|
|
|
def run(self, action_parameters): |
40
|
|
|
remote_action = self._get_remote_action(action_parameters) |
41
|
|
|
|
42
|
|
|
LOG.debug('Executing remote command action.', extra={'_action_params': remote_action}) |
43
|
|
|
result = self._run(remote_action) |
44
|
|
|
LOG.debug('Executed remote_action.', extra={'_result': result}) |
45
|
|
|
status = self._get_result_status(result, cfg.CONF.ssh_runner.allow_partial_failure) |
46
|
|
|
|
47
|
|
|
return (status, result, None) |
48
|
|
|
|
49
|
|
|
def _run(self, remote_action): |
50
|
|
|
command = remote_action.get_full_command_string() |
51
|
|
|
return self._parallel_ssh_client.run(command, timeout=remote_action.get_timeout()) |
52
|
|
|
|
53
|
|
|
def _get_remote_action(self, action_paramaters): |
54
|
|
|
# remote script actions with entry_point don't make sense, user probably wanted to use |
55
|
|
|
# "remote-shell-script" action |
56
|
|
|
if self.entry_point: |
57
|
|
|
msg = ('Action "%s" specified "entry_point" attribute. Perhaps wanted to use ' |
58
|
|
|
'"remote-shell-script" runner?' % (self.action_name)) |
59
|
|
|
raise Exception(msg) |
60
|
|
|
|
61
|
|
|
command = self.runner_parameters.get(RUNNER_COMMAND, None) |
62
|
|
|
env_vars = self._get_env_vars() |
63
|
|
|
return ParamikoRemoteCommandAction(self.action_name, |
64
|
|
|
str(self.liveaction_id), |
65
|
|
|
command, |
66
|
|
|
env_vars=env_vars, |
67
|
|
|
on_behalf_user=self._on_behalf_user, |
68
|
|
|
user=self._username, |
69
|
|
|
password=self._password, |
70
|
|
|
private_key=self._private_key, |
71
|
|
|
passphrase=self._passphrase, |
72
|
|
|
hosts=self._hosts, |
73
|
|
|
parallel=self._parallel, |
74
|
|
|
sudo=self._sudo, |
75
|
|
|
timeout=self._timeout, |
76
|
|
|
cwd=self._cwd) |
77
|
|
|
|