Support flavor and image properties for Compute translation

- If the tosca.nodes.Compute object does not have host or
    os capabilities specified, look for image and flavor properties
    to use, instead of leaving them set to None.  This allows the
    user to define nodes that inherit from Compute and contain
    properties that contain specific image and flavors to be used.

Change-Id: Ia2841639836795a8a6b7ca7fa0d03481cf7e5fd9
This commit is contained in:
Bob.Haddleton 2016-01-26 09:32:54 -06:00
parent 792249b925
commit 01d2731aba
4 changed files with 48 additions and 2 deletions

View File

@ -112,14 +112,16 @@ class ToscaCompute(HotResource):
for prop in host_capability.get_properties_objects():
host_cap_props[prop.name] = prop.value
flavor = self._best_flavor(host_cap_props)
else:
flavor = self.nodetemplate.get_property_value("flavor") or None
if os_capability:
for prop in os_capability.get_properties_objects():
os_cap_props[prop.name] = prop.value
image = self._best_image(os_cap_props)
else:
image = self.nodetemplate.get_property_value("image") or None
hot_properties['flavor'] = flavor
hot_properties['image'] = image
# TODO(anyone): consider adding the flavor or image as a template
# parameter if no match is found.
return hot_properties
def _check_for_env_variables(self):

View File

@ -0,0 +1,15 @@
heat_template_version: 2013-05-23
description: >
Template for deploying a server with custom properties for image and flavor.
parameters: {}
resources:
my_server:
type: OS::Nova::Server
properties:
flavor: m1.medium
image: rhel-6.5-test-image
key_name: userkey
user_data_format: SOFTWARE_CONFIG
outputs: {}

View File

@ -0,0 +1,20 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: Template for deploying a server with custom properties for image and flavor.
node_types:
tosca.nodes.nfv.VDU:
derived_from: tosca.nodes.Compute
properties:
image:
type: string
flavor:
type: string
topology_template:
node_templates:
my_server:
type: tosca.nodes.nfv.VDU
properties:
flavor: m1.medium
image: rhel-6.5-test-image

View File

@ -501,3 +501,12 @@ class ToscaHotTranslationTest(TestCase):
'heat-translator/master/translator/tests/data/'
'custom_types/wordpress1.yaml" cannot be accessed.')
ExceptionCollector.assertExceptionMessage(URLException, expected_msg)
def test_hot_translate_flavor_image(self):
tosca_file = '../tests/data/test_tosca_flavor_and_image.yaml'
hot_file = '../tests/data/hot_output/hot_flavor_and_image.yaml'
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
hot_file,
{})
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))