Ejemplo n.º 1
0
def create_cluster(resource_root, name, version=None, fullVersion=None):
    """Create a cluster

    :param resource_root: The root Resource object.
    :param name: Cluster name
    :param version: Cluster CDH major version (eg: "CDH4")
                    - The CDH minor version will be assumed to be the
                      latest released version for CDH4, or 5.0 for CDH5.
    :param fullVersion: Cluster's full CDH version. (eg: "5.1.1")
                        - If specified, 'version' will be ignored.
                        - Since: v6
    :return: An ApiCluster object
    """
    if version is None and fullVersion is None:
        raise ex.CMApiVersionError(
            _("Either 'version' or 'fullVersion' must be specified"))
    if fullVersion is not None:
        api_version = 6
        version = None
    else:
        api_version = 1

    apicluster = ApiCluster(resource_root, name, version, fullVersion)
    return types.call(resource_root.post, CLUSTERS_PATH, ApiCluster, True,
                      data=[apicluster], api_version=api_version)[0]
Ejemplo n.º 2
0
def check_api_version(resource_root, min_version):
    """Check API version

    Checks if the resource_root's API version it at least the given minimum
    version.
    """
    if resource_root.version < min_version:
        raise ex.CMApiVersionError(
            _("API version %(minv)s is required but %(acv)s is in use.") % {
                'minv': min_version,
                'acv': resource_root.version
            })
Ejemplo n.º 3
0
    def _require_min_api_version(self, version):
        """Check mininum verson requirement

        Raise an exception if the version of the api is less than the given
        version.

        :param version: The minimum required version.
        """
        actual_version = self._get_resource_root().version
        version = max(version, self._api_version())
        if actual_version < version:
            raise ex.CMApiVersionError(
                _("API version %(minv)s is required but %(acv)s is in use.") %
                {
                    'minv': version,
                    'acv': actual_version
                })