~rconradharris/nova/lp821209

« back to all changes in this revision

Viewing changes to nova/compute/manager.py

Moves code restarting instances after compute node reboot from libvirt driver to compute manager; makes start_guests_on_host_boot flag global.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
from eventlet import greenthread
46
46
 
 
47
import nova.context
47
48
from nova import exception
48
49
from nova import flags
49
50
import nova.image
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'])
 
157
 
 
158
            expect_running = db_state == power_state.RUNNING \
 
159
                             and drv_state != db_state
 
160
 
 
161
            LOG.debug(_('Current state of %(inst_name)s is %(drv_state)s, '
 
162
                        'state in DB is %(db_state)s.'), locals())
 
163
 
 
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'))
150
174
 
151
175
    def _update_state(self, context, instance_id, state=None):
152
176
        """Update the state of an instance from the driver info."""
154
178
 
155
179
        if state is None:
156
180
            try:
 
181
                LOG.debug(_('Checking state of %s'), instance_ref['name'])
157
182
                info = self.driver.get_info(instance_ref['name'])
158
183
            except exception.NotFound:
159
184
                info = None
164
189
                state = power_state.FAILED
165
190
 
166
191
        self.db.instance_set_state(context, instance_id, state)
 
192
        return state
167
193
 
168
194
    def _update_launched_at(self, context, instance_id, launched_at=None):
169
195
        """Update the launched_at parameter of the given instance."""