vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / orchestrator / workflows / executor / dry.py
1 # Licensed to the Apache Software Foundation (ASF) 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 """
17 Dry task executor.
18 """
19
20 from datetime import datetime
21
22 from . import base
23
24
25 class DryExecutor(base.BaseExecutor):                                                                    # pylint: disable=abstract-method
26     """
27     Dry task executor: prints task information without causing any side effects.
28     """
29     def execute(self, ctx):
30         with ctx.persist_changes:
31             # updating the task manually instead of calling self._task_started(task),
32             # to avoid any side effects raising that event might cause
33             ctx.task.started_at = datetime.utcnow()
34             ctx.task.status = ctx.task.STARTED
35
36             dry_msg = '<dry> {name} {task.interface_name}.{task.operation_name} {suffix}'
37             logger = ctx.logger.info if ctx.task.function else ctx.logger.debug
38
39             if hasattr(ctx.task.actor, 'source_node'):
40                 name = '{source_node.name}->{target_node.name}'.format(
41                     source_node=ctx.task.actor.source_node, target_node=ctx.task.actor.target_node)
42             else:
43                 name = ctx.task.actor.name
44
45             if ctx.task.function:
46                 logger(dry_msg.format(name=name, task=ctx.task, suffix='started...'))
47                 logger(dry_msg.format(name=name, task=ctx.task, suffix='successful'))
48             else:
49                 logger(dry_msg.format(name=name, task=ctx.task, suffix='has no implementation'))
50
51             # updating the task manually instead of calling self._task_succeeded(task),
52             # to avoid any side effects raising that event might cause
53             ctx.task.ended_at = datetime.utcnow()
54             ctx.task.status = ctx.task.SUCCESS