Add a host argument to virt driver's init_host method. It will be set to the name of host it's running on.
Make libvirt's init_host method go and look at what virtual machines are running when the compute worker starts up. This ensures firewalls are set up correctly for existing VM's. It also enables easier rolling upgrades.
This commit is contained in:
@@ -118,7 +118,7 @@ class ComputeManager(manager.Manager):
|
||||
"""Do any initialization that needs to be run if this is a
|
||||
standalone service.
|
||||
"""
|
||||
self.driver.init_host()
|
||||
self.driver.init_host(host=self.host)
|
||||
|
||||
def _update_state(self, context, instance_id):
|
||||
"""Update the state of an instance from the driver info."""
|
||||
|
||||
@@ -351,6 +351,11 @@ def instance_get_all_by_project(context, project_id):
|
||||
return IMPL.instance_get_all_by_project(context, project_id)
|
||||
|
||||
|
||||
def instance_get_all_by_host(context, host):
|
||||
"""Get all instance belonging to a host."""
|
||||
return IMPL.instance_get_all_by_host(context, host)
|
||||
|
||||
|
||||
def instance_get_all_by_reservation(context, reservation_id):
|
||||
"""Get all instance belonging to a reservation."""
|
||||
return IMPL.instance_get_all_by_reservation(context, reservation_id)
|
||||
|
||||
@@ -723,6 +723,17 @@ def instance_get_all_by_user(context, user_id):
|
||||
all()
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def instance_get_all_by_host(context, host):
|
||||
session = get_session()
|
||||
return session.query(models.Instance).\
|
||||
options(joinedload_all('fixed_ip.floating_ips')).\
|
||||
options(joinedload('security_groups')).\
|
||||
filter_by(host=host).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
all()
|
||||
|
||||
|
||||
@require_context
|
||||
def instance_get_all_by_project(context, project_id):
|
||||
authorize_project_context(context, project_id)
|
||||
|
||||
@@ -76,9 +76,10 @@ class FakeConnection(object):
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
||||
def init_host(self):
|
||||
def init_host(self, host):
|
||||
"""
|
||||
Initialize anything that is necessary for the driver to function
|
||||
Initialize anything that is necessary for the driver to function,
|
||||
including catching up with currently running VM's on the given host.
|
||||
"""
|
||||
return
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ class HyperVConnection(object):
|
||||
self._conn = wmi.WMI(moniker='//./root/virtualization')
|
||||
self._cim_conn = wmi.WMI(moniker='//./root/cimv2')
|
||||
|
||||
def init_host(self):
|
||||
def init_host(self, host):
|
||||
#FIXME(chiradeep): implement this
|
||||
LOG.debug(_('In init host'))
|
||||
pass
|
||||
|
||||
@@ -157,8 +157,31 @@ class LibvirtConnection(object):
|
||||
else:
|
||||
self.firewall_driver = utils.import_object(FLAGS.firewall_driver)
|
||||
|
||||
def init_host(self):
|
||||
pass
|
||||
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)
|
||||
|
||||
if state == power_state.SHUTOFF:
|
||||
# TODO(soren): This is what the compute manager does when you
|
||||
# terminate # an instance. At some point I figure we'll have a
|
||||
# "terminated" state and some sort of cleanup job that runs
|
||||
# occasionally, cleaning them out.
|
||||
db.instance_destroy(ctxt, instance['id'])
|
||||
|
||||
if state != power_state.RUNNING:
|
||||
continue
|
||||
self.firewall_driver.prepare_instance_filter(instance)
|
||||
self.firewall_driver.apply_instance_filter(instance)
|
||||
|
||||
def _get_connection(self):
|
||||
if not self._wrapped_conn or not self._test_connection():
|
||||
|
||||
@@ -141,7 +141,7 @@ class XenAPIConnection(object):
|
||||
self._vmops = VMOps(session)
|
||||
self._volumeops = VolumeOps(session)
|
||||
|
||||
def init_host(self):
|
||||
def init_host(self, host):
|
||||
#FIXME(armando): implement this
|
||||
#NOTE(armando): would we need a method
|
||||
#to call when shutting down the host?
|
||||
|
||||
Reference in New Issue
Block a user