Exemplo n.º 1
0
Arquivo: vm.py Projeto: kstev/nova-1
def reboot(adapter, instance, hard):
    """Reboots a VM.

    :param adapter: A pypowervm.adapter.Adapter.
    :param instance: The nova instance to reboot.
    :param hard: Boolean True if hard reboot, False otherwise.
    :raises: InstanceRebootFailure
    """
    # Synchronize power-on and power-off ops on a given instance
    with lockutils.lock('power_%s' % instance.uuid):
        try:
            entry = get_instance_wrapper(adapter, instance)
            if entry.state != pvm_bp.LPARState.NOT_ACTIVATED:
                if hard:
                    power.PowerOp.stop(
                        entry, opts=popts.PowerOffOpts().vsp_hard().restart())
                else:
                    power.power_off_progressive(entry, restart=True)
            else:
                # pypowervm does NOT throw an exception if "already down".
                # Any other exception from pypowervm is a legitimate failure;
                # let it raise up.
                # If we get here, pypowervm thinks the instance is down.
                power.power_on(entry, None)
        except pvm_exc.Error as e:
            LOG.exception("PowerVM error during reboot.", instance=instance)
            raise exc.InstanceRebootFailure(reason=six.text_type(e))
Exemplo n.º 2
0
Arquivo: vm.py Projeto: arbrandes/nova
def reboot(adapter, instance, hard):
    """Reboots a VM.

    :param adapter: A pypowervm.adapter.Adapter.
    :param instance: The nova instance to reboot.
    :param hard: Boolean True if hard reboot, False otherwise.
    :raises: InstanceRebootFailure
    """
    # Synchronize power-on and power-off ops on a given instance
    with lockutils.lock('power_%s' % instance.uuid):
        try:
            entry = get_instance_wrapper(adapter, instance)
            if entry.state != pvm_bp.LPARState.NOT_ACTIVATED:
                if hard:
                    power.PowerOp.stop(
                        entry, opts=popts.PowerOffOpts().vsp_hard().restart())
                else:
                    power.power_off_progressive(entry, restart=True)
            else:
                # pypowervm does NOT throw an exception if "already down".
                # Any other exception from pypowervm is a legitimate failure;
                # let it raise up.
                # If we get here, pypowervm thinks the instance is down.
                power.power_on(entry, None)
        except pvm_exc.Error as e:
            LOG.exception("PowerVM error during reboot.", instance=instance)
            raise exc.InstanceRebootFailure(reason=six.text_type(e))
Exemplo n.º 3
0
def power_off(adapter, instance, force_immediate=False, timeout=None):
    """Powers off a VM.

    :param adapter: A pypowervm.adapter.Adapter.
    :param instance: The nova instance to power off.
    :param force_immediate: (Optional, Default False) Should it be immediately
                            shut down.
    :param timeout: (Optional, Default None) How long to wait for the job
                    to complete.  By default, is None which indicates it should
                    use the default from pypowervm's power off method.
    :return: True if the instance was stopped.  False if it was not in a
             stoppable state.
    :raises: InstancePowerOffFailure
    """
    # Synchronize power-on and power-off ops on a given instance
    with lockutils.lock('power_%s' % instance.uuid):
        entry = get_instance_wrapper(adapter, instance)

        # Get the current state and see if we can stop the VM
        LOG.debug(
            "Power off requested for instance in state %(state)s. Force "
            "Immediate Flag: %(force)s.", {
                'state': entry.state,
                'force': force_immediate
            },
            instance=instance)
        if entry.state in POWERVM_STOPABLE_STATE:
            # Now stop the lpar
            try:
                LOG.debug("Power off executing.", instance=instance)
                kwargs = {'timeout': timeout} if timeout else {}
                if force_immediate:
                    power.PowerOp.stop(entry,
                                       opts=popts.PowerOffOpts().vsp_hard(),
                                       **kwargs)
                else:
                    power.power_off_progressive(entry, **kwargs)
            except Exception as e:
                LOG.exception("Failed to power off instance.",
                              instance=instance)
                raise exception.InstancePowerOffFailure(
                    reason=six.text_type(e))
            return True
        else:
            LOG.debug("Power off not required.", instance=instance)

    return False
Exemplo n.º 4
0
    def test_pwroff_progressive(self, mock_prog_internal):
        # The internal _power_off_progressive is exercised via the existing
        # tests for power_off. This test just ensures the public
        # power_off_progressive calls it appropriately.

        # Default kwargs
        power.power_off_progressive('part')
        mock_prog_internal.assert_called_once_with('part',
                                                   1800,
                                                   False,
                                                   ibmi_immed=False)

        mock_prog_internal.reset_mock()

        # Non-default kwargs
        power.power_off_progressive('part',
                                    restart=True,
                                    ibmi_immed=True,
                                    timeout=10)
        mock_prog_internal.assert_called_once_with('part',
                                                   10,
                                                   True,
                                                   ibmi_immed=True)
Exemplo n.º 5
0
Arquivo: vm.py Projeto: arbrandes/nova
def power_off(adapter, instance, force_immediate=False, timeout=None):
    """Powers off a VM.

    :param adapter: A pypowervm.adapter.Adapter.
    :param instance: The nova instance to power off.
    :param timeout: (Optional, Default None) How long to wait for the job
                    to complete.  By default, is None which indicates it should
                    use the default from pypowervm's power off method.
     :param force_immediate: (Optional, Default False) Should it be immediately
                            shut down.
    :raises: InstancePowerOffFailure
    """
    # Synchronize power-on and power-off ops on a given instance
    with lockutils.lock('power_%s' % instance.uuid):
        entry = get_instance_wrapper(adapter, instance)
        # Get the current state and see if we can stop the VM
        LOG.debug("Powering off request for instance in state %(state)s. "
                  "Force Immediate Flag: %(force)s.",
                  {'state': entry.state, 'force': force_immediate},
                  instance=instance)
        if entry.state in _POWERVM_STOPPABLE_STATE:
            # Now stop the lpar
            try:
                LOG.debug("Power off executing.", instance=instance)
                kwargs = {'timeout': timeout} if timeout else {}
                if force_immediate:
                    power.PowerOp.stop(
                        entry, opts=popts.PowerOffOpts().vsp_hard(), **kwargs)
                else:
                    power.power_off_progressive(entry, **kwargs)
            except pvm_exc.Error as e:
                LOG.exception("PowerVM error during power_off.",
                              instance=instance)
                raise exc.InstancePowerOffFailure(reason=six.text_type(e))
        else:
            LOG.debug("Power off not required for instance %(inst)s.",
                      {'inst': instance.name})