VMware: Refactor the formatting instance metadata

Use a list of tuple instead of string format to join the instance
metadata in vmops _get_instance_metadata(), so that there would be
good correspondence between key and value.

Change-Id: I8c2f6e7199d97b77526a9ffefe5ad743c582dc1c
This commit is contained in:
Javeme 2016-01-18 19:02:26 +08:00
parent f35e65bd37
commit e930f00d44

View File

@ -247,31 +247,21 @@ class VMwareVMOps(object):
def _get_instance_metadata(self, context, instance):
flavor = instance.flavor
return ('name:%s\n'
'userid:%s\n'
'username:%s\n'
'projectid:%s\n'
'projectname:%s\n'
'flavor:name:%s\n'
'flavor:memory_mb:%s\n'
'flavor:vcpus:%s\n'
'flavor:ephemeral_gb:%s\n'
'flavor:root_gb:%s\n'
'flavor:swap:%s\n'
'imageid:%s\n'
'package:%s\n') % (instance.display_name,
context.user_id,
context.user_name,
context.project_id,
context.project_name,
flavor.name,
flavor.memory_mb,
flavor.vcpus,
flavor.ephemeral_gb,
flavor.root_gb,
flavor.swap,
instance.image_ref,
version.version_string_with_package())
metadata = [('name', instance.display_name),
('userid', context.user_id),
('username', context.user_name),
('projectid', context.project_id),
('projectname', context.project_name),
('flavor:name', flavor.name),
('flavor:memory_mb', flavor.memory_mb),
('flavor:vcpus', flavor.vcpus),
('flavor:ephemeral_gb', flavor.ephemeral_gb),
('flavor:root_gb', flavor.root_gb),
('flavor:swap', flavor.swap),
('imageid', instance.image_ref),
('package', version.version_string_with_package())]
# NOTE: formatted as lines like this: 'name:NAME\nuserid:ID\n...'
return ''.join(['%s:%s\n' % (k, v) for k, v in metadata])
def _create_folders(self, parent_folder, folder_path):
folders = folder_path.split('/')