Implements get_operation_output function.

Change-Id: Ic1c45e5123cc68bc062bd387b9b0f6ed6ed11b3c
This commit is contained in:
Mathieu Velten 2016-06-30 14:51:50 +02:00
parent f17a5c24af
commit bf2f9041c0
6 changed files with 156 additions and 0 deletions

View File

@ -395,9 +395,43 @@ class TranslateNodeTemplates(object):
else: else:
return {'get_param': self.translate_param_value( return {'get_param': self.translate_param_value(
get_input_args, resource)} get_input_args, resource)}
elif isinstance(param_value, dict) \
and 'get_operation_output' in param_value:
res = self._translate_get_operation_output_function(
param_value['get_operation_output'], tosca_template)
if res:
return res
return param_value return param_value
def _translate_get_operation_output_function(self, args, tosca_template):
tosca_target = self._find_tosca_node(args[0],
tosca_template)
if tosca_target and len(args) >= 4:
operations = HotResource.get_all_operations(tosca_target)
# ignore Standard interface name,
# it is the only one supported in the translator anyway
op_name = args[2]
output_name = args[3]
if op_name in operations:
operation = operations[op_name]
if operation in self.hot_lookup:
matching_deploy = self.hot_lookup[operation]
matching_config_name = matching_deploy.\
properties['config']['get_resource']
matching_config = self.find_hot_resource(
matching_config_name)
if matching_config:
outputs = matching_config.properties.get('outputs')
if outputs is None:
outputs = []
outputs.append({'name': output_name})
matching_config.properties['outputs'] = outputs
return {'get_attr': [
matching_deploy.name,
output_name
]}
@staticmethod @staticmethod
def _unfold_value(value, value_arg): def _unfold_value(value, value_arg):
if value_arg is not None: if value_arg is not None:

View File

@ -0,0 +1,4 @@
#!/bin/bash
test -d /root/.ssh || mkdir /root/.ssh
test -f /root/.ssh/id_rsa.pub || ssh-keygen -q -t rsa -N "" -f /root/.ssh/id_rsa
cat /root/.ssh/id_rsa.pub > ${heat_outputs_path}.public_key

View File

@ -0,0 +1,3 @@
#!/bin/bash
test -d /root/.ssh || mkdir /root/.ssh
echo "$public_key" >> /root/.ssh/authorized_keys

View File

@ -0,0 +1,55 @@
heat_template_version: 2013-05-23
description: >
TOSCA template to test get_operation_output by exchanging ssh public key
parameters: {}
resources:
generate_ssh_key_create_deploy:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: generate_ssh_key_create_config
server:
get_resource: server1
import_public_key_create_deploy:
type: OS::Heat::SoftwareDeployment
properties:
config:
get_resource: import_public_key_create_config
input_values:
public_key:
get_attr:
- generate_ssh_key_create_deploy
- public_key
server:
get_resource: server2
depends_on:
- generate_ssh_key_create_deploy
server1:
type: OS::Nova::Server
properties:
flavor: m1.small
image: ubuntu-12.04-software-config-os-init
user_data_format: SOFTWARE_CONFIG
server2:
type: OS::Nova::Server
properties:
flavor: m1.small
image: ubuntu-12.04-software-config-os-init
user_data_format: SOFTWARE_CONFIG
generate_ssh_key_create_config:
type: OS::Heat::SoftwareConfig
properties:
config:
get_file: artifacts/ssh/ssh_generate_keys.sh
group: script
outputs:
- name: public_key
import_public_key_create_config:
type: OS::Heat::SoftwareConfig
properties:
config:
get_file: artifacts/ssh/ssh_import_public_key.sh
group: script
outputs: {}

View File

@ -0,0 +1,54 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: TOSCA template to test get_operation_output by exchanging ssh public key
topology_template:
node_templates:
server1:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 1
mem_size: 1 GB
os:
properties:
type: Linux
distribution: Ubuntu
version: 12.04
architecture: x86_64
server2:
type: tosca.nodes.Compute
capabilities:
host:
properties:
num_cpus: 1
mem_size: 1 GB
os:
properties:
type: Linux
distribution: Ubuntu
version: 12.04
architecture: x86_64
generate_ssh_key:
type: tosca.nodes.SoftwareComponent
interfaces:
Standard:
create: artifacts/ssh/ssh_generate_keys.sh
requirements:
- host: server1
import_public_key:
type: tosca.nodes.SoftwareComponent
interfaces:
Standard:
create:
implementation: artifacts/ssh/ssh_import_public_key.sh
inputs:
public_key: { get_operation_output: [generate_ssh_key, Standard, create, public_key] }
requirements:
- host: server2
- dependency: generate_ssh_key

View File

@ -483,3 +483,9 @@ class ToscaHotTranslationTest(TestCase):
hot_file = '../tests/data/hot_output/hot_get_functions_semantic.yaml' hot_file = '../tests/data/hot_output/hot_get_functions_semantic.yaml'
params = {} params = {}
self._test_successful_translation(tosca_file, hot_file, params) self._test_successful_translation(tosca_file, hot_file, params)
def test_hot_exchange_public_ssh_key(self):
tosca_file = '../tests/data/tosca_exchange_public_ssh_key.yaml'
hot_file = '../tests/data/hot_output/hot_exchange_public_ssh_key.yaml'
params = {}
self._test_successful_translation(tosca_file, hot_file, params)