1
# Copyright 2012-2014 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Define json schema for power parameters."""
6
from __future__ import (
16
"JSON_POWER_TYPE_PARAMETERS",
17
"JSON_POWER_TYPE_SCHEMA",
18
"POWER_TYPE_PARAMETER_FIELD_SCHEMA",
22
from jsonschema import validate
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 = ''
37
IPMI_DRIVER_CHOICES = [
38
[IPMI_DRIVER.LAN, "LAN [IPMI 1.5]"],
39
[IPMI_DRIVER.LAN_2_0, "LAN_2_0 [IPMI 2.0]"],
43
# Represent the Django choices format as JSON; an array of 2-item
45
CHOICE_FIELD_SCHEMA = {
48
'title': "Power type paramter field choice",
60
POWER_TYPE_PARAMETER_FIELD_SCHEMA = {
61
'title': "Power type parameter field",
76
'choices': CHOICE_FIELD_SCHEMA,
81
'required': ['field_type', 'label', 'required'],
85
# A basic JSON schema for what power type parameters should look like.
86
JSON_POWER_TYPE_SCHEMA = {
87
'title': "Power parameters set",
90
'title': "Power type parameters",
101
'items': POWER_TYPE_PARAMETER_FIELD_SCHEMA,
104
'required': ['name', 'description', 'fields'],
109
# Power control choices for sm15k power type
110
SM15K_POWER_CONTROL_CHOICES = [
112
["restapi", "REST API v0.9"],
113
["restapi2", "REST API v2.0"],
118
name, label, field_type=None, choices=None, default=None,
120
"""Helper function for building a JSON power type parameters field.
122
:param name: The name of the field.
124
:param label: The label to be presented to the user for this field.
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.
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
138
if field_type not in ('string', 'mac_address', 'choice'):
139
field_type = 'string'
142
validate(choices, CHOICE_FIELD_SCHEMA)
148
'required': required,
149
'field_type': field_type,
156
JSON_POWER_TYPE_PARAMETERS = [
158
'name': 'ether_wake',
159
'description': 'Wake-on-LAN',
162
'mac_address', "MAC Address", field_type='mac_address'),
167
'description': 'virsh (virtual systems)',
169
make_json_field('power_address', "Power address"),
170
make_json_field('power_id', "Power ID"),
175
'description': 'Sentry Switch CDU',
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"),
185
'description': 'IPMI',
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"),
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."),
201
'description': 'iLO4 Moonshot Chassis',
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"),
211
'description': 'SeaMicro 15000',
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"),
218
'power_control', "Power control type", field_type='choice',
219
choices=SM15K_POWER_CONTROL_CHOICES, default='ipmi'),
224
'description': 'Intel AMT',
227
'mac_address', "MAC Address", field_type='mac_address'),
228
make_json_field('power_pass', "Power password"),
233
'description': 'Digital Loggers, Inc. PDU',
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"),