Skip to content

Commit

Permalink
Implements #216
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Dec 11, 2017
1 parent ed97ced commit 178e865
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
27 changes: 26 additions & 1 deletion IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 14 additions & 4 deletions test/files/tosca_long.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ topology_template:
capabilities:
scalable:
properties:
count: 0
count: 1
host:
properties:
num_cpus: 1
Expand Down Expand Up @@ -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 ]
3 changes: 3 additions & 0 deletions test/unit/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit 178e865

Please sign in to comment.