Github user tliron commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/143#discussion_r126353859
  
    --- Diff: aria/modeling/service_template.py ---
    @@ -690,19 +666,104 @@ def dump(self):
                 console.puts(context.style.meta(self.description))
             with context.style.indent:
                 console.puts('Type: 
{0}'.format(context.style.type(self.type.name)))
    -            console.puts('Instances: {0:d} ({1:d}{2})'.format(
    -                self.default_instances,
    -                self.min_instances,
    -                ' to {0:d}'.format(self.max_instances)
    -                if self.max_instances is not None
    -                else ' or more'))
                 utils.dump_dict_values(self.properties, 'Properties')
                 utils.dump_dict_values(self.attributes, 'Attributes')
                 utils.dump_interfaces(self.interface_templates)
                 utils.dump_dict_values(self.artifact_templates, 'Artifact 
templates')
                 utils.dump_dict_values(self.capability_templates, 'Capability 
templates')
                 utils.dump_list_values(self.requirement_templates, 
'Requirement templates')
     
    +    @property
    +    def next_index(self):
    +        """
    +        Next available node index.
    +
    +        :returns: node index
    +        :rtype: int
    +        """
    +
    +        max_index = 0
    +        if self.nodes:
    +            max_index = max(int(n.name.rsplit('_', 1)[-1]) for n in 
self.nodes)
    +        return max_index + 1
    +
    +    @property
    +    def next_name(self):
    +        """
    +        Next available node name.
    +
    +        :returns: node name
    +        :rtype: basestring
    +        """
    +
    +        return '{name}_{index}'.format(name=self.name, 
index=self.next_index)
    +
    +    @property
    +    def scaling(self):
    +        scaling = {}
    +
    +        def extract_property(properties, name):
    +            if name in scaling:
    +                return
    +            prop = properties.get(name)
    +            if (prop is not None) and (prop.type_name == 'integer') and 
(prop.value is not None):
    +                scaling[name] = prop.value
    +
    +        def extract_properties(properties):
    +            extract_property(properties, 'min_instances')
    +            extract_property(properties, 'max_instances')
    +            extract_property(properties, 'default_instances')
    +
    +        def default_property(name, value):
    +            if name not in scaling:
    +                scaling[name] = value
    +
    +        # From our scaling capabilities
    +        for capability_template in self.capability_templates.itervalues():
    +            if capability_template.type.role == 'scaling':
    +                extract_properties(capability_template.properties)
    +
    +        # From service scaling policies
    +        for policy_template in 
self.service_template.policy_templates.itervalues():
    +            if policy_template.type.role == 'scaling':
    +                if policy_template.is_for_node_template(self.name):
    +                    extract_properties(policy_template.properties)
    +
    +        # Defaults
    +        default_property('min_instances', 0)
    +        default_property('max_instances', 1)
    +        default_property('default_instances', 1)
    +
    +        # Validate
    +        # pylint: disable=too-many-boolean-expressions
    +        if (scaling['min_instances'] < 0) or \
    --- End diff --
    
    I see no difference in readability between this and using `or`, seems to me 
just to be bowing to PyLint's weirdness... but I don't mind switching.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to