def power_off(adapter, instance, opts=None, force_immediate=False, timeout=None): """Powers off a VM. :param adapter: A pypowervm.adapter.Adapter. :param instance: The nova instance to power off. :param opts: (Optional) Additional parameters to the pypowervm power_off method. See that method's docstring for details. :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( "Powering off request for instance %(inst)s which is in " "state %(state)s. Force Immediate Flag: %(force)s.", { 'inst': instance.name, 'state': entry.state, 'force': force_immediate }) if entry.state in POWERVM_STOPABLE_STATE: # Now stop the lpar try: LOG.debug("Power off executing for instance %(inst)s.", {'inst': instance.name}) kwargs = {'timeout': timeout} if timeout else {} force_flag = (power.Force.TRUE if force_immediate else power.Force.ON_FAILURE) power.power_off(entry, None, force_immediate=force_flag, add_parms=opts, **kwargs) except Exception as e: LOG.exception(e) raise exception.InstancePowerOffFailure( reason=six.text_type(e)) return True else: LOG.debug("Power off not required for instance %(inst)s.", {'inst': instance.name}) return False
def power_off(self, instance, node=None): """Power off the specified instance.""" if not node: node = _get_baremetal_node_by_instance_uuid(instance['uuid']) pm = get_power_manager(node=node, instance=instance) pm.deactivate_node() if pm.state != baremetal_states.DELETED: raise exception.InstancePowerOffFailure( _("Baremetal power manager failed to stop node " "for instance %r") % instance['uuid']) pm.stop_console()
def power_off(self, instance, timeout=0, retry_interval=0, node=None): """Power off the specified instance.""" # TODO(PhilDay): Add support for timeout (clean shutdown) if not node: node = _get_baremetal_node_by_instance_uuid(instance['uuid']) pm = get_power_manager(node=node, instance=instance) pm.deactivate_node() if pm.state != baremetal_states.DELETED: raise exception.InstancePowerOffFailure(_( "Baremetal power manager failed to stop node " "for instance %r") % instance['uuid']) pm.stop_console()
def power_off(self, instance, timeout=0, retry_interval=0): try: async_vm_action = self.compute.virtual_machines.power_off( CONF.azure.resource_group, instance.uuid) async_vm_action.wait(CONF.azure.async_timeout) LOG.info(_LI("Power off Instance in Azure Finish."), instance=instance) except Exception as e: msg = six.text_type(e) LOG.exception(msg) ex = nova_ex.InstancePowerOffFailure(reason=msg) raise ex
def destroy(self, context, instance, network_info, block_device_info=None, destroy_disks=True, migrate_data=None): """Destroy VM instance.""" # Destroy gets triggered when Resource Claim in resource_tracker # is not successful. When resource claim is not successful, # node is not set in instance. Perform destroy only if node is set if not instance['node']: return try: _vmops = self._get_vmops_for_compute_node(instance['node']) _vmops.destroy(instance, destroy_disks) except exception.NotFound as exc: LOG.debug(_("Destory instance failed : %s") % str(exc)) raise exception.InstancePowerOffFailure(reason=str(exc))
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
def power_off(adapter, instance, host_uuid, entry=None, add_parms=None, force_immediate=False): if entry is None: entry = get_instance_wrapper(adapter, instance, host_uuid) # Get the current state and see if we can stop the VM if entry.state in POWERVM_STOPABLE_STATE: # Now stop the lpar try: power.power_off(entry, host_uuid, force_immediate=force_immediate, add_parms=add_parms) except Exception as e: LOG.exception(e) raise exception.InstancePowerOffFailure(reason=six.text_type(e)) return True return False