vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / cli / commands / plugins.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 ``plugins`` sub-commands.
18 """
19
20 from .. import table
21 from .. import utils
22 from ..core import aria
23
24
25 PLUGIN_COLUMNS = ['id', 'package_name', 'package_version', 'supported_platform',
26                   'distribution', 'distribution_release', 'uploaded_at']
27
28
29 @aria.group(name='plugins')
30 @aria.options.verbose()
31 def plugins():
32     """
33     Manage plugins
34     """
35     pass
36
37
38 @plugins.command(name='validate',
39                  short_help='Validate a plugin archive')
40 @aria.argument('plugin-path')
41 @aria.options.verbose()
42 @aria.pass_plugin_manager
43 @aria.pass_logger
44 def validate(plugin_path, plugin_manager, logger):
45     """
46     Validate a plugin archive
47
48     A valid plugin is a wagon (`http://github.com/cloudify-cosmo/wagon`) in the ZIP format (suffix
49     may also be `.wgn`).
50
51     PLUGIN_PATH is the path to the wagon archive.
52     """
53     logger.info('Validating plugin {0}...'.format(plugin_path))
54     plugin_manager.validate_plugin(plugin_path)
55     logger.info('Plugin validated successfully')
56
57
58 @plugins.command(name='install',
59                  short_help='Install a plugin')
60 @aria.argument('plugin-path')
61 @aria.options.verbose()
62 @aria.pass_context
63 @aria.pass_plugin_manager
64 @aria.pass_logger
65 def install(ctx, plugin_path, plugin_manager, logger):
66     """
67     Install a plugin
68
69     A valid plugin is a wagon (`http://github.com/cloudify-cosmo/wagon`) in the ZIP format (suffix
70     may also be `.wgn`).
71
72     PLUGIN_PATH is the path to the wagon archive.
73     """
74     ctx.invoke(validate, plugin_path=plugin_path)
75     logger.info('Installing plugin {0}...'.format(plugin_path))
76     plugin = plugin_manager.install(plugin_path)
77     logger.info("Plugin installed. The plugin's id is {0}".format(plugin.id))
78
79
80 @plugins.command(name='show',
81                  short_help='Show information for an installed plugin')
82 @aria.argument('plugin-id')
83 @aria.options.verbose()
84 @aria.pass_model_storage
85 @aria.pass_logger
86 def show(plugin_id, model_storage, logger):
87     """
88     Show information for an installed plugin
89
90     PLUGIN_ID is the unique installed plugin ID in this ARIA instance.
91     """
92     logger.info('Showing plugin {0}...'.format(plugin_id))
93     plugin = model_storage.plugin.get(plugin_id)
94     table.print_data(PLUGIN_COLUMNS, plugin, 'Plugin:')
95
96
97 @plugins.command(name='list',
98                  short_help='List all installed plugins')
99 @aria.options.sort_by('uploaded_at')
100 @aria.options.descending
101 @aria.options.verbose()
102 @aria.pass_model_storage
103 @aria.pass_logger
104 def list(sort_by, descending, model_storage, logger):
105     """
106     List all installed plugins
107     """
108     logger.info('Listing all plugins...')
109     plugins_list = model_storage.plugin.list(
110         sort=utils.storage_sort_param(sort_by, descending)).items
111     table.print_data(PLUGIN_COLUMNS, plugins_list, 'Plugins:')