752
765
{'instance_id': instance_id, 'action_str': action_str})
768
@scheduler_api.reroute_compute("soft_delete")
769
def soft_delete(self, context, instance_id):
770
"""Terminate an instance."""
771
LOG.debug(_("Going to try to soft delete %s"), instance_id)
772
instance = self._get_instance(context, instance_id, 'soft delete')
774
if not _is_able_to_shutdown(instance, instance_id):
777
# NOTE(jerdfelt): The compute daemon handles reclaiming instances
778
# that are in soft delete. If there is no host assigned, there is
779
# no daemon to reclaim, so delete it immediately.
780
host = instance['host']
784
vm_state=vm_states.SOFT_DELETE,
785
task_state=task_states.POWERING_OFF,
786
deleted_at=utils.utcnow())
788
self._cast_compute_message('power_off_instance', context,
791
LOG.warning(_("No host for instance %s, deleting immediately"),
793
terminate_volumes(self.db, context, instance_id)
794
self.db.instance_destroy(context, instance_id)
755
796
@scheduler_api.reroute_compute("delete")
756
797
def delete(self, context, instance_id):
757
798
"""Terminate an instance."""
758
799
LOG.debug(_("Going to try to terminate %s"), instance_id)
759
instance = self._get_instance(context, instance_id, 'terminating')
800
instance = self._get_instance(context, instance_id, 'delete')
761
802
if not _is_able_to_shutdown(instance, instance_id):
805
host = instance['host']
809
task_state=task_states.DELETING)
811
self._cast_compute_message('terminate_instance', context,
814
terminate_volumes(self.db, context, instance_id)
815
self.db.instance_destroy(context, instance_id)
817
@scheduler_api.reroute_compute("restore")
818
def restore(self, context, instance_id):
819
"""Restore a previously deleted (but not reclaimed) instance."""
820
instance = self._get_instance(context, instance_id, 'restore')
822
if not _is_queued_delete(instance, instance_id):
827
vm_state=vm_states.ACTIVE,
831
host = instance['host']
835
task_state=task_states.POWERING_ON)
836
self._cast_compute_message('power_on_instance', context,
839
@scheduler_api.reroute_compute("force_delete")
840
def force_delete(self, context, instance_id):
841
"""Force delete a previously deleted (but not reclaimed) instance."""
842
instance = self._get_instance(context, instance_id, 'force delete')
844
if not _is_queued_delete(instance, instance_id):
764
847
self.update(context,
766
849
task_state=task_states.DELETING)
931
1014
return instances
1016
def _get_instances_by_filters(self, context, filters):
1018
if 'ip6' in filters or 'ip' in filters:
1019
res = self.network_api.get_instance_uuids_by_ip_filter(context,
1021
# NOTE(jkoelker) It is possible that we will get the same
1022
# instance uuid twice (one for ipv4 and ipv6)
1023
uuids = set([r['instance_uuid'] for r in res])
1024
filters['uuid'] = uuids
1026
return self.db.instance_get_all_by_filters(context, filters)
933
1028
def _cast_compute_message(self, method, context, instance_id, host=None,
935
1030
"""Generic handler for RPC casts to compute.