Merge "Small refactor."
This commit is contained in:
commit
ae42530044
|
@ -127,6 +127,14 @@ class HotResource(object):
|
||||||
hosting_server = None
|
hosting_server = None
|
||||||
if self.nodetemplate.requirements is not None:
|
if self.nodetemplate.requirements is not None:
|
||||||
hosting_server = self._get_hosting_server()
|
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():
|
for operation in operations.values():
|
||||||
if operation.name in operations_deploy_sequence:
|
if operation.name in operations_deploy_sequence:
|
||||||
config_name = node_name + '_' + operation.name + '_config'
|
config_name = node_name + '_' + operation.name + '_config'
|
||||||
|
@ -137,17 +145,6 @@ class HotResource(object):
|
||||||
'OS::Heat::SoftwareConfig',
|
'OS::Heat::SoftwareConfig',
|
||||||
{'config':
|
{'config':
|
||||||
{'get_file': operation.implementation}}))
|
{'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 \
|
if operation.name == reserve_current and \
|
||||||
base_type != 'tosca.nodes.Compute':
|
base_type != 'tosca.nodes.Compute':
|
||||||
deploy_resource = self
|
deploy_resource = self
|
||||||
|
@ -329,8 +326,8 @@ class HotResource(object):
|
||||||
# capability is a list of dict
|
# capability is a list of dict
|
||||||
# For now just check if it's type tosca.nodes.Compute
|
# For now just check if it's type tosca.nodes.Compute
|
||||||
# TODO(anyone): match up requirement and capability
|
# TODO(anyone): match up requirement and capability
|
||||||
base_type = HotResource.get_base_type(node.type_definition)
|
base_type = HotResource.get_base_type_str(node.type_definition)
|
||||||
if base_type.type == 'tosca.nodes.Compute':
|
if base_type == 'tosca.nodes.Compute':
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -375,9 +372,9 @@ class HotResource(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_interface_operations_from_type(node_type, node, lifecycle_name):
|
def _get_interface_operations_from_type(node_type, node, lifecycle_name):
|
||||||
operations = {}
|
operations = {}
|
||||||
if isinstance(node_type, str) or \
|
base_type = HotResource.get_base_type_str(node_type)
|
||||||
node_type.type == "tosca.policies.Placement":
|
if base_type == "tosca.policies.Placement":
|
||||||
return operations
|
return operations
|
||||||
if node_type.interfaces and lifecycle_name in node_type.interfaces:
|
if node_type.interfaces and lifecycle_name in node_type.interfaces:
|
||||||
for name, elems in node_type.interfaces[lifecycle_name].items():
|
for name, elems in node_type.interfaces[lifecycle_name].items():
|
||||||
# ignore empty operations (only type)
|
# ignore empty operations (only type)
|
||||||
|
@ -390,11 +387,19 @@ class HotResource(object):
|
||||||
return operations
|
return operations
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_base_type(node_type):
|
def get_base_type_str(node_type):
|
||||||
if node_type.parent_type is not None:
|
if isinstance(node_type, six.string_types):
|
||||||
if node_type.parent_type.type.endswith('.Root'):
|
|
||||||
return node_type
|
|
||||||
else:
|
|
||||||
return HotResource.get_base_type(node_type.parent_type)
|
|
||||||
else:
|
|
||||||
return node_type
|
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
|
||||||
|
|
|
@ -178,14 +178,14 @@ class TranslateNodeTemplates(object):
|
||||||
suffix = 0
|
suffix = 0
|
||||||
# Copy the TOSCA graph: nodetemplate
|
# Copy the TOSCA graph: nodetemplate
|
||||||
for node in self.nodetemplates:
|
for node in self.nodetemplates:
|
||||||
base_type = HotResource.get_base_type(node.type_definition)
|
base_type = HotResource.get_base_type_str(node.type_definition)
|
||||||
hot_node = TOSCA_TO_HOT_TYPE[base_type.type](node)
|
hot_node = TOSCA_TO_HOT_TYPE[base_type](node)
|
||||||
self.hot_resources.append(hot_node)
|
self.hot_resources.append(hot_node)
|
||||||
self.hot_lookup[node] = hot_node
|
self.hot_lookup[node] = hot_node
|
||||||
|
|
||||||
# BlockStorage Attachment is a special case,
|
# BlockStorage Attachment is a special case,
|
||||||
# which doesn't match to Heat Resources 1 to 1.
|
# 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
|
volume_name = None
|
||||||
requirements = node.requirements
|
requirements = node.requirements
|
||||||
if requirements:
|
if requirements:
|
||||||
|
@ -266,9 +266,9 @@ class TranslateNodeTemplates(object):
|
||||||
# if the source of dependency is a server and the
|
# if the source of dependency is a server and the
|
||||||
# relationship type is 'tosca.relationships.HostedOn',
|
# relationship type is 'tosca.relationships.HostedOn',
|
||||||
# add dependency as properties.server
|
# add dependency as properties.server
|
||||||
base_type = HotResource.get_base_type(
|
base_type = HotResource.get_base_type_str(
|
||||||
node_depend.type_definition)
|
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.related[node_depend].type == \
|
||||||
node.type_definition.HOSTEDON:
|
node.type_definition.HOSTEDON:
|
||||||
self.hot_lookup[node].properties['server'] = \
|
self.hot_lookup[node].properties['server'] = \
|
||||||
|
|
Loading…
Reference in New Issue