Support os_version, os_type, and os_distro image properties

Modified default images to use os_type, os_version and os_distro
properties.  Added logic to look for distribution/os_distro,
type/os_type and version/os_version image properties when
matching image properties.

Cleaned up minor python warnings in tosca_compute.py

Removed DOS-style newline characters from
tosca_cluster_policies_scaling.py

Change-Id: I72043cf4a4358cfdbc8f98238276d85dc2f5bcc0
Closes-Bug: 1689673
This commit is contained in:
Bob.Haddleton 2017-05-17 21:53:36 -05:00 committed by Bob Haddleton
parent db5a60659b
commit 6904aab001
3 changed files with 266 additions and 239 deletions

61
translator/common/images.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@ -24,37 +25,46 @@ log = logging.getLogger('heat-translator')
PREDEF_IMAGES = {
'ubuntu-software-config-os-init': {'architecture': 'x86_64',
'type': 'Linux',
'distribution': 'Ubuntu',
'version': '14.04'},
'os_type': 'linux',
'os_distro': 'ubuntu',
'os_version': '14.04'
},
'ubuntu-12.04-software-config-os-init': {'architecture': 'x86_64',
'type': 'Linux',
'distribution': 'Ubuntu',
'version': '12.04'},
'os_type': 'linux',
'os_distro': 'ubuntu',
'os_version': '12.04'
},
'fedora-amd64-heat-config': {'architecture': 'x86_64',
'type': 'Linux',
'distribution': 'Fedora',
'version': '18.0'},
'os_type': 'linux',
'os_distro': 'fedora',
'os_version': '18.0'
},
'F18-x86_64-cfntools': {'architecture': 'x86_64',
'type': 'Linux',
'distribution': 'Fedora',
'version': '19'},
'os_type': 'linux',
'os_distro': 'fedora',
'os_version': '19'
},
'Fedora-x86_64-20-20131211.1-sda': {'architecture': 'x86_64',
'type': 'Linux',
'distribution': 'Fedora',
'version': '20'},
'os_type': 'linux',
'os_distro': 'fedora',
'os_version': '20'
},
'cirros-0.3.1-x86_64-uec': {'architecture': 'x86_64',
'type': 'Linux',
'distribution': 'CirrOS',
'version': '0.3.1'},
'os_type': 'linux',
'os_distro': 'cirros',
'os_version': '0.3.1'
},
'cirros-0.3.2-x86_64-uec': {'architecture': 'x86_64',
'type': 'Linux',
'distribution': 'CirrOS',
'version': '0.3.2'},
'os_type': 'linux',
'os_distro': 'cirros',
'os_version': '0.3.2'
},
'rhel-6.5-test-image': {'architecture': 'x86_64',
'type': 'Linux',
'distribution': 'RHEL',
'version': '6.5'}
'os_type': 'linux',
'os_distro': 'rhel',
'os_version': '6.5'
}
}
SESSION = None
@ -78,7 +88,8 @@ def get_images():
else:
for image in client.images.list():
image_name = image.name.encode('ascii', 'ignore')
metadata = ["architecture", "type", "distribution", "version"]
metadata = ["architecture", "type", "distribution", "version",
"os_distro", "os_type", "os_version"]
if any(key in image.keys() for key in metadata):
IMAGES[image_name] = {}
for key in metadata:

View File

@ -28,13 +28,16 @@ TARGET_CLASS_NAME = 'ToscaCompute'
class ToscaCompute(HotResource):
'''Translate TOSCA node type tosca.nodes.Compute.'''
"""Translate TOSCA node type tosca.nodes.Compute."""
COMPUTE_HOST_PROP = (DISK_SIZE, MEM_SIZE, NUM_CPUS) = \
('disk_size', 'mem_size', 'num_cpus')
COMPUTE_OS_PROP = (ARCHITECTURE, DISTRIBUTION, TYPE, VERSION) = \
('architecture', 'distribution', 'type', 'version')
IMAGE_OS_PROP = (OS_DISTRO, OS_TYPE, OS_VERSION) = \
('os_distro', 'os_type', 'os_version')
toscatype = 'tosca.nodes.Compute'
ALLOWED_NOVA_SERVER_PROPS = \
@ -141,32 +144,41 @@ class ToscaCompute(HotResource):
# Check whether user exported all required environment variables.
images = glance_images.get_images()
match_all = images.keys()
architecture = properties.get(self.ARCHITECTURE)
if architecture is None:
self._log_compute_msg(self.ARCHITECTURE, 'image')
match_arch = self._match_images(match_all, images,
self.ARCHITECTURE, architecture)
type = properties.get(self.TYPE)
if type is None:
[self.ARCHITECTURE], architecture)
image_type = properties.get(self.TYPE)
if image_type is None:
self._log_compute_msg(self.TYPE, 'image')
match_type = self._match_images(match_arch, images, self.TYPE, type)
match_type = self._match_images(match_arch, images, [self.TYPE,
self.OS_TYPE],
image_type)
distribution = properties.get(self.DISTRIBUTION)
if distribution is None:
self._log_compute_msg(self.DISTRIBUTION, 'image')
match_distribution = self._match_images(match_type, images,
self.DISTRIBUTION,
[self.DISTRIBUTION,
self.OS_DISTRO],
distribution)
version = properties.get(self.VERSION)
if version is None:
self._log_compute_msg(self.VERSION, 'image')
match_version = self._match_images(match_distribution, images,
self.VERSION, version)
[self.VERSION, self.OS_VERSION],
version)
if len(match_version):
return list(match_version)[0]
def _match_flavors(self, this_list, this_dict, attr, size):
'''Return from this list all flavors matching the attribute size.'''
@staticmethod
def _match_flavors(this_list, this_dict, attr, size):
"""Return from this list all flavors matching the attribute size."""
if not size:
return list(this_list)
matching_flavors = []
@ -177,19 +189,22 @@ class ToscaCompute(HotResource):
log.debug(_('Returning list of flavors matching the attribute size.'))
return matching_flavors
def _least_flavor(self, this_list, this_dict, attr):
'''Return from this list the flavor with the smallest attr.'''
@staticmethod
def _least_flavor(this_list, this_dict, attr):
"""Return from this list the flavor with the smallest attr."""
least_flavor = this_list[0]
for flavor in this_list:
if this_dict[flavor][attr] < this_dict[least_flavor][attr]:
least_flavor = flavor
return least_flavor
def _match_images(self, this_list, this_dict, attr, prop):
@staticmethod
def _match_images(this_list, this_dict, attr_list, prop):
if not prop:
return this_list
matching_images = []
for image in this_list:
for attr in attr_list:
if attr in this_dict[image]:
if this_dict[image][attr].lower() == str(prop).lower():
matching_images.insert(0, image)
@ -214,8 +229,9 @@ class ToscaCompute(HotResource):
return attr
def _log_compute_msg(self, prop, what):
@staticmethod
def _log_compute_msg(prop, what):
msg = _('No value is provided for Compute capability '
'property "%(prop)s". This may set an undesired "%(what)s" '
'in the template.') % {'prop': prop, 'what': what}
log.warn(msg)
log.warning(msg)