diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-02-20 06:16:33 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-02-20 06:16:33 +0000 |
| commit | 6d0ed8f86fbaa7c52e66a1d335dcf063232de8dd (patch) | |
| tree | 25d1bbf94abb1f9c35e2578dd128fec764f28847 /nova/virt | |
| parent | 4e54c59b8888a2c5a8ab41c213d3bff2faba5570 (diff) | |
| parent | a9add7d35e27b90f0c420d2b24b1af88b978fd7b (diff) | |
Merge "Add support for network adapter hotplug."
Diffstat (limited to 'nova/virt')
| -rwxr-xr-x | nova/virt/driver.py | 8 | ||||
| -rwxr-xr-x | nova/virt/fake.py | 14 | ||||
| -rwxr-xr-x | nova/virt/libvirt/driver.py | 44 |
3 files changed, 66 insertions, 0 deletions
diff --git a/nova/virt/driver.py b/nova/virt/driver.py index ba0dfbafe..994f85ec1 100755 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -302,6 +302,14 @@ class ComputeDriver(object): """Detach the disk attached to the instance.""" raise NotImplementedError() + def attach_interface(self, instance, image_meta, network_info): + """Attach an interface to the instance.""" + raise NotImplementedError() + + def detach_interface(self, instance, network_info): + """Detach an interface from the instance.""" + raise NotImplementedError() + def migrate_disk_and_power_off(self, context, instance, dest, instance_type, network_info, block_device_info=None): diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 30a5fc758..5545dcf96 100755 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -102,6 +102,7 @@ class FakeDriver(driver.ComputeDriver): 'hypervisor_hostname': 'fake-mini', } self._mounts = {} + self._interfaces = {} def init_host(self, host): return @@ -222,6 +223,19 @@ class FakeDriver(driver.ComputeDriver): pass return True + def attach_interface(self, instance, image_meta, network_info): + for (network, mapping) in network_info: + if mapping['vif_uuid'] in self._interfaces: + raise exception.InterfaceAttachFailed('duplicate') + self._interfaces[mapping['vif_uuid']] = mapping + + def detach_interface(self, instance, network_info): + for (network, mapping) in network_info: + try: + del self._interfaces[mapping['vif_uuid']] + except KeyError: + raise exception.InterfaceDetachFailed('not attached') + def get_info(self, instance): if instance['name'] not in self.instances: raise exception.InstanceNotFound(instance_id=instance['name']) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 9ac5e047b..02ca98a3f 100755 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -796,6 +796,50 @@ class LibvirtDriver(driver.ComputeDriver): connection_info, disk_dev) + @exception.wrap_exception() + def attach_interface(self, instance, image_meta, network_info): + virt_dom = self._lookup_by_name(instance['name']) + for (network, mapping) in network_info: + self.vif_driver.plug(instance, (network, mapping)) + self.firewall_driver.setup_basic_filtering(instance, + [(network, mapping)]) + cfg = self.vif_driver.get_config(instance, network, mapping, + image_meta) + try: + flags = libvirt.VIR_DOMAIN_AFFECT_CONFIG + state = LIBVIRT_POWER_STATE[virt_dom.info()[0]] + if state == power_state.RUNNING: + flags |= libvirt.VIR_DOMAIN_AFFECT_LIVE + virt_dom.attachDeviceFlags(cfg.to_xml(), flags) + except libvirt.libvirtError as ex: + LOG.error(_('attaching network adapter failed.'), + instance=instance) + self.vif_driver.unplug(instance, (network, mapping)) + raise exception.InterfaceAttachFailed(instance) + + @exception.wrap_exception() + def detach_interface(self, instance, network_info): + virt_dom = self._lookup_by_name(instance['name']) + for (network, mapping) in network_info: + cfg = self.vif_driver.get_config(instance, network, mapping, None) + try: + self.vif_driver.unplug(instance, (network, mapping)) + flags = libvirt.VIR_DOMAIN_AFFECT_CONFIG + state = LIBVIRT_POWER_STATE[virt_dom.info()[0]] + if state == power_state.RUNNING: + flags |= libvirt.VIR_DOMAIN_AFFECT_LIVE + virt_dom.detachDeviceFlags(cfg.to_xml(), flags) + except libvirt.libvirtError as ex: + error_code = ex.get_error_code() + if error_code == libvirt.VIR_ERR_NO_DOMAIN: + LOG.warn(_("During detach_interface, " + "instance disappeared."), + instance=instance) + else: + LOG.error(_('detaching network adapter failed.'), + instance=instance) + raise exception.InterfaceDetachFailed(instance) + def snapshot(self, context, instance, image_href, update_task_state): """Create snapshot from a running VM instance. |
