summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-06-22 06:22:39 +0000
committerGerrit Code Review <review@openstack.org>2013-06-22 06:22:39 +0000
commitcefb0510b8f12dab17126907661d82094c31741d (patch)
treed65ab4d19e739b46d165fd0df799be320e547eab
parent76750f3dcce19098c9fb9793db1fe0c40411f7af (diff)
parent967e9675874fc2a02a585cc6f9b99175f9cd656c (diff)
downloadnova-cefb0510b8f12dab17126907661d82094c31741d.tar.gz
nova-cefb0510b8f12dab17126907661d82094c31741d.tar.xz
nova-cefb0510b8f12dab17126907661d82094c31741d.zip
Merge "Fix sys_meta access in prep for instance object"
-rw-r--r--nova/api/metadata/password.py8
-rw-r--r--nova/cells/messaging.py10
-rwxr-xr-xnova/compute/manager.py13
-rw-r--r--nova/compute/utils.py3
-rw-r--r--nova/virt/xenapi/agent.py2
-rw-r--r--nova/virt/xenapi/vm_utils.py4
6 files changed, 18 insertions, 22 deletions
diff --git a/nova/api/metadata/password.py b/nova/api/metadata/password.py
index 50f6c94ac..793dcc0a7 100644
--- a/nova/api/metadata/password.py
+++ b/nova/api/metadata/password.py
@@ -27,10 +27,10 @@ MAX_SIZE = CHUNKS * CHUNK_LENGTH
def extract_password(instance):
result = ''
- for datum in sorted(instance.get('system_metadata', []),
- key=lambda x: x['key']):
- if datum['key'].startswith('password_'):
- result += datum['value']
+ sys_meta = utils.instance_sys_meta(instance)
+ for key in sorted(sys_meta.keys()):
+ if key.startswith('password_'):
+ result += sys_meta[key]
return result or None
diff --git a/nova/cells/messaging.py b/nova/cells/messaging.py
index 319067836..6f4183f5d 100644
--- a/nova/cells/messaging.py
+++ b/nova/cells/messaging.py
@@ -813,12 +813,10 @@ class _BroadcastMessageMethods(_BaseMessageMethods):
info_cache.pop('id', None)
info_cache.pop('instance', None)
- # Fixup system_metadata (should be a dict for update, not a list)
- if ('system_metadata' in instance and
- isinstance(instance['system_metadata'], list)):
- sys_metadata = dict([(md['key'], md['value'])
- for md in instance['system_metadata']])
- instance['system_metadata'] = sys_metadata
+ if 'system_metadata' in instance:
+ # Make sure we have the dict form that we need for
+ # instance_update.
+ instance['system_metadata'] = utils.instance_sys_meta(instance)
LOG.debug(_("Got update for instance: %(instance)s"),
{'instance': instance}, instance_uuid=instance_uuid)
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 237831cd1..e0b2f38e8 100755
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1447,7 +1447,7 @@ class ComputeManager(manager.SchedulerDependentManager):
vm_state=vm_states.DELETED,
task_state=None,
terminated_at=timeutils.utcnow())
- system_meta = utils.metadata_to_dict(instance['system_metadata'])
+ system_meta = utils.instance_sys_meta(instance)
self.conductor_api.instance_destroy(context, instance)
except Exception:
with excutils.save_and_reraise_exception():
@@ -2072,7 +2072,7 @@ class ComputeManager(manager.SchedulerDependentManager):
def _get_rescue_image_ref(self, context, instance):
"""Determine what image should be used to boot the rescue VM."""
- system_meta = utils.metadata_to_dict(instance['system_metadata'])
+ system_meta = utils.instance_sys_meta(instance)
rescue_image_ref = system_meta.get('image_base_image_ref')
@@ -2174,7 +2174,7 @@ class ComputeManager(manager.SchedulerDependentManager):
Returns the updated system_metadata as a dict, as well as the
post-cleanup current instance type.
"""
- sys_meta = utils.metadata_to_dict(instance['system_metadata'])
+ sys_meta = utils.instance_sys_meta(instance)
if restore_old:
instance_type = flavors.extract_flavor(instance, 'old_')
sys_meta = flavors.save_flavor_info(sys_meta, instance_type)
@@ -2428,9 +2428,8 @@ class ComputeManager(manager.SchedulerDependentManager):
# NOTE(danms): Stash the new instance_type to avoid having to
# look it up in the database later
- sys_meta = utils.metadata_to_dict(instance['system_metadata'])
- flavors.save_flavor_info(sys_meta, instance_type,
- prefix='new_')
+ sys_meta = utils.instance_sys_meta(instance)
+ flavors.save_flavor_info(sys_meta, instance_type, prefix='new_')
# NOTE(mriedem): Stash the old vm_state so we can set the
# resized/reverted instance back to the same state later.
vm_state = instance['vm_state']
@@ -2600,7 +2599,7 @@ class ComputeManager(manager.SchedulerDependentManager):
old_instance_type_id = migration['old_instance_type_id']
new_instance_type_id = migration['new_instance_type_id']
old_instance_type = flavors.extract_flavor(instance)
- sys_meta = utils.metadata_to_dict(instance['system_metadata'])
+ sys_meta = utils.instance_sys_meta(instance)
# NOTE(mriedem): Get the old_vm_state so we know if we should
# power on the instance. If old_vm_sate is not set we need to default
# to ACTIVE for backwards compatibility
diff --git a/nova/compute/utils.py b/nova/compute/utils.py
index 9637d8773..3db4a14f2 100644
--- a/nova/compute/utils.py
+++ b/nova/compute/utils.py
@@ -203,8 +203,7 @@ def notify_usage_exists(context, instance_ref, current_period=False,
ignore_missing_network_data)
if system_metadata is None:
- system_metadata = utils.metadata_to_dict(
- instance_ref['system_metadata'])
+ system_metadata = utils.instance_sys_meta(instance_ref)
# add image metadata to the notification:
image_meta = notifications.image_meta(system_metadata)
diff --git a/nova/virt/xenapi/agent.py b/nova/virt/xenapi/agent.py
index 05a0fae41..0bd6d776e 100644
--- a/nova/virt/xenapi/agent.py
+++ b/nova/virt/xenapi/agent.py
@@ -197,7 +197,7 @@ class XenAPIBasedAgent(object):
if sshkey:
ctxt = context.get_admin_context()
enc = crypto.ssh_encrypt_text(sshkey, new_pass)
- sys_meta = utils.metadata_to_dict(self.instance['system_metadata'])
+ sys_meta = utils.instance_sys_meta(self.instance)
sys_meta.update(password.convert_password(ctxt,
base64.b64encode(enc)))
self.virtapi.instance_update(ctxt, self.instance['uuid'],
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index ff6f7f266..ac8c9c58b 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -1017,7 +1017,7 @@ def _create_image(context, session, instance, name_label, image_id,
elif cache_images == 'all':
cache = True
elif cache_images == 'some':
- sys_meta = utils.metadata_to_dict(instance['system_metadata'])
+ sys_meta = utils.instance_sys_meta(instance)
try:
cache = strutils.bool_from_string(sys_meta['image_cache_in_nova'])
except KeyError:
@@ -1112,7 +1112,7 @@ def _image_uses_bittorrent(context, instance):
if xenapi_torrent_images == 'all':
bittorrent = True
elif xenapi_torrent_images == 'some':
- sys_meta = utils.metadata_to_dict(instance['system_metadata'])
+ sys_meta = utils.instance_sys_meta(instance)
try:
bittorrent = strutils.bool_from_string(
sys_meta['image_bittorrent'])