Merge "Small refactor."

This commit is contained in:
Jenkins 2016-07-14 16:33:01 +00:00 committed by Gerrit Code Review
commit ae42530044
2 changed files with 33 additions and 28 deletions

View File

@ -127,6 +127,14 @@ class HotResource(object):
hosting_server = None
if self.nodetemplate.requirements is not None:
hosting_server = self._get_hosting_server()
# hosting_server is None if requirements is None
hosting_on_server = hosting_server.name if hosting_server else None
base_type = HotResource.get_base_type_str(
self.nodetemplate.type_definition)
# if we are on a compute node the host is self
if hosting_on_server is None and base_type == 'tosca.nodes.Compute':
hosting_on_server = self.name
for operation in operations.values():
if operation.name in operations_deploy_sequence:
config_name = node_name + '_' + operation.name + '_config'
@ -137,17 +145,6 @@ class HotResource(object):
'OS::Heat::SoftwareConfig',
{'config':
{'get_file': operation.implementation}}))
# hosting_server is None if requirements is None
hosting_on_server = (hosting_server.name if
hosting_server else None)
base_type = HotResource.get_base_type(
self.nodetemplate.type_definition).type
# handle interfaces directly defined on a compute
if hosting_on_server is None \
and base_type == 'tosca.nodes.Compute':
hosting_on_server = self.name
if operation.name == reserve_current and \
base_type != 'tosca.nodes.Compute':
deploy_resource = self
@ -329,8 +326,8 @@ class HotResource(object):
# capability is a list of dict
# For now just check if it's type tosca.nodes.Compute
# TODO(anyone): match up requirement and capability
base_type = HotResource.get_base_type(node.type_definition)
if base_type.type == 'tosca.nodes.Compute':
base_type = HotResource.get_base_type_str(node.type_definition)
if base_type == 'tosca.nodes.Compute':
return True
else:
return False
@ -375,9 +372,9 @@ class HotResource(object):
@staticmethod
def _get_interface_operations_from_type(node_type, node, lifecycle_name):
operations = {}
if isinstance(node_type, str) or \
node_type.type == "tosca.policies.Placement":
return operations
base_type = HotResource.get_base_type_str(node_type)
if base_type == "tosca.policies.Placement":
return operations
if node_type.interfaces and lifecycle_name in node_type.interfaces:
for name, elems in node_type.interfaces[lifecycle_name].items():
# ignore empty operations (only type)
@ -390,11 +387,19 @@ class HotResource(object):
return operations
@staticmethod
def get_base_type(node_type):
if node_type.parent_type is not None:
if node_type.parent_type.type.endswith('.Root'):
return node_type
else:
return HotResource.get_base_type(node_type.parent_type)
else:
def get_base_type_str(node_type):
if isinstance(node_type, six.string_types):
return node_type
if node_type.parent_type is not None:
parent_type_str = None
if isinstance(node_type.parent_type, six.string_types):
parent_type_str = node_type.parent_type
else:
parent_type_str = node_type.parent_type.type
if parent_type_str and parent_type_str.endswith('.Root'):
return node_type.type
else:
return HotResource.get_base_type_str(node_type.parent_type)
return node_type.type

View File

@ -178,14 +178,14 @@ class TranslateNodeTemplates(object):
suffix = 0
# Copy the TOSCA graph: nodetemplate
for node in self.nodetemplates:
base_type = HotResource.get_base_type(node.type_definition)
hot_node = TOSCA_TO_HOT_TYPE[base_type.type](node)
base_type = HotResource.get_base_type_str(node.type_definition)
hot_node = TOSCA_TO_HOT_TYPE[base_type](node)
self.hot_resources.append(hot_node)
self.hot_lookup[node] = hot_node
# BlockStorage Attachment is a special case,
# which doesn't match to Heat Resources 1 to 1.
if base_type.type == "tosca.nodes.Compute":
if base_type == "tosca.nodes.Compute":
volume_name = None
requirements = node.requirements
if requirements:
@ -266,9 +266,9 @@ class TranslateNodeTemplates(object):
# if the source of dependency is a server and the
# relationship type is 'tosca.relationships.HostedOn',
# add dependency as properties.server
base_type = HotResource.get_base_type(
base_type = HotResource.get_base_type_str(
node_depend.type_definition)
if base_type.type == 'tosca.nodes.Compute' and \
if base_type == 'tosca.nodes.Compute' and \
node.related[node_depend].type == \
node.type_definition.HOSTEDON:
self.hot_lookup[node].properties['server'] = \