blob: f47f62922b0150ccf2cee07ef8c63b1c8ee3310c [file] [log] [blame]
Oleksiy Petrenkoa5eb0602018-07-26 15:12:25 +03001from ironicv1.common import send
2try:
3 from urllib.parse import urlencode
4except ImportError:
5 from urllib import urlencode
6
7
8# NOTE(opetrenko): Each driver require different driver_info or do not require
9# it at all. To make things work, please use driver_get_properties with driver
10# you want to use to get list of required arguments for driver_info.
11# For more take a look at Baremetal API Reference
12@send('post')
13def node_create(driver, **kwargs):
14 url = '/nodes'
15 json = {
16 'driver': driver,
17 }
18 json.update(kwargs)
19 return url, {'json': json}
20
21
22@send('get')
23def node_list(**kwargs):
24 url = '/nodes?{}'.format(urlencode(kwargs))
25 return url, {}
26
27
28@send('get')
29def node_get_details(node_ident, **kwargs):
30 url = '/nodes/{}?{}'.format(node_ident, urlencode(kwargs))
31 return url, {}
32
33
34@send('patch')
35def node_update(node_ident, properties, **kwargs):
36 url = '/nodes/{}'.format(node_ident)
37 return url, {'json': properties}
38
39
40@send('delete')
41def node_delete(node_ident, **kwargs):
42 url = '/nodes/{}'.format(node_ident)
43 return url, {}
44
45
46# NOTE: Node management API
47@send('get')
48def node_validate(node_ident, **kwargs):
49 url = '/nodes/{}/validate'.format(node_ident)
50 return url, {}
51
52
53@send('put')
54def node_maintenance_flag_set(node_ident, **kwargs):
55 url = '/nodes/{}/maintenance'.format(node_ident)
56 json = {}
57 if 'reason' in kwargs:
58 json['reason'] = kwargs['reason']
59 return url, {'json': json}
60
61
62@send('delete')
63def node_maintenance_flag_clear(node_ident, **kwargs):
64 url = '/nodes/{}/maintenance'.format(node_ident)
65 return url, {}
66
67
68@send('put')
69def node_boot_device_set(node_ident, boot_device, **kwargs):
70 url = '/nodes/{}/management/boot_device'.format(node_ident)
71 json = {
72 'boot_device': boot_device,
73 }
74 json.update(kwargs)
75 return url, {'json': json}
76
77
78@send('get')
79def node_boot_device_get(node_ident, **kwargs):
80 url = '/nodes/{}/management/boot_device'.format(node_ident)
81 return url, {}
82
83
84@send('get')
85def node_boot_device_get_supported(node_ident, **kwargs):
86 url = '/nodes/{}/management/boot_device/supported'.format(node_ident)
87 return url, {}
88
89
90@send('put')
91def node_inject_nmi(node_ident, **kwargs):
92 url = '/nodes/{}/management/inject_nmi'.format(node_ident)
93 return url, {'json': {}}
94
95
96@send('get')
97def node_state_summary(node_ident, **kwargs):
98 url = '/nodes/{}/states'.format(node_ident)
99 return url, {}
100
101
102@send('put')
103def node_power_state_change(node_ident, target, **kwargs):
104 url = '/nodes/{}/states/power'.format(node_ident)
105 json = {
106 'target': target,
107 }
108 json.update(kwargs)
109 return url, {'json': json}
110
111
112@send('put')
113def node_provision_state_change(node_ident, target, **kwargs):
114 url = '/nodes/{}/states/provision'.format(node_ident)
115 json = {
116 'target': target,
117 }
118 json.update(kwargs)
119 return url, {'json': json}
120
121
122@send('put')
123def node_raid_config_set(node_ident, target_raid_config, **kwargs):
124 url = 'nodes/{}/states/raid'.format(node_ident)
125 return url, {'json': target_raid_config}
126
127
128@send('get')
129def node_console_get(node_ident, **kwargs):
130 url = '/nodes/{}/states/console'.format(node_ident)
131 return url, {}
132
133
134@send('put')
135def node_console_start_stop(node_ident, enabled, **kwargs):
136 url = '/nodes/{}/states/console'.format(node_ident)
137 json = {
138 'enabled': enabled,
139 }
140 return url, {'json': json}
141
142
143# NOTE: Node Traits API
144@send('get')
145def node_traits_list(node_ident, **kwargs):
146 url = '/nodes/{}/traits'.format(node_ident)
147 return url, {}
148
149
150@send('put')
151def node_traits_set(node_ident, traits, **kwargs):
152 url = '/nodes/{}/traits'.format(node_ident)
153 json = {
154 'traits': traits,
155 }
156 return url, {'json': json}
157
158
159@send('put')
160def node_traits_set_single(node_ident, trait, **kwargs):
161 url = '/nodes/{}/traits/{}'.format(node_ident, trait)
162 return url, {'json': {}}
163
164
165@send('delete')
166def node_traits_delete(node_ident, **kwargs):
167 url = '/nodes/{}/traits'.format(node_ident)
168 return url, {}
169
170
171@send('delete')
172def node_traits_delete_single(node_ident, trait, **kwargs):
173 url = '/nodes/{}/traits/{}'.format(node_ident, trait)
174 return url, {}
175
176
177# NOTE: VIFs API
178@send('get')
179def node_vif_list(node_ident, **kwargs):
180 url = '/nodes/{}/vifs'.format(node_ident)
181 return url, {}
182
183
184@send('post')
185def node_vif_attach(node_ident, id, **kwargs):
186 url = '/nodes/{}/vifs'.format(node_ident)
187 json = {
188 'id': id,
189 }
190 return url, {'json': json}
191
192
193@send('delete')
194def node_vif_detach(node_ident, vif_ident, **kwargs):
195 url = '/nodes/{}/vifs/{}'.format(node_ident, vif_ident)
196 return url, {}