Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

# 

#    Licensed 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. 

 

"""Starter script for magnum-template-manage.""" 

import operator 

 

from oslo_config import cfg 

 

from magnum.conductor import template_definition as tdef 

from magnum.openstack.common import cliutils 

from magnum.openstack.common import log as logging 

 

LOG = logging.getLogger(__name__) 

CONF = cfg.CONF 

 

 

def is_enabled(name): 

    return name in CONF.bay.enabled_definitions 

 

 

def print_rows(rows): 

    fields = ['name', 'enabled'] 

    field_labels = ['Name', 'Enabled'] 

 

    if CONF.command.details: 

        fields.extend(['platform', 'os', 'coe']) 

        field_labels.extend(['Platform', 'OS', 'COE']) 

    if CONF.command.paths: 

        fields.append('path') 

        field_labels.append('Template Path') 

 

    formatters = dict((key, operator.itemgetter(key)) for key in fields) 

 

    cliutils.print_list(rows, fields, 

                        formatters=formatters, 

                        field_labels=field_labels) 

 

 

def list_templates(): 

    rows = [] 

 

    for entry_point, cls in tdef.TemplateDefinition.load_entry_points(): 

        name = entry_point.name 

        if ((is_enabled(name) and not CONF.command.disabled) or 

                (not is_enabled(name) and not CONF.command.enabled)): 

            definition = cls() 

            template = dict(name=name, enabled=is_enabled(name), 

                            path=definition.template_path) 

 

            if CONF.command.details: 

                for bay_type in definition.provides: 

                    row = dict() 

                    row.update(template) 

                    row.update(bay_type) 

                    rows.append(row) 

            else: 

                rows.append(template) 

 

    print_rows(rows) 

 

 

def add_command_parsers(subparsers): 

    parser = subparsers.add_parser('list-templates') 

    parser.set_defaults(func=list_templates) 

 

    parser.add_argument('-d', '--details', action='store_true', 

                        help='display the bay types provided by each template') 

    parser.add_argument('-p', '--paths', action='store_true', 

                        help='display the path to each template file') 

 

    group = parser.add_mutually_exclusive_group() 

    group.add_argument('--enabled', action='store_true', 

                       help="display only enabled templates") 

    group.add_argument('--disabled', action='store_true', 

                       help="display only disabled templates") 

 

 

def main(): 

    command_opt = cfg.SubCommandOpt('command', 

                                    title='Command', 

                                    help='Available commands', 

                                    handler=add_command_parsers) 

    CONF.register_cli_opt(command_opt) 

 

    CONF(project='magnum') 

    CONF.command.func()