示例#1
0
    def test_check_node_group_template_usage(self):

        ng1 = FakeNGT(1)
        ng2 = FakeNGT(2)

        cluster = FakeCluster("cluster", [ng1])
        template = FakeCluster("template", [ng2])

        cluster_users, template_users = utils.check_node_group_template_usage(1, [cluster], [template])
        self.assertEqual([cluster.name], cluster_users)
        self.assertEqual([], template_users)

        cluster_users, template_users = utils.check_node_group_template_usage(2, [cluster], [template])
        self.assertEqual([], cluster_users)
        self.assertEqual([template.name], template_users)
示例#2
0
def check_usage_of_existing(ctx, ng_templates, cl_templates):
    '''Determine if any of the specified templates are in use

    This method searches for the specified templates by name and
    determines whether or not any existing templates are in use
    by a cluster or cluster template. Returns True if any of
    the templates are in use.

    :param ng_templates: A list of dictionaries. Each dictionary
                         has a "template" entry that represents
                         a node group template.
    :param cl_templates: A list of dictionaries. Each dictionary
                         has a "template" entry that represents
                         a cluster template
    :returns: True if any of the templates are in use, False otherwise
    '''
    error = False
    clusters = conductor.API.cluster_get_all(ctx)

    for ng_info in ng_templates:
        ng = u.find_node_group_template_by_name(ctx,
                                                ng_info["template"]["name"])
        if ng:
            cluster_users, template_users = u.check_node_group_template_usage(
                ng["id"], clusters)

            if cluster_users:
                LOG.warning(
                    _LW("Node group template {name} "
                        "in use by clusters {clusters}").format(
                            name=ng["name"], clusters=cluster_users))
            if template_users:
                LOG.warning(
                    _LW("Node group template {name} "
                        "in use by cluster templates {templates}").format(
                            name=ng["name"], templates=template_users))

            if cluster_users or template_users:
                LOG.warning(
                    _LW("Update of node group template "
                        "{name} is not allowed").format(name=ng["name"]))
                error = True

    for cl_info in cl_templates:
        cl = u.find_cluster_template_by_name(ctx, cl_info["template"]["name"])
        if cl:
            cluster_users = u.check_cluster_template_usage(cl["id"], clusters)

            if cluster_users:
                LOG.warning(
                    _LW("Cluster template {name} "
                        "in use by clusters {clusters}").format(
                            name=cl["name"], clusters=cluster_users))

                LOG.warning(
                    _LW("Update of cluster template "
                        "{name} is not allowed").format(name=cl["name"]))
                error = True

    return error
示例#3
0
    def test_check_node_group_template_usage(self):

        ng1 = FakeNGT(1)
        ng2 = FakeNGT(2)

        cluster = FakeCluster("cluster", [ng1])
        template = FakeCluster("template", [ng2])

        cluster_users, template_users = utils.check_node_group_template_usage(
            1, [cluster], [template])
        self.assertEqual([cluster.name], cluster_users)
        self.assertEqual([], template_users)

        cluster_users, template_users = utils.check_node_group_template_usage(
            2, [cluster], [template])
        self.assertEqual([], cluster_users)
        self.assertEqual([template.name], template_users)
示例#4
0
文件: api.py 项目: thefuyang/sahara
def check_usage_of_existing(ctx, ng_templates, cl_templates):
    '''Determine if any of the specified templates are in use

    This method searches for the specified templates by name and
    determines whether or not any existing templates are in use
    by a cluster or cluster template. Returns True if any of
    the templates are in use.

    :param ng_templates: A list of dictionaries. Each dictionary
                         has a "template" entry that represents
                         a node group template.
    :param cl_templates: A list of dictionaries. Each dictionary
                         has a "template" entry that represents
                         a cluster template
    :returns: True if any of the templates are in use, False otherwise
    '''
    error = False
    clusters = conductor.API.cluster_get_all(ctx)

    for ng_info in ng_templates:
        ng = u.find_node_group_template_by_name(ctx,
                                                ng_info["template"]["name"])
        if ng:
            cluster_users, template_users = u.check_node_group_template_usage(
                ng["id"], clusters)

            if cluster_users:
                LOG.warning(_LW("Node group template {name} "
                            "in use by clusters {clusters}").format(
                                name=ng["name"], clusters=cluster_users))
            if template_users:
                LOG.warning(_LW("Node group template {name} "
                            "in use by cluster templates {templates}").format(
                                name=ng["name"], templates=template_users))

            if cluster_users or template_users:
                LOG.warning(_LW("Update of node group template "
                            "{name} is not allowed").format(name=ng["name"]))
                error = True

    for cl_info in cl_templates:
        cl = u.find_cluster_template_by_name(ctx, cl_info["template"]["name"])
        if cl:
            cluster_users = u.check_cluster_template_usage(cl["id"], clusters)

            if cluster_users:
                LOG.warning(_LW("Cluster template {name} "
                            "in use by clusters {clusters}").format(
                                name=cl["name"], clusters=cluster_users))

                LOG.warning(_LW("Update of cluster template "
                            "{name} is not allowed").format(name=cl["name"]))
                error = True

    return error
示例#5
0
def delete_node_group_template(ctx, template, rollback=False):
    rollback_msg = " on rollback" if rollback else ""

    # If we are not deleting something that we just created,
    # do usage checks to ensure that the template is not in
    # use by a cluster or a cluster template
    if not rollback:
        clusters = conductor.API.cluster_get_all(ctx)
        cluster_templates = conductor.API.cluster_template_get_all(ctx)
        cluster_users, template_users = u.check_node_group_template_usage(
            template["id"], clusters, cluster_templates)

        if cluster_users:
            LOG.warning(
                _LW("Node group template {info} "
                    "in use by clusters {clusters}").format(
                        info=u.name_and_id(template), clusters=cluster_users))
        if template_users:
            LOG.warning(
                _LW("Node group template {info} "
                    "in use by cluster templates {templates}").format(
                        info=u.name_and_id(template),
                        templates=template_users))

        if cluster_users or template_users:
            LOG.warning(
                _LW("Deletion of node group template "
                    "{info} failed").format(info=u.name_and_id(template)))
            return

    try:
        conductor.API.node_group_template_destroy(ctx,
                                                  template["id"],
                                                  ignore_prot_on_def=True)
    except Exception as e:
        LOG.warning(
            _LW("Deletion of node group template {info} "
                "failed{rollback}, {reason}").format(
                    info=u.name_and_id(template),
                    reason=e,
                    rollback=rollback_msg))
    else:
        LOG.info(
            _LI("Deleted node group template {info}{rollback}").format(
                info=u.name_and_id(template), rollback=rollback_msg))
示例#6
0
文件: api.py 项目: thefuyang/sahara
def delete_node_group_template(ctx, template, rollback=False):
    rollback_msg = " on rollback" if rollback else ""

    # If we are not deleting something that we just created,
    # do usage checks to ensure that the template is not in
    # use by a cluster or a cluster template
    if not rollback:
        clusters = conductor.API.cluster_get_all(ctx)
        cluster_templates = conductor.API.cluster_template_get_all(ctx)
        cluster_users, template_users = u.check_node_group_template_usage(
            template["id"], clusters, cluster_templates)

        if cluster_users:
            LOG.warning(_LW("Node group template {info} "
                        "in use by clusters {clusters}").format(
                            info=u.name_and_id(template),
                            clusters=cluster_users))
        if template_users:
            LOG.warning(_LW("Node group template {info} "
                        "in use by cluster templates {templates}").format(
                            info=u.name_and_id(template),
                            templates=template_users))

        if cluster_users or template_users:
            LOG.warning(_LW("Deletion of node group template "
                        "{info} failed").format(info=u.name_and_id(template)))
            return

    try:
        conductor.API.node_group_template_destroy(ctx, template["id"],
                                                  ignore_default=True)
    except Exception as e:
        LOG.warning(_LW("Deletion of node group template {info} "
                    "failed{rollback}, {reason}").format(
                        info=u.name_and_id(template),
                        reason=e,
                        rollback=rollback_msg))
    else:
        LOG.info(_LI("Deleted node group template {info}{rollback}").format(
            info=u.name_and_id(template), rollback=rollback_msg))