~lutostag/ubuntu/trusty/maas/1.5.4+keystone

« back to all changes in this revision

Viewing changes to src/provisioningserver/power_schema.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Andres Rodriguez, Julian Edwards, Dustin Kirkland
  • Date: 2014-03-28 10:43:53 UTC
  • mfrom: (1.2.26)
  • Revision ID: package-import@ubuntu.com-20140328104353-9hj74f1nvl7xis5z
Tags: 1.5+bzr2204-0ubuntu1
* New upstream release (LP: #1281881)

[ Andres Rodriguez ]
* debian/maas-region-controller-min.templates: Set installation note to false
  by default.
* Check rabbitmqctl is present before running commands:
  - debian/maas-region-controller-min.maas-region-celery.upstart.
  - debian/maas-region-controller-min.maas-txlongpoll.upstart.
* make sure maas_longpoll rabbitmq user is created/with correct password on
  a package reconfigure.
* debian/maas-dns.postinst: Fix upgrade setup of named.conf.options.
* debian/maas-cluster-controller.install: Install UEFI templates (LP: #1299143)

[ Julian Edwards ]
* debian/extas/maas: Echo warning to stderr so json stdout is not polluted
* debian/maas-cluster-controller.postinst: Run upgrade-cluster on each
  upgrade
* debian/maas-dns.postinst: Call edit_named_options to add a line in
  /etc/bind/named.conf.options that includes the
  /etc/named/maas/named.conf.options.inside.maas file.
* debian/control:
  - maas-dns depends on python-iscpy
  - maas-cluster-controller depends on python-seamicroclient
* debian/maas-cluster-controller.install: Install bootresources.yaml

[ Dustin Kirkland ]
* debian/control: LP: #1297097
  - clean up package descriptions, modernize, and more clearly/simply
    explain what each package does
  - drop "Ubuntu" in front of MAAS, clean up command line/API description

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012-2014 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Define json schema for power parameters."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
str = None
 
13
 
 
14
__metaclass__ = type
 
15
__all__ = [
 
16
    "JSON_POWER_TYPE_PARAMETERS",
 
17
    "JSON_POWER_TYPE_SCHEMA",
 
18
    "POWER_TYPE_PARAMETER_FIELD_SCHEMA",
 
19
    ]
 
20
 
 
21
 
 
22
from jsonschema import validate
 
23
 
 
24
# We specifically declare this here so that a node not knowing its own
 
25
# powertype won't fail to enlist. However, we don't want it in the list
 
26
# of power types since setting a node's power type to "I don't know"
 
27
# from another type doens't make any sense.
 
28
UNKNOWN_POWER_TYPE = ''
 
29
 
 
30
 
 
31
class IPMI_DRIVER:
 
32
    DEFAULT = ''
 
33
    LAN = 'LAN'
 
34
    LAN_2_0 = 'LAN_2_0'
 
35
 
 
36
 
 
37
IPMI_DRIVER_CHOICES = [
 
38
    [IPMI_DRIVER.LAN, "LAN [IPMI 1.5]"],
 
39
    [IPMI_DRIVER.LAN_2_0, "LAN_2_0 [IPMI 2.0]"],
 
40
    ]
 
41
 
 
42
 
 
43
# Represent the Django choices format as JSON; an array of 2-item
 
44
# arrays.
 
45
CHOICE_FIELD_SCHEMA = {
 
46
    'type': 'array',
 
47
    'items': {
 
48
        'title': "Power type paramter field choice",
 
49
        'type': 'array',
 
50
        'minItems': 2,
 
51
        'maxItems': 2,
 
52
        'uniqueItems': True,
 
53
        'items': {
 
54
            'type': 'string',
 
55
        }
 
56
    },
 
57
}
 
58
 
 
59
 
 
60
POWER_TYPE_PARAMETER_FIELD_SCHEMA = {
 
61
    'title': "Power type parameter field",
 
62
    'type': 'object',
 
63
    'properties': {
 
64
        'name': {
 
65
            'type': 'string',
 
66
        },
 
67
        'field_type': {
 
68
            'type': 'string',
 
69
        },
 
70
        'label': {
 
71
            'type': 'string',
 
72
        },
 
73
        'required': {
 
74
            'type': 'boolean',
 
75
        },
 
76
        'choices': CHOICE_FIELD_SCHEMA,
 
77
        'default': {
 
78
            'type': 'string',
 
79
        },
 
80
    },
 
81
    'required': ['field_type', 'label', 'required'],
 
82
}
 
83
 
 
84
 
 
85
# A basic JSON schema for what power type parameters should look like.
 
86
JSON_POWER_TYPE_SCHEMA = {
 
87
    'title': "Power parameters set",
 
88
    'type': 'array',
 
89
    'items': {
 
90
        'title': "Power type parameters",
 
91
        'type': 'object',
 
92
        'properties': {
 
93
            'name': {
 
94
                'type': 'string',
 
95
            },
 
96
            'description': {
 
97
                'type': 'string',
 
98
            },
 
99
            'fields': {
 
100
                'type': 'array',
 
101
                'items': POWER_TYPE_PARAMETER_FIELD_SCHEMA,
 
102
            },
 
103
        },
 
104
        'required': ['name', 'description', 'fields'],
 
105
    },
 
106
}
 
107
 
 
108
 
 
109
# Power control choices for sm15k power type
 
110
SM15K_POWER_CONTROL_CHOICES = [
 
111
    ["ipmi", "IPMI"],
 
112
    ["restapi", "REST API v0.9"],
 
113
    ["restapi2", "REST API v2.0"],
 
114
    ]
 
115
 
 
116
 
 
117
def make_json_field(
 
118
        name, label, field_type=None, choices=None, default=None,
 
119
        required=False):
 
120
    """Helper function for building a JSON power type parameters field.
 
121
 
 
122
    :param name: The name of the field.
 
123
    :type name: string
 
124
    :param label: The label to be presented to the user for this field.
 
125
    :type label: string
 
126
    :param field_type: The type of field to create. Can be one of
 
127
        (string, choice, mac_address). Defaults to string.
 
128
    :type field_type: string.
 
129
    :param choices: The collection of choices to present to the user.
 
130
        Needs to be structured as a list of lists, otherwise
 
131
        make_json_field() will raise a ValidationError.
 
132
    :type list:
 
133
    :param default: The default value for the field.
 
134
    :type default: string
 
135
    :param required: Whether or not a value for the field is required.
 
136
    :type required: boolean
 
137
    """
 
138
    if field_type not in ('string', 'mac_address', 'choice'):
 
139
        field_type = 'string'
 
140
    if choices is None:
 
141
        choices = []
 
142
    validate(choices, CHOICE_FIELD_SCHEMA)
 
143
    if default is None:
 
144
        default = ""
 
145
    field = {
 
146
        'name': name,
 
147
        'label': label,
 
148
        'required': required,
 
149
        'field_type': field_type,
 
150
        'choices': choices,
 
151
        'default': default,
 
152
    }
 
153
    return field
 
154
 
 
155
 
 
156
JSON_POWER_TYPE_PARAMETERS = [
 
157
    {
 
158
        'name': 'ether_wake',
 
159
        'description': 'Wake-on-LAN',
 
160
        'fields': [
 
161
            make_json_field(
 
162
                'mac_address', "MAC Address", field_type='mac_address'),
 
163
        ],
 
164
    },
 
165
    {
 
166
        'name': 'virsh',
 
167
        'description': 'virsh (virtual systems)',
 
168
        'fields': [
 
169
            make_json_field('power_address', "Power address"),
 
170
            make_json_field('power_id', "Power ID"),
 
171
        ],
 
172
    },
 
173
    {
 
174
        'name': 'fence_cdu',
 
175
        'description': 'Sentry Switch CDU',
 
176
        'fields': [
 
177
            make_json_field('power_address', "Power address"),
 
178
            make_json_field('power_id', "Power ID"),
 
179
            make_json_field('power_user', "Power user"),
 
180
            make_json_field('power_pass', "Power password"),
 
181
        ],
 
182
    },
 
183
    {
 
184
        'name': 'ipmi',
 
185
        'description': 'IPMI',
 
186
        'fields': [
 
187
            make_json_field(
 
188
                'power_driver', "Power driver", field_type='choice',
 
189
                choices=IPMI_DRIVER_CHOICES, default=IPMI_DRIVER.LAN_2_0),
 
190
            make_json_field('power_address', "IP address"),
 
191
            make_json_field('power_user', "Power user"),
 
192
            make_json_field('power_pass', "Power password"),
 
193
            make_json_field(
 
194
                'mac_address',
 
195
                "MAC address - the IP is looked up with ARP and is used if "
 
196
                "IP address is empty. This is better when the BMC uses DHCP."),
 
197
        ],
 
198
    },
 
199
    {
 
200
        'name': 'moonshot',
 
201
        'description': 'iLO4 Moonshot Chassis',
 
202
        'fields': [
 
203
            make_json_field('power_address', "Power address"),
 
204
            make_json_field('power_user', "Power user"),
 
205
            make_json_field('power_pass', "Power password"),
 
206
            make_json_field('power_hwaddress', "Power hardware address"),
 
207
        ],
 
208
    },
 
209
    {
 
210
        'name': 'sm15k',
 
211
        'description': 'SeaMicro 15000',
 
212
        'fields': [
 
213
            make_json_field('system_id', "System ID"),
 
214
            make_json_field('power_address', "Power address"),
 
215
            make_json_field('power_user', "Power user"),
 
216
            make_json_field('power_pass', "Power password"),
 
217
            make_json_field(
 
218
                'power_control', "Power control type", field_type='choice',
 
219
                choices=SM15K_POWER_CONTROL_CHOICES, default='ipmi'),
 
220
        ],
 
221
    },
 
222
    {
 
223
        'name': 'amt',
 
224
        'description': 'Intel AMT',
 
225
        'fields': [
 
226
            make_json_field(
 
227
                'mac_address', "MAC Address", field_type='mac_address'),
 
228
            make_json_field('power_pass', "Power password"),
 
229
        ],
 
230
    },
 
231
    {
 
232
        'name': 'dli',
 
233
        'description': 'Digital Loggers, Inc. PDU',
 
234
        'fields': [
 
235
            make_json_field('system_id', "Outlet ID"),
 
236
            make_json_field('power_address', "Power address"),
 
237
            make_json_field('power_user', "Power user"),
 
238
            make_json_field('power_pass', "Power password"),
 
239
        ],
 
240
    },
 
241
]