From 1845c5df145251f1e90709a91cc02ee5ec787e2f Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 11 Apr 2011 14:16:30 -0500 Subject: network manager changes, compute changes, various other --- nova/virt/xenapi/vmops.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 0235e2dc4..89860c5e2 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -807,7 +807,6 @@ class VMOps(object): "ip": utils.to_global_ipv6(network['cidr_v6'], instance['mac_address']), "netmask": network['netmask_v6'], - "gateway": network['gateway_v6'], "enabled": "1"} info = { @@ -820,10 +819,12 @@ class VMOps(object): 'ips': [ip_dict(ip) for ip in network_IPs]} if network['cidr_v6']: info['ip6s'] = [ip6_dict(ip) for ip in network_IPs] + if network['gateway_v6']: + info['gateway6'] = network['gateway_v6'] network_info.append((network, info)) return network_info - def inject_network_info(self, instance, vm_ref, network_info): + def inject_network_info(self, instance, vm_ref=None, network_info): """ Generate the network info and make calls to place it into the xenstore and the xenstore param list @@ -831,7 +832,10 @@ class VMOps(object): logging.debug(_("injecting network info to xs for vm: |%s|"), vm_ref) # this function raises if vm_ref is not a vm_opaque_ref - self._session.get_xenapi().VM.get_record(vm_ref) + if vm_ref: + self._session.get_xenapi().VM.get_record(vm_ref) + else: + vm_ref = VMHelper.lookup(self._session, instance.name) for (network, info) in network_info: location = 'vm-data/networking/%s' % info['mac'].replace(':', '') -- cgit From b93abf52587da04f8079be9be1ed0f9a473a9613 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 21 Apr 2011 11:48:47 -0500 Subject: commit to push for testing --- nova/virt/xenapi_conn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index 0cabccf08..b8a24d5a2 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -183,9 +183,9 @@ class XenAPIConnection(driver.ComputeDriver): def list_instances_detail(self): return self._vmops.list_instances_detail() - def spawn(self, instance): + def spawn(self, instance, network_info): """Create VM instance""" - self._vmops.spawn(instance) + self._vmops.spawn(instance, network_info) def revert_resize(self, instance): """Reverts a resize, powering back on the instance""" -- cgit From 08a22883fd5bf58b5b74645d1b2065a0be8c733b Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 19 May 2011 10:40:49 -0500 Subject: updated the hypervisors and ec2 api to support receiving lists from pluralized mac_addresses and fixed_ips --- nova/virt/hyperv.py | 7 ++++++- nova/virt/vmwareapi/vm_util.py | 6 +++++- nova/virt/vmwareapi/vmops.py | 14 ++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/hyperv.py b/nova/virt/hyperv.py index 13f403a66..10f3b2f4b 100644 --- a/nova/virt/hyperv.py +++ b/nova/virt/hyperv.py @@ -158,7 +158,12 @@ class HyperVConnection(driver.ComputeDriver): self._create_vm(instance) self._create_disk(instance['name'], vhdfile) - self._create_nic(instance['name'], instance['mac_address']) + + mac_address = None + if instance['mac_addresses']: + mac_address = instance['mac_addresses'][0]['address'] + + self._create_nic(instance['name'], mac_address) LOG.debug(_('Starting VM %s '), instance.name) self._set_vm_state(instance['name'], 'Enabled') diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index a2fa7600c..1638149f1 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -61,8 +61,12 @@ def get_vm_create_spec(client_factory, instance, data_store_name, config_spec.numCPUs = int(instance.vcpus) config_spec.memoryMB = int(instance.memory_mb) + mac_address = None + if instance['mac_addresses']: + mac_address = instance['mac_addresses'][0]['address'] + nic_spec = create_network_spec(client_factory, - network_name, instance.mac_address) + network_name, mac_address) device_config_spec = [nic_spec] diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index cf6c88bbd..55517a007 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -714,19 +714,25 @@ class VMWareVMOps(object): Set the machine id of the VM for guest tools to pick up and change the IP. """ + admin_context = context.get_admin_context() vm_ref = self._get_vm_ref_from_the_name(instance.name) if vm_ref is None: raise exception.NotFound(_("instance - %s not present") % instance.name) network = db.network_get_by_instance(context.get_admin_context(), instance['id']) - mac_addr = instance.mac_address + mac_address = None + if instance['mac_addresses']: + mac_address = instance['mac_addresses'][0]['address'] + net_mask = network["netmask"] gateway = network["gateway"] - ip_addr = db.instance_get_fixed_address(context.get_admin_context(), - instance['id']) + addresses = db.instance_get_fixed_addresses(admin_context, + instance['id']) + ip_addr = addresses[0] if addresses else None + machine_id_chanfge_spec = \ - vm_util.get_machine_id_change_spec(client_factory, mac_addr, + vm_util.get_machine_id_change_spec(client_factory, mac_address, ip_addr, net_mask, gateway) LOG.debug(_("Reconfiguring VM instance %(name)s to set the machine id " "with ip - %(ip_addr)s") % -- cgit From bed6e707247c297771661fd8bac7b939b0d9bbcb Mon Sep 17 00:00:00 2001 From: Jason Kölker Date: Tue, 24 May 2011 15:09:34 -0500 Subject: let the fake driver accept the network info --- nova/virt/fake.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/virt') diff --git a/nova/virt/fake.py b/nova/virt/fake.py index c3d5230df..a1d637b1c 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -114,7 +114,7 @@ class FakeConnection(driver.ComputeDriver): info_list.append(self._map_to_instance_info(instance)) return info_list - def spawn(self, instance): + def spawn(self, instance, network_info): """ Create a new instance/VM/domain on the virtualization platform. -- cgit From 924d7a88aa9e6d81e20babc0f1d780b3e916300a Mon Sep 17 00:00:00 2001 From: Cerberus Date: Thu, 26 May 2011 16:30:47 -0500 Subject: Virt tests passing while assuming the old style single nics --- nova/virt/libvirt_conn.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index fa918b0a3..81c2a7769 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -164,10 +164,18 @@ def _get_network_info(instance): # we should cache network_info admin_context = context.get_admin_context() - ip_addresses = db.fixed_ip_get_all_by_instance(admin_context, + try: + ip_addresses = db.fixed_ip_get_all_by_instance(admin_context, instance['id']) - networks = db.network_get_all_by_instance(admin_context, - instance['id']) + except exception.NoFixedIpsFoundForInstance, e: + pass + + try: + networks = db.network_get_all_by_instance(admin_context, + instance['id']) + except exception.NetworkNotFoundForInstance, e: + return [] + flavor = db.instance_type_get_by_id(admin_context, instance['instance_type_id']) network_info = [] @@ -176,6 +184,17 @@ def _get_network_info(instance): network_ips = [ip for ip in ip_addresses if ip['network_id'] == network['id']] + # FIXME(anyone): remove this once libvirt multinic is implemented + # correctly. This is merely a shim to make the unit tests continue to + # work + mac_address = None + try: + fixed_ip = db.fixed_ip_get_by_instance_and_network(admin_context, + instance['id'], network['id']) + mac_address = fixed_ip.mac_address.address + except exception.NoFixedIpsFoundForInstance, e: + pass + def ip_dict(ip): return { 'ip': ip['address'], @@ -184,7 +203,7 @@ def _get_network_info(instance): def ip6_dict(): prefix = network['cidr_v6'] - mac = instance['mac_address'] + mac = mac_address project_id = instance['project_id'] return { 'ip': ipv6.to_global(prefix, mac, project_id), @@ -195,7 +214,7 @@ def _get_network_info(instance): 'label': network['label'], 'gateway': network['gateway'], 'broadcast': network['broadcast'], - 'mac': instance['mac_address'], + 'mac': mac_address, 'rxtx_cap': flavor['rxtx_cap'], 'dns': [network['dns']], 'ips': [ip_dict(ip) for ip in network_ips]} -- cgit From 03a179ed2e75f00d4321bf6835d163f581f3a193 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Fri, 27 May 2011 14:59:04 -0500 Subject: XenAPI tests pass --- nova/virt/xenapi/vmops.py | 1 + 1 file changed, 1 insertion(+) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 0074444f8..1919e274d 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -870,6 +870,7 @@ class VMOps(object): def create_vifs(self, vm_ref, network_info): """Creates vifs for an instance.""" + logging.debug(_("creating vif(s) for vm: |%s|"), vm_ref) # this function raises if vm_ref is not a vm_opaque_ref -- cgit From eee29c8142e530c801d655cf27858297946010ec Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 2 Jun 2011 13:21:35 -0500 Subject: some comment docstring modifications --- nova/virt/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/virt') diff --git a/nova/virt/driver.py b/nova/virt/driver.py index eb9626d08..37ca4d2d4 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -234,7 +234,7 @@ class ComputeDriver(object): """ raise NotImplementedError() - def inject_network_info(self, instance): + def inject_network_info(self, instance, nw_info): """inject network info for specified instance""" raise NotImplementedError() -- cgit From 0438855659d89133e588dd4201956a901ed85787 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 8 Jun 2011 12:41:09 -0500 Subject: removed network_info shims in vmops --- nova/virt/xenapi/vmops.py | 70 +++-------------------------------------------- nova/virt/xenapi_conn.py | 4 +-- 2 files changed, 6 insertions(+), 68 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 32dae97c2..e5154b655 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -115,7 +115,7 @@ class VMOps(object): disk_image_type) return vdis - def spawn(self, instance, network_info=None): + def spawn(self, instance, network_info): vdis = self._create_disks(instance) vm_ref = self._create_vm(instance, vdis, network_info) self._spawn(instance, vm_ref) @@ -124,7 +124,7 @@ class VMOps(object): """Spawn a rescue instance.""" self.spawn(instance) - def _create_vm(self, instance, vdis, network_info=None): + def _create_vm(self, instance, vdis, network_info): """Create VM instance.""" instance_name = instance.name vm_ref = VMHelper.lookup(self._session, instance_name) @@ -181,11 +181,6 @@ class VMOps(object): bootable=False) userdevice += 1 - # TODO(tr3buchet) - check to make sure we have network info, otherwise - # create it now. This goes away once nova-multi-nic hits. - if network_info is None: - network_info = self._get_network_info(instance) - # Alter the image before VM start for, e.g. network injection if FLAGS.xenapi_inject_image: VMHelper.preconfigure_instance(self._session, instance, @@ -813,76 +808,19 @@ class VMOps(object): # TODO: implement this! return 'http://fakeajaxconsole/fake_url' - # TODO(tr3buchet) - remove this function after nova multi-nic - def _get_network_info(self, instance): - """Creates network info list for instance.""" - admin_context = context.get_admin_context() - ips = db.fixed_ip_get_all_by_instance(admin_context, - instance['id']) - networks = db.network_get_all_by_instance(admin_context, - instance['id']) - - inst_type = db.instance_type_get_by_id(admin_context, - instance['instance_type_id']) - - network_info = [] - for network in networks: - network_ips = [ip for ip in ips if ip.network_id == network.id] - - def ip_dict(ip): - return { - "ip": ip.address, - "netmask": network["netmask"], - "enabled": "1"} - - def ip6_dict(): - return { - "ip": ipv6.to_global(network['cidr_v6'], - instance['mac_address'], - instance['project_id']), - "netmask": network['netmask_v6'], - "enabled": "1"} - - info = { - 'label': network['label'], - 'gateway': network['gateway'], - 'broadcast': network['broadcast'], - 'mac': instance.mac_address, - 'rxtx_cap': inst_type['rxtx_cap'], - 'dns': [network['dns']], - 'ips': [ip_dict(ip) for ip in network_ips]} - if network['cidr_v6']: - info['ip6s'] = [ip6_dict()] - if network['gateway_v6']: - info['gateway6'] = network['gateway_v6'] - network_info.append((network, info)) - return network_info - - #TODO{tr3buchet) remove this shim with nova-multi-nic - def inject_network_info(self, instance, network_info=None, vm_ref=None): - """ - shim in place which makes inject_network_info work without being - passed network_info. - shim goes away after nova-multi-nic - """ - if not network_info: - network_info = self._get_network_info(instance) - self._inject_network_info(instance, network_info, vm_ref) - - def _inject_network_info(self, instance, network_info, vm_ref=None): + def inject_network_info(self, instance, network_info, vm_ref=None): """ Generate the network info and make calls to place it into the xenstore and the xenstore param list. vm_ref can be passed in because it will sometimes be different than what VMHelper.lookup(session, instance.name) will find (ex: rescue) """ - logging.debug(_("injecting network info to xs for vm: |%s|"), vm_ref) - if vm_ref: # this function raises if vm_ref is not a vm_opaque_ref self._session.get_xenapi().VM.get_record(vm_ref) else: vm_ref = VMHelper.lookup(self._session, instance.name) + logging.debug(_("injecting network info to xs for vm: |%s|"), vm_ref) for (network, info) in network_info: location = 'vm-data/networking/%s' % info['mac'].replace(':', '') diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index 9e48f86b7..764a3a5af 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -265,9 +265,9 @@ class XenAPIConnection(driver.ComputeDriver): """reset networking for specified instance""" self._vmops.reset_network(instance) - def inject_network_info(self, instance): + def inject_network_info(self, instance, network_info): """inject network info for specified instance""" - self._vmops.inject_network_info(instance) + self._vmops.inject_network_info(instance, network_info) def get_info(self, instance_id): """Return data about VM instance""" -- cgit From d7925b3890f651b3f6fd002a45b2add86e388d10 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 8 Jun 2011 14:46:31 -0500 Subject: updated docstring for nova-manage network create --- nova/virt/libvirt/netutils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/libvirt/netutils.py b/nova/virt/libvirt/netutils.py index 4d596078a..c8c2dbc67 100644 --- a/nova/virt/libvirt/netutils.py +++ b/nova/virt/libvirt/netutils.py @@ -53,8 +53,7 @@ def get_network_info(instance): # we should cache network_info admin_context = context.get_admin_context() - ip_addresses = db.fixed_ip_get_all_by_instance(admin_context, - instance['id']) + ip_addresses = db.fixed_ip_get_by_instance(admin_context, instance['id']) networks = db.network_get_all_by_instance(admin_context, instance['id']) flavor = db.instance_type_get_by_id(admin_context, -- cgit From d632e9883ef2fecb74b3bfdc62b8871a2c74ff93 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 15 Jun 2011 11:29:07 -0500 Subject: updated finish_resize to accept network_info, updated compute and tests in accordance --- nova/virt/xenapi/vmops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 6b2287cab..5bbbb52e1 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -88,13 +88,13 @@ class VMOps(object): vm_ref = VMHelper.lookup(self._session, instance.name) self._start(instance, vm_ref) - def finish_resize(self, instance, disk_info): + def finish_resize(self, instance, disk_info, network_info): vdi_uuid = self.link_disks(instance, disk_info['base_copy'], disk_info['cow']) vm_ref = self._create_vm(instance, [dict(vdi_type='os', vdi_uuid=vdi_uuid)]) self.resize_instance(instance, vdi_uuid) - self._spawn(instance, vm_ref) + self._spawn(instance, vm_ref, network_info) def _start(self, instance, vm_ref=None): """Power on a VM instance""" -- cgit From b3e9402579ea395e7ca0f66d0c6ff9996d1b74ad Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 15 Jun 2011 12:06:30 -0500 Subject: updated xenapi_conn finish_resize arguments --- nova/virt/xenapi_conn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index 764a3a5af..cbd4699ca 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -202,9 +202,9 @@ class XenAPIConnection(driver.ComputeDriver): """Reverts a resize, powering back on the instance""" self._vmops.revert_resize(instance) - def finish_resize(self, instance, disk_info): + def finish_resize(self, instance, disk_info, network_info): """Completes a resize, turning on the migrated instance""" - self._vmops.finish_resize(instance, disk_info) + self._vmops.finish_resize(instance, disk_info, network_info) def snapshot(self, instance, image_id): """ Create snapshot from a running VM instance """ -- cgit From c220bfd9d233ae0b18b5181eeafa2e70c17f7a30 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 15 Jun 2011 12:13:28 -0500 Subject: network info to _create_vm --- nova/virt/xenapi/vmops.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 5bbbb52e1..7931d117d 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -92,9 +92,10 @@ class VMOps(object): vdi_uuid = self.link_disks(instance, disk_info['base_copy'], disk_info['cow']) vm_ref = self._create_vm(instance, - [dict(vdi_type='os', vdi_uuid=vdi_uuid)]) + [dict(vdi_type='os', vdi_uuid=vdi_uuid)], + network_info) self.resize_instance(instance, vdi_uuid) - self._spawn(instance, vm_ref, network_info) + self._spawn(instance, vm_ref) def _start(self, instance, vm_ref=None): """Power on a VM instance""" -- cgit From 7620db9454dd391ce3080e99cdb8237eaa9a4835 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Wed, 15 Jun 2011 22:28:32 +0000 Subject: Windows instances will often take a few minutes setting up the image on first boot and then reboot. We should be more patient for those systems as well check if the domid changes so we can send agent requests to the current domid --- nova/virt/xenapi/vmops.py | 60 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 11 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 6b61ca9b5..190bf7c20 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -25,6 +25,7 @@ import M2Crypto import os import pickle import subprocess +import time import uuid from nova import context @@ -44,7 +45,10 @@ from nova.virt.xenapi.vm_utils import ImageType XenAPI = None LOG = logging.getLogger("nova.virt.xenapi.vmops") + FLAGS = flags.FLAGS +flags.DEFINE_integer('windows_version_timeout', 300, + 'time to wait for windows agent to be fully operational') def _cmp_version(a, b): @@ -244,7 +248,16 @@ class VMOps(object): 'architecture': instance.architecture}) def _check_agent_version(): - version = self.get_agent_version(instance) + if instance.os_type == 'windows': + # Windows will generally perform a setup process on first boot + # that can take a couple of minutes and then reboot. So we + # need to be more patient than normal as well as watch for + # domid changes + version = self.get_agent_version(instance, + timeout=FLAGS.windows_version_timeout, + check_domid_changes=True) + else: + version = self.get_agent_version(instance) if not version: LOG.info(_('No agent version returned by instance')) return @@ -500,18 +513,43 @@ class VMOps(object): task = self._session.call_xenapi('Async.VM.clean_reboot', vm_ref) self._session.wait_for_task(task, instance.id) - def get_agent_version(self, instance): + def get_agent_version(self, instance, timeout=None, + check_domid_changes=False): """Get the version of the agent running on the VM instance.""" - # Send the encrypted password - transaction_id = str(uuid.uuid4()) - args = {'id': transaction_id} - resp = self._make_agent_call('version', instance, '', args) - if resp is None: - # No response from the agent - return - resp_dict = json.loads(resp) - return resp_dict['message'] + def _call(): + # Send the encrypted password + transaction_id = str(uuid.uuid4()) + args = {'id': transaction_id} + resp = self._make_agent_call('version', instance, '', args) + if resp is None: + # No response from the agent + return + resp_dict = json.loads(resp) + return resp_dict['message'] + + if timeout: + vm_ref = self._get_vm_opaque_ref(instance) + vm_rec = self._session.get_xenapi().VM.get_record(vm_ref) + + domid = vm_rec['domid'] + + timeout = time.time() + timeout + while time.time() < timeout: + ret = _call() + if ret: + return ret + + if check_domid_changes: + vm_rec = self._session.get_xenapi().VM.get_record(vm_ref) + if vm_rec['domid'] != domid: + LOG.info(_('domid changed from %(olddomid)s to ' + '%(newdomid)s') % { + 'olddomid': domid, + 'newdomid': vm_rec['domid']}) + domid = vm_rec['domid'] + else: + return _call() def agent_update(self, instance, url, md5sum): """Update agent on the VM instance.""" -- cgit From 0ebfe3121c9abc00e0cb749dcc0f4b3dc5cbacb6 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Tue, 21 Jun 2011 11:09:54 -0500 Subject: some libvirt multi-nic just to get it to work, from tushar --- nova/virt/libvirt/connection.py | 24 ++++++++++++------------ nova/virt/libvirt/firewall.py | 8 ++++---- nova/virt/libvirt/netutils.py | 20 +++++++++++++------- 3 files changed, 29 insertions(+), 23 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 96ef92825..9016933d6 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -771,8 +771,6 @@ class LibvirtConnection(driver.ComputeDriver): def _create_image(self, inst, libvirt_xml, suffix='', disk_images=None, network_info=None, block_device_mapping=None): block_device_mapping = block_device_mapping or [] - if not network_info: - network_info = netutils.get_network_info(inst) if not suffix: suffix = '' @@ -881,18 +879,20 @@ class LibvirtConnection(driver.ComputeDriver): have_injected_networks = True address = mapping['ips'][0]['ip'] + netmask = mapping['ips'][0]['netmask'] address_v6 = None if FLAGS.use_ipv6: address_v6 = mapping['ip6s'][0]['ip'] + netmask_v6 = mapping['ip6s'][0]['netmask'] net_info = {'name': 'eth%d' % ifc_num, 'address': address, - 'netmask': network_ref['netmask'], - 'gateway': network_ref['gateway'], - 'broadcast': network_ref['broadcast'], - 'dns': network_ref['dns'], + 'netmask': netmask, + 'gateway': mapping['gateway'], + 'broadcast': mapping['broadcast'], + 'dns': mapping['dns'], 'address_v6': address_v6, - 'gateway_v6': network_ref['gateway_v6'], - 'netmask_v6': network_ref['netmask_v6']} + 'gateway6': mapping['gateway6'], + 'netmask_v6': netmask_v6} nets.append(net_info) if have_injected_networks: @@ -928,8 +928,8 @@ class LibvirtConnection(driver.ComputeDriver): def _get_nic_for_xml(self, network, mapping): # Assume that the gateway also acts as the dhcp server. - dhcp_server = network['gateway'] - gateway_v6 = network['gateway_v6'] + dhcp_server = mapping['gateway'] + gateway6 = mapping.get('gateway6') mac_id = mapping['mac'].replace(':', '') if FLAGS.allow_project_net_traffic: @@ -955,8 +955,8 @@ class LibvirtConnection(driver.ComputeDriver): 'extra_params': extra_params, } - if gateway_v6: - result['gateway_v6'] = gateway_v6 + "/128" + if gateway6: + result['gateway6'] = gateway6 + "/128" return result diff --git a/nova/virt/libvirt/firewall.py b/nova/virt/libvirt/firewall.py index 84153fa1e..d990d6f15 100644 --- a/nova/virt/libvirt/firewall.py +++ b/nova/virt/libvirt/firewall.py @@ -543,7 +543,7 @@ class IptablesFirewallDriver(FirewallDriver): ipv4_rules += ['-m state --state ESTABLISHED,RELATED -j ACCEPT'] ipv6_rules += ['-m state --state ESTABLISHED,RELATED -j ACCEPT'] - dhcp_servers = [network['gateway'] for (network, _m) in network_info] + dhcp_servers = [info['gateway'] for (_n, info) in network_info] for dhcp_server in dhcp_servers: ipv4_rules.append('-s %s -p udp --sport 67 --dport 68 ' @@ -560,7 +560,7 @@ class IptablesFirewallDriver(FirewallDriver): # they're not worth the clutter. if FLAGS.use_ipv6: # Allow RA responses - gateways_v6 = [network['gateway_v6'] for (network, _) in + gateways_v6 = [mapping['gateway6'] for (_n, mapping) in network_info] for gateway_v6 in gateways_v6: ipv6_rules.append( @@ -568,8 +568,8 @@ class IptablesFirewallDriver(FirewallDriver): #Allow project network traffic if FLAGS.allow_project_net_traffic: - cidrv6s = [network['cidr_v6'] for (network, _m) - in network_info] + cidrv6s = [network['cidr_v6'] for (network, _m) in + network_info] for cidrv6 in cidrv6s: ipv6_rules.append('-s %s -j ACCEPT' % (cidrv6,)) diff --git a/nova/virt/libvirt/netutils.py b/nova/virt/libvirt/netutils.py index c8c2dbc67..773f0a09c 100644 --- a/nova/virt/libvirt/netutils.py +++ b/nova/virt/libvirt/netutils.py @@ -49,30 +49,36 @@ def get_ip_version(cidr): def get_network_info(instance): + # TODO(tr3buchet): this function needs to go away! network info + # MUST be passed down from compute # TODO(adiantum) If we will keep this function # we should cache network_info admin_context = context.get_admin_context() - ip_addresses = db.fixed_ip_get_by_instance(admin_context, instance['id']) + fixed_ips = db.fixed_ip_get_by_instance(admin_context, instance['id']) + vifs = db.virtual_interface_get_by_instance(admin_context, instance['id']) networks = db.network_get_all_by_instance(admin_context, instance['id']) flavor = db.instance_type_get_by_id(admin_context, instance['instance_type_id']) network_info = [] - for network in networks: - network_ips = [ip for ip in ip_addresses - if ip['network_id'] == network['id']] + for vif in vifs: + network = vif['network'] + + # determine which of the instance's IPs belong to this network + network_ips = [fixed_ip['address'] for fixed_ip in fixed_ips if + fixed_ip['network_id'] == network['id']] def ip_dict(ip): return { - 'ip': ip['address'], + 'ip': ip, 'netmask': network['netmask'], 'enabled': '1'} def ip6_dict(): prefix = network['cidr_v6'] - mac = instance['mac_address'] + mac = vif['address'] project_id = instance['project_id'] return { 'ip': ipv6.to_global(prefix, mac, project_id), @@ -83,7 +89,7 @@ def get_network_info(instance): 'label': network['label'], 'gateway': network['gateway'], 'broadcast': network['broadcast'], - 'mac': instance['mac_address'], + 'mac': vif['address'], 'rxtx_cap': flavor['rxtx_cap'], 'dns': [network['dns']], 'ips': [ip_dict(ip) for ip in network_ips]} -- cgit From c16f97249e4f0626f8b8d4a7af070201641770b8 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Mon, 27 Jun 2011 15:54:43 +0000 Subject: Clarify help verbiage --- nova/virt/xenapi/vmops.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index ad096f7eb..1e908f513 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -48,7 +48,8 @@ LOG = logging.getLogger("nova.virt.xenapi.vmops") FLAGS = flags.FLAGS flags.DEFINE_integer('windows_version_timeout', 300, - 'time to wait for windows agent to be fully operational') + 'number of seconds to wait for windows agent to be ' + 'fully operational') def cmp_version(a, b): -- cgit From 3d4ec00de0458533d5e8d5eac9d686dd6b626e49 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Mon, 27 Jun 2011 10:51:05 -0700 Subject: make sure basic filters are setup on instance restart --- nova/virt/libvirt/connection.py | 1 + 1 file changed, 1 insertion(+) (limited to 'nova/virt') diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index b06bfb714..fadf77629 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -185,6 +185,7 @@ class LibvirtConnection(driver.ComputeDriver): if state != power_state.RUNNING: continue + self.firewall_driver.setup_basic_filtering(instance) self.firewall_driver.prepare_instance_filter(instance) self.firewall_driver.apply_instance_filter(instance) -- cgit From 68b313077578870908ebcc5b668df67ce921929a Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Wed, 29 Jun 2011 16:08:34 +0000 Subject: check_domid_changes is superfluous right now since it's only used when timeout is used. So simplify code a little bit --- nova/virt/xenapi/vmops.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 1e908f513..22ef0eb67 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -258,8 +258,7 @@ class VMOps(object): # need to be more patient than normal as well as watch for # domid changes version = self.get_agent_version(instance, - timeout=FLAGS.windows_version_timeout, - check_domid_changes=True) + timeout=FLAGS.windows_version_timeout) else: version = self.get_agent_version(instance) if not version: @@ -516,8 +515,7 @@ class VMOps(object): task = self._session.call_xenapi('Async.VM.clean_reboot', vm_ref) self._session.wait_for_task(task, instance.id) - def get_agent_version(self, instance, timeout=None, - check_domid_changes=False): + def get_agent_version(self, instance, timeout=None): """Get the version of the agent running on the VM instance.""" def _call(): @@ -543,14 +541,13 @@ class VMOps(object): if ret: return ret - if check_domid_changes: - vm_rec = self._session.get_xenapi().VM.get_record(vm_ref) - if vm_rec['domid'] != domid: - LOG.info(_('domid changed from %(olddomid)s to ' - '%(newdomid)s') % { - 'olddomid': domid, - 'newdomid': vm_rec['domid']}) - domid = vm_rec['domid'] + vm_rec = self._session.get_xenapi().VM.get_record(vm_ref) + if vm_rec['domid'] != domid: + LOG.info(_('domid changed from %(olddomid)s to ' + '%(newdomid)s') % { + 'olddomid': domid, + 'newdomid': vm_rec['domid']}) + domid = vm_rec['domid'] else: return _call() -- cgit From c1e799795e9634f4b56aaeb76c4a9553da3846e2 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Wed, 29 Jun 2011 21:39:43 +0000 Subject: Rename one use of timeout to expiration to make the purpose clearer --- nova/virt/xenapi/vmops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 22ef0eb67..53d2d2cec 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -535,8 +535,8 @@ class VMOps(object): domid = vm_rec['domid'] - timeout = time.time() + timeout - while time.time() < timeout: + expiration = time.time() + timeout + while time.time() < expiration: ret = _call() if ret: return ret -- cgit