Example #1
0
    def update_coe_cluster(self, name_or_id, operation, **kwargs):
        """Update a COE cluster.

        :param name_or_id: Name or ID of the COE cluster being updated.
        :param operation: Operation to perform - add, remove, replace.

        Other arguments will be passed with kwargs.

        :returns: a dict representing the updated cluster.

        :raises: OpenStackCloudException on operation error.
        """
        self.list_coe_clusters.invalidate(self)
        cluster = self.get_coe_cluster(name_or_id)
        if not cluster:
            raise exc.OpenStackCloudException("COE cluster %s not found." %
                                              name_or_id)

        if operation not in ['add', 'replace', 'remove']:
            raise TypeError("%s operation not in 'add', 'replace', 'remove'" %
                            operation)

        patches = _utils.generate_patches_from_kwargs(operation, **kwargs)
        # No need to fire an API call if there is an empty patch
        if not patches:
            return cluster

        with _utils.shade_exceptions(
                "Error updating COE cluster {0}".format(name_or_id)):
            self._container_infra_client.patch(
                '/clusters/{id}'.format(id=cluster['id']), json=patches)

        new_cluster = self.get_coe_cluster(name_or_id)
        return new_cluster
Example #2
0
    def update_cluster_template(self, name_or_id, operation, **kwargs):
        """Update a cluster template.

        :param name_or_id: Name or ID of the cluster template being updated.
        :param operation: Operation to perform - add, remove, replace.

        Other arguments will be passed with kwargs.

        :returns: a dict representing the updated cluster template.

        :raises: OpenStackCloudException on operation error.
        """
        self.list_cluster_templates.invalidate(self)
        cluster_template = self.get_cluster_template(name_or_id)
        if not cluster_template:
            raise exc.OpenStackCloudException(
                "Cluster template %s not found." % name_or_id)

        if operation not in ['add', 'replace', 'remove']:
            raise TypeError("%s operation not in 'add', 'replace', 'remove'" %
                            operation)

        patches = _utils.generate_patches_from_kwargs(operation, **kwargs)
        # No need to fire an API call if there is an empty patch
        if not patches:
            return cluster_template

        with _utils.shade_exceptions(
                "Error updating cluster template {0}".format(name_or_id)):
            if getattr(self._container_infra_client,
                       '_has_magnum_after_newton', False):
                self._container_infra_client.patch(
                    '/clustertemplates/{id}'.format(id=cluster_template['id']),
                    json=patches)
            else:
                self._container_infra_client.patch(
                    '/baymodels/{id}'.format(id=cluster_template['id']),
                    json=patches)

        new_cluster_template = self.get_cluster_template(name_or_id)
        return new_cluster_template