summaryrefslogtreecommitdiffstats
path: root/moonclient/moonclient/configuration.py
blob: a05d715129c30621f19facbda2ef7e861e375ccb (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
# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
# This software is distributed under the terms and conditions of the 'Apache-2.0'
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.

import logging

from cliff.lister import Lister


class TemplatesList(Lister):
    """List all policy templates."""

    log = logging.getLogger(__name__)

    def get_parser(self, prog_name):
        parser = super(TemplatesList, self).get_parser(prog_name)
        return parser

    def take_action(self, parsed_args):
        templates = self.app.get_url(self.app.url_prefix+"/configuration/templates", authtoken=True)
        return (
            ("id", "name", "description"),
            ((template_id, templates[template_id]["name"], templates[template_id]["description"])
             for template_id in templates)
        )


class AggregationAlgorithmsList(Lister):
    """List all aggregation algorithms."""

    log = logging.getLogger(__name__)

    def get_parser(self, prog_name):
        parser = super(AggregationAlgorithmsList, self).get_parser(prog_name)
        return parser

    def take_action(self, parsed_args):
        templates = self.app.get_url(self.app.url_prefix+"/configuration/aggregation_algorithms", authtoken=True)
        return (
            ("id", "name", "description"),
            ((template_id, templates[template_id]["name"], templates[template_id]["description"])
             for template_id in templates)
        )


class SubMetaRuleAlgorithmsList(Lister):
    """List all sub meta rule algorithms."""

    log = logging.getLogger(__name__)

    def get_parser(self, prog_name):
        parser = super(SubMetaRuleAlgorithmsList, self).get_parser(prog_name)
        return parser

    def take_action(self, parsed_args):
        templates = self.app.get_url(self.app.url_prefix+"/configuration/sub_meta_rule_algorithms", authtoken=True)
        return (
            ("id", "name", "description"),
            ((template_id, templates[template_id]["name"], templates[template_id]["description"])
             for template_id in templates)
        )