Example #1
0
    def get_heat_params(self, cluster_template):
        heat_params = {}
        try:
            kube_tag = cluster_template.labels["kube_tag"]
            kube_tag_params = {
                "kube_tag": kube_tag,
                "kube_version": kube_tag,
                "master_kube_tag": kube_tag,
                "minion_kube_tag": kube_tag,
            }
            heat_params.update(kube_tag_params)
        except KeyError:
            LOG.debug(("Cluster template %s does not contain a "
                       "valid kube_tag"), cluster_template.name)

        for ostree_tag in ["ostree_commit", "ostree_remote"]:
            try:
                ostree_param = {
                    ostree_tag: cluster_template.labels[ostree_tag]
                }
                heat_params.update(ostree_param)
            except KeyError:
                LOG.debug("Cluster template %s does not define %s",
                          (cluster_template.name, ostree_tag))

        upgrade_labels = ['kube_tag', 'ostree_remote', 'ostree_commit']
        if not any([u in heat_params.keys() for u in upgrade_labels]):
            reason = ("Cluster template %s does not contain any supported "
                      "upgrade labels: [%s]") % (cluster_template.name,
                                                 ', '.join(upgrade_labels))
            raise exception.InvalidClusterTemplateForUpgrade(reason=reason)

        return heat_params
Example #2
0
    def upgrade(self, cluster_ident, cluster_upgrade_req):
        """Upgrade a cluster.

        :param cluster_ident: UUID of a cluster or logical name of the cluster.
        """
        context = pecan.request.context
        cluster = api_utils.get_resource('Cluster', cluster_ident)
        policy.enforce(context,
                       'cluster:upgrade',
                       cluster,
                       action='cluster:upgrade')

        new_cluster_template = api_utils.get_resource(
            'ClusterTemplate', cluster_upgrade_req.cluster_template)

        if (cluster_upgrade_req.nodegroup == wtypes.Unset
                or not cluster_upgrade_req.nodegroup):
            # NOTE(ttsiouts): If the nodegroup is not specified
            # reflect the change to the default worker nodegroup
            nodegroup = cluster.default_ng_worker
        else:
            nodegroup = objects.NodeGroup.get(context, cluster.uuid,
                                              cluster_upgrade_req.nodegroup)
            if (new_cluster_template.uuid != cluster.cluster_template_id
                    and not nodegroup.is_default):
                reason = ("Nodegroup %s can be upgraded only to "
                          "match cluster's template (%s).")
                reason = reason % (nodegroup.name,
                                   cluster.cluster_template.name)
                raise exception.InvalidClusterTemplateForUpgrade(reason=reason)

        pecan.request.rpcapi.cluster_upgrade(
            cluster, new_cluster_template, cluster_upgrade_req.max_batch_size,
            nodegroup)
        return ClusterID(cluster.uuid)