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

« back to all changes in this revision

Viewing changes to ironic/drivers/modules/ilo/management.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:
15
15
iLO Management Interface
16
16
"""
17
17
 
18
 
from oslo.utils import importutils
 
18
from oslo_config import cfg
 
19
from oslo_utils import importutils
19
20
 
20
21
from ironic.common import boot_devices
21
22
from ironic.common import exception
22
23
from ironic.common.i18n import _
 
24
from ironic.common.i18n import _LI
 
25
from ironic.common.i18n import _LW
23
26
from ironic.conductor import task_manager
24
27
from ironic.drivers import base
25
28
from ironic.drivers.modules.ilo import common as ilo_common
28
31
 
29
32
LOG = logging.getLogger(__name__)
30
33
 
31
 
ilo_client = importutils.try_import('proliantutils.ilo.ribcl')
 
34
ilo_error = importutils.try_import('proliantutils.exception')
32
35
 
33
36
BOOT_DEVICE_MAPPING_TO_ILO = {boot_devices.PXE: 'NETWORK',
34
37
                               boot_devices.DISK: 'HDD',
35
38
                               boot_devices.CDROM: 'CDROM'
36
 
                             }
 
39
                              }
37
40
BOOT_DEVICE_ILO_TO_GENERIC = {v: k
38
41
                              for k, v in BOOT_DEVICE_MAPPING_TO_ILO.items()}
39
42
 
 
43
MANAGEMENT_PROPERTIES = ilo_common.REQUIRED_PROPERTIES.copy()
 
44
MANAGEMENT_PROPERTIES.update(ilo_common.CLEAN_PROPERTIES)
 
45
 
 
46
clean_step_opts = [
 
47
    cfg.IntOpt('clean_priority_reset_ilo',
 
48
               default=1,
 
49
               help='Priority for reset_ilo clean step.'),
 
50
    cfg.IntOpt('clean_priority_reset_bios_to_default',
 
51
               default=10,
 
52
               help='Priority for reset_bios_to_default clean step.'),
 
53
    cfg.IntOpt('clean_priority_reset_secure_boot_keys_to_default',
 
54
               default=20,
 
55
               help='Priority for reset_secure_boot_keys clean step. This '
 
56
                    'step will reset the secure boot keys to manufacturing '
 
57
                    ' defaults.'),
 
58
    cfg.IntOpt('clean_priority_clear_secure_boot_keys',
 
59
               default=0,
 
60
               help='Priority for clear_secure_boot_keys clean step. This '
 
61
                    'step is not enabled by default. It can be enabled to '
 
62
                    'to clear all secure boot keys enrolled with iLO.'),
 
63
    cfg.IntOpt('clean_priority_reset_ilo_credential',
 
64
               default=30,
 
65
               help='Priority for reset_ilo_credential clean step. This step '
 
66
                    'requires "ilo_change_password" parameter to be updated '
 
67
                    'in nodes\'s driver_info with the new password.'),
 
68
]
 
69
 
 
70
CONF = cfg.CONF
 
71
CONF.register_opts(clean_step_opts, group='ilo')
 
72
 
 
73
 
 
74
def _execute_ilo_clean_step(node, step, *args, **kwargs):
 
75
    """Executes a particular clean step.
 
76
 
 
77
    :param node: an Ironic node object.
 
78
    :param step: a clean step to be executed.
 
79
    :param args: The args to be passed to the clean step.
 
80
    :param kwargs: The kwargs to be passed to the clean step.
 
81
    :raises: NodeCleaningFailure, on failure to execute step.
 
82
    """
 
83
    ilo_object = ilo_common.get_ilo_object(node)
 
84
 
 
85
    try:
 
86
        clean_step = getattr(ilo_object, step)
 
87
    except AttributeError:
 
88
        # The specified clean step is not present in the proliantutils
 
89
        # package. Raise exception to update the proliantutils package
 
90
        # to newer version.
 
91
        raise exception.NodeCleaningFailure(_("Clean step '%s' not "
 
92
                "found. 'proliantutils' package needs to be updated.") % step)
 
93
    try:
 
94
        clean_step(*args, **kwargs)
 
95
    except ilo_error.IloCommandNotSupportedError:
 
96
        # This clean step is not supported on Gen8 and below servers.
 
97
        # Log the failure and continue with cleaning.
 
98
        LOG.warn(_LW("'%(step)s' clean step is not supported on node "
 
99
                     "%(uuid)s. Skipping the clean step."),
 
100
                     {'step': step, 'uuid': node.uuid})
 
101
    except ilo_error.IloError as ilo_exception:
 
102
        raise exception.NodeCleaningFailure(_("Clean step %(step)s failed "
 
103
                    "on node %(node)s with error: %(err)s") %
 
104
                    {'node': node.uuid, 'step': step, 'err': ilo_exception})
 
105
 
40
106
 
41
107
class IloManagement(base.ManagementInterface):
42
108
 
43
109
    def get_properties(self):
44
 
        return ilo_common.REQUIRED_PROPERTIES
 
110
        return MANAGEMENT_PROPERTIES
45
111
 
46
112
    def validate(self, task):
47
113
        """Check that 'driver_info' contains required ILO credentials.
96
162
                persistent = True
97
163
                next_boot = ilo_object.get_persistent_boot_device()
98
164
 
99
 
        except ilo_client.IloError as ilo_exception:
 
165
        except ilo_error.IloError as ilo_exception:
100
166
            operation = _("Get boot device")
101
167
            raise exception.IloOperationError(operation=operation,
102
168
                                              error=ilo_exception)
139
205
            else:
140
206
                ilo_object.update_persistent_boot([boot_device])
141
207
 
142
 
        except ilo_client.IloError as ilo_exception:
 
208
        except ilo_error.IloError as ilo_exception:
143
209
            operation = _("Setting %s as boot device") % device
144
210
            raise exception.IloOperationError(operation=operation,
145
211
                                              error=ilo_exception)
162
228
        ilo_common.update_ipmi_properties(task)
163
229
        ipmi_management = ipmitool.IPMIManagement()
164
230
        return ipmi_management.get_sensors_data(task)
 
231
 
 
232
    @base.clean_step(priority=CONF.ilo.clean_priority_reset_ilo)
 
233
    def reset_ilo(self, task):
 
234
        """Resets the iLO.
 
235
 
 
236
        :param task: a task from TaskManager.
 
237
        :raises: NodeCleaningFailure, on failure to execute step.
 
238
        """
 
239
        return _execute_ilo_clean_step(task.node, 'reset_ilo')
 
240
 
 
241
    @base.clean_step(priority=CONF.ilo.clean_priority_reset_ilo_credential)
 
242
    def reset_ilo_credential(self, task):
 
243
        """Resets the iLO password.
 
244
 
 
245
        :param task: a task from TaskManager.
 
246
        :raises: NodeCleaningFailure, on failure to execute step.
 
247
        """
 
248
        info = task.node.driver_info
 
249
        password = info.pop('ilo_change_password', None)
 
250
 
 
251
        if not password:
 
252
            LOG.info(_LI("Missing 'ilo_change_password' parameter in "
 
253
                         "driver_info. Clean step 'reset_ilo_credential' is "
 
254
                         "not performed on node %s."), task.node.uuid)
 
255
            return
 
256
 
 
257
        _execute_ilo_clean_step(task.node, 'reset_ilo_credential', password)
 
258
 
 
259
        info['ilo_password'] = password
 
260
        task.node.driver_info = info
 
261
        task.node.save()
 
262
 
 
263
    @base.clean_step(priority=CONF.ilo.clean_priority_reset_bios_to_default)
 
264
    def reset_bios_to_default(self, task):
 
265
        """Resets the BIOS settings to default values.
 
266
 
 
267
        Resets BIOS to default settings. This operation is currently supported
 
268
        only on HP Proliant Gen9 and above servers.
 
269
 
 
270
        :param task: a task from TaskManager.
 
271
        :raises: NodeCleaningFailure, on failure to execute step.
 
272
        """
 
273
        return _execute_ilo_clean_step(task.node, 'reset_bios_to_default')
 
274
 
 
275
    @base.clean_step(priority=CONF.ilo.
 
276
                     clean_priority_reset_secure_boot_keys_to_default)
 
277
    def reset_secure_boot_keys_to_default(self, task):
 
278
        """Reset secure boot keys to manufacturing defaults.
 
279
 
 
280
        Resets the secure boot keys to manufacturing defaults. This
 
281
        operation is supported only on HP Proliant Gen9 and above servers.
 
282
 
 
283
        :param task: a task from TaskManager.
 
284
        :raises: NodeCleaningFailure, on failure to execute step.
 
285
        """
 
286
        return _execute_ilo_clean_step(task.node, 'reset_secure_boot_keys')
 
287
 
 
288
    @base.clean_step(priority=CONF.ilo.clean_priority_clear_secure_boot_keys)
 
289
    def clear_secure_boot_keys(self, task):
 
290
        """Clear all secure boot keys.
 
291
 
 
292
        Clears all the secure boot keys. This operation is supported only
 
293
        on HP Proliant Gen9 and above servers.
 
294
 
 
295
        :param task: a task from TaskManager.
 
296
        :raises: NodeCleaningFailure, on failure to execute step.
 
297
        """
 
298
        return _execute_ilo_clean_step(task.node, 'clear_secure_boot_keys')