From 5a0d4fbc24e897e4aa861819fd2f861e7dedcb6b Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 14 Mar 2011 16:33:01 -0500 Subject: added structure to virt.xenapi.vmops to support network info being passed in --- nova/virt/xenapi/vmops.py | 109 ++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 47 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index fcb290d03..bec403543 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -80,11 +80,11 @@ class VMOps(object): instance.image_id, user, project, disk_image_type) return vdi_uuid - def spawn(self, instance): + def spawn(self, instance, network_info=None): vdi_uuid = self.create_disk(instance) - self._spawn_with_disk(instance, vdi_uuid=vdi_uuid) + self._spawn_with_disk(instance, vdi_uuid=vdi_uuid, network_info) - def _spawn_with_disk(self, instance, vdi_uuid): + def _spawn_with_disk(self, instance, vdi_uuid, network_info=None): """Create VM instance""" instance_name = instance.name vm_ref = VMHelper.lookup(self._session, instance_name) @@ -128,8 +128,13 @@ class VMOps(object): vdi_ref=vdi_ref, userdevice=0, bootable=True) # inject_network_info and create vifs - networks = self.inject_network_info(instance) - self.create_vifs(instance, networks) + if network_info is not None: + self.inject_network_info(instance, network_info) + self.create_vifs(instance, [nw for (nw, mapping) in network_info]) + else: + # TODO(tr3buchet) - goes away with multi-nic + networks = self.inject_network_info(instance) + self.create_vifs(instance, networks) LOG.debug(_('Starting VM %s...'), vm_ref) self._start(instance, vm_ref) @@ -684,59 +689,68 @@ class VMOps(object): # TODO: implement this! return 'http://fakeajaxconsole/fake_url' - def inject_network_info(self, instance): + def inject_network_info(self, instance, network_info=None): """ Generate the network info and make calls to place it into the xenstore and the xenstore param list """ - # TODO(tr3buchet) - remove comment in multi-nic - # I've decided to go ahead and consider multiple IPs and networks - # at this stage even though they aren't implemented because these will - # be needed for multi-nic and there was no sense writing it for single - # network/single IP and then having to turn around and re-write it vm_ref = self._get_vm_opaque_ref(instance.id) logging.debug(_("injecting network info to xenstore for vm: |%s|"), vm_ref) - 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, + if network_info is not None: + for (network, mapping) in network_info: + self.write_to_param_xenstore(vm_ref, {location: mapping}) + try: + self.write_to_xenstore(vm_ref, location, + mapping['location']) + except KeyError: + # catch KeyError for domid if instance isn't running + pass + else: + # TODO(tr3buchet) - this bit here when network_info is None goes + # away with multi-nic + admin_context = context.get_admin_context() + IPs = db.fixed_ip_get_all_by_instance(admin_context, instance['id']) - 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(ip6): - return { - "ip": ip6.addressV6, - "netmask": ip6.netmaskV6, - "gateway": ip6.gatewayV6, - "enabled": "1"} - - mac_id = instance.mac_address.replace(':', '') - location = 'vm-data/networking/%s' % mac_id - mapping = { - 'label': network['label'], - 'gateway': network['gateway'], - 'mac': instance.mac_address, - 'dns': [network['dns']], - 'ips': [ip_dict(ip) for ip in network_IPs], - 'ip6s': [ip6_dict(ip) for ip in network_IPs]} - - self.write_to_param_xenstore(vm_ref, {location: mapping}) + networks = db.network_get_all_by_instance(admin_context, + instance['id']) + 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(ip6): + return { + "ip": ip6.addressV6, + "netmask": ip6.netmaskV6, + "gateway": ip6.gatewayV6, + "enabled": "1"} + + mac_id = instance.mac_address.replace(':', '') + location = 'vm-data/networking/%s' % mac_id + mapping = { + 'label': network['label'], + 'gateway': network['gateway'], + 'mac': instance.mac_address, + 'dns': [network['dns']], + 'ips': [ip_dict(ip) for ip in network_IPs], + 'ip6s': [ip6_dict(ip) for ip in network_IPs]} + + self.write_to_param_xenstore(vm_ref, {location: mapping}) - try: - self.write_to_xenstore(vm_ref, location, mapping['location']) - except KeyError: - # catch KeyError for domid if instance isn't running - pass + try: + self.write_to_xenstore(vm_ref, location, + mapping['location']) + except KeyError: + # catch KeyError for domid if instance isn't running + pass - return networks + return networks def create_vifs(self, instance, networks=None): """ @@ -745,6 +759,7 @@ class VMOps(object): """ vm_ref = self._get_vm_opaque_ref(instance.id) logging.debug(_("creating vif(s) for vm: |%s|"), vm_ref) + # TODO(tr3buchet) - goes away with multi-nic if networks is None: networks = db.network_get_all_by_instance(admin_context, instance['id']) -- cgit From 1d1e5e38175ff7956b3a28ccc1ce61f700700e8b Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 14 Mar 2011 16:38:53 -0500 Subject: fixed keyword arg error --- nova/virt/xenapi/vmops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index bec403543..64f2c6231 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -82,7 +82,7 @@ class VMOps(object): def spawn(self, instance, network_info=None): vdi_uuid = self.create_disk(instance) - self._spawn_with_disk(instance, vdi_uuid=vdi_uuid, network_info) + self._spawn_with_disk(instance, vdi_uuid, network_info) def _spawn_with_disk(self, instance, vdi_uuid, network_info=None): """Create VM instance""" -- cgit From 5379f3654e04a0443f3237623f772a17f13e9d90 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 16 Mar 2011 12:44:38 -0500 Subject: refactored, bugfixes --- nova/virt/xenapi/vm_utils.py | 4 +- nova/virt/xenapi/vmops.py | 163 +++++++++++++++++++------------------------ 2 files changed, 72 insertions(+), 95 deletions(-) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index f07b57796..1f03b4124 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -234,11 +234,11 @@ class VMHelper(HelperBase): raise StorageError(_('Unable to destroy VBD %s') % vbd_ref) @classmethod - def create_vif(cls, session, vm_ref, network_ref, mac_address, dev="0"): + def create_vif(cls, session, vm_ref, network_ref, mac_address, dev): """Create a VIF record. Returns a Deferred that gives the new VIF reference.""" vif_rec = {} - vif_rec['device'] = dev + vif_rec['device'] = str(dev) vif_rec['network'] = network_ref vif_rec['VM'] = vm_ref vif_rec['MAC'] = mac_address diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 64f2c6231..485dd41ca 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -128,13 +128,17 @@ class VMOps(object): vdi_ref=vdi_ref, userdevice=0, bootable=True) # inject_network_info and create vifs - if network_info is not None: - self.inject_network_info(instance, network_info) - self.create_vifs(instance, [nw for (nw, mapping) in network_info]) - else: - # TODO(tr3buchet) - goes away with multi-nic - networks = self.inject_network_info(instance) - self.create_vifs(instance, networks) + # 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: + 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']) + network_info = self._get_network_info(instance, networks, IPs) + self.inject_network_info(vm_ref, network_info) + self.create_vifs(vm_ref, network_info) LOG.debug(_('Starting VM %s...'), vm_ref) self._start(instance, vm_ref) @@ -689,104 +693,77 @@ class VMOps(object): # TODO: implement this! return 'http://fakeajaxconsole/fake_url' - def inject_network_info(self, instance, network_info=None): + # TODO(tr3buchet) - remove this function after nova multi-nic + def _get_network_info(self, instance, networks, IPs): + """creates network info list for instance""" + + tuple_list = [] + 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(ip6): + return { + "ip": ip6.addressV6, + "netmask": ip6.netmaskV6, + "gateway": ip6.gatewayV6, + "enabled": "1"} + + mac_id = instance.mac_address.replace(':', '') + location = 'vm-data/networking/%s' % mac_id + info = { + 'label': network['label'], + 'gateway': network['gateway'], + 'mac': instance.mac_address, + 'dns': [network['dns']], + 'ips': [ip_dict(ip) for ip in network_IPs], + 'ip6s': [ip6_dict(ip) for ip in network_IPs]} + tuple_list.append((network, info)) + + def inject_network_info(self, vm_ref, network_info): """ Generate the network info and make calls to place it into the xenstore and the xenstore param list - """ - vm_ref = self._get_vm_opaque_ref(instance.id) - logging.debug(_("injecting network info to xenstore for vm: |%s|"), - vm_ref) - if network_info is not None: - for (network, mapping) in network_info: - self.write_to_param_xenstore(vm_ref, {location: mapping}) - try: - self.write_to_xenstore(vm_ref, location, - mapping['location']) - except KeyError: - # catch KeyError for domid if instance isn't running - pass - else: - # TODO(tr3buchet) - this bit here when network_info is None goes - # away with multi-nic - 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']) - 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(ip6): - return { - "ip": ip6.addressV6, - "netmask": ip6.netmaskV6, - "gateway": ip6.gatewayV6, - "enabled": "1"} - - mac_id = instance.mac_address.replace(':', '') - location = 'vm-data/networking/%s' % mac_id - mapping = { - 'label': network['label'], - 'gateway': network['gateway'], - 'mac': instance.mac_address, - 'dns': [network['dns']], - 'ips': [ip_dict(ip) for ip in network_IPs], - 'ip6s': [ip6_dict(ip) for ip in network_IPs]} - - self.write_to_param_xenstore(vm_ref, {location: mapping}) - - try: - self.write_to_xenstore(vm_ref, location, - mapping['location']) - except KeyError: - # catch KeyError for domid if instance isn't running - pass - - return networks - - def create_vifs(self, instance, networks=None): - """ - Creates vifs for an instance + logging.debug(_("injecting network info to xs for vm: |%s|"), vm_ref) - """ - vm_ref = self._get_vm_opaque_ref(instance.id) + # make sure we have a vm opaque ref (raises otherwise) + self._session.get_xenapi().VM.get_record(vm_ref) + + for (network, info) in network_info: + location = 'vm-data/networking/%s' % info['mac'].replace(':', '') + self.write_to_param_xenstore(vm_ref, {location: info}) + try: + self.write_to_xenstore(vm_ref, location, info) + except KeyError: + # catch KeyError for domid if instance isn't running + pass + + def create_vifs(self, vm_ref, network_info): + """Creates vifs for an instance""" logging.debug(_("creating vif(s) for vm: |%s|"), vm_ref) - # TODO(tr3buchet) - goes away with multi-nic - if networks is None: - networks = db.network_get_all_by_instance(admin_context, - instance['id']) - # TODO(tr3buchet) - remove comment in multi-nic - # this bit here about creating the vifs will be updated - # in multi-nic to handle multiple IPs on the same network - # and multiple networks - # for now it works as there is only one of each - for network in networks: + + # make sure we have a vm opaque ref (raises otherwise) + self._session.get_xenapi().VM.get_record(vm_ref) + + device = 0 + for (network, info) in networks: + mac_address = info['mac'] bridge = network['bridge'] network_ref = \ NetworkHelper.find_network_with_bridge(self._session, bridge) - if network_ref: - try: - device = "1" if instance._rescue else "0" - except AttributeError: - device = "0" - - VMHelper.create_vif(self._session, vm_ref, network_ref, - instance.mac_address, device) + VMHelper.create_vif(self._session, vm_ref, network_ref, + mac_address, device) + device += 1 def reset_network(self, instance): - """ - Creates uuid arg to pass to make_agent_call and calls it. - - """ + """Creates uuid arg to pass to make_agent_call and calls it.""" args = {'id': str(uuid.uuid4())} resp = self._make_agent_call('resetnetwork', instance, '', args) -- cgit From d418926b514372f0f48922024e600bafcc657fd9 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 16 Mar 2011 12:50:11 -0500 Subject: forgot to return network info - teehee --- nova/virt/xenapi/vmops.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 485dd41ca..27f9a3a17 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -697,7 +697,7 @@ class VMOps(object): def _get_network_info(self, instance, networks, IPs): """creates network info list for instance""" - tuple_list = [] + network_info = [] for network in networks: network_IPs = [ip for ip in IPs if ip.network_id == network.id] @@ -714,8 +714,6 @@ class VMOps(object): "gateway": ip6.gatewayV6, "enabled": "1"} - mac_id = instance.mac_address.replace(':', '') - location = 'vm-data/networking/%s' % mac_id info = { 'label': network['label'], 'gateway': network['gateway'], @@ -723,7 +721,8 @@ class VMOps(object): 'dns': [network['dns']], 'ips': [ip_dict(ip) for ip in network_IPs], 'ip6s': [ip6_dict(ip) for ip in network_IPs]} - tuple_list.append((network, info)) + network_info.append((network, info)) + return network_info def inject_network_info(self, vm_ref, network_info): """ @@ -752,7 +751,7 @@ class VMOps(object): self._session.get_xenapi().VM.get_record(vm_ref) device = 0 - for (network, info) in networks: + for (network, info) in network_info: mac_address = info['mac'] bridge = network['bridge'] network_ref = \ -- cgit From adb9c0f0d933f8a56e688b89cfa632ce5c9e4888 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 16 Mar 2011 17:48:39 -0500 Subject: commit before monster --- nova/virt/xenapi/vmops.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 27f9a3a17..fbc7ab64d 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -761,10 +761,11 @@ class VMOps(object): mac_address, device) device += 1 - def reset_network(self, instance): + def reset_network(self, instance, vm_ref): """Creates uuid arg to pass to make_agent_call and calls it.""" args = {'id': str(uuid.uuid4())} - resp = self._make_agent_call('resetnetwork', instance, '', args) + resp = self._make_agent_call('resetnetwork', instance, '', args, + vm_ref) def list_from_xenstore(self, vm, path): """Runs the xenstore-ls command to get a listing of all records @@ -805,25 +806,27 @@ class VMOps(object): """ self._make_xenstore_call('delete_record', vm, path) - def _make_xenstore_call(self, method, vm, path, addl_args={}): + def _make_xenstore_call(self, method, vm, path, addl_args=None, + vm_ref=None): """Handles calls to the xenstore xenapi plugin.""" return self._make_plugin_call('xenstore.py', method=method, vm=vm, - path=path, addl_args=addl_args) + path=path, addl_args=addl_args, vm_ref=vm_ref) - def _make_agent_call(self, method, vm, path, addl_args={}): + def _make_agent_call(self, method, vm, path, addl_args=None, vm_ref=None): """Abstracts out the interaction with the agent xenapi plugin.""" return self._make_plugin_call('agent', method=method, vm=vm, - path=path, addl_args=addl_args) + path=path, addl_args=addl_args, vm_ref=vm_ref) - def _make_plugin_call(self, plugin, method, vm, path, addl_args={}): + def _make_plugin_call(self, plugin, method, vm, path, addl_args=None, + vm_ref=None): """Abstracts out the process of calling a method of a xenapi plugin. Any errors raised by the plugin will in turn raise a RuntimeError here. """ instance_id = vm.id - vm_ref = self._get_vm_opaque_ref(vm) + vm_ref = vm_ref or self._get_vm_opaque_ref(vm) vm_rec = self._session.get_xenapi().VM.get_record(vm_ref) args = {'dom_id': vm_rec['domid'], 'path': path} - args.update(addl_args) + args.update(addl_args or {}) try: task = self._session.async_call_plugin(plugin, method, args) ret = self._session.wait_for_task(task, instance_id) -- cgit From 038d99d9fa4354bd617adfa332d69a87a9f7918e Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 16 Mar 2011 18:18:07 -0500 Subject: hacks in place --- nova/virt/xenapi/vmops.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index fbc7ab64d..a9a6800b1 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -137,7 +137,7 @@ class VMOps(object): networks = db.network_get_all_by_instance(admin_context, instance['id']) network_info = self._get_network_info(instance, networks, IPs) - self.inject_network_info(vm_ref, network_info) + self.inject_network_info(instance, vm_ref, network_info) self.create_vifs(vm_ref, network_info) LOG.debug(_('Starting VM %s...'), vm_ref) @@ -188,7 +188,7 @@ class VMOps(object): timer.f = _wait_for_boot # call to reset network to configure network from xenstore - self.reset_network(instance) + self.reset_network(instance, vm_ref) return timer.start(interval=0.5, now=True) @@ -724,7 +724,7 @@ class VMOps(object): network_info.append((network, info)) return network_info - def inject_network_info(self, vm_ref, network_info): + def inject_network_info(self, instance, vm_ref, network_info): """ Generate the network info and make calls to place it into the xenstore and the xenstore param list @@ -738,7 +738,11 @@ class VMOps(object): location = 'vm-data/networking/%s' % info['mac'].replace(':', '') self.write_to_param_xenstore(vm_ref, {location: info}) try: - self.write_to_xenstore(vm_ref, location, info) + # TODO(tr3buchet): fix function call after refactor + #self.write_to_xenstore(vm_ref, location, info) + self._make_plugin_call('xenstore.py', 'write_record', instance, + location, {'value': json.dumps(info)}, + vm_ref) except KeyError: # catch KeyError for domid if instance isn't running pass @@ -764,8 +768,10 @@ class VMOps(object): def reset_network(self, instance, vm_ref): """Creates uuid arg to pass to make_agent_call and calls it.""" args = {'id': str(uuid.uuid4())} - resp = self._make_agent_call('resetnetwork', instance, '', args, - vm_ref) + # TODO(tr3buchet): fix function call after refactor + #resp = self._make_agent_call('resetnetwork', instance, '', args) + resp = self._make_plugin_call('agent', 'resetnetwork', instance, '', + args, vm_ref) def list_from_xenstore(self, vm, path): """Runs the xenstore-ls command to get a listing of all records @@ -806,16 +812,15 @@ class VMOps(object): """ self._make_xenstore_call('delete_record', vm, path) - def _make_xenstore_call(self, method, vm, path, addl_args=None, - vm_ref=None): + def _make_xenstore_call(self, method, vm, path, addl_args=None): """Handles calls to the xenstore xenapi plugin.""" return self._make_plugin_call('xenstore.py', method=method, vm=vm, - path=path, addl_args=addl_args, vm_ref=vm_ref) + path=path, addl_args=addl_args) - def _make_agent_call(self, method, vm, path, addl_args=None, vm_ref=None): + def _make_agent_call(self, method, vm, path, addl_args=None): """Abstracts out the interaction with the agent xenapi plugin.""" return self._make_plugin_call('agent', method=method, vm=vm, - path=path, addl_args=addl_args, vm_ref=vm_ref) + path=path, addl_args=addl_args) def _make_plugin_call(self, plugin, method, vm, path, addl_args=None, vm_ref=None): -- cgit From a437ea845bd83c8b1da9de81253132cbad6b48b7 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 17 Mar 2011 16:14:48 -0500 Subject: create vifs before inject network info to remove rxtx_cap from network info (don't need to inject it) --- nova/virt/xenapi/vmops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index a35d36b9e..aff4fb445 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -133,8 +133,8 @@ class VMOps(object): # create it now. This goes away once nova-multi-nic hits. if network_info is None: network_info = self._get_network_info(instance) - self.inject_network_info(instance, vm_ref, network_info) self.create_vifs(vm_ref, network_info) + self.inject_network_info(instance, vm_ref, network_info) LOG.debug(_('Starting VM %s...'), vm_ref) self._start(instance, vm_ref) -- cgit From b05bdeaf77ccb91ac59b4a2dde4a6cad94eb22b2 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 17 Mar 2011 16:17:03 -0500 Subject: syntax error --- nova/virt/xenapi/vmops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index aff4fb445..6542630c1 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -698,7 +698,7 @@ class VMOps(object): networks = db.network_get_all_by_instance(admin_context, instance['id']) flavor = db.instance_type_get_by_name(admin_context, - instance.['instance_type']) + instance['instance_type']) network_info = [] for network in networks: network_IPs = [ip for ip in IPs if ip.network_id == network.id] -- cgit From ac66fde6d787742e9d5d6af9ebfe3302d9375073 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 18 Mar 2011 17:22:13 -0500 Subject: comment more descriptive --- nova/virt/xenapi/vmops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 6542630c1..cfd74e5de 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -734,7 +734,7 @@ class VMOps(object): """ logging.debug(_("injecting network info to xs for vm: |%s|"), vm_ref) - # make sure we have a vm opaque ref (raises otherwise) + # this function raises if vm_ref is not a vm_opaque_ref self._session.get_xenapi().VM.get_record(vm_ref) for (network, info) in network_info: @@ -754,7 +754,7 @@ class VMOps(object): """Creates vifs for an instance""" logging.debug(_("creating vif(s) for vm: |%s|"), vm_ref) - # make sure we have a vm opaque ref (raises otherwise) + # this function raises if vm_ref is not a vm_opaque_ref self._session.get_xenapi().VM.get_record(vm_ref) device = 0 -- cgit From 6a893eabc83f4561025a9a655b0aabb2d3e1b3a7 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 21 Mar 2011 13:19:20 -0500 Subject: added an enumerate to track device in vmops.create_vifs() --- nova/virt/xenapi/vmops.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index cfd74e5de..61ff00903 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -757,8 +757,7 @@ class VMOps(object): # this function raises if vm_ref is not a vm_opaque_ref self._session.get_xenapi().VM.get_record(vm_ref) - device = 0 - for (network, info) in network_info: + for device, (network, info) in enumerate(network_info): mac_address = info['mac'] bridge = network['bridge'] rxtx_cap = info.pop('rxtx_cap') @@ -767,7 +766,6 @@ class VMOps(object): VMHelper.create_vif(self._session, vm_ref, network_ref, mac_address, device, rxtx_cap) - device += 1 def reset_network(self, instance, vm_ref): """Creates uuid arg to pass to make_agent_call and calls it.""" -- cgit