def download_dse_version(version, username, password, verbose=False):
    url = DSE_ARCHIVE % version
    _, target = tempfile.mkstemp(suffix=".tar.gz", prefix="ccm-")
    try:
        if username is None:
            common.warning(
                "No dse username detected, specify one using --dse-username or passing in a credentials file using --dse-credentials."
            )
        if password is None:
            common.warning(
                "No dse password detected, specify one using --dse-password or passing in a credentials file using --dse-credentials."
            )
        __download(url,
                   target,
                   username=username,
                   password=password,
                   show_progress=verbose)
        common.debug("Extracting {} as version {} ...".format(target, version))
        tar = tarfile.open(target)
        dir = tar.next().name.split("/")[0]
        tar.extractall(path=__get_dir())
        tar.close()
        target_dir = os.path.join(__get_dir(), version)
        if os.path.exists(target_dir):
            rmdirs(target_dir)
        shutil.move(os.path.join(__get_dir(), dir), target_dir)
    except urllib.error.URLError as e:
        msg = "Invalid version %s" % version if url is None else "Invalid url %s" % url
        msg = msg + " (underlying error is: %s)" % str(e)
        raise ArgumentError(msg)
    except tarfile.ReadError as e:
        raise ArgumentError("Unable to uncompress downloaded file: %s" %
                            str(e))
Exemplo n.º 2
0
def download_opscenter_version(version, username, password, target_version, verbose=False):
    url = OPSC_ARCHIVE
    if CCM_CONFIG.has_option('repositories', 'opscenter'):
        url = CCM_CONFIG.get('repositories', 'opscenter')

    url = url % version
    _, target = tempfile.mkstemp(suffix=".tar.gz", prefix="ccm-")
    try:
        if username is None:
            common.warning("No dse username detected, specify one using --dse-username or passing in a credentials file using --dse-credentials.")
        if password is None:
            common.warning("No dse password detected, specify one using --dse-password or passing in a credentials file using --dse-credentials.")
        __download(url, target, username=username, password=password, show_progress=verbose)
        common.info("Extracting {} as version {} ...".format(target, target_version))
        tar = tarfile.open(target)
        dir = tar.next().name.split("/")[0]  # pylint: disable=all
        tar.extractall(path=__get_dir())
        tar.close()
        target_dir = os.path.join(__get_dir(), target_version)
        if os.path.exists(target_dir):
            rmdirs(target_dir)
        shutil.move(os.path.join(__get_dir(), dir), target_dir)
    except urllib.error.URLError as e:
        msg = "Invalid version {}".format(version) if url is None else "Invalid url {}".format(url)
        msg = msg + " (underlying error is: {})".format(str(e))
        raise ArgumentError(msg)
    except tarfile.ReadError as e:
        raise ArgumentError("Unable to uncompress downloaded file: {}".format(str(e)))
Exemplo n.º 3
0
def setup(version, verbose=False):
    binary = True
    fallback = True

    if version.startswith('git:'):
        clone_development(GIT_REPO, version, verbose=verbose)
        return (version_directory(version), None)
    elif version.startswith('local:'):
        # local: slugs take the form of: "local:/some/path/:somebranch"
        try:
            _, path, branch = version.split(':')
        except ValueError:
            raise CCMError("local version ({}) appears to be invalid. Please format as local:/some/path/:somebranch".format(version))

        clone_development(path, version, verbose=verbose)
        version_dir = version_directory(version)

        if version_dir is None:
            raise CCMError("Path provided in local slug appears invalid ({})".format(path))
        return (version_dir, None)

    elif version.startswith('binary:'):
        version = version.replace('binary:', '')
        fallback = False

    elif version.startswith('github:'):
        user_name, _ = github_username_and_branch_name(version)
        clone_development(github_repo_for_user(user_name), version, verbose=verbose)
        return (directory_name(version), None)

    elif version.startswith('source:'):
        version = version.replace('source:', '')
        binary = False
        fallback = False

    if version in ('stable', 'oldstable', 'testing'):
        version = get_tagged_version_numbers(version)[0]

    cdir = version_directory(version)
    if cdir is None:
        try:
            download_version(version, verbose=verbose, binary=binary)
            cdir = version_directory(version)
        except Exception as e:
            # If we failed to download from ARCHIVE,
            # then we build from source from the git repo,
            # as it is more reliable.
            # We don't do this if binary: or source: were
            # explicitly specified.
            if fallback:
                common.warning("Downloading {} failed, due to {}. Trying to build from git instead.".format(version, e))
                version = 'git:cassandra-{}'.format(version)
                clone_development(GIT_REPO, version, verbose=verbose)
                return (version_directory(version), None)
            else:
                raise e
    return (cdir, version)
def setup(version, verbose=False):
    binary = True
    fallback = True

    if version.startswith('git:'):
        clone_development(GIT_REPO, version, verbose=verbose)
        return (version_directory(version), None)

    elif version.startswith('local:'):
        if LOCAL_GIT_REPO is None:
            raise CCMError("LOCAL_GIT_REPO is not defined!")
        clone_development(LOCAL_GIT_REPO, version, verbose=verbose)
        return (version_directory(version), None)

    elif version.startswith('binary:'):
        version = version.replace('binary:', '')
        fallback = False

    elif version.startswith('github:'):
        user_name, _ = github_username_and_branch_name(version)
        clone_development(github_repo_for_user(user_name),
                          version,
                          verbose=verbose)
        return (directory_name(version), None)

    elif version.startswith('source:'):
        version = version.replace('source:', '')
        binary = False
        fallback = False

    if version in ('stable', 'oldstable', 'testing'):
        version = get_tagged_version_numbers(version)[0]

    cdir = version_directory(version)
    if cdir is None:
        try:
            download_version(version, verbose=verbose, binary=binary)
            cdir = version_directory(version)
        except Exception as e:
            # If we failed to download from ARCHIVE,
            # then we build from source from the git repo,
            # as it is more reliable.
            # We don't do this if binary: or source: were
            # explicitly specified.
            if fallback:
                common.warning(
                    "Downloading {} failed, due to {}. Trying to build from git instead."
                    .format(version, e))
                version = 'git:cassandra-{}'.format(version)
                clone_development(GIT_REPO, version, verbose=verbose)
                return (version_directory(version), None)
            else:
                raise e
    return (cdir, version)
Exemplo n.º 5
0
def setup(version, verbose=False):
    binary = True
    fallback = True

    if version.startswith('git:'):
        clone_development(GIT_REPO, version, verbose=verbose)
        return (version_directory(version), None)

    elif version.startswith('local:'):
        if LOCAL_GIT_REPO is None:
            raise CCMError("LOCAL_GIT_REPO is not defined!")
        clone_development(LOCAL_GIT_REPO, version, verbose=verbose)
        return (version_directory(version), None)

    elif version.startswith('binary:'):
        version = version.replace('binary:', '')
        fallback = False

    elif version.startswith('github:'):
        user_name, _ = github_username_and_branch_name(version)
        clone_development(github_repo_for_user(user_name), version, verbose=verbose)
        return (directory_name(version), None)

    elif version.startswith('source:'):
        version = version.replace('source:', '')
        binary = False
        fallback = False

    if version in ('stable', 'oldstable', 'testing'):
        version = get_tagged_version_numbers(version)[0]

    cdir = version_directory(version)
    if cdir is None:
        try:
            download_version(version, verbose=verbose, binary=binary)
            cdir = version_directory(version)
        except Exception as e:
            # If we failed to download from ARCHIVE,
            # then we build from source from the git repo,
            # as it is more reliable.
            # We don't do this if binary: or source: were
            # explicitly specified.
            if fallback:
                common.warning("Downloading {} failed, due to {}. Trying to build from git instead.".format(version, e))
                version = 'git:cassandra-{}'.format(version)
                clone_development(GIT_REPO, version, verbose=verbose)
                return (version_directory(version), None)
            else:
                raise e
    return (cdir, version)
Exemplo n.º 6
0
    def load_credentials_from_file(self, dse_credentials_file):
        # Use .dse.ini if it exists in the default .ccm directory.
        if dse_credentials_file is None:
            creds_file = os.path.join(common.get_default_path(), '.dse.ini')
            if os.path.isfile(creds_file):
                dse_credentials_file = creds_file

        if dse_credentials_file is not None:
            parser = ConfigParser.ConfigParser()
            parser.read(dse_credentials_file)
            if parser.has_section('dse_credentials'):
                if parser.has_option('dse_credentials', 'dse_username'):
                    self.dse_username = parser.get('dse_credentials', 'dse_username')
                if parser.has_option('dse_credentials', 'dse_password'):
                    self.dse_password = parser.get('dse_credentials', 'dse_password')
            else:
                common.warning("{} does not contain a 'dse_credentials' section.".format(dse_credentials_file))
Exemplo n.º 7
0
    def load_credentials_from_file(self, dse_credentials_file):
        # Use .dse.ini if it exists in the default .ccm directory.
        if dse_credentials_file is None:
            creds_file = os.path.join(common.get_default_path(), '.dse.ini')
            if os.path.isfile(creds_file):
                dse_credentials_file = creds_file

        if dse_credentials_file is not None:
            parser = ConfigParser.RawConfigParser()
            parser.read(dse_credentials_file)
            if parser.has_section('dse_credentials'):
                if parser.has_option('dse_credentials', 'dse_username'):
                    self.dse_username = parser.get('dse_credentials', 'dse_username')
                if parser.has_option('dse_credentials', 'dse_password'):
                    self.dse_password = parser.get('dse_credentials', 'dse_password')
            else:
                common.warning("{} does not contain a 'dse_credentials' section.".format(dse_credentials_file))
Exemplo n.º 8
0
def download_dse_version(version, username, password, verbose=False):
    url = DSE_ARCHIVE % version
    _, target = tempfile.mkstemp(suffix=".tar.gz", prefix="ccm-")
    try:
        if username is None:
            common.warning("No dse username detected, specify one using --dse-username or passing in a credentials file using --dse-credentials.")
        if password is None:
            common.warning("No dse password detected, specify one using --dse-password or passing in a credentials file using --dse-credentials.")
        __download(url, target, username=username, password=password, show_progress=verbose)
        common.debug("Extracting {} as version {} ...".format(target, version))
        tar = tarfile.open(target)
        dir = tar.next().name.split("/")[0]  # pylint: disable=all
        tar.extractall(path=__get_dir())
        tar.close()
        target_dir = os.path.join(__get_dir(), version)
        if os.path.exists(target_dir):
            rmdirs(target_dir)
        shutil.move(os.path.join(__get_dir(), dir), target_dir)
    except urllib.error.URLError as e:
        msg = "Invalid version %s" % version if url is None else "Invalid url %s" % url
        msg = msg + " (underlying error is: %s)" % str(e)
        raise ArgumentError(msg)
    except tarfile.ReadError as e:
        raise ArgumentError("Unable to uncompress downloaded file: %s" % str(e))
Exemplo n.º 9
0
def setup(version, verbose=False, elassandra_version=None):
    binary = True
    fallback = True

    if version.startswith('git:'):
        clone_development(GIT_REPO, version, verbose=verbose, elassandra_version=elassandra_version)
        return (elassandra_version_directory(version, elassandra_version), None)
    elif version.startswith('local:'):
        # local: slugs take the form of: "local:/some/path/:somebranch"
        try:
            _, path, branch = version.split(':')
        except ValueError:
            raise CCMError("local version ({}) appears to be invalid. Please format as local:/some/path/:somebranch".format(version))

        clone_development(path, version, verbose=verbose, elassandra_version=elassandra_version)
        version_dir = elassandra_version_directory(version, elassandra_version)

        if version_dir is None:
            raise CCMError("Path provided in local slug appears invalid ({})".format(path))
        return (version_dir, None)

    elif version.startswith('binary:'):
        version = version.replace('binary:', '')
        fallback = False

    elif version.startswith('github:'):
        user_name, _ = github_username_and_branch_name(version)
        clone_development(github_repo_for_user(user_name), version, verbose=verbose, elassandra_version=elassandra_version)
        return (elassandra_version_directory(version, elassandra_version), None)

    elif version.startswith('source:'):
        version = version.replace('source:', '')
        binary = False
        fallback = False

    elif version.startswith('alias:'):
        alias = version.split(":")[1].split("/")[0]
        try:
            git_repo = CCM_CONFIG.get("aliases", alias)
            clone_development(git_repo, version, verbose=verbose, alias=True, elassandra_version=elassandra_version)
            return (elassandra_version_directory(version, elassandra_version), None)
        except ConfigParser.NoOptionError as e:
            common.warning("Unable to find alias {} in configuration file.".format(alias))
            raise e

    if version in ('stable', 'oldstable', 'testing'):
        version = get_tagged_version_numbers(version)[0]

    if elassandra_version is None:
        elassandra_version = version

    cdir = version_directory(elassandra_version)
    if cdir is None:
        try:
            download_version(elassandra_version, verbose=verbose, binary=binary)
            cdir = version_directory(elassandra_version)
        except Exception as e:
            # If we failed to download from ARCHIVE,
            # then we build from source from the git repo,
            # as it is more reliable.
            # We don't do this if binary: or source: were
            # explicitly specified.
            if fallback and False: # skip fallback, would not work with elassandra that way
                common.warning("Downloading {} failed, due to {}. Trying to build from git instead.".format(version, e))
                version = 'git:cassandra-{}'.format(version)
                clone_development(GIT_REPO, version, verbose=verbose, elassandra_version=elassandra_version)
                return (version_directory(version), None)
            else:
                raise e
    return (cdir, elassandra_version)
Exemplo n.º 10
0
def setup(version, verbose=False):
    binary = True
    fallback = True

    if version.startswith('git:'):
        clone_development(GIT_REPO, version, verbose=verbose)
        return (version_directory(version), None)
    elif version.startswith('local:'):
        # local: slugs take the form of: "local:/some/path/:somebranch"
        try:
            _, path, branch = version.split(':')
        except ValueError:
            raise CCMError(
                "local version ({}) appears to be invalid. Please format as local:/some/path/:somebranch"
                .format(version))

        clone_development(path, version, verbose=verbose)
        version_dir = version_directory(version)

        if version_dir is None:
            raise CCMError(
                "Path provided in local slug appears invalid ({})".format(
                    path))
        return (version_dir, None)

    elif version.startswith('binary:'):
        version = version.replace('binary:', '')
        fallback = False

    elif version.startswith('github:'):
        user_name, _ = github_username_and_branch_name(version)
        # make sure to use http for cloning read-only repos such as 'github:apache/cassandra-2.1'
        if user_name == "apache":
            clone_development(GITHUB_REPO, version, verbose=verbose)
        else:
            clone_development(github_repo_for_user(user_name),
                              version,
                              verbose=verbose)
        return (directory_name(version), None)

    elif version.startswith('source:'):
        version = version.replace('source:', '')

    elif version.startswith('clone:'):
        # locally present C* source tree
        version = version.replace('clone:', '')
        return (version, None)

    elif version.startswith('alias:'):
        alias = version.split(":")[1].split("/")[0]
        try:
            git_repo = CCM_CONFIG.get("aliases", alias)
            clone_development(git_repo, version, verbose=verbose, alias=True)
            return (directory_name(version), None)
        except ConfigParser.NoOptionError as e:
            common.warning(
                "Unable to find alias {} in configuration file.".format(alias))
            raise e

    if version in ('stable', 'oldstable', 'testing'):
        version = get_tagged_version_numbers(version)[0]

    cdir = version_directory(version)
    if cdir is None:
        try:
            download_version(version, verbose=verbose, binary=binary)
            cdir = version_directory(version)
        except Exception as e:
            # If we failed to download from ARCHIVE,
            # then we build from source from the git repo,
            # as it is more reliable.
            # We don't do this if binary: or source: were
            # explicitly specified.
            if fallback:
                common.warning(
                    "Downloading {} failed, trying to build from git instead.\n"
                    "The error was: {}".format(version, e))
                version = 'git:cassandra-{}'.format(version)
                clone_development(GIT_REPO, version, verbose=verbose)
                return (version_directory(version), None)
            else:
                raise e
    return (cdir, version)