summaryrefslogtreecommitdiffstats
path: root/azure/aria/aria-extension-cloudify/src/aria/aria/cli/commands/plugins.py
blob: b5d68a211fdbd5ce3bc3130a685b4c19a1d0cd42 (plain)
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
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

"""
CLI ``plugins`` sub-commands.
"""

from .. import table
from .. import utils
from ..core import aria


PLUGIN_COLUMNS = ['id', 'package_name', 'package_version', 'supported_platform',
                  'distribution', 'distribution_release', 'uploaded_at']


@aria.group(name='plugins')
@aria.options.verbose()
def plugins():
    """
    Manage plugins
    """
    pass


@plugins.command(name='validate',
                 short_help='Validate a plugin archive')
@aria.argument('plugin-path')
@aria.options.verbose()
@aria.pass_plugin_manager
@aria.pass_logger
def validate(plugin_path, plugin_manager, logger):
    """
    Validate a plugin archive

    A valid plugin is a wagon (`http://github.com/cloudify-cosmo/wagon`) in the ZIP format (suffix
    may also be `.wgn`).

    PLUGIN_PATH is the path to the wagon archive.
    """
    logger.info('Validating plugin {0}...'.format(plugin_path))
    plugin_manager.validate_plugin(plugin_path)
    logger.info('Plugin validated successfully')


@plugins.command(name='install',
                 short_help='Install a plugin')
@aria.argument('plugin-path')
@aria.options.verbose()
@aria.pass_context
@aria.pass_plugin_manager
@aria.pass_logger
def install(ctx, plugin_path, plugin_manager, logger):
    """
    Install a plugin

    A valid plugin is a wagon (`http://github.com/cloudify-cosmo/wagon`) in the ZIP format (suffix
    may also be `.wgn`).

    PLUGIN_PATH is the path to the wagon archive.
    """
    ctx.invoke(validate, plugin_path=plugin_path)
    logger.info('Installing plugin {0}...'.format(plugin_path))
    plugin = plugin_manager.install(plugin_path)
    logger.info("Plugin installed. The plugin's id is {0}".format(plugin.id))


@plugins.command(name='show',
                 short_help='Show information for an installed plugin')
@aria.argument('plugin-id')
@aria.options.verbose()
@aria.pass_model_storage
@aria.pass_logger
def show(plugin_id, model_storage, logger):
    """
    Show information for an installed plugin

    PLUGIN_ID is the unique installed plugin ID in this ARIA instance.
    """
    logger.info('Showing plugin {0}...'.format(plugin_id))
    plugin = model_storage.plugin.get(plugin_id)
    table.print_data(PLUGIN_COLUMNS, plugin, 'Plugin:')


@plugins.command(name='list',
                 short_help='List all installed plugins')
@aria.options.sort_by('uploaded_at')
@aria.options.descending
@aria.options.verbose()
@aria.pass_model_storage
@aria.pass_logger
def list(sort_by, descending, model_storage, logger):
    """
    List all installed plugins
    """
    logger.info('Listing all plugins...')
    plugins_list = model_storage.plugin.list(
        sort=utils.storage_sort_param(sort_by, descending)).items
    table.print_data(PLUGIN_COLUMNS, plugins_list, 'Plugins:')