コード例 #1
0
    def _create_template(self,
                         num_instances,
                         num_replace=0,
                         template_version=('HeatTemplateFormatVersion',
                                           '2012-12-12')):
        """
        Create a template to represent autoscaled instances.

        Also see heat.scaling.template.member_definitions.
        """
        instance_definition = self._get_resource_definition()
        old_resources = self._get_instance_templates()
        definitions = template.member_definitions(old_resources,
                                                  instance_definition,
                                                  num_instances, num_replace,
                                                  short_id.generate_id)

        child_env = environment.get_child_environment(
            self.stack.env,
            self.child_params(),
            item_to_remove=self.resource_info)

        return template.make_template(definitions,
                                      version=template_version,
                                      child_env=child_env)
コード例 #2
0
    def child_template(self):
        resource_types = self.properties[self.RESOURCES]
        resource_names = self._resource_names(resource_types)
        name_def_tuples = []
        for index, rt in enumerate(resource_types):
            name = resource_names[index]

            depends_on = None
            if index > 0 and not self.properties[self.CONCURRENT]:
                depends_on = [resource_names[index - 1]]

            t = (name,
                 self._build_resource_definition(name,
                                                 rt,
                                                 depends_on=depends_on))
            name_def_tuples.append(t)

        nested_template = scl_template.make_template(name_def_tuples)

        att_func = 'get_attr'
        get_attr = functools.partial(nested_template.functions[att_func], None,
                                     att_func)
        res_names = [k for k, d in name_def_tuples]
        for odefn in self._nested_output_defns(res_names, get_attr):
            nested_template.add_output(odefn)

        return nested_template
コード例 #3
0
    def _assemble_for_rolling_update(
        self, total_capacity, max_updates, include_all=False, template_version=("heat_template_version", "2015-04-30")
    ):
        names = list(self._resource_names(total_capacity))
        name_blacklist = self._name_blacklist()

        valid_resources = [(n, d) for n, d in grouputils.get_member_definitions(self) if n not in name_blacklist]

        targ_cap = self.get_size()

        def replace_priority(res_item):
            name, defn = res_item
            try:
                index = names.index(name)
            except ValueError:
                # High priority - delete immediately
                return 0
            else:
                if index < targ_cap:
                    # Update higher indices first
                    return targ_cap - index
                else:
                    # Low priority - don't update
                    return total_capacity

        old_resources = sorted(valid_resources, key=replace_priority)
        existing_names = set(n for n, d in valid_resources)
        new_names = six.moves.filterfalse(lambda n: n in existing_names, names)
        res_def = self.get_resource_def(include_all)
        definitions = scl_template.member_definitions(
            old_resources, res_def, total_capacity, max_updates, lambda: next(new_names), self.build_resource_definition
        )
        return scl_template.make_template(definitions, version=template_version)
コード例 #4
0
ファイル: instance_group.py プロジェクト: aaratn/heat
    def _create_template(self, num_instances, num_replace=0,
                         template_version=('HeatTemplateFormatVersion',
                                           '2012-12-12')):
        """Create a template to represent autoscaled instances.

        Also see heat.scaling.template.member_definitions.
        """
        instance_definition = self._get_resource_definition()
        old_resources = grouputils.get_member_definitions(self,
                                                          include_failed=True)
        definitions = list(template.member_definitions(
            old_resources, instance_definition, num_instances, num_replace,
            short_id.generate_id))

        child_env = environment.get_child_environment(
            self.stack.env,
            self.child_params(), item_to_remove=self.resource_info)

        tmpl = template.make_template(definitions, version=template_version,
                                      child_env=child_env)

        # Subclasses use HOT templates
        att_func = 'get_attr'
        if att_func not in tmpl.functions:
            att_func = 'Fn::GetAtt'
        get_attr = functools.partial(tmpl.functions[att_func], None, att_func)
        for odefn in self._nested_output_defns([k for k, d in definitions],
                                               get_attr):
            tmpl.add_output(odefn)

        return tmpl
コード例 #5
0
ファイル: instance_group.py プロジェクト: rohits47/heat
    def _create_template(self, num_instances, num_replace=0,
                         template_version=('HeatTemplateFormatVersion',
                                           '2012-12-12')):
        """Create a template to represent autoscaled instances.

        Also see heat.scaling.template.member_definitions.
        """
        instance_definition = self._get_resource_definition()
        old_resources = grouputils.get_member_definitions(self,
                                                          include_failed=True)
        definitions = list(template.member_definitions(
            old_resources, instance_definition, num_instances, num_replace,
            short_id.generate_id))

        child_env = environment.get_child_environment(
            self.stack.env,
            self.child_params(), item_to_remove=self.resource_info)

        tmpl = template.make_template(definitions, version=template_version,
                                      child_env=child_env)

        # Subclasses use HOT templates
        att_func, res_func = 'get_attr', 'get_resource'
        if att_func not in tmpl.functions or res_func not in tmpl.functions:
            att_func, res_func = 'Fn::GetAtt', 'Ref'
        get_attr = functools.partial(tmpl.functions[att_func], None, att_func)
        get_res = functools.partial(tmpl.functions[res_func], None, res_func)
        for odefn in self._nested_output_defns([k for k, d in definitions],
                                               get_attr, get_res):
            tmpl.add_output(odefn)

        return tmpl
コード例 #6
0
ファイル: resource_chain.py プロジェクト: noironetworks/heat
    def child_template(self):
        resource_types = self.properties[self.RESOURCES]
        resource_names = self._resource_names(resource_types)
        name_def_tuples = []
        # Impose a concurrency limit if concurrent is set. This minimizes the
        # memory usage when the chain contains lots of resources, but it keeps
        # performance to a reasonable level.
        concurrency_limit = service_objects.Service.active_service_count(
            self.context) or 1
        for index, rt in enumerate(resource_types):
            name = resource_names[index]

            depends_on = None
            if index > 0 and not self.properties[self.CONCURRENT]:
                depends_on = [resource_names[index - 1]]
            elif index >= concurrency_limit:
                depends_on = [resource_names[index - concurrency_limit]]

            t = (name, self._build_resource_definition(name, rt,
                                                       depends_on=depends_on))
            name_def_tuples.append(t)

        nested_template = scl_template.make_template(name_def_tuples)

        att_func = 'get_attr'
        get_attr = functools.partial(nested_template.functions[att_func],
                                     None, att_func)
        res_func = 'get_resource'
        get_res = functools.partial(nested_template.functions[res_func],
                                    None, res_func)
        res_names = [k for k, d in name_def_tuples]
        for odefn in self._nested_output_defns(res_names, get_attr, get_res):
            nested_template.add_output(odefn)

        return nested_template
コード例 #7
0
    def _assemble_nested(self, names, include_all=False,
                         template_version=('heat_template_version',
                                           '2015-04-30')):

        def_dict = self.get_resource_def(include_all)
        definitions = [(k, self.build_resource_definition(k, def_dict))
                       for k in names]
        return scl_template.make_template(definitions,
                                          version=template_version)
コード例 #8
0
ファイル: resource_group.py プロジェクト: gederian/heat
    def _assemble_nested(self, names, include_all=False,
                         template_version=('heat_template_version',
                                           '2015-04-30')):

        def_dict = self.get_resource_def(include_all)
        definitions = [(k, self.build_resource_definition(k, def_dict))
                       for k in names]
        return scl_template.make_template(definitions,
                                          version=template_version)
コード例 #9
0
ファイル: resource_group.py プロジェクト: FengyunPan2/heat
    def _assemble_nested(self, names, include_all=False,
                         template_version=('heat_template_version',
                                           '2015-04-30')):

        def_dict = self.get_resource_def(include_all)
        definitions = [(k, self.build_resource_definition(k, def_dict))
                       for k in names]
        tmpl = scl_template.make_template(definitions,
                                          version=template_version)
        self._add_output_defns_to_template(tmpl, [k for k, d in definitions])
        return tmpl
コード例 #10
0
ファイル: resource_group.py プロジェクト: openstack/heat
    def _assemble_nested(self, names, include_all=False,
                         template_version=('heat_template_version',
                                           '2015-04-30')):

        def_dict = self.get_resource_def(include_all)
        definitions = [(k, self.build_resource_definition(k, def_dict))
                       for k in names]
        tmpl = scl_template.make_template(definitions,
                                          version=template_version)
        self._add_output_defns_to_template(tmpl, [k for k, d in definitions])
        return tmpl
コード例 #11
0
ファイル: instance_group.py プロジェクト: blitzbs/heat
    def _create_template(self, num_instances, num_replace=0,
                         template_version=('HeatTemplateFormatVersion',
                                           '2012-12-12')):
        """
        Create a template to represent autoscaled instances.

        Also see heat.scaling.template.resource_templates.
        """
        instance_definition = self._get_instance_definition()
        old_resources = self._get_instance_templates()
        definitions = template.resource_templates(
            old_resources, instance_definition, num_instances, num_replace)

        return template.make_template(definitions, version=template_version)
コード例 #12
0
ファイル: instance_group.py プロジェクト: gerryw/heat
    def _create_template(self, num_instances, num_replace=0,
                         template_version=('HeatTemplateFormatVersion',
                                           '2012-12-12')):
        """
        Create a template to represent autoscaled instances.

        Also see heat.scaling.template.resource_templates.
        """
        instance_definition = self._get_instance_definition()
        old_resources = self._get_instance_templates()
        definitions = template.resource_templates(
            old_resources, instance_definition, num_instances, num_replace)

        return template.make_template(definitions, version=template_version)
コード例 #13
0
ファイル: resource_chain.py プロジェクト: kitch/heat
    def child_template(self):
        resource_types = self.properties[self.RESOURCES]
        resource_names = self._resource_names(resource_types)
        name_def_tuples = []
        for index, rt in enumerate(resource_types):
            name = resource_names[index]

            depends_on = None
            if index > 0 and not self.properties[self.CONCURRENT]:
                depends_on = resource_names[index - 1]

            t = (name, self._build_resource_definition(name, rt,
                                                       depends_on=depends_on))
            name_def_tuples.append(t)

        nested_template = scl_template.make_template(name_def_tuples)
        return nested_template
コード例 #14
0
ファイル: resource_group.py プロジェクト: aaratn/heat
    def _assemble_nested(self, names, include_all=False,
                         template_version=('heat_template_version',
                                           '2015-04-30')):

        def_dict = self.get_resource_def(include_all)
        definitions = [(k, self.build_resource_definition(k, def_dict))
                       for k in names]
        tmpl = scl_template.make_template(definitions,
                                          version=template_version)

        att_func = 'get_attr'
        get_attr = functools.partial(tmpl.functions[att_func], None, att_func)
        for odefn in self._nested_output_defns([k for k, d in definitions],
                                               get_attr):
            tmpl.add_output(odefn)

        return tmpl
コード例 #15
0
ファイル: resource_chain.py プロジェクト: dulek/heat
    def child_template(self):
        resource_types = self.properties[self.RESOURCES]
        resource_names = self._resource_names(resource_types)
        name_def_tuples = []
        for index, rt in enumerate(resource_types):
            name = resource_names[index]

            depends_on = None
            if index > 0 and not self.properties[self.CONCURRENT]:
                depends_on = [resource_names[index - 1]]

            t = (name, self._build_resource_definition(name, rt,
                                                       depends_on=depends_on))
            name_def_tuples.append(t)

        nested_template = scl_template.make_template(name_def_tuples)
        return nested_template
コード例 #16
0
ファイル: instance_group.py プロジェクト: openstack/heat
    def _create_template(
        self, num_instances, num_replace=0, template_version=("HeatTemplateFormatVersion", "2012-12-12")
    ):
        """Create a template to represent autoscaled instances.

        Also see heat.scaling.template.member_definitions.
        """
        instance_definition = self._get_resource_definition()
        old_resources = grouputils.get_member_definitions(self, include_failed=True)
        definitions = template.member_definitions(
            old_resources, instance_definition, num_instances, num_replace, short_id.generate_id
        )

        child_env = environment.get_child_environment(
            self.stack.env, self.child_params(), item_to_remove=self.resource_info
        )

        return template.make_template(definitions, version=template_version, child_env=child_env)
コード例 #17
0
    def _assemble_nested(self,
                         names,
                         include_all=False,
                         template_version=('heat_template_version',
                                           '2015-04-30')):

        def_dict = self.get_resource_def(include_all)
        definitions = [(k, self.build_resource_definition(k, def_dict))
                       for k in names]
        tmpl = scl_template.make_template(definitions,
                                          version=template_version)

        att_func = 'get_attr'
        get_attr = functools.partial(tmpl.functions[att_func], None, att_func)
        for odefn in self._nested_output_defns([k for k, d in definitions],
                                               get_attr):
            tmpl.add_output(odefn)

        return tmpl
コード例 #18
0
ファイル: instance_group.py プロジェクト: junxu/heat
    def _create_template(self, num_instances, num_replace=0,
                         template_version=('HeatTemplateFormatVersion',
                                           '2012-12-12')):
        """
        Create a template to represent autoscaled instances.

        Also see heat.scaling.template.resource_templates.
        """
        instance_definition = self._get_instance_definition()
        old_resources = self._get_instance_templates()
        definitions = template.resource_templates(
            old_resources, instance_definition, num_instances, num_replace)

        child_env = environment.get_child_environment(
            self.stack.env,
            self.child_params(), item_to_remove=self.resource_info)

        return template.make_template(definitions, version=template_version,
                                      child_env=child_env)
コード例 #19
0
ファイル: resource_group.py プロジェクト: FengyunPan2/heat
    def _assemble_for_rolling_update(self, total_capacity, max_updates,
                                     include_all=False,
                                     template_version=('heat_template_version',
                                                       '2015-04-30')):
        names = list(self._resource_names(total_capacity))
        name_blacklist = self._name_blacklist()

        valid_resources = [(n, d) for n, d in
                           grouputils.get_member_definitions(self)
                           if n not in name_blacklist]

        targ_cap = self.get_size()

        def replace_priority(res_item):
            name, defn = res_item
            try:
                index = names.index(name)
            except ValueError:
                # High priority - delete immediately
                return 0
            else:
                if index < targ_cap:
                    # Update higher indices first
                    return targ_cap - index
                else:
                    # Low priority - don't update
                    return total_capacity

        old_resources = sorted(valid_resources, key=replace_priority)
        existing_names = set(n for n, d in valid_resources)
        new_names = six.moves.filterfalse(lambda n: n in existing_names,
                                          names)
        res_def = self.get_resource_def(include_all)
        definitions = scl_template.member_definitions(
            old_resources, res_def,
            total_capacity,
            max_updates,
            lambda: next(new_names),
            self.build_resource_definition)
        tmpl = scl_template.make_template(definitions,
                                          version=template_version)
        self._add_output_defns_to_template(tmpl, names)
        return tmpl
コード例 #20
0
    def _create_template(self, num_instances, num_replace=0,
                         template_version=('HeatTemplateFormatVersion',
                                           '2012-12-12')):
        """Create a template to represent autoscaled instances.

        Also see heat.scaling.template.member_definitions.
        """
        instance_definition = self._get_resource_definition()
        old_resources = grouputils.get_member_definitions(self,
                                                          include_failed=True)
        # WRS: Detect a scale down.  Issue a vote
        # If any vote is rejected, set new_resources to be same size as old
        existing = grouputils.get_members(self)
        if num_instances < len(existing):
            LOG.info("WRS downscale detected, vote initiated")
            for i in range(num_instances, len(existing)):
                if existing[i].wrs_vote() is False:
                    LOG.info("WRS downscale blocked by vote")
                    num_instances = len(existing)
                    break

        definitions = list(template.member_definitions(
            old_resources, instance_definition, num_instances, num_replace,
            short_id.generate_id, delete_oldest=False))

        child_env = environment.get_child_environment(
            self.stack.env,
            self.child_params(), item_to_remove=self.resource_info)

        tmpl = template.make_template(definitions, version=template_version,
                                      child_env=child_env)

        # Subclasses use HOT templates
        att_func = 'get_attr'
        if att_func not in tmpl.functions:
            att_func = 'Fn::GetAtt'
        get_attr = functools.partial(tmpl.functions[att_func], None, att_func)
        for odefn in self._nested_output_defns([k for k, d in definitions],
                                               get_attr):
            tmpl.add_output(odefn)

        return tmpl
コード例 #21
0
    def _scale_up(self, adjustment, adjustment_type):
        old_resources = self._get_instance_templates()
        rsrc = self.properties[self.RESOURCE]
        m_cpu = self.properties.get(self.MAX_CPU, 128)
        m_mem = self.properties.get(self.MAX_MEM, 32768)
        flag = 0
        definition_name= None
        for (name, definition) in old_resources:
            c_cpu = definition["Properties"].get("core")
            c_mem = definition["Properties"].get("memory")
            d_cpu = c_cpu+adjustment*self.properties.get(self.CPU_RESIZE, 1)
            d_mem = c_mem+adjustment*self.properties.get(self.MEM_RESIZE, 512)
            LOG.debug(_("resource name: %s c_cpu: %s  c_mem: %s  d_cpu: %s d_mem: %s m_cpu: %s m_mem: %s"
                        " scale_up_cpu: %s scale_up_mem: %s") %(name, c_cpu, c_mem, d_cpu, d_mem, m_cpu, m_mem, self.scale_up_cpu, self.scale_up_mem ))

            if c_cpu <= m_cpu and c_mem < m_mem and d_cpu > m_cpu and d_mem > m_mem:
                flag = 1
                d_cpu = m_cpu
                d_mem = m_mem
                definition_name= name
                break
            if d_cpu <=  m_cpu and d_mem <=  m_mem and d_cpu >=  self.scale_up_cpu and d_mem >=  self.scale_up_mem:
                flag = 1
                definition_name= name
                LOG.debug(_("scale up  resource %s") %definition_name)
                break

        if flag:
            rsrc['properties']['core'] = d_cpu
            rsrc['properties']['memory'] = d_mem
            instance_definition = rsrc_defn.ResourceDefinition(None, rsrc['type'],
                                                               rsrc.get('properties'), rsrc.get('metadata'))

            definitions = template.resource_templates_by_name(old_resources, instance_definition, definition_name)
            template_version=('HeatTemplateFormatVersion','2012-12-12')
            new_template = template.make_template(definitions, version=template_version)
            self.update_template(new_template)
        else:
            LOG.debug(_("exceed max vm configure or  exceed min vm configure"))
            return True
コード例 #22
0
    def child_template(self):
        resource_types = self.properties[self.RESOURCES]
        resource_names = self._resource_names(resource_types)
        name_def_tuples = []
        # Impose a concurrency limit if concurrent is set. This minimizes the
        # memory usage when the chain contains lots of resources, but it keeps
        # performance to a reasonable level.
        concurrency_limit = service_objects.Service.active_service_count(
            self.context) or 1
        for index, rt in enumerate(resource_types):
            name = resource_names[index]

            depends_on = None
            if index > 0 and not self.properties[self.CONCURRENT]:
                depends_on = [resource_names[index - 1]]
            elif index >= concurrency_limit:
                depends_on = [resource_names[index - concurrency_limit]]

            t = (name,
                 self._build_resource_definition(name,
                                                 rt,
                                                 depends_on=depends_on))
            name_def_tuples.append(t)

        nested_template = scl_template.make_template(name_def_tuples)

        att_func = 'get_attr'
        get_attr = functools.partial(nested_template.functions[att_func], None,
                                     att_func)
        res_func = 'get_resource'
        get_res = functools.partial(nested_template.functions[res_func], None,
                                    res_func)
        res_names = [k for k, d in name_def_tuples]
        for odefn in self._nested_output_defns(res_names, get_attr, get_res):
            nested_template.add_output(odefn)

        return nested_template