From 178e8653a7cce03c27a08e931d28d368e1faed65 Mon Sep 17 00:00:00 2001 From: micafer Date: Mon, 11 Dec 2017 16:44:31 +0100 Subject: [PATCH] Implements #216 --- IM/tosca/Tosca.py | 27 ++++++++++++++++++++++++++- test/files/tosca_long.yml | 18 ++++++++++++++---- test/unit/Tosca.py | 3 +++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/IM/tosca/Tosca.py b/IM/tosca/Tosca.py index bbd569400..1754c2831 100644 --- a/IM/tosca/Tosca.py +++ b/IM/tosca/Tosca.py @@ -44,6 +44,30 @@ def serialize(self): def deserialize(str_data): return Tosca(str_data) + def _get_cloud_id(self, sys_name): + """ + Get the cloud ID of the deployment based on policies + """ + for policy in self.tosca.policies: + if policy.type_definition.type == "tosca.policies.Placement": + node_list = [] + if policy.targets_type == "node_templates": + node_list = policy.targets_list + elif policy.targets_type == "groups": + for group in policy.targets_list: + node_list.extend(group.member_nodes) + + for node in node_list: + if node.name == sys_name: + if 'cloud_id' in policy.properties: + Tosca.logger.debug("Set cloud id: %s to system: %s." % (policy.properties['cloud_id'], + sys_name)) + return policy.properties['cloud_id'] + else: + Tosca.logger.warn("Policy %s not supported. Ignoring it." % policy.type_definition.type) + + return None + def to_radl(self, inf_info=None): """ Converts the current ToscaTemplate object in a RADL object @@ -111,7 +135,8 @@ def to_radl(self, inf_info=None): all_removal_list.extend(removal_list[0:-num_instances]) if num_instances > 0: - dep = deploy(sys.name, num_instances) + cloud_id = self._get_cloud_id(sys.name) + dep = deploy(sys.name, num_instances, cloud_id) radl.deploys.append(dep) compute = node else: diff --git a/test/files/tosca_long.yml b/test/files/tosca_long.yml index 5a4de041e..9c9c792e0 100644 --- a/test/files/tosca_long.yml +++ b/test/files/tosca_long.yml @@ -123,7 +123,7 @@ topology_template: capabilities: scalable: properties: - count: 0 + count: 1 host: properties: num_cpus: 1 @@ -155,8 +155,18 @@ topology_template: galaxy_url: value: { concat: [ 'http://', get_attribute: [ lrms_server, public_address, 0 ], ':8080' ] } + groups: + my_placement_group: + type: tosca.groups.Root + members: [ lrms_server, lrms_wn ] + policies: - - deploy_on_aws: + - deploy_on_cloudid: + type: tosca.policies.Placement + properties: { cloud_id: cloudid } + targets: [ other_server ] + + - deploy_group_on_cloudid: type: tosca.policies.Placement - properties: { sla_id: SLA_provider-AWS-us-east-1_indigo-dc, username: {get_input: access_key}, password: {get_input: secret_key}} - targets: [ lrms_wn ] + properties: { cloud_id: cloudid } + targets: [ my_placement_group ] \ No newline at end of file diff --git a/test/unit/Tosca.py b/test/unit/Tosca.py index 0dda407d4..d8bb45d52 100755 --- a/test/unit/Tosca.py +++ b/test/unit/Tosca.py @@ -63,6 +63,9 @@ def test_tosca_to_radl(self): lrms_server = radl.get_system_by_name('lrms_server') self.assertEqual(lrms_server.getValue('memory.size'), 1000000000) self.assertEqual(lrms_server.getValue('net_interface.0.dns_name'), 'slurmserver') + self.assertEqual("cloudid", radl.deploys[0].cloud_id) + self.assertEqual("cloudid", radl.deploys[1].cloud_id) + self.assertEqual("cloudid", radl.deploys[2].cloud_id) def test_tosca_get_outputs(self): """Test TOSCA get_outputs function"""