Skip to content

Commit

Permalink
Merge pull request #615 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored May 21, 2018
2 parents 0db32b9 + 520c06b commit 6d46487
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion IM/InfrastructureList.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def remove_inf(del_inf):
"""Remove destroyed infrastructure."""

with InfrastructureList._lock:
del InfrastructureList.infrastructure_list[del_inf.id]
if del_inf.id in InfrastructureList.infrastructure_list:
del InfrastructureList.infrastructure_list[del_inf.id]

@staticmethod
def get_inf_ids(auth=None):
Expand Down
25 changes: 14 additions & 11 deletions IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def serialize(self):
def deserialize(str_data):
return Tosca(str_data)

def _get_cloud_id(self, sys_name):
def _get_placement_property(self, sys_name, prop):
"""
Get the cloud ID of the deployment based on policies
Get the specified property of the deployment based on policies
"""
for policy in self.tosca.policies:
if policy.type_definition.type == "tosca.policies.Placement":
Expand All @@ -59,10 +59,11 @@ def _get_cloud_id(self, sys_name):

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']
if prop in policy.properties:
Tosca.logger.debug("Set %s: %s to system: %s." % (prop,
policy.properties[prop],
sys_name))
return policy.properties[prop]
else:
Tosca.logger.warn("Policy %s not supported. Ignoring it." % policy.type_definition.type)

Expand Down Expand Up @@ -108,8 +109,7 @@ def to_radl(self, inf_info=None):
sys = self._gen_system(node, self.tosca.nodetemplates)
# add networks using the simple method with the public_ip
# property
self._add_node_nets(
node, radl, sys, self.tosca.nodetemplates)
self._add_node_nets(node, radl, sys, self.tosca.nodetemplates)
radl.systems.append(sys)
# Add the deploy element for this system
min_instances, _, default_instances, count, removal_list = self._get_scalable_properties(
Expand All @@ -135,14 +135,13 @@ def to_radl(self, inf_info=None):
all_removal_list.extend(removal_list[0:-num_instances])

if num_instances > 0:
cloud_id = self._get_cloud_id(sys.name)
cloud_id = self._get_placement_property(sys.name, "cloud_id")
dep = deploy(sys.name, num_instances, cloud_id)
radl.deploys.append(dep)
compute = node
else:
# Select the host to host this element
compute = self._find_host_compute(
node, self.tosca.nodetemplates)
compute = self._find_host_compute(node, self.tosca.nodetemplates)
if not compute:
Tosca.logger.warn(
"Node %s has not compute node to host in." % node.name)
Expand Down Expand Up @@ -1259,6 +1258,10 @@ def _gen_system(self, node, nodetemplates):

self._add_ansible_roles(node, nodetemplates, res)

availability_zone = self._get_placement_property(res.name, "availability_zone")
if availability_zone:
res.setValue('availability_zone', availability_zone)

return res

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion test/files/tosca_long.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ topology_template:
policies:
- deploy_on_cloudid:
type: tosca.policies.Placement
properties: { cloud_id: cloudid }
properties: { cloud_id: cloudid, availability_zone: some_zone }
targets: [ other_server ]

- deploy_group_on_cloudid:
Expand Down
2 changes: 2 additions & 0 deletions test/unit/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def test_tosca_to_radl(self):
self.assertEqual("cloudid", radl.deploys[0].cloud_id)
self.assertEqual("cloudid", radl.deploys[1].cloud_id)
self.assertEqual("cloudid", radl.deploys[2].cloud_id)
other_server = radl.get_system_by_name('other_server')
self.assertEqual(other_server.getValue("availability_zone"), 'some_zone')

def test_tosca_get_outputs(self):
"""Test TOSCA get_outputs function"""
Expand Down

0 comments on commit 6d46487

Please sign in to comment.