Merge "Fix metadata access in prep for instance objects"
This commit is contained in:
commit
5073504642
@ -32,6 +32,8 @@ from nova.compute import flavors
|
||||
from nova import conductor
|
||||
from nova import context
|
||||
from nova import network
|
||||
from nova import utils
|
||||
|
||||
from nova.openstack.common import timeutils
|
||||
from nova.virt import netutils
|
||||
|
||||
@ -127,9 +129,7 @@ class InstanceMetadata():
|
||||
self.address = address
|
||||
|
||||
# expose instance metadata.
|
||||
self.launch_metadata = {}
|
||||
for item in instance.get('metadata', []):
|
||||
self.launch_metadata[item['key']] = item['value']
|
||||
self.launch_metadata = utils.instance_meta(instance)
|
||||
|
||||
self.password = password.extract_password(instance)
|
||||
|
||||
|
@ -25,6 +25,7 @@ from nova.api.openstack.compute.views import images as views_images
|
||||
from nova.compute import flavors
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.openstack.common import timeutils
|
||||
from nova import utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -132,8 +133,7 @@ class ViewBuilder(common.ViewBuilder):
|
||||
|
||||
@staticmethod
|
||||
def _get_metadata(instance):
|
||||
metadata = instance.get("metadata", [])
|
||||
return dict((item['key'], item['value']) for item in metadata)
|
||||
return utils.instance_meta(instance)
|
||||
|
||||
@staticmethod
|
||||
def _get_vm_state(instance):
|
||||
|
@ -71,6 +71,7 @@ INSTANCES = (
|
||||
'info_cache': {'network_info': []},
|
||||
'hostname': 'test.novadomain',
|
||||
'display_name': 'my_displayname',
|
||||
'metadata': {}
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -981,6 +981,13 @@ def dict_to_metadata(metadata):
|
||||
return result
|
||||
|
||||
|
||||
def instance_meta(instance):
|
||||
if isinstance(instance['metadata'], dict):
|
||||
return instance['metadata']
|
||||
else:
|
||||
return metadata_to_dict(instance['metadata'])
|
||||
|
||||
|
||||
def instance_sys_meta(instance):
|
||||
if isinstance(instance['system_metadata'], dict):
|
||||
return instance['system_metadata']
|
||||
|
Loading…
Reference in New Issue
Block a user