-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathserver_hardware.py
405 lines (325 loc) · 14.6 KB
/
server_hardware.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# -*- coding: utf-8 -*-
###
# (C) Copyright [2021] Hewlett Packard Enterprise Development LP
#
# 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.
###
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
from hpeOneView.resources.resource import (Resource, ResourceUtilizationMixin,
ResourcePatchMixin, ensure_resource_client)
class ServerHardware(ResourcePatchMixin, ResourceUtilizationMixin, Resource):
"""
The server hardware resource is a representation of a physical server.
The server hardware resource provides methods for server management tasks such
as applying a profile, importing a server and managing an iLO.
"""
URI = '/rest/server-hardware'
def __init__(self, connection, data=None):
super(ServerHardware, self).__init__(connection, data)
def add(self, information, timeout=-1):
"""
Adds a rack-mount server for management by the appliance. This API initiates the asynchronous addition of
supported server models.
Note: Servers in an enclosure are added by adding the enclosure resource. This is
only supported on appliances that support rack-mounted servers.
Args:
information (dict): Object to create
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
dict: Created rack-mount server.
"""
return self.create(information, timeout=timeout)
def add_multiple_servers(self, information, timeout=-1):
"""
Adds multiple rack-mount servers for management by the appliance. This API initiates the asynchronous addition of
supported server models.
Note: Servers in an enclosure are added by adding the enclosure resource. This is
only supported on appliances that support rack-mounted servers.
This is only supported for api version 600
Args:
information (dict): Objects to create
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
dict: Created rack-mount servers.
"""
uri = "{}/discovery".format(self.URI)
return self.create(information, uri=uri, timeout=timeout)
def remove(self, force=False, timeout=-1):
"""
Removes the rackserver with the specified URI.
Note: This operation is only supported on appliances that support rack-mounted servers.
Args:
force (bool):
If set to true, the operation completes despite any problems with
network connectivity or errors on the resource itself. The default is false.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
bool: Indicates whether the resource was successfully removed.
"""
return self.delete(force=force, timeout=timeout)
@ensure_resource_client
def get_bios(self):
"""
Gets the list of BIOS/UEFI values currently set on the physical server.
Returns:
dict: Dictionary of BIOS/UEFI values.
"""
uri = "{}/bios".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def get_environmental_configuration(self):
"""
Gets the settings that describe the environmental configuration (supported feature set, calibrated minimum and
maximum power, location and dimensions, etc.) of the server hardware resource.
Returns:
dict: Environmental configuration settings.
"""
uri = "{}/environmentalConfiguration".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def update_environmental_configuration(self, configuration, timeout=-1):
"""
Sets the calibrated max power of an unmanaged or unsupported server hardware resource.
Args:
configuration (dict): Environmental configuration.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
dict: Environmental configuration settings.
"""
uri = "{}/environmentalConfiguration".format(self.data["uri"])
return self._helper.update(configuration, uri, timeout=timeout)
@ensure_resource_client
def get_ilo_sso_url(self, ip=None):
"""
Retrieves the URL to launch a Single Sign-On (SSO) session for the iLO web interface. If the server hardware is
unsupported, the resulting URL will not use SSO and the iLO web interface will prompt for credentials.
This is not supported on G7/iLO3 or earlier servers.
Args:
ip: IP address or host name of the server's iLO management processor
Returns:
URL
"""
uri = "{}/iloSsoUrl".format(self.data["uri"])
if ip:
uri = "{}?ip={}".format(uri, ip)
return self._helper.do_get(uri)
def get_all_firmwares(self, filter='', start=0, count=-1, query='', sort=''):
"""
Gets a list of firmware inventory across all servers. To filter the returned data, specify a filter
expression to select a particular server model, component name, and/or component firmware version.
Note:
This method is available for API version 300 or later.
Args:
start:
The first item to return, using 0-based indexing.
If not specified, the default is 0 - start with the first available item.
count:
The number of resources to return. A count of -1 requests all items.
The actual number of items in the response might differ from the requested
count if the sum of start and count exceeds the total number of items.
filter (list or str):
A general filter/query string to narrow the list of items returned. The
default is no filter; all resources are returned.
query:
A general query string to narrow the list of resources returned. The default is no query; all resources
are returned.
sort:
The sort order of the returned data set. By default, the sort order is based
on create time with the oldest entry first.
Returns:
list: List of firmware inventory.
"""
uri = self.URI + "/*/firmware"
return self._helper.get_all(start, count, filter, query, sort, '', '', uri)
@ensure_resource_client
def get_firmware(self):
"""
Get the firmware inventory of a server.
Note:
This method is available for API version 300 or later.
Returns:
dict: Server Hardware firmware.
"""
uri = "{}/firmware".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def get_java_remote_console_url(self, ip=None):
"""
Generates a Single Sign-On (SSO) session for the iLO Java Applet console and returns the URL to launch it.
If the server hardware is unmanaged or unsupported, the resulting URL will not use SSO and the iLO Java Applet
will prompt for credentials. This is not supported on G7/iLO3 or earlier servers.
Args:
ip: IP address or host name of the server's iLO management processor
Returns:
URL
"""
uri = "{}/javaRemoteConsoleUrl".format(self.data["uri"])
if ip:
uri = "{}?ip={}".format(uri, ip)
return self._helper.do_get(uri)
@ensure_resource_client
def update_mp_firware_version(self, timeout=-1):
"""
Updates the iLO firmware on a physical server to a minimum ILO firmware version required by OneView to
manage the server.
Args:
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
Resource
"""
uri = "{}/mpFirmwareVersion".format(self.data["uri"])
return self._helper.do_put(uri, None, timeout, None)
@ensure_resource_client
def update_power_state(self, configuration, timeout=-1):
"""
Refreshes the server hardware to fix configuration issues.
Args:
configuration (dict): Power state configuration.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
Resource
"""
uri = "{}/powerState".format(self.data["uri"])
return self._helper.update(configuration, uri, timeout=timeout)
@ensure_resource_client
def refresh_state(self, configuration, timeout=-1):
"""
Refreshes the server hardware to fix configuration issues.
Args:
configuration: Refresh state configuration.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
Resource
"""
uri = "{}/refreshState".format(self.data["uri"])
return self._helper.update(configuration, uri=uri, timeout=timeout)
@ensure_resource_client
def get_remote_console_url(self, ip=None, consoleType=None):
"""
Generates a Single Sign-On (SSO) session for the iLO Integrated Remote Console Application (IRC) and returns the
URL to launch it. If the server hardware is unmanaged or unsupported, the resulting URL will not use SSO and the
IRC application will prompt for credentials. Use of this URL requires a previous installation of the iLO IRC and
is supported only on Windows clients.
Args:
ip: IP address or host name of the server's iLO management processor
consoleType: Type of console requested
Returns:
URL
"""
uri = "{}/remoteConsoleUrl".format(self.data["uri"])
if ip:
uri = "{}?ip={}".format(uri, ip)
elif consoleType:
uri = "{}?consoleType={}".format(uri, consoleType)
return self._helper.do_get(uri)
@ensure_resource_client
def get_physical_server_hardware(self):
"""
Information describing an 'SDX' partition including a list of physical server blades represented by a server
hardware. Used with SDX enclosures only.
Returns:
Resource
"""
uri = "{}/physicalServerHardware".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def get_local_storage(self, ip=None):
"""
Gets the updated version 2 local storage resource for the server, including storage controllers,
drives, and volumes.
Args:
ip: IP address or host name of the server's iLO management processor
Returns:
Resource
"""
uri = "{}/localStorageV2".format(self.data["uri"])
if ip:
uri = "{}?ip={}".format(uri, ip)
return self._helper.do_get(uri)
@ensure_resource_client
def get_chassis(self):
"""
Gets the list of chassis values currently set on the physical server.
Returns:
dict: Dictionary of chassis values.
"""
uri = "{}/chassis".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def get_firmware_inventory(self):
"""
Gets the list of firmwareInventory values currently set on the physical server.
Returns:
dict: Dictionary of firmwareInventory values.
"""
uri = "{}/firmwareInventory".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def get_network_adapters(self):
"""
Gets the list of networkAdapters values currently set on the physical server.
Returns:
dict: Dictionary of networkAdapters values.
"""
uri = "{}/networkAdapters".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def get_power_supplies(self):
"""
Gets the list of powerSupplies values currently set on the physical server.
Returns:
dict: Dictionary of powerSupplies values.
"""
uri = "{}/powerSupplies".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def get_processors(self):
"""
Gets the list of processors values currently set on the physical server.
Returns:
dict: Dictionary of processors values.
"""
uri = "{}/processors".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def get_software_inventory(self):
"""
Gets the list of softwareInventory values currently set on the physical server.
Returns:
dict: Dictionary of softwareInventory values.
"""
uri = "{}/softwareInventory".format(self.data["uri"])
return self._helper.do_get(uri)
@ensure_resource_client
def get_thermal(self):
"""
Gets the list of thermal values currently set on the physical server.
Returns:
dict: Dictionary of thermal values.
"""
uri = "{}/thermal".format(self.data["uri"])
return self._helper.do_get(uri)