~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/drivers/modules/ilo/common.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-03-30 11:14:57 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20150330111457-kr4ju3guf22m4vbz
Tags: 2015.1~b3-0ubuntu1
* New upstream release.
  + d/control: 
    - Align with upstream dependencies.
    - Add dh-python to build-dependencies.
    - Add psmisc as a dependency. (LP: #1358820)
  + d/p/fix-requirements.patch: Rediffed.
  + d/ironic-conductor.init.in: Fixed typos in LSB headers,
    thanks to JJ Asghar. (LP: #1429962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import tempfile
20
20
 
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
23
24
 
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
31
33
from ironic.drivers import utils as driver_utils
32
34
from ironic.openstack.common import log as logging
33
35
 
34
 
ilo_client = importutils.try_import('proliantutils.ilo.ribcl')
 
36
ilo_client = importutils.try_import('proliantutils.ilo.client')
 
37
ilo_error = importutils.try_import('proliantutils.exception')
35
38
 
36
39
STANDARD_LICENSE = 1
37
40
ESSENTIALS_LICENSE = 2
66
69
}
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."),
70
73
}
71
74
CONSOLE_PROPERTIES = {
72
75
    'console_port': _("node's UDP port to connect to. Only required for "
73
76
                      "console access.")
74
77
}
 
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.")
 
86
}
 
87
CLEAN_PROPERTIES = {
 
88
    'ilo_change_password': _("new password for iLO. Required if the clean "
 
89
                             "step 'reset_ilo_credential' is enabled.")
 
90
}
75
91
 
76
92
COMMON_PROPERTIES = REQUIRED_PROPERTIES.copy()
77
93
COMMON_PROPERTIES.update(OPTIONAL_PROPERTIES)
125
141
            except ValueError:
126
142
                not_integers.append(param)
127
143
 
 
144
    for param in INSPECT_PROPERTIES:
 
145
        value = info.get(param)
 
146
        if value:
 
147
            d_info[param] = value
 
148
 
128
149
    if not_integers:
129
150
        raise exception.InvalidParameterValue(_(
130
151
                "The following iLO parameters from the node's driver_info "
173
194
    ilo_object = get_ilo_object(node)
174
195
    try:
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))
179
200
 
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)
304
325
 
305
326
    try:
306
327
        p_boot_mode = ilo_object.get_pending_boot_mode()
307
 
    except ilo_client.IloCommandNotSupportedError:
 
328
    except ilo_error.IloCommandNotSupportedError:
308
329
        p_boot_mode = DEFAULT_BOOT_MODE
309
330
 
310
331
    if BOOT_MODE_ILO_TO_GENERIC[p_boot_mode.lower()] == boot_mode:
315
336
    try:
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})
325
346
 
326
347
 
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.
329
350
 
 
351
    This method updates the 'boot_mode' capability in node's 'capabilities'
 
352
    property if not set.
 
353
    It also sets the boot mode to be used in the next boot.
 
354
 
330
355
    :param task: Task object.
331
 
 
 
356
    :raises: IloOperationError if setting boot mode failed.
332
357
    """
 
358
    node = task.node
 
359
 
 
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)
 
365
        return
 
366
 
333
367
    ilo_object = get_ilo_object(task.node)
334
368
 
335
369
    try:
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
346
380
 
347
381
    driver_utils.rm_node_capability(task, 'boot_mode')
357
391
    the required parameters to it via virtual floppy image.
358
392
 
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
 
395
        of below:
 
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>;
 
401
        * An HTTP(S) URL.
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)
377
414
 
378
 
    boot_iso_temp_url = None
379
 
    scheme, boot_iso_ref = boot_iso.split(':')
380
 
    if scheme == 'swift':
 
415
    boot_iso_url = None
 
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,
386
423
                timeout)
387
 
    elif scheme == 'glance':
388
 
        glance_uuid = boot_iso_ref
389
 
        boot_iso_temp_url = images.get_temp_url_for_glance_image(task.context,
390
 
                glance_uuid)
 
424
    elif service_utils.is_glance_image(boot_iso):
 
425
        boot_iso_url = images.get_temp_url_for_glance_image(task.context,
 
426
                boot_iso)
391
427
 
392
 
    attach_vmedia(task.node, 'CDROM', boot_iso_temp_url)
 
428
    attach_vmedia(task.node, 'CDROM', boot_iso_url or boot_iso)
393
429
 
394
430
 
395
431
def cleanup_vmedia_boot(task):
418
454
    for device in ('FLOPPY', 'CDROM'):
419
455
        try:
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})
 
462
 
 
463
 
 
464
def get_secure_boot_mode(task):
 
465
    """Retrieves current enabled state of UEFI secure boot on the node
 
466
 
 
467
    Returns the current enabled state of UEFI secure boot on the node.
 
468
 
 
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
 
474
              on the node.
 
475
    """
 
476
 
 
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)
 
480
 
 
481
    try:
 
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()
 
485
 
 
486
    except ilo_error.IloCommandNotSupportedError as ilo_exception:
 
487
        raise exception.IloOperationNotSupported(operation=operation,
 
488
                                                 error=ilo_exception)
 
489
    except ilo_error.IloError as ilo_exception:
 
490
        raise exception.IloOperationError(operation=operation,
 
491
                                          error=ilo_exception)
 
492
 
 
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
 
496
 
 
497
 
 
498
def set_secure_boot_mode(task, flag):
 
499
    """Enable or disable UEFI Secure Boot for the next boot
 
500
 
 
501
    Enable or disable UEFI Secure Boot for the next boot
 
502
 
 
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.
 
508
    """
 
509
 
 
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)
 
513
 
 
514
    try:
 
515
        ilo_object.set_secure_boot_mode(flag)
 
516
        LOG.debug(operation)
 
517
 
 
518
    except ilo_error.IloCommandNotSupportedError as ilo_exception:
 
519
        raise exception.IloOperationNotSupported(operation=operation,
 
520
                                                 error=ilo_exception)
 
521
 
 
522
    except ilo_error.IloError as ilo_exception:
 
523
        raise exception.IloOperationError(operation=operation,
 
524
                                          error=ilo_exception)