79
80
flags.DEFINE_integer("rescue_timeout", 0,
80
81
"Automatically unrescue an instance after N seconds."
81
82
" Set to 0 to disable.")
83
flags.DEFINE_integer("resize_confirm_window", 0,
84
"Automatically confirm resizes after N seconds."
85
" Set to 0 to disable.")
82
86
flags.DEFINE_integer('host_state_interval', 120,
83
87
'Interval in seconds for querying the host status')
88
flags.DEFINE_integer('reclaim_instance_interval', 0,
89
'Interval in seconds for reclaiming deleted instances')
85
91
LOG = logging.getLogger('nova.compute.manager')
172
178
'nova-compute restart.'), locals())
173
179
self.reboot_instance(context, instance['id'])
174
180
elif drv_state == power_state.RUNNING:
175
# Hyper-V and VMWareAPI drivers will raise and exception
181
# Hyper-V and VMWareAPI drivers will raise an exception
177
183
net_info = self._get_instance_nw_info(context, instance)
178
184
self.driver.ensure_filtering_rules_for_instance(instance,
484
490
if action_str == 'Terminating':
485
491
terminate_volumes(self.db, context, instance_id)
487
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
488
@checks_instance_lock
489
def terminate_instance(self, context, instance_id):
490
"""Terminate an instance on this host."""
493
def _delete_instance(self, context, instance_id):
494
"""Delete an instance on this host."""
491
495
self._shutdown_instance(context, instance_id, 'Terminating')
492
496
instance = self.db.instance_get(context.elevated(), instance_id)
493
497
self._instance_update(context,
506
510
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
507
511
@checks_instance_lock
512
def terminate_instance(self, context, instance_id):
513
"""Terminate an instance on this host."""
514
self._delete_instance(context, instance_id)
516
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
517
@checks_instance_lock
508
518
def stop_instance(self, context, instance_id):
509
519
"""Stopping an instance on this host."""
510
520
self._shutdown_instance(context, instance_id, 'Stopping')
516
526
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
517
527
@checks_instance_lock
528
def power_off_instance(self, context, instance_id):
529
"""Power off an instance on this host."""
530
instance = self.db.instance_get(context, instance_id)
531
self.driver.power_off(instance)
532
current_power_state = self._get_power_state(context, instance)
533
self._instance_update(context,
535
power_state=current_power_state,
538
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
539
@checks_instance_lock
540
def power_on_instance(self, context, instance_id):
541
"""Power on an instance on this host."""
542
instance = self.db.instance_get(context, instance_id)
543
self.driver.power_on(instance)
544
current_power_state = self._get_power_state(context, instance)
545
self._instance_update(context,
547
power_state=current_power_state,
550
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
551
@checks_instance_lock
518
552
def rebuild_instance(self, context, instance_id, **kwargs):
519
553
"""Destroy and re-make this instance.
1648
1682
self.driver.poll_rescued_instances(FLAGS.rescue_timeout)
1649
1683
except Exception as ex:
1650
1684
LOG.warning(_("Error during poll_rescued_instances: %s"),
1686
error_list.append(ex)
1689
if FLAGS.resize_confirm_window > 0:
1690
self.driver.poll_unconfirmed_resizes(
1691
FLAGS.resize_confirm_window)
1692
except Exception as ex:
1693
LOG.warning(_("Error during poll_unconfirmed_resizes: %s"),
1652
1695
error_list.append(ex)
1655
1698
self._report_driver_status()
1656
1699
except Exception as ex:
1657
1700
LOG.warning(_("Error during report_driver_status(): %s"),
1659
1702
error_list.append(ex)
1664
1707
LOG.warning(_("Error during power_state sync: %s"), unicode(ex))
1665
1708
error_list.append(ex)
1711
self._reclaim_queued_deletes(context)
1712
except Exception as ex:
1713
LOG.warning(_("Error during reclamation of queued deletes: %s"),
1715
error_list.append(ex)
1667
1717
return error_list
1669
1719
def _report_driver_status(self):
1713
1763
self._instance_update(context,
1714
1764
db_instance["id"],
1715
1765
power_state=vm_power_state)
1767
def _reclaim_queued_deletes(self, context):
1768
"""Reclaim instances that are queued for deletion."""
1770
instances = self.db.instance_get_all_by_host(context, self.host)
1772
queue_time = datetime.timedelta(
1773
seconds=FLAGS.reclaim_instance_interval)
1774
curtime = utils.utcnow()
1775
for instance in instances:
1776
if instance['vm_state'] == vm_states.SOFT_DELETE and \
1777
(curtime - instance['deleted_at']) >= queue_time:
1778
LOG.info('Deleting %s' % instance['name'])
1779
self._delete_instance(context, instance['id'])