summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Sokolov <nsokolov@griddynamics.com>2011-07-22 17:26:11 +0400
committerNikolay Sokolov <nsokolov@griddynamics.com>2011-07-22 17:26:11 +0400
commit8d97118be776fcaad3053d1f93f61d339685a4ae (patch)
tree70923f2a26195eefb2caabda9b81808bf0fa97e3
parent35deb55f304bc380b2b17aa1caf65001a38ae486 (diff)
Moved restaring instances from livbirt driver to ComputeManager.
-rw-r--r--nova/compute/manager.py19
-rw-r--r--nova/flags.py3
-rw-r--r--nova/virt/libvirt/connection.py25
3 files changed, 24 insertions, 23 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 5819a520a..c7d3004a5 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -146,7 +146,26 @@ class ComputeManager(manager.SchedulerDependentManager):
def init_host(self):
"""Initialization for a standalone compute service."""
+ # NOTE(nsokolov): based on itoumsn's implementation from libvirt driver
+ from nova import context
self.driver.init_host(host=self.host)
+ admin_context = context.get_admin_context()
+ for instance in self.db.instance_get_all_by_host(admin_context, self.host):
+ try:
+ LOG.debug(_('Checking state of %s'), instance['name'])
+ state = self.driver.get_info(instance['name'])['state']
+ except exception.NotFound:
+ state = power_state.SHUTOFF
+
+ LOG.debug(_('Current state of %(name)s is %(state)s, state in DB is %(db_state)s.'),
+ {'name': instance['name'], 'state': state, 'db_state': instance['state']})
+
+ if instance['state'] == power_state.RUNNING and state != power_state.RUNNING \
+ and FLAGS.start_guests_on_host_boot:
+ LOG.debug(_('Rebooting instance %(name)s after nova-compute restart.'))
+ self.reboot_instance(admin_context, instance[id])
+ else:
+ self.db.instance_set_state(ctxt, instance['id'], state)
def _update_state(self, context, instance_id, state=None):
"""Update the state of an instance from the driver info."""
diff --git a/nova/flags.py b/nova/flags.py
index 49355b436..23ca38b17 100644
--- a/nova/flags.py
+++ b/nova/flags.py
@@ -387,3 +387,6 @@ DEFINE_list('zone_capabilities',
'Key/Multi-value list representng capabilities of this zone')
DEFINE_string('build_plan_encryption_key', None,
'128bit (hex) encryption key for scheduler build plans.')
+
+DEFINE_bool('start_guests_on_host_boot', False,
+ 'Whether to restart guests when the host reboots')
diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py
index 342dea98f..d85b91ee2 100644
--- a/nova/virt/libvirt/connection.py
+++ b/nova/virt/libvirt/connection.py
@@ -121,8 +121,6 @@ flags.DEFINE_integer('live_migration_bandwidth', 0,
'Define live migration behavior')
flags.DEFINE_string('qemu_img', 'qemu-img',
'binary to use for qemu-img commands')
-flags.DEFINE_bool('start_guests_on_host_boot', False,
- 'Whether to restart guests when the host reboots')
def get_connection(read_only):
@@ -167,27 +165,8 @@ class LibvirtConnection(driver.ComputeDriver):
self.firewall_driver = fw_class(get_connection=self._get_connection)
def init_host(self, host):
- # Adopt existing VM's running here
- ctxt = context.get_admin_context()
- for instance in db.instance_get_all_by_host(ctxt, host):
- try:
- LOG.debug(_('Checking state of %s'), instance['name'])
- state = self.get_info(instance['name'])['state']
- except exception.NotFound:
- state = power_state.SHUTOFF
-
- LOG.debug(_('Current state of %(name)s was %(state)s.'),
- {'name': instance['name'], 'state': state})
- db.instance_set_state(ctxt, instance['id'], state)
-
- # NOTE(justinsb): We no longer delete SHUTOFF instances,
- # the user may want to power them back on
-
- if state != power_state.RUNNING:
- continue
- self.firewall_driver.setup_basic_filtering(instance)
- self.firewall_driver.prepare_instance_filter(instance)
- self.firewall_driver.apply_instance_filter(instance)
+ # NOTE(nsokolov): moved instance restarting to ComputeManager
+ pass
def _get_connection(self):
if not self._wrapped_conn or not self._test_connection():