summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorSoren Hansen <soren@linux2go.dk>2011-01-25 20:49:29 +0100
committerSoren Hansen <soren@linux2go.dk>2011-01-25 20:49:29 +0100
commitf51526b596f3d89cda2ec4501e19baf085c534e0 (patch)
treef529768512dcedb2a2b9e0ba7e44524c8fb15df9 /nova/virt
parent3b06788ba2e8184e17f875f41ced0bbc0254beac (diff)
downloadnova-f51526b596f3d89cda2ec4501e19baf085c534e0.tar.gz
nova-f51526b596f3d89cda2ec4501e19baf085c534e0.tar.xz
nova-f51526b596f3d89cda2ec4501e19baf085c534e0.zip
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.
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/fake.py5
-rw-r--r--nova/virt/hyperv.py2
-rw-r--r--nova/virt/libvirt_conn.py27
-rw-r--r--nova/virt/xenapi_conn.py2
4 files changed, 30 insertions, 6 deletions
diff --git a/nova/virt/fake.py b/nova/virt/fake.py
index f8b3c7807..161445b86 100644
--- a/nova/virt/fake.py
+++ b/nova/virt/fake.py
@@ -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
diff --git a/nova/virt/hyperv.py b/nova/virt/hyperv.py
index 30dc1c79b..cb52e1ade 100644
--- a/nova/virt/hyperv.py
+++ b/nova/virt/hyperv.py
@@ -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
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index d8c1bf48a..5808d273a 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -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():
diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py
index 927f5905b..acf89f0c1 100644
--- a/nova/virt/xenapi_conn.py
+++ b/nova/virt/xenapi_conn.py
@@ -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?