21
from oslo.utils import importutils
22
21
from oslo_config import cfg
22
from oslo_utils import importutils
23
import six.moves.urllib.parse as urlparse
24
25
from ironic.common import exception
26
from ironic.common.glance_service import service_utils
25
27
from ironic.common.i18n import _
26
28
from ironic.common.i18n import _LE
27
29
from ironic.common.i18n import _LI
67
70
OPTIONAL_PROPERTIES = {
68
71
'client_port': _("port to be used for iLO operations. Optional."),
69
'client_timeout': _("timeout (in seconds) for iLO operations. Optional.")
72
'client_timeout': _("timeout (in seconds) for iLO operations. Optional."),
71
74
CONSOLE_PROPERTIES = {
72
75
'console_port': _("node's UDP port to connect to. Only required for "
78
INSPECT_PROPERTIES = {
79
'inspect_ports': _("Comma-separated values of ethernet ports "
80
"to be identified for creating node "
81
"ports. Valid values may be "
82
"inspect_ports = '1,2,...n' or "
83
"inspect_ports = 'all' or "
84
"inspect_ports = 'none'. "
85
"Required only for inspection.")
88
'ilo_change_password': _("new password for iLO. Required if the clean "
89
"step 'reset_ilo_credential' is enabled.")
76
92
COMMON_PROPERTIES = REQUIRED_PROPERTIES.copy()
77
93
COMMON_PROPERTIES.update(OPTIONAL_PROPERTIES)
173
194
ilo_object = get_ilo_object(node)
175
196
license_info = ilo_object.get_all_licenses()
176
except ilo_client.IloError as ilo_exception:
197
except ilo_error.IloError as ilo_exception:
177
198
raise exception.IloOperationError(operation=_('iLO license check'),
178
199
error=str(ilo_exception))
285
306
ilo_object.insert_virtual_media(url, device=device)
286
307
ilo_object.set_vm_status(device=device, boot_option='CONNECT',
287
308
write_protect='YES')
288
except ilo_client.IloError as ilo_exception:
309
except ilo_error.IloError as ilo_exception:
289
310
operation = _("Inserting virtual media %s") % device
290
311
raise exception.IloOperationError(operation=operation,
291
312
error=ilo_exception)
316
337
ilo_object.set_pending_boot_mode(
317
338
BOOT_MODE_GENERIC_TO_ILO[boot_mode].upper())
318
except ilo_client.IloError as ilo_exception:
339
except ilo_error.IloError as ilo_exception:
319
340
operation = _("Setting %s as boot mode") % boot_mode
320
341
raise exception.IloOperationError(operation=operation,
321
342
error=ilo_exception)
324
345
{'uuid': node.uuid, 'boot_mode': boot_mode})
327
def update_boot_mode_capability(task):
348
def update_boot_mode(task):
328
349
"""Update 'boot_mode' capability value of node's 'capabilities' property.
351
This method updates the 'boot_mode' capability in node's 'capabilities'
353
It also sets the boot mode to be used in the next boot.
330
355
:param task: Task object.
356
:raises: IloOperationError if setting boot mode failed.
360
boot_mode = driver_utils.get_node_capability(node, 'boot_mode')
361
if boot_mode is not None:
362
LOG.debug("Node %(uuid)s boot mode is being set to %(boot_mode)s",
363
{'uuid': node.uuid, 'boot_mode': boot_mode})
364
set_boot_mode(node, boot_mode)
333
367
ilo_object = get_ilo_object(task.node)
341
375
# and if it fails then we fall back to BIOS boot mode.
342
376
ilo_object.set_pending_boot_mode('UEFI')
343
377
p_boot_mode = 'UEFI'
344
except ilo_client.IloCommandNotSupportedError:
378
except ilo_error.IloCommandNotSupportedError:
345
379
p_boot_mode = DEFAULT_BOOT_MODE
347
381
driver_utils.rm_node_capability(task, 'boot_mode')
357
391
the required parameters to it via virtual floppy image.
359
393
:param task: a TaskManager instance containing the node to act on.
360
:param boot_iso: a bootable ISO image to attach to. The boot iso
361
should be present in either Glance or in Swift. If present in
362
Glance, it should be of format 'glance:<glance-image-uuid>'.
363
If present in Swift, it should be of format 'swift:<object-name>'.
364
It is assumed that object is present in CONF.ilo.swift_ilo_container.
394
:param boot_iso: a bootable ISO image to attach to. Should be either
396
* A Swift object - It should be of format 'swift:<object-name>'.
397
It is assumed that the image object is present in
398
CONF.ilo.swift_ilo_container;
399
* A Glance image - It should be format 'glance://<glance-image-uuid>'
400
or just <glance-image-uuid>;
365
402
:param parameters: the parameters to pass in the virtual floppy image
366
403
in a dictionary. This is optional.
367
404
:raises: ImageCreationFailed, if it failed while creating the floppy image.
375
412
floppy_image_temp_url = _prepare_floppy_image(task, parameters)
376
413
attach_vmedia(task.node, 'FLOPPY', floppy_image_temp_url)
378
boot_iso_temp_url = None
379
scheme, boot_iso_ref = boot_iso.split(':')
380
if scheme == 'swift':
416
parsed_ref = urlparse.urlparse(boot_iso)
417
if parsed_ref.scheme == 'swift':
381
418
swift_api = swift.SwiftAPI()
382
419
container = CONF.ilo.swift_ilo_container
383
object_name = boot_iso_ref
420
object_name = parsed_ref.path
384
421
timeout = CONF.ilo.swift_object_expiry_timeout
385
boot_iso_temp_url = swift_api.get_temp_url(container, object_name,
422
boot_iso_url = swift_api.get_temp_url(container, object_name,
387
elif scheme == 'glance':
388
glance_uuid = boot_iso_ref
389
boot_iso_temp_url = images.get_temp_url_for_glance_image(task.context,
424
elif service_utils.is_glance_image(boot_iso):
425
boot_iso_url = images.get_temp_url_for_glance_image(task.context,
392
attach_vmedia(task.node, 'CDROM', boot_iso_temp_url)
428
attach_vmedia(task.node, 'CDROM', boot_iso_url or boot_iso)
395
431
def cleanup_vmedia_boot(task):
418
454
for device in ('FLOPPY', 'CDROM'):
420
456
ilo_object.eject_virtual_media(device)
421
except ilo_client.IloError as ilo_exception:
457
except ilo_error.IloError as ilo_exception:
422
458
LOG.exception(_LE("Error while ejecting virtual media %(device)s "
423
459
"from node %(uuid)s. Error: %(error)s"),
424
460
{'device': device, 'uuid': task.node.uuid,
425
461
'error': ilo_exception})
464
def get_secure_boot_mode(task):
465
"""Retrieves current enabled state of UEFI secure boot on the node
467
Returns the current enabled state of UEFI secure boot on the node.
469
:param task: a task from TaskManager.
470
:raises: MissingParameterValue if a required iLO parameter is missing.
471
:raises: IloOperationError on an error from IloClient library.
472
:raises: IloOperationNotSupported if UEFI secure boot is not supported.
473
:returns: Boolean value indicating current state of UEFI secure boot
477
operation = _("Get secure boot mode for node %s.") % task.node.uuid
478
secure_boot_state = False
479
ilo_object = get_ilo_object(task.node)
482
current_boot_mode = ilo_object.get_current_boot_mode()
483
if current_boot_mode == 'UEFI':
484
secure_boot_state = ilo_object.get_secure_boot_mode()
486
except ilo_error.IloCommandNotSupportedError as ilo_exception:
487
raise exception.IloOperationNotSupported(operation=operation,
489
except ilo_error.IloError as ilo_exception:
490
raise exception.IloOperationError(operation=operation,
493
LOG.debug("Get secure boot mode for node %(node)s returned %(value)s",
494
{'value': secure_boot_state, 'node': task.node.uuid})
495
return secure_boot_state
498
def set_secure_boot_mode(task, flag):
499
"""Enable or disable UEFI Secure Boot for the next boot
501
Enable or disable UEFI Secure Boot for the next boot
503
:param task: a task from TaskManager.
504
:param flag: Boolean value. True if the secure boot to be
505
enabled in next boot.
506
:raises: IloOperationError on an error from IloClient library.
507
:raises: IloOperationNotSupported if UEFI secure boot is not supported.
510
operation = (_("Setting secure boot to %(flag)s for node %(node)s.") %
511
{'flag': flag, 'node': task.node.uuid})
512
ilo_object = get_ilo_object(task.node)
515
ilo_object.set_secure_boot_mode(flag)
518
except ilo_error.IloCommandNotSupportedError as ilo_exception:
519
raise exception.IloOperationNotSupported(operation=operation,
522
except ilo_error.IloError as ilo_exception:
523
raise exception.IloOperationError(operation=operation,