Beispiel #1
0
def _attach_virtual_cd(node, bootable_iso_filename):
    """Attaches the given url as virtual media on the node.

    :param node: an ironic node object.
    :param bootable_iso_filename: a bootable ISO image to attach to.
        The iso file should be present in NFS/CIFS server.
    :raises: IRMCOperationError if attaching virtual media failed.
    """
    try:
        irmc_client = irmc_common.get_irmc_client(node)

        cd_set_params = scci.get_virtual_cd_set_params_cmd(
            CONF.irmc.remote_image_server, CONF.irmc.remote_image_user_domain,
            scci.get_share_type(CONF.irmc.remote_image_share_type),
            CONF.irmc.remote_image_share_name, bootable_iso_filename,
            CONF.irmc.remote_image_user_name,
            CONF.irmc.remote_image_user_password)

        irmc_client(cd_set_params, async=False)
        irmc_client(scci.MOUNT_CD, async=False)

    except scci.SCCIClientError as irmc_exception:
        LOG.exception(
            "Error while inserting virtual cdrom "
            "into node %(uuid)s. Error: %(error)s", {
                'uuid': node.uuid,
                'error': irmc_exception
            })
        operation = _("Inserting virtual cdrom")
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    LOG.info("Attached virtual cdrom successfully" " for node %s", node.uuid)
Beispiel #2
0
def _attach_virtual_fd(node, floppy_image_filename):
    """Attaches virtual floppy on the node.

    :param node: an ironic node object.
    :raises: IRMCOperationError if insert virtual floppy failed.
    """
    try:
        irmc_client = irmc_common.get_irmc_client(node)

        fd_set_params = scci.get_virtual_fd_set_params_cmd(
            CONF.irmc.remote_image_server, CONF.irmc.remote_image_user_domain,
            scci.get_share_type(CONF.irmc.remote_image_share_type),
            CONF.irmc.remote_image_share_name, floppy_image_filename,
            CONF.irmc.remote_image_user_name,
            CONF.irmc.remote_image_user_password)

        irmc_client(fd_set_params, async=False)
        irmc_client(scci.MOUNT_FD, async=False)

    except scci.SCCIClientError as irmc_exception:
        LOG.exception(
            "Error while inserting virtual floppy "
            "into node %(uuid)s. Error: %(error)s", {
                'uuid': node.uuid,
                'error': irmc_exception
            })
        operation = _("Inserting virtual floppy")
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    LOG.info("Attached virtual floppy successfully" " for node %s", node.uuid)
Beispiel #3
0
def _attach_virtual_fd(node, floppy_image_filename):
    """Attaches virtual floppy on the node.

    :param node: an ironic node object.
    :raises: IRMCOperationError if insert virtual floppy failed.
    """
    try:
        irmc_client = irmc_common.get_irmc_client(node)

        fd_set_params = scci.get_virtual_fd_set_params_cmd(
            CONF.irmc.remote_image_server,
            CONF.irmc.remote_image_user_domain,
            scci.get_share_type(CONF.irmc.remote_image_share_type),
            CONF.irmc.remote_image_share_name,
            floppy_image_filename,
            CONF.irmc.remote_image_user_name,
            CONF.irmc.remote_image_user_password)

        irmc_client(fd_set_params, do_async=False)
        irmc_client(scci.MOUNT_FD, do_async=False)

    except scci.SCCIClientError as irmc_exception:
        LOG.exception("Error while inserting virtual floppy "
                      "into node %(uuid)s. Error: %(error)s",
                      {'uuid': node.uuid, 'error': irmc_exception})
        operation = _("Inserting virtual floppy")
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    LOG.info("Attached virtual floppy successfully"
             " for node %s", node.uuid)
Beispiel #4
0
def _attach_virtual_cd(node, bootable_iso_filename):
    """Attaches the given url as virtual media on the node.

    :param node: an ironic node object.
    :param bootable_iso_filename: a bootable ISO image to attach to.
        The iso file should be present in NFS/CIFS server.
    :raises: IRMCOperationError if attaching virtual media failed.
    """
    try:
        irmc_client = irmc_common.get_irmc_client(node)

        cd_set_params = scci.get_virtual_cd_set_params_cmd(
            CONF.irmc.remote_image_server,
            CONF.irmc.remote_image_user_domain,
            scci.get_share_type(CONF.irmc.remote_image_share_type),
            CONF.irmc.remote_image_share_name,
            bootable_iso_filename,
            CONF.irmc.remote_image_user_name,
            CONF.irmc.remote_image_user_password)

        irmc_client(cd_set_params, do_async=False)
        irmc_client(scci.MOUNT_CD, do_async=False)

    except scci.SCCIClientError as irmc_exception:
        LOG.exception("Error while inserting virtual cdrom "
                      "into node %(uuid)s. Error: %(error)s",
                      {'uuid': node.uuid, 'error': irmc_exception})
        operation = _("Inserting virtual cdrom")
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    LOG.info("Attached virtual cdrom successfully"
             " for node %s", node.uuid)
Beispiel #5
0
def _set_power_state(task, target_state):
    """Turns the server power on/off or do a reboot.

    :param task: a TaskManager instance containing the node to act on.
    :param target_state: target state of the node.
    :raises: InvalidParameterValue if an invalid power state was specified.
    :raises: MissingParameterValue if some mandatory information
        is missing on the node
    :raises: IRMCOperationError on an error from SCCI
    """

    node = task.node
    irmc_client = irmc_common.get_irmc_client(node)

    try:
        irmc_client(STATES_MAP[target_state])

    except KeyError:
        msg = _("_set_power_state called with invalid power state "
                "'%s'") % target_state
        raise exception.InvalidParameterValue(msg)

    except scci.SCCIClientError as irmc_exception:
        LOG.error(
            _LE("iRMC set_power_state failed to set state to %(tstate)s "
                " for node %(node_id)s with error: %(error)s"), {
                    'tstate': target_state,
                    'node_id': node.uuid,
                    'error': irmc_exception
                })
        operation = _('iRMC set_power_state')
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)
Beispiel #6
0
def _set_power_state(task, target_state):
    """Turns the server power on/off or do a reboot.

    :param task: a TaskManager instance containing the node to act on.
    :param target_state: target state of the node.
    :raises: InvalidParameterValue if an invalid power state was specified.
    :raises: MissingParameterValue if some mandatory information
        is missing on the node
    :raises: IRMCOperationError on an error from SCCI
    """

    node = task.node
    irmc_client = irmc_common.get_irmc_client(node)

    if target_state in (states.POWER_ON, states.REBOOT):
        _attach_boot_iso_if_needed(task)

    try:
        irmc_client(STATES_MAP[target_state])

    except KeyError:
        msg = _("_set_power_state called with invalid power state "
                "'%s'") % target_state
        raise exception.InvalidParameterValue(msg)

    except scci.SCCIClientError as irmc_exception:
        LOG.error(_LE("iRMC set_power_state failed to set state to %(tstate)s "
                      " for node %(node_id)s with error: %(error)s"),
                  {'tstate': target_state, 'node_id': node.uuid,
                   'error': irmc_exception})
        operation = _('iRMC set_power_state')
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)
Beispiel #7
0
def _set_power_state(task, target_state, timeout=None):
    """Turn the server power on/off or do a reboot.

    :param task: a TaskManager instance containing the node to act on.
    :param target_state: target state of the node.
    :param timeout: timeout (in seconds) positive integer (> 0) for any
      power state. ``None`` indicates default timeout.
    :raises: InvalidParameterValue if an invalid power state was specified.
    :raises: MissingParameterValue if some mandatory information
      is missing on the node
    :raises: IRMCOperationError on an error from SCCI or SNMP
    """
    node = task.node
    irmc_client = irmc_common.get_irmc_client(node)

    if target_state in (states.POWER_ON, states.REBOOT, states.SOFT_REBOOT):
        irmc_boot.attach_boot_iso_if_needed(task)

    try:
        irmc_client(STATES_MAP[target_state])

    except KeyError:
        msg = _("_set_power_state called with invalid power state "
                "'%s'") % target_state
        raise exception.InvalidParameterValue(msg)

    except scci.SCCIClientError as irmc_exception:
        LOG.error(
            "iRMC set_power_state failed to set state to %(tstate)s "
            " for node %(node_id)s with error: %(error)s", {
                'tstate': target_state,
                'node_id': node.uuid,
                'error': irmc_exception
            })
        operation = _('iRMC set_power_state')
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    try:
        if target_state in (states.SOFT_REBOOT, states.SOFT_POWER_OFF):
            # note (naohirot):
            # The following call covers both cases since SOFT_REBOOT matches
            # 'unknown' and SOFT_POWER_OFF matches 'off' or 'unknown'.
            _wait_power_state(task, states.SOFT_POWER_OFF, timeout=timeout)
        if target_state == states.SOFT_REBOOT:
            _wait_power_state(task, states.SOFT_REBOOT, timeout=timeout)

    except exception.SNMPFailure as snmp_exception:
        LOG.error(
            "iRMC failed to acknowledge the target state "
            "for node %(node_id)s. Error: %(error)s", {
                'node_id': node.uuid,
                'error': snmp_exception
            })
        raise exception.IRMCOperationError(operation=target_state,
                                           error=snmp_exception)
Beispiel #8
0
 def test_get_irmc_client(self, mock_scci):
     self.info['irmc_port'] = 80
     self.info['irmc_auth_method'] = 'digest'
     self.info['irmc_client_timeout'] = 60
     mock_scci.get_client.return_value = 'get_client'
     returned_mock_scci_get_client = irmc_common.get_irmc_client(self.node)
     mock_scci.get_client.assert_called_with(
         self.info['irmc_address'],
         self.info['irmc_username'],
         self.info['irmc_password'],
         port=self.info['irmc_port'],
         auth_method=self.info['irmc_auth_method'],
         client_timeout=self.info['irmc_client_timeout'])
     self.assertEqual('get_client', returned_mock_scci_get_client)
Beispiel #9
0
 def test_get_irmc_client(self, mock_scci):
     self.info['irmc_port'] = 80
     self.info['irmc_auth_method'] = 'digest'
     self.info['irmc_client_timeout'] = 60
     mock_scci.get_client.return_value = 'get_client'
     returned_mock_scci_get_client = irmc_common.get_irmc_client(self.node)
     mock_scci.get_client.assert_called_with(
         self.info['irmc_address'],
         self.info['irmc_username'],
         self.info['irmc_password'],
         port=self.info['irmc_port'],
         auth_method=self.info['irmc_auth_method'],
         client_timeout=self.info['irmc_client_timeout'])
     self.assertEqual('get_client', returned_mock_scci_get_client)
Beispiel #10
0
def _set_power_state(task, target_state, timeout=None):
    """Turn the server power on/off or do a reboot.

    :param task: a TaskManager instance containing the node to act on.
    :param target_state: target state of the node.
    :param timeout: timeout (in seconds) positive integer (> 0) for any
      power state. ``None`` indicates default timeout.
    :raises: InvalidParameterValue if an invalid power state was specified.
    :raises: MissingParameterValue if some mandatory information
      is missing on the node
    :raises: IRMCOperationError on an error from SCCI or SNMP
    """
    node = task.node
    irmc_client = irmc_common.get_irmc_client(node)

    if target_state in (states.POWER_ON, states.REBOOT, states.SOFT_REBOOT):
        irmc_boot.attach_boot_iso_if_needed(task)

    try:
        irmc_client(STATES_MAP[target_state])

    except KeyError:
        msg = _("_set_power_state called with invalid power state "
                "'%s'") % target_state
        raise exception.InvalidParameterValue(msg)

    except scci.SCCIClientError as irmc_exception:
        LOG.error("iRMC set_power_state failed to set state to %(tstate)s "
                  " for node %(node_id)s with error: %(error)s",
                  {'tstate': target_state, 'node_id': node.uuid,
                   'error': irmc_exception})
        operation = _('iRMC set_power_state')
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    try:
        if target_state in (states.SOFT_REBOOT, states.SOFT_POWER_OFF):
            # note (naohirot):
            # The following call covers both cases since SOFT_REBOOT matches
            # 'unknown' and SOFT_POWER_OFF matches 'off' or 'unknown'.
            _wait_power_state(task, states.SOFT_POWER_OFF, timeout=timeout)
        if target_state == states.SOFT_REBOOT:
            _wait_power_state(task, states.SOFT_REBOOT, timeout=timeout)

    except exception.SNMPFailure as snmp_exception:
        LOG.error("iRMC failed to acknowledge the target state "
                  "for node %(node_id)s. Error: %(error)s",
                  {'node_id': node.uuid, 'error': snmp_exception})
        raise exception.IRMCOperationError(operation=target_state,
                                           error=snmp_exception)
Beispiel #11
0
 def test_get_irmc_client(self, mock_scci):
     self.info["irmc_port"] = 80
     self.info["irmc_auth_method"] = "digest"
     self.info["irmc_client_timeout"] = 60
     mock_scci.get_client.return_value = "get_client"
     returned_mock_scci_get_client = irmc_common.get_irmc_client(self.node)
     mock_scci.get_client.assert_called_with(
         self.info["irmc_address"],
         self.info["irmc_username"],
         self.info["irmc_password"],
         port=self.info["irmc_port"],
         auth_method=self.info["irmc_auth_method"],
         client_timeout=self.info["irmc_client_timeout"],
     )
     self.assertEqual("get_client", returned_mock_scci_get_client)
Beispiel #12
0
    def inject_nmi(self, task):
        """Inject NMI, Non Maskable Interrupt.

        Inject NMI (Non Maskable Interrupt) for a node immediately.

        :param task: A TaskManager instance containing the node to act on.
        :raises: IRMCOperationError on an error from SCCI
        :returns: None

        """
        node = task.node
        irmc_client = irmc_common.get_irmc_client(node)
        try:
            irmc_client(irmc.scci.POWER_RAISE_NMI)
        except irmc.scci.SCCIClientError as err:
            LOG.error('iRMC Inject NMI failed for node %(node)s: %(err)s.',
                      {'node': node.uuid, 'err': err})
            raise exception.IRMCOperationError(
                operation=irmc.scci.POWER_RAISE_NMI, error=err)
Beispiel #13
0
def _detach_virtual_fd(node):
    """Detaches virtual media floppy on the node.

    :param node: an ironic node object.
    :raises: IRMCOperationError if eject virtual media floppy failed.
    """
    try:
        irmc_client = irmc_common.get_irmc_client(node)

        irmc_client(scci.UNMOUNT_FD)

    except scci.SCCIClientError as irmc_exception:
        LOG.exception(
            _LE("Error while ejecting virtual floppy " "from node %(uuid)s. Error: %(error)s"),
            {"uuid": node.uuid, "error": irmc_exception},
        )
        operation = _("Ejecting virtual floppy")
        raise exception.IRMCOperationError(operation=operation, error=irmc_exception)

    LOG.info(_LI("Detached virtual floppy successfully" " for node %s"), node.uuid)
Beispiel #14
0
def _detach_virtual_cd(node):
    """Detaches virtual cdrom on the node.

    :param node: an ironic node object.
    :raises: IRMCOperationError if eject virtual cdrom failed.
    """
    try:
        irmc_client = irmc_common.get_irmc_client(node)

        irmc_client(scci.UNMOUNT_CD)

    except scci.SCCIClientError as irmc_exception:
        LOG.exception("Error while ejecting virtual cdrom "
                      "from node %(uuid)s. Error: %(error)s",
                      {'uuid': node.uuid, 'error': irmc_exception})
        operation = _("Ejecting virtual cdrom")
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    LOG.info("Detached virtual cdrom successfully"
             " for node %s", node.uuid)
Beispiel #15
0
def _detach_virtual_fd(node):
    """Detaches virtual media floppy on the node.

    :param node: an ironic node object.
    :raises: IRMCOperationError if eject virtual media floppy failed.
    """
    try:
        irmc_client = irmc_common.get_irmc_client(node)

        irmc_client(scci.UNMOUNT_FD)

    except scci.SCCIClientError as irmc_exception:
        LOG.exception(_LE("Error while ejecting virtual floppy "
                          "from node %(uuid)s. Error: %(error)s"),
                      {'uuid': node.uuid, 'error': irmc_exception})
        operation = _("Ejecting virtual floppy")
        raise exception.IRMCOperationError(operation=operation,
                                           error=irmc_exception)

    LOG.info(_LI("Detached virtual floppy successfully"
                 " for node %s"), node.uuid)