示例#1
0
def rsync(
    remote: str, secrets: Optional[str] = None, skip_secrets_upload: bool = False
) -> None:
    if not remote_exists(remote):
        sudo("mkdir -p {}".format(remote))
        sudo("chown {} {}".format(env.user, remote))

    rsync_project(
        local_dir="./",
        remote_dir=remote,
        exclude=(
            "data",
            "boostrap",
            "local-mode-cache",
            ".git",
            "nodes",
            "secrets",
            "ohai/plugins",
        ),
        extra_opts="-q",
        delete=True,
    )

    if secrets and not skip_secrets_upload:
        sudo(f"mkdir -p {remote}/secrets")
        put(secrets, os.path.join(remote, secrets), mode="0640", use_sudo=True)
def retrieve(agent_packages):
    ctx.logger.info('Downloading Cloudify Agents...')

    for agent, source in agent_packages.items():
        # if source is not a downloadable link, it will not be downloaded
        if not source.startswith(('http', 'https', 'ftp')):
            continue

        dest_path = ctx.instance.runtime_properties['agent_packages_path']
        agent_name = agent.replace('_', '-')

        # This is a workaround for mapping Centos release names to versions
        # to provide a better UX when providing agent inputs.
        if agent_name == 'centos-7x-agent':
            agent_name = 'centos-core-agent'
        elif agent_name == 'centos-6x-agent':
            agent_name = 'centos-final-agent'
        elif agent_name == 'redhat-7x-agent':
            agent_name = 'redhat-maipo-agent'
        elif agent_name == 'redhat-6x-agent':
            agent_name = 'redhat-santiago-agent'

        if agent_name == 'cloudify-windows-agent':
            filename = '{0}.exe'.format(agent_name)
        else:
            filename = '{0}.tar.gz'.format(agent_name)
        dest_file = '{0}/{1}'.format(dest_path, filename)

        ctx.logger.info('Downloading Agent Package {0} to {1} if it does not '
                        'already exist...'.format(source, dest_file))
        if remote_exists(dest_file):
            ctx.logger.info('agent package file will be '
                            'overridden: {0}'.format(dest_file))
        dl_cmd = 'curl --retry 10 -f -s -S -L {0} --create-dirs -o {1}'
        fabric.api.sudo(dl_cmd.format(source, dest_file))
def retrieve(agent_packages):
    ctx.logger.info('Downloading Cloudify Agents...')
    if not agent_packages:
        raise NonRecoverableError(
            'Cannot find agent packages. At least one agent package must be '
            'provided compatible with {0}.'.format(_get_distro_info()))

    for agent, source_url in agent_packages.items():
        dest_path = ctx.instance.runtime_properties['agent_packages_path']
        agent_name = agent.replace('_', '-')

        # This is a workaround for mapping Centos release names to versions
        # to provide a better UX when providing agent inputs.
        if agent_name == 'centos-7x-agent':
            agent_name = 'centos-core-agent'
        elif agent_name == 'centos-6x-agent':
            agent_name = 'centos-final-agent'
        elif agent_name == 'redhat-7x-agent':
            agent_name = 'redhat-maipo-agent'
        elif agent_name == 'redhat-6x-agent':
            agent_name = 'redhat-santiago-agent'

        if agent_name == 'cloudify-windows-agent':
            filename = '{0}.exe'.format(agent_name)
        else:
            filename = '{0}.tar.gz'.format(agent_name)
        dest_file = '{0}/{1}'.format(dest_path, filename)

        ctx.logger.info('Downloading Agent Package {0} to {1} if it does not '
                        'already exist...'.format(source_url, dest_file))
        if not remote_exists(dest_file):
            dl_cmd = 'curl --retry 10 -f -s -S -L {0} --create-dirs -o {1}'
            fabric.api.sudo(dl_cmd.format(source_url, dest_file))
示例#4
0
def inbox_list(state, match):
    """List the current contents of the inbox"""
    if not remote_exists(state.inbox_dest):
        return
    with cd(state.inbox_dest), hide('running', 'stdout', 'stderr'):
        output = run('ls {} | grep -v "\.md5"'.format(match),
                     warn_only=True, quiet=True)
        for f in output.split():
            print(cyan(f))
示例#5
0
def inbox_list(state, match):
    """List the current contents of the inbox"""
    if not remote_exists(state.inbox_dest):
        return
    with cd(state.inbox_dest), hide('running', 'stdout', 'stderr'):
        output = run('ls {} | grep -v "\.md5"'.format(match),
                     warn_only=True,
                     quiet=True)
        for f in output.split():
            print(cyan(f))
示例#6
0
def inbox_symlink(state, file, count):
    """Create copies of an existing inbox file via symlinks"""
    remote_path = state.inbox_dest.child(file)
    if not remote_exists(remote_path, verbose=True):
        abort("remote file {} not found".format(remote_path))

    with cd(state.inbox_path):
        for i in range(count):
            link = remote_path.stem + '_' + str(i + 1) + remote_path.ext
            sudo("ln -sf {} {}".format(remote_path, link))
        return
示例#7
0
def inbox_symlink(state, file, count):
    """Create copies of an existing inbox file via symlinks"""
    remote_path = state.inbox_dest.child(file)
    if not remote_exists(remote_path, verbose=True):
        abort("remote file {} not found".format(remote_path))

    with cd(state.inbox_path):
        for i in range(count):
            link = remote_path.stem + '_' + str(i + 1) + remote_path.ext
            sudo("ln -sf {} {}".format(remote_path, link))
        return
示例#8
0
    def wrapped(state, *args, **kwargs):

        # set up the fabric env
        env.host_string = state.host
        if state.ssh_user:
            env.user = state.ssh_user

        if not remote_exists(state.inbox_path):
            raise UsageError(
                "Invalid remote inbox path: %s" % state.inbox_path)

        return click_cmd(state, *args, **kwargs)
示例#9
0
    def wrapped(state, *args, **kwargs):

        # set up the fabric env
        env.host_string = state.host
        if state.ssh_user:
            env.user = state.ssh_user

        if not remote_exists(state.inbox_path):
            raise UsageError(
                "Invalid remote inbox path: %s" % state.inbox_path)

        return click_cmd(state, *args, **kwargs)
示例#10
0
def chef(host: str, remote: str, secrets: Optional[str] = None) -> None:
    secrets_opts = ""
    if secrets:
        secrets_opts = f" -j {secrets}"

    cmd = chef_command.format(host=host, secrets=secrets_opts)

    wrapper = "/usr/local/bin/run-chef-{}".format(env.user)
    if not remote_exists(script) or not remote_contains(script, cmd):
        put(
            StringIO(chef_script.format(remote=remote, chef_command=cmd)),
            script,
            use_sudo=True,
            mode="0750",
        )
    if remote_exists(sudoers):
        sudo("rm -f {}".format(sudoers))
    if not remote_exists(wrapper):
        put(StringIO(wrapper_script), wrapper, mode="0750", use_sudo=True)

    sudo(script)
示例#11
0
def create_compressor():
    sudo("apt-get install -y -q g++ make checkinstall")

    if not remote_exists("~/src", use_sudo=True):
        sudo("mkdir ~/src")

    with cd("~/src"):
        sudo("wget -N http://nodejs.org/dist/v0.10.13/node-v0.10.13.tar.gz")
        sudo("tar xzvf node-v0.10.13.tar.gz")

        with cd("node-v0.10.13"):
            sudo("./configure")
            #TODO: Currently prompts you to fill out documentation and change node version number
            sudo("checkinstall")
            sudo("dpkg -i node_*")

    sudo("npm install -g less")
示例#12
0
def create_compressor():
    sudo("apt-get install -y -q g++ make checkinstall")

    if not remote_exists("~/src", use_sudo=True):
        sudo("mkdir ~/src")

    with cd("~/src"):
        sudo("wget -N http://nodejs.org/dist/v0.10.13/node-v0.10.13.tar.gz")
        sudo("tar xzvf node-v0.10.13.tar.gz")

        with cd("node-v0.10.13"):
            sudo("./configure")
            #TODO: Currently prompts you to fill out documentation and change node version number
            sudo("checkinstall")
            sudo("dpkg -i node_*")

    sudo("npm install -g less")
示例#13
0
def validate_secrets(
    secrets_local: str, secrets: str, remote: str, local: bool
) -> bool:
    remote_path = os.path.join(remote, secrets)
    try:
        with open(secrets_local) as f:
            json.load(f)

        return False

    except Exception as e:
        print(f"Invalid secrets file at {secrets_local}: {e}.", file=sys.stderr)
        if not local and remote_exists(remote_path):
            print("File is not valid locally, but exists remotely.", file=sys.stderr)
            print("Using remote version.", file=sys.stderr)
            return True
        else:
            print("aborting", file=sys.stderr)
            sys.exit(1)
示例#14
0
def make_base_install_dir(cluster):
    """
    Creates a new install directory after backing up the old one.
    All service binaries and config files will be placed under this
    directory.
    """
    install_dir = cluster.get_hadoop_install_dir()
    backup_dir = '{}/{}.backup'.format(
        cluster.get_config(constants.KEY_HOMEDIR),
        cluster.get_hadoop_distro_name())

    get_logger().debug("Making install dir {} on host {}".format(
        install_dir, env.host))
    if remote_exists(install_dir):
        sudo('rm -rf {}'.format(backup_dir))
        sudo('mv {} {}'.format(install_dir, backup_dir))
    sudo('mkdir -p {}'.format(install_dir))
    sudo('chmod 0755 {}'.format(install_dir))
    return True
示例#15
0
def select_bin(*commands, **kwargs):
    from fabric.contrib.files import exists as remote_exists

    paths = kwargs.get('paths', None)
    remote = kwargs.get('remote', True)
    if paths is None:
        paths = ('/usr/bin', '/bin',)
    elif not isinstance(paths, (list, tuple)):
        paths = [paths]
    for path in paths:
        for command in commands:
            if remote:
                command_path = posixpath.join(path, command)
                if remote_exists(command_path):
                    return command_path
            else:
                command_path = os.path.join(path, command)
                if os.path.exists(command_path):
                    return command_path
    raise CommandNotFoundException('Could not find suitable binary for %s' % ','.join(commands))
示例#16
0
def install_pip(remote_path="/opt/resource", python_path="/opt/python/bin/python2.7"):
    # 1. check python exists in servers
    if not remote_exists(python_path):
        print "Not found python in python_path."
        need_install = confirm("Install python? ", default=False)
        if not need_install:
            _occur_error("Please install python first.")

        python_prefix = prompt("Python install path: ", default="/opt/python")
        install_python(remote_path, python_prefix)
        python_path = os.path.join(python_prefix, "bin", "python2.7")

    # 2. download setuptools
    setuptools_path = os.path.join(local_path, "setuptools-7.0.tar.gz")
    if not os.path.exists(setuptools_path):
        _download_file("https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz#md5=6245d6752e2ef803c365f560f7f2f940", setuptools_path)

    # 3. download pip source code
    pip_path = os.path.join(local_path, "pip-1.5.6.tar.gz")
    if not os.path.exists(pip_path):
        _download_file("https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e", pip_path)

    # 4. put to server
    put(setuptools_path, remote_path)
    put(pip_path, remote_path)

    # 5. install setuptools
    with cd(remote_path):
        run("tar xvf setuptools-7.0.tar.gz")
        run("rm setuptools-7.0.tar.gz")

    with cd(os.path.join(remote_path, "setuptools-7.0")):
        run(python_path + " setup.py install")

    # 6. install pip
    with cd(remote_path):
        run("tar xvf pip-1.5.6.tar.gz")
        run("rm pip-1.5.6.tar.gz")

    with cd(os.path.join(remote_path, "pip-1.5.6")):
        run(python_path + " setup.py install")
示例#17
0
def install_python(remote_path="/opt/resource", install_path="/opt/python"):
    if not remote_exists(remote_path):
        os.makedirs(remote_path)

    # 0. check if python package exists in local_path
    python_path = os.path.join(local_path, "Python-2.7.8.tgz")

    if not os.path.exists(python_path):
        # 1. download python source code
        _download_file("https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz", python_path)

    # 2. put to server
    put(python_path, remote_path)

    # 3. install python
    with cd(remote_path):
        run("tar xvf Python-2.7.8.tgz")
        run("rm Python-2.7.8.tgz")

    with cd(os.path.join(remote_path, "Python-2.7.8")):
        run("./configure --prefix=" + install_path + " && make && make install")
示例#18
0
def select_bin(*commands, **kwargs):
    from fabric.contrib.files import exists as remote_exists

    paths = kwargs.get('paths', None)
    remote = kwargs.get('remote', True)
    if paths is None:
        paths = (
            '/usr/bin',
            '/bin',
        )
    elif not isinstance(paths, (list, tuple)):
        paths = [paths]
    for path in paths:
        for command in commands:
            if remote:
                command_path = posixpath.join(path, command)
                if remote_exists(command_path):
                    return command_path
            else:
                command_path = os.path.join(path, command)
                if os.path.exists(command_path):
                    return command_path
    raise CommandNotFoundException('Could not find suitable binary for %s' %
                                   ','.join(commands))
示例#19
0
def release(branch="master"):
    env.host_name = "Dabory"
    env.branch = branch
    env.project_root = release_project_root
    env.user = release_user

    print("Releasing woosym-korean-localization...")

    if not remote_exists(os.path.join(release_project_root, ".git")):
        print(".git not present! Cloning from git repository...")

        run('rm -rf "%s"' % env.project_root)
        path = os.path.dirname(env.project_root)
        clone_name = os.path.basename(env.project_root)

        # git clone
        with cd(path):
            with prefix("if [[ -n $SSH_ASKPASS ]]; then unset SSH_ASKPASS; fi"):
                run('git clone "%s" "%s"' % (git_url, clone_name))
                run("git checkout %s" % env.branch)
    else:
        with cd(env.project_root):
            with prefix("if [[ -n $SSH_ASKPASS ]]; then unset SSH_ASKPASS; fi"):
                run("git fetch")
                run("git checkout %s" % env.branch)
                run("git pull")

    # AGS 결제 모듈 후처리
    run("chmod 755 %s" % os.path.join(env.project_root, ags_log_path))

    # retrieve version
    with cd(env.project_root):
        out = run("grep \"define( 'WSKL_VERSION', \" woosym-korean-localization.php")
        s = re.search(r"define\(\s*(\'|\")WSKL_VERSION(\'|\"),\s*\'(.+)\'\s*\);", out.stdout.strip())

        if s:
            version_info = s.groups()[2]
            print(green("Current branch's WSKL version: %s" % version_info))
        else:
            version_info = "unversioned"
            print(red("Version information not found! Setting version name as %s" % version_info))

    # creating archive
    with cd(os.path.dirname(env.project_root)):
        output_file_gz = "wskl-%s.tar.gz" % version_info
        output_file_zip = "wskl-%s.zip" % version_info

        relative_dir = os.path.basename(env.project_root)
        latest_file_gz = "latest.tar.gz"
        latest_file_zip = "latest.zip"

        run("rm -f %s" % output_file_gz)
        run("tar -cpzf %s --exclude='.git' --exclude='.gitignore' %s" % (output_file_gz, relative_dir))

        run("rm -f %s" % output_file_zip)
        run("zip -r %s %s -x \\*/*.git\\* \\*/.gitignore" % (output_file_zip, relative_dir))

        print(green("Do you want to make current output files be aliased as latest?"))
        q = raw_input("y/N ")

        if q.lower() == "y":
            print(green("You have answered 'Yes'. Creating soft symlink."))
            run("rm -f %s" % latest_file_gz)
            run("rm -f %s" % latest_file_zip)
            run("ln -s %s %s" % (output_file_gz, latest_file_gz))
            run("ln -s %s %s" % (output_file_zip, latest_file_zip))