vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / cli / commands / logs.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 CLI ``logs`` sub-commands.
18 """
19
20 from .. import execution_logging
21 from ..logger import ModelLogIterator
22 from ..core import aria
23
24
25 @aria.group(name='logs')
26 @aria.options.verbose()
27 def logs():
28     """
29     Manage logs of workflow executions
30     """
31     pass
32
33
34 @logs.command(name='list',
35               short_help='List logs for an execution')
36 @aria.argument('execution-id')
37 @aria.options.verbose()
38 @aria.options.mark_pattern()
39 @aria.pass_model_storage
40 @aria.pass_logger
41 def list(execution_id, mark_pattern, model_storage, logger):
42     """
43     List logs for an execution
44
45     EXECUTION_ID is the unique ID of the execution.
46     """
47     logger.info('Listing logs for execution id {0}'.format(execution_id))
48     log_iterator = ModelLogIterator(model_storage, execution_id)
49
50     any_logs = execution_logging.log_list(log_iterator, mark_pattern=mark_pattern)
51
52     if not any_logs:
53         logger.info('\tNo logs')
54
55
56 @logs.command(name='delete',
57               short_help='Delete logs of an execution')
58 @aria.argument('execution-id')
59 @aria.options.verbose()
60 @aria.pass_model_storage
61 @aria.pass_logger
62 def delete(execution_id, model_storage, logger):
63     """
64     Delete logs of an execution
65
66     EXECUTION_ID is the unique ID of the execution.
67     """
68     logger.info('Deleting logs for execution id {0}'.format(execution_id))
69     logs_list = model_storage.log.list(filters=dict(execution_fk=execution_id))
70     for log in logs_list:
71         model_storage.log.delete(log)
72     logger.info('Deleted logs for execution id {0}'.format(execution_id))