147
148
def init_host(self):
148
149
"""Initialization for a standalone compute service."""
149
150
self.driver.init_host(host=self.host)
151
context = nova.context.get_admin_context()
152
instances = self.db.instance_get_all_by_host(context, self.host)
153
for instance in instances:
154
inst_name = instance['name']
155
db_state = instance['state']
156
drv_state = self._update_state(context, instance['id'])
158
expect_running = db_state == power_state.RUNNING \
159
and drv_state != db_state
161
LOG.debug(_('Current state of %(inst_name)s is %(drv_state)s, '
162
'state in DB is %(db_state)s.'), locals())
164
if (expect_running and FLAGS.resume_guests_state_on_host_boot)\
165
or FLAGS.start_guests_on_host_boot:
166
LOG.info(_('Rebooting instance %(inst_name)s after '
167
'nova-compute restart.'), locals())
168
self.reboot_instance(context, instance['id'])
169
elif drv_state == power_state.RUNNING:
170
try: # Hyper-V and VMWareAPI drivers will raise and exception
171
self.driver.ensure_filtering_rules_for_instance(instance)
172
except NotImplementedError:
173
LOG.warning(_('Hypervisor driver does not support firewall rules'))
151
175
def _update_state(self, context, instance_id, state=None):
152
176
"""Update the state of an instance from the driver info."""
164
189
state = power_state.FAILED
166
191
self.db.instance_set_state(context, instance_id, state)
168
194
def _update_launched_at(self, context, instance_id, launched_at=None):
169
195
"""Update the launched_at parameter of the given instance."""