diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-11-30 19:28:14 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-11-30 19:28:14 +0000 |
| commit | 0fc6c8f0d24a015b7ee8dd02cd433533ff6ebd65 (patch) | |
| tree | 412bf29a9a9e9720a85896cb9179b23f3bfc86ee | |
| parent | a32c98384f020696368d6640034ca338c47e25e6 (diff) | |
| parent | 32b1027815acc52ba2a112f65b2322164a3c781b (diff) | |
| download | nova-0fc6c8f0d24a015b7ee8dd02cd433533ff6ebd65.tar.gz nova-0fc6c8f0d24a015b7ee8dd02cd433533ff6ebd65.tar.xz nova-0fc6c8f0d24a015b7ee8dd02cd433533ff6ebd65.zip | |
Merge "Split out part of compute's init_host."
| -rw-r--r-- | nova/compute/manager.py | 107 |
1 files changed, 55 insertions, 52 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 1a844386e..4baeab255 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -352,69 +352,72 @@ class ComputeManager(manager.SchedulerDependentManager): 'trying to set it to ERROR'), instance_uuid=instance_uuid) - def init_host(self): - """Initialization for a standalone compute service.""" - self.driver.init_host(host=self.host) - context = nova.context.get_admin_context() - instances = self.db.instance_get_all_by_host(context, self.host) + def _init_instance(self, context, instance): + '''Initialize this instance during service init.''' + db_state = instance['power_state'] + drv_state = self._get_power_state(context, instance) + closing_vm_states = (vm_states.DELETED, + vm_states.SOFT_DELETED) + + # instance was supposed to shut down - don't attempt + # recovery in any case + if instance['vm_state'] in closing_vm_states: + return - if CONF.defer_iptables_apply: - self.driver.filter_defer_apply_on() + expect_running = (db_state == power_state.RUNNING and + drv_state != db_state) - try: - for instance in instances: - db_state = instance['power_state'] - drv_state = self._get_power_state(context, instance) - closing_vm_states = (vm_states.DELETED, - vm_states.SOFT_DELETED) - - # instance was supposed to shut down - don't attempt - # recovery in any case - if instance['vm_state'] in closing_vm_states: - continue + LOG.debug(_('Current state is %(drv_state)s, state in DB is ' + '%(db_state)s.'), locals(), instance=instance) - expect_running = (db_state == power_state.RUNNING and - drv_state != db_state) + net_info = compute_utils.get_nw_info_for_instance(instance) - LOG.debug(_('Current state is %(drv_state)s, state in DB is ' - '%(db_state)s.'), locals(), instance=instance) + # We're calling plug_vifs to ensure bridge and iptables + # rules exist. This needs to be called for each instance. + legacy_net_info = self._legacy_nw_info(net_info) + self.driver.plug_vifs(instance, legacy_net_info) - net_info = compute_utils.get_nw_info_for_instance(instance) + if expect_running and CONF.resume_guests_state_on_host_boot: + LOG.info( + _('Rebooting instance after nova-compute restart.'), + locals(), instance=instance) - # We're calling plug_vifs to ensure bridge and iptables - # rules exist. This needs to be called for each instance. - legacy_net_info = self._legacy_nw_info(net_info) - self.driver.plug_vifs(instance, legacy_net_info) + block_device_info = \ + self._get_instance_volume_block_device_info( + context, instance['uuid']) - if expect_running and CONF.resume_guests_state_on_host_boot: - LOG.info( - _('Rebooting instance after nova-compute restart.'), - locals(), instance=instance) + try: + self.driver.resume_state_on_host_boot( + context, + instance, + self._legacy_nw_info(net_info), + block_device_info) + except NotImplementedError: + LOG.warning(_('Hypervisor driver does not support ' + 'resume guests'), instance=instance) - block_device_info = \ - self._get_instance_volume_block_device_info( - context, instance['uuid']) + elif drv_state == power_state.RUNNING: + # VMWareAPI drivers will raise an exception + try: + self.driver.ensure_filtering_rules_for_instance( + instance, + self._legacy_nw_info(net_info)) + except NotImplementedError: + LOG.warning(_('Hypervisor driver does not support ' + 'firewall rules'), instance=instance) - try: - self.driver.resume_state_on_host_boot( - context, - instance, - self._legacy_nw_info(net_info), - block_device_info) - except NotImplementedError: - LOG.warning(_('Hypervisor driver does not support ' - 'resume guests'), instance=instance) + def init_host(self): + """Initialization for a standalone compute service.""" + self.driver.init_host(host=self.host) + context = nova.context.get_admin_context() + instances = self.db.instance_get_all_by_host(context, self.host) - elif drv_state == power_state.RUNNING: - # VMWareAPI drivers will raise an exception - try: - self.driver.ensure_filtering_rules_for_instance( - instance, - self._legacy_nw_info(net_info)) - except NotImplementedError: - LOG.warning(_('Hypervisor driver does not support ' - 'firewall rules'), instance=instance) + if CONF.defer_iptables_apply: + self.driver.filter_defer_apply_on() + try: + for instance in instances: + self._init_instance(context, instance) finally: if CONF.defer_iptables_apply: self.driver.filter_defer_apply_off() |
