/usr/lib/python2.7/dist-packages/mistralclient/commands/v2/action_executions.py is in python-mistralclient 1:3.3.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | # Copyright 2014 - Mirantis, Inc.
# Copyright 2016 - Brocade Communications Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import json
import logging
from osc_lib.command import command
from mistralclient.commands.v2 import base
from mistralclient import utils
LOG = logging.getLogger(__name__)
def format_list(action_ex=None):
columns = (
'ID',
'Name',
'Workflow name',
'Workflow namespace',
'Task name',
'Task ID',
'State',
'Accepted',
'Created at',
'Updated at'
)
if action_ex:
data = (
action_ex.id,
action_ex.name,
action_ex.workflow_name,
action_ex.workflow_namespace,
action_ex.task_name if hasattr(action_ex, 'task_name') else None,
action_ex.task_execution_id,
action_ex.state,
action_ex.accepted,
action_ex.created_at,
action_ex.updated_at or '<none>'
)
else:
data = (tuple('' for _ in range(len(columns))),)
return columns, data
def format(action_ex=None):
columns = (
'ID',
'Name',
'Workflow name',
'Workflow namespace',
'Task name',
'Task ID',
'State',
'State info',
'Accepted',
'Created at',
'Updated at',
)
if action_ex:
data = (
action_ex.id,
action_ex.name,
action_ex.workflow_name,
action_ex.workflow_namespace,
action_ex.task_name if hasattr(action_ex, 'task_name') else None,
action_ex.task_execution_id,
action_ex.state,
action_ex.state_info,
action_ex.accepted,
action_ex.created_at,
action_ex.updated_at or '<none>'
)
else:
data = (tuple('' for _ in range(len(columns))),)
return columns, data
class Create(command.ShowOne):
"""Create new Action execution or just run specific action."""
def produce_output(self, parsed_args, column_names, data):
if not column_names:
return 0
return super(Create, self).produce_output(
parsed_args,
column_names,
data
)
def get_parser(self, prog_name):
parser = super(Create, self).get_parser(prog_name)
parser.add_argument(
'name',
help='Action name to execute.'
)
parser.add_argument(
dest='input',
nargs='?',
help='Action input.'
)
parser.add_argument(
'-s',
'--save-result',
dest='save_result',
action='store_true',
help='Save the result into DB.'
)
parser.add_argument(
'--run-sync',
dest='run_sync',
action='store_true',
help='Run the action synchronously.'
)
parser.add_argument(
'-t',
'--target',
dest='target',
help='Action will be executed on <target> executor.'
)
return parser
def take_action(self, parsed_args):
params = {}
if parsed_args.save_result:
params['save_result'] = parsed_args.save_result
if parsed_args.run_sync:
params['run_sync'] = parsed_args.run_sync
if parsed_args.target:
params['target'] = parsed_args.target
action_input = None
if parsed_args.input:
action_input = utils.load_json(parsed_args.input)
mistral_client = self.app.client_manager.workflow_engine
action_ex = mistral_client.action_executions.create(
parsed_args.name,
action_input,
**params
)
if not parsed_args.run_sync and parsed_args.save_result:
return format(action_ex)
else:
self.app.stdout.write("%s\n" % action_ex.output)
return None, None
class List(base.MistralLister):
"""List all Action executions."""
def _get_format_function(self):
return format_list
def get_parser(self, prog_name):
parser = super(List, self).get_parser(prog_name)
parser.add_argument(
'task_execution_id',
nargs='?',
help='Task execution ID.'
)
parser.add_argument(
'--limit',
type=int,
help='Maximum number of action-executions to return in a single '
'result. limit is set to %s by default. Use --limit -1 to '
'fetch the full result set.' % base.DEFAULT_LIMIT,
nargs='?'
)
return parser
def _get_resources(self, parsed_args):
if parsed_args.limit is None:
parsed_args.limit = base.DEFAULT_LIMIT
LOG.info(
"limit is set to %s by default. Set "
"the limit explicitly using \'--limit\', if required. "
"Use \'--limit\' -1 to fetch the full result set.",
base.DEFAULT_LIMIT
)
mistral_client = self.app.client_manager.workflow_engine
return mistral_client.action_executions.list(
parsed_args.task_execution_id,
limit=parsed_args.limit,
)
class Get(command.ShowOne):
"""Show specific Action execution."""
def get_parser(self, prog_name):
parser = super(Get, self).get_parser(prog_name)
parser.add_argument('action_execution', help='Action execution ID.')
return parser
def take_action(self, parsed_args):
mistral_client = self.app.client_manager.workflow_engine
execution = mistral_client.action_executions.get(
parsed_args.action_execution
)
return format(execution)
class Update(command.ShowOne):
"""Update specific Action execution."""
def get_parser(self, prog_name):
parser = super(Update, self).get_parser(prog_name)
parser.add_argument(
'id',
help='Action execution ID.')
parser.add_argument(
'--state',
dest='state',
choices=['IDLE', 'RUNNING', 'SUCCESS', 'ERROR', 'CANCELLED'],
help='Action execution state')
parser.add_argument(
'--output',
dest='output',
help='Action execution output')
return parser
def take_action(self, parsed_args):
output = None
if parsed_args.output:
output = utils.load_json(parsed_args.output)
mistral_client = self.app.client_manager.workflow_engine
execution = mistral_client.action_executions.update(
parsed_args.id,
parsed_args.state,
output
)
return format(execution)
class GetOutput(command.Command):
"""Show Action execution output data."""
def get_parser(self, prog_name):
parser = super(GetOutput, self).get_parser(prog_name)
parser.add_argument(
'id',
help='Action execution ID.')
return parser
def take_action(self, parsed_args):
mistral_client = self.app.client_manager.workflow_engine
output = mistral_client.action_executions.get(parsed_args.id).output
try:
output = json.loads(output)
output = json.dumps(output, indent=4) + "\n"
except Exception:
LOG.debug("Task result is not JSON.")
self.app.stdout.write(output or "\n")
class GetInput(command.Command):
"""Show Action execution input data."""
def get_parser(self, prog_name):
parser = super(GetInput, self).get_parser(prog_name)
parser.add_argument(
'id',
help='Action execution ID.'
)
return parser
def take_action(self, parsed_args):
mistral_client = self.app.client_manager.workflow_engine
result = mistral_client.action_executions.get(parsed_args.id).input
try:
result = json.loads(result)
result = json.dumps(result, indent=4) + "\n"
except Exception:
LOG.debug("Task result is not JSON.")
self.app.stdout.write(result or "\n")
class Delete(command.Command):
"""Delete action execution."""
def get_parser(self, prog_name):
parser = super(Delete, self).get_parser(prog_name)
parser.add_argument(
'action_execution',
nargs='+',
help='Id of action execution identifier(s).'
)
return parser
def take_action(self, parsed_args):
mistral_client = self.app.client_manager.workflow_engine
utils.do_action_on_many(
lambda s: mistral_client.action_executions.delete(s),
parsed_args.action_execution,
"Request to delete action execution %s has been accepted.",
"Unable to delete the specified action execution(s)."
)
|