Skip to content

Commit

Permalink
Merge "Split out part of compute's init_host."
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Nov 30, 2012
2 parents a32c983 + 32b1027 commit 0fc6c8f
Showing 1 changed file with 55 additions and 52 deletions.
107 changes: 55 additions & 52 deletions nova/compute/manager.py
Expand Up @@ -352,69 +352,72 @@ def _set_instance_error_state(self, context, instance_uuid):
'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()
Expand Down

0 comments on commit 0fc6c8f

Please sign in to comment.