Python fabric.api.put() Examples

The following are 30 code examples of fabric.api.put(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fabric.api , or try the search function .
Example #1
Source File: fabfile.py    From ocl_web with Mozilla Public License 2.0 6 votes vote down vote up
def setup_environment():
    """Create OCL directories and files.
    """
    for directory in ['/opt/virtualenvs', '/opt/deploy']:
        if not files.exists(directory):
            print yellow('Creating directory %s...' % directory)
            sudo('mkdir %s' % directory)
            sudo('chown deploy:deploy %s' % directory)

    # all logs go to /var/log/ocl subdirectories.
    if not files.exists('/var/log/ocl'):
        sudo('mkdir /var/log/ocl')
        sudo('chown deploy:deploy /var/log/ocl')

    # This backup dir is used by the current API server deployment
    # process.
    if not files.exists(BACKUP_DIR):
        sudo('mkdir -p %s' % BACKUP_DIR)
        sudo('chown deploy:deploy %s' % BACKUP_DIR)

    # A few shell aliases that PK likes...
    put(_conf_path('ocl_aliases'), '~/.bash_aliases')
    put(_conf_path('tmux.conf'), '~/.tmux.conf') 
Example #2
Source File: __init__.py    From automation-tools with GNU General Public License v3.0 6 votes vote down vote up
def setenforce(mode):
    """Modify the mode SELinux is running in

    :param mode: Use 'enforcing' or 1 or True to put SELinux in enforcing mode.
        Use 'permissive' or 0 or False to put SELinux in permissive mode.

    """
    if isinstance(mode, str):
        mode = mode.lower()

    enforcing_modes = ('enforcing', 1, True)
    permissive_modes = ('permissive', 0, False)
    if mode in enforcing_modes:
        mode = 1
    elif mode in permissive_modes:
        mode = 0
    else:
        raise ValueError('Mode should be one of {0}'.format(
            enforcing_modes + permissive_modes
        ))

    run('setenforce {0}'.format(mode)) 
Example #3
Source File: __init__.py    From automation-tools with GNU General Public License v3.0 6 votes vote down vote up
def create_personal_git_repo(name, private=False):
    """Creates a new personal git repository under the public_git repository"""
    # Command-line arguments are passed in as strings.
    if isinstance(private, str):
        private = (private.lower() == 'true')

    # Create a repository locally, upload it and delete the local repository.
    # Do not create a repository directly on the remote machine because its
    # version of git may be old.
    repo_name = '{0}.git'.format(name)
    local(
        'git init --bare --shared={0} {1}'
        .format('none' if private else 'all', repo_name)
    )
    run('install -d -m 755 ~/public_git/')
    put(repo_name, '~/public_git/')
    local('rm -rf {0}'.format(repo_name)) 
Example #4
Source File: postgres.py    From fabricio with MIT License 6 votes vote down vote up
def update_config(self, content, path):
        old_file = six.BytesIO()
        if files.exists(path, use_sudo=self.sudo):
            fab.get(remote_path=path, local_path=old_file, use_sudo=self.sudo)
        old_content = old_file.getvalue()
        need_update = content != old_content
        if need_update:
            fabricio.move_file(
                path_from=path,
                path_to=path + '.backup',
                sudo=self.sudo,
                ignore_errors=True,
            )
            fab.put(six.BytesIO(content), path, use_sudo=self.sudo, mode='0644')
            fabricio.log('{path} updated'.format(path=path))
        else:
            fabricio.log('{path} not changed'.format(path=path))
        return need_update 
Example #5
Source File: cli.py    From docker-fabric with MIT License 6 votes vote down vote up
def build(self, tag, add_latest_tag=False, add_tags=None, raise_on_error=True, **kwargs):
        try:
            context = kwargs.pop('fileobj')
        except KeyError:
            raise ValueError("'fileobj' needs to be provided. Using 'path' is currently not implemented.")
        for a in ['custom_context', 'encoding']:
            kwargs.pop(a, None)

        with temp_dir() as remote_tmp:
            remote_fn = posixpath.join(remote_tmp, 'context')
            put(context, remote_fn)
            cmd_str = self._out.get_cmd('build', '- <', remote_fn, tag=tag, **kwargs)
            with settings(warn_only=not raise_on_error):
                res = self._call(cmd_str)
        if res:
            image_id = _find_image_id(res)
            if image_id:
                self.add_extra_tags(image_id, tag, add_tags, add_latest_tag)
                return image_id
        return None 
Example #6
Source File: fabricapi.py    From presto-admin with Apache License 2.0 6 votes vote down vote up
def put_secure(user_group, mode, *args, **kwargs):
    missing_owner_code = 42
    user, group = user_group.split(":")

    files = put(*args, mode=mode, **kwargs)

    for file in files:
        with settings(warn_only=True):
            command = \
                "( getent passwd {user} >/dev/null || ( rm -f {file} ; " \
                "exit {missing_owner_code} ) ) && " \
                "chown {user_group} {file}".format(
                    user=user, file=file, user_group=user_group,
                    missing_owner_code=missing_owner_code)

            result = sudo(command)

            if result.return_code == missing_owner_code:
                abort("User %s does not exist. Make sure the Presto "
                      "server RPM is installed and try again" % (user,))
            elif result.failed:
                abort("Failed to chown file %s" % (file,)) 
Example #7
Source File: windows.py    From clusterfuzz with Apache License 2.0 6 votes vote down vote up
def stage(self, config_dir):
    """Stage a zip (built by `python butler.py package`)."""
    os.environ['CONFIG_DIR_OVERRIDE'] = config_dir

    self.restart()
    time.sleep(1)

    zip_path = package.package(
        revision=butler_common.compute_staging_revision(),
        platform_name='windows')
    remote_zip_path = (
        '{clusterfuzz_parent_path}\\{staging_source_filename}'.format(
            clusterfuzz_parent_path=self.clusterfuzz_parent_path,
            staging_source_filename=self.staging_source_filename))
    api.put(zip_path, remote_zip_path)

    api.put(EXTRACT_ZIP_PS_LOCAL_PATH, EXTRACT_ZIP_PS_REMOTE_PATH)
    self._powershell(EXTRACT_ZIP_PS_REMOTE_PATH, 'file')

    self.restart() 
Example #8
Source File: fabfile.py    From ocl_web with Mozilla Public License 2.0 6 votes vote down vote up
def setup_supervisor():
    """Setup supervisor daemon for running OCL processes.

    One of the key function is to put the API tokens required in the
    environment for Web server.
     """

    # first time this will fail because we have a chicken and egg
    # situation, we need the API server to get the tokens, but
    # we need supervisor to run the API server
    auth_token, anon_token = get_api_tokens()
    if auth_token is not None and anon_token is not None:
        env.OCL_API_TOKEN = auth_token
        env.OCL_ANON_API_TOKEN = anon_token
    files.upload_template(_conf_path('ocl_supervisor.conf'),
                          '/etc/supervisor/conf.d', env, use_sudo=True)
    put(_conf_path('supervisord.conf'), '/etc/supervisor', use_sudo=True)
    # restart to run as deploy
    sudo('/etc/init.d/supervisor restart') 
Example #9
Source File: fab_dse.py    From cstar_perf with Apache License 2.0 6 votes vote down vote up
def _configure_spark_env(config):
    # Place spark environment file on hosts:
    spark_env = config.get('spark_env', '')

    if isinstance(spark_env, list) or isinstance(spark_env, tuple):
        spark_env = "\n".join(spark_env)
    spark_env += "\n"

    spark_env_script = "spark-{name}.sh".format(name=uuid.uuid1())
    spark_env_file = StringIO(spark_env)
    fab.run('mkdir -p ~/fab/scripts')
    fab.put(spark_env_file, '~/fab/scripts/{spark_env_script}'.format(spark_env_script=spark_env_script))

    fab.puts('spark-env is: {}'.format(spark_env))
    if len(spark_env_script) > 0:
        spark_env_path = os.path.join(get_dse_path(), 'resources', 'spark', 'conf', 'spark-env.sh')
        fab.run('cat ~/fab/scripts/{spark_env_script} >> {spark_env_path}'.format(spark_env_script=spark_env_script,
                                                                                  spark_env_path=spark_env_path)) 
Example #10
Source File: fab_dse.py    From cstar_perf with Apache License 2.0 6 votes vote down vote up
def bootstrap(config, replace_existing_dse_install=True):
    if replace_existing_dse_install:
        filename = os.path.join(dse_cache_local, dse_tarball)
        dest = os.path.join(dse_builds_remote, dse_tarball)

        # remove build folder if it exists
        fab.run('rm -rf {}'.format(os.path.join(dse_builds_remote, dse_tarball.replace('-bin.tar.gz', ''))))

        # Upload the binaries
        fab.run('mkdir -p {dse_builds}'.format(dse_builds=dse_builds_remote))
        fab.put(filename, dest)

        # Extract the binaries
        fab.run('tar -C {dse_builds} -xf {dest}'.format(dse_builds=dse_builds_remote, dest=dest))

        # Symlink current build to ~/fab/dse
        fab.run('ln -sfn {dse_build} {dse_home}'.format(
            dse_build=os.path.join(dse_builds_remote, dse_tarball.replace('-bin.tar.gz', '')),
            dse_home=get_dse_path()))

    return config['revision'] 
Example #11
Source File: cli.py    From docker-fabric with MIT License 5 votes vote down vote up
def copy_resource(container, resource, local_filename, contents_only=True):
    """
    Copies a resource from a container to a compressed tarball and downloads it.

    :param container: Container name or id.
    :type container: unicode
    :param resource: Name of resource to copy.
    :type resource: unicode
    :param local_filename: Path to store the tarball locally.
    :type local_filename: unicode
    :param contents_only: In case ``resource`` is a directory, put all contents at the root of the tar file. If this is
      set to ``False``, the directory itself will be at the root instead.
    :type contents_only: bool
    """
    with temp_dir() as remote_tmp:
        base_name = os.path.basename(resource)
        copy_path = posixpath.join(remote_tmp, 'copy_tmp')
        run(mkdir(copy_path, check_if_exists=True))
        remote_name = posixpath.join(copy_path, base_name)
        archive_name = 'container_{0}.tar.gz'.format(container)
        archive_path = posixpath.join(remote_tmp, archive_name)
        run('docker cp {0}:{1} {2}'.format(container, resource, copy_path), shell=False)
        if contents_only and is_directory(remote_name):
            src_dir = remote_name
            src_files = '*'
        else:
            src_dir = copy_path
            src_files = base_name
        with cd(src_dir):
            run(targz(archive_path, src_files))
        get(archive_path, local_filename) 
Example #12
Source File: linux.py    From clusterfuzz with Apache License 2.0 5 votes vote down vote up
def _copy_staging_archive_from_local_to_remote(self, local_zip_path):
    """Copy staging archive from local to remote."""
    remote_zip_path = (
        '{clusterfuzz_parent_path}/{staging_source_filename}'.format(
            clusterfuzz_parent_path=self.clusterfuzz_parent_path,
            staging_source_filename=self.staging_source_filename))
    self._run('rm -f ' + remote_zip_path)

    api.sudo('chmod a+w ' + self.clusterfuzz_parent_path_outside)
    api.put(local_zip_path, self._path_outside_docker(remote_zip_path)) 
Example #13
Source File: posix.py    From clusterfuzz with Apache License 2.0 5 votes vote down vote up
def _copy_staging_archive_from_local_to_remote(self, local_zip_path):
    """Copy staging archive from local to remote."""
    remote_zip_path = (
        '{clusterfuzz_parent_path}/{staging_source_filename}'.format(
            clusterfuzz_parent_path=self.clusterfuzz_parent_path,
            staging_source_filename=self.staging_source_filename))
    self._run('rm -f ' + remote_zip_path)
    api.put(local_zip_path, remote_zip_path) 
Example #14
Source File: __init__.py    From automation-tools with GNU General Public License v3.0 5 votes vote down vote up
def setup_rubytfm_code_coverage():
    """Task to setup ruby code coverage for tfm files on Satellite 6.

    The following environment variables affect this task:

        * `RUBY_TFM_COVERAGE_URL`
    """

    run('mkdir -p /etc/coverage/ruby/tfm/')
    coverageruby_file = StringIO()
    coverageruby_file.write(u'---\n')
    coverageruby_file.write(u'project_folder_name :')
    coverageruby_file.write(u' \'/opt/theforeman/tfm')
    coverageruby_file.write(u'/root/usr/share/gems/gems/\'\n')
    coverageruby_file.write(u'report_directory :')
    coverageruby_file.write(u' \'/etc/coverage/ruby/tfm/reports/\'\n')
    coverageruby_file.write(u'analysis_name : \'ruby_subprocess_coverage\'\n')
    coverageruby_file.write(u'...\n')
    put(local_path=coverageruby_file,
        remote_path='/etc/coverage/ruby/tfm/config_tfm.yml')
    coverageruby_file.close()

    coverage_tfm_url = os.getenv('RUBY_TFM_COVERAGE_URL')
    coverage_tfm_file = '/root/coverage_tfm.rb'
    coverage_tfm_rubygems = (
                          '/opt/rh/rh-ruby23/root'
                          '/usr/share/rubygems/rubygems.rb')
    if not coverage_tfm_url:
        print('You need to provide the TFM Coverage Url.')
        sys.exit(1)

    run('wget -O {0} {1}'.format(coverage_tfm_file, coverage_tfm_url))
    run('cat {0} >> {1}'.format(coverage_tfm_file, coverage_tfm_rubygems)) 
Example #15
Source File: __init__.py    From automation-tools with GNU General Public License v3.0 5 votes vote down vote up
def setup_rubysys_code_coverage():
    """Task to setup ruby code coverage for system file on Satellite 6.

    The following environment variables affect this task:

        * `RUBY_SYS_COVERAGE_URL`
    """

    run('mkdir -p /etc/coverage/ruby/sys/')
    coverageruby_file = StringIO()
    coverageruby_file.write(u'---\n')
    coverageruby_file.write(u'project_folder_name :')
    coverageruby_file.write(u' \'/usr/share/gems/gems/\'\n')
    coverageruby_file.write(u'report_directory :')
    coverageruby_file.write(u' \'/etc/coverage/ruby/sys/reports/\'\n')
    coverageruby_file.write(u'analysis_name : \'ruby_subprocess_coverage\'\n')
    coverageruby_file.write(u'...\n')
    put(local_path=coverageruby_file,
        remote_path='/etc/coverage/ruby/sys/config_sys.yml')
    coverageruby_file.close()

    coverage_sys_url = os.getenv('RUBY_SYS_COVERAGE_URL')
    coverage_sys_file = '/root/coverage_sys.rb'
    coverage_sys_rubygems = '/usr/share/rubygems/rubygems.rb'
    if not coverage_sys_url:
        print('You need to provide the SYS Coverage Url.')
        sys.exit(1)

    run('wget -O {0} {1}'.format(coverage_sys_file, coverage_sys_url))
    run('cat {0} >> {1}'.format(coverage_sys_file, coverage_sys_rubygems))


# This function sets up the ruby code coverage around foreman and katello(tfm).
# This mostly deals with tfm rubygems from RedHat software collections (scl). 
Example #16
Source File: baseimage.py    From automation-tools with GNU General Public License v3.0 5 votes vote down vote up
def deploy_baseimage(image, hypervisors=[]):
    """Task to deploy specific image to set of hypervisors

    The following environment variables affect this command:

    PROVISIONING_HOSTS
        Set of hypervisor FQDNs/IPs to deploy image to

    :param str image: Image name to be deployed (without extension .img)
    :param list hypervisors: Set of hypervisor FQDNs/IPs to deploy image to

    """
    hypervisors = hypervisors or os.environ.get('PROVISIONING_HOSTS', '')
    if isinstance(hypervisors, str):
        hypervisors = hypervisors.split()

    tmpimg = run('mktemp')
    run('qemu-img convert /var/lib/libvirt/images/{}.img -O qcow2 {}'.format(image, tmpimg))
    src_fqdn = run('hostname')

    for target in hypervisors:
        if target == src_fqdn:  # omit image hosting machine from deployment
            continue
        if env.forward_agent:  # set by `-A` fab option and ssh agent must be available
            run('scp -p {} {}:{}'.format(tmpimg, target, tmpimg), warn_only=True)
        else:  # no ssh agent, scp works only 3way
            get(tmpimg, tmpimg)
            with settings(host_string=target):
                put(tmpimg, tmpimg)

        with settings(host_string=target):
            run('qemu-img convert {} -O raw /var/lib/libvirt/images/{}.img'.format(tmpimg, image))
            run('rm -f {}'.format(tmpimg))

    run('rm -f {}'.format(tmpimg)) 
Example #17
Source File: postgres.py    From fabricio with MIT License 5 votes vote down vote up
def update(self, tag=None, registry=None, account=None, force=False):
        if not fab.env.parallel:
            fab.abort(
                'Master-slave configuration update requires parallel mode. '
                'Use Fabric\'s `--parallel` option to enable this mode '
                'for a current session.'
            )

        self.instances.put(None)

        try:
            recovery_config_updated = self.update_recovery_config(
                tag=tag,
                registry=registry,
                account=account,
            )

            container_updated = super(
                StreamingReplicatedPostgresqlContainer,
                self,
            ).update(force=force, tag=tag, registry=registry, account=account)

            if not container_updated and recovery_config_updated:
                self.reload()
            self.master_obtained.set()  # one who first comes here is master
            return container_updated or recovery_config_updated
        except Exception as exception:
            self.multiprocessing_data.exception = exception
            raise
        finally:
            try:
                self.master_lock.release()
            except ValueError:  # ignore "released too many times" error
                pass
            self.instances.get()
            self.instances.task_done()
            self.instances.join()  # wait until all instances will be updated

            # reset state at the end to prevent fail of the next Fabric command
            self.master_obtained.clear() 
Example #18
Source File: stack.py    From fabricio with MIT License 5 votes vote down vote up
def upload_configuration(self, configuration):  # pragma: no cover
        warnings.warn(
            'this method is deprecated and will be removed in v0.6, '
            'use upload_configuration_file context manager instead',
            DeprecationWarning,
        )
        warnings.warn(
            'upload_configuration is deprecated and will be removed in v0.6, '
            'use upload_configuration_file context manager instead',
            RuntimeWarning, stacklevel=2,
        )
        fab.put(six.BytesIO(configuration), os.path.basename(self.config)) 
Example #19
Source File: stack.py    From fabricio with MIT License 5 votes vote down vote up
def upload_configuration_file(self, configuration=None):
        if self._current_configuration is not None or not self.is_manager():
            yield self._current_configuration
        else:
            config_file = os.path.basename(self.config)
            with fab.cd(self.temp_dir):
                try:
                    configuration = configuration or self.get_configuration()
                    self._current_configuration = configuration
                    fab.put(six.BytesIO(configuration), config_file)
                    yield configuration
                finally:
                    fabricio.remove_file(config_file, ignore_errors=True)
                    self._current_configuration = None 
Example #20
Source File: fabfile.py    From fabricio with MIT License 5 votes vote down vote up
def localhost(force_local=False):
    if utils.strtobool(force_local):
        # replace fabricio.run by fabricio.local to run all commands locally
        fabricio.run = functools.partial(fabricio.local, capture=True)

        # uncomment row below to skip file uploading (e.g. docker-compose.yml)
        # fab.put = lambda *args, **kwargs: None

    fab.env.update(
        roledefs={
            'web': ['localhost'],
        },
    ) 
Example #21
Source File: fab_common.py    From cstar_perf with Apache License 2.0 5 votes vote down vote up
def bash(script):
    """Run a bash script on the host"""
    script = StringIO(script)
    fab.run('mkdir -p ~/fab/scripts')
    script_path = '~/fab/scripts/{script_name}.sh'.format(script_name=uuid.uuid1())
    fab.put(script, script_path)
    output = StringIO()
    fab.run('bash {script_path}'.format(script_path=script_path), stdout=output, stderr=output)
    output.seek(0)
    return output.read().splitlines() 
Example #22
Source File: deploy.py    From rorolite with Apache License 2.0 5 votes vote down vote up
def push_directory(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            archive = self.archive(rootdir=".", output_dir=tmpdir)
            remote.put(archive, "/tmp/rorolite-project.tgz")

            with lcd(tmpdir):
                self.generate_supervisor_config(rootdir=tmpdir)

                supervisor_archive = self.archive(tmpdir, base_dir=".rorolite", filename="rorolite-supervisor")
                remote.put(supervisor_archive, "/tmp/rorolite-supervisor.tgz")

            with remote.cd(self.deploy_root):
                remote.sudo("chown {} .".format(env.user))
                remote.run("tar xzf /tmp/rorolite-project.tgz")
                remote.run("tar xzf /tmp/rorolite-supervisor.tgz") 
Example #23
Source File: fabfile.py    From ocl_web with Mozilla Public License 2.0 5 votes vote down vote up
def setup_solr():
    """ Setup solr server """
    sudo('apt-get -y -q install openjdk-7-jdk')

    ## no need?
    ## sudo('mkdir /usr/java')
    ## sudo('ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default')

    with cd('/opt'):
        sudo('wget http://archive.apache.org/dist/lucene/solr/4.9.1/solr-4.9.1.tgz')
        sudo('tar -xvf solr-4.9.1.tgz')
        sudo('cp -R solr-4.9.1/example /opt/solr')
        sudo('chown -R deploy:deploy /opt/solr')

    with settings(user='root'):
        put(_conf_path('default.jetty'), '/etc/default/jetty')
        put(_conf_path('jetty'), '/etc/init.d')
        run('chmod a+x /etc/init.d/jetty')

    if not files.exists('/var/log/solr'):
        sudo('mkdir /var/log/solr')
        sudo('chown deploy:deploy /var/log/solr')

    with cd('/opt/deploy/'):
        print yellow('creating project root for %s' % 'solr')
        run('mkdir %s' % 'solr') 
Example #24
Source File: fabfile.py    From ocl_web with Mozilla Public License 2.0 5 votes vote down vote up
def setup_mongo():
    """ Setup mongo database """
    sudo('sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10')
    put(_conf_path('mongo.apt'), '/etc/apt/sources.list.d/mongodb.list', use_sudo=True)
    sudo('apt-get update')
    sudo('apt-get install -y -q mongodb-org') 
Example #25
Source File: fab_common.py    From cstar_perf with Apache License 2.0 5 votes vote down vote up
def destroy(leave_data=False, kill_delay=0):
    """Uninstall Cassandra and clean up data and logs"""
    # We used to have a better pattern match for the Cassandra
    # process, but it got fragile if you put too many JVM params.
    if leave_data:
        fab.run('JAVA_HOME={java_home} {nodetool_cmd} drain'.format(java_home=config['java_home'], nodetool_cmd=_nodetool_cmd()), quiet=True)
        fab.run('rm -rf {commitlog}/*'.format(commitlog=config['commitlog_directory']))
        _clean_up_cdc_directories()

    if kill_delay:
        fab.run('killall java', quiet=True)
        time.sleep(kill_delay)   # kill delay waiting the jvm to exit, profiling stuff require some time to be dumped
    fab.run('killall -9 java', quiet=True)
    fab.run('pkill -f "python.*fincore_capture"', quiet=True)
    fab.run('rm -rf fab/cassandra')
    fab.run('rm -rf fab/dse')
    fab.run('rm -rf fab/scripts')
    fab.run('rm -f {startup_log}'.format(startup_log=CASSANDRA_STARTUP_LOG))

    # Ensure directory configurations look sane
    assert type(config['data_file_directories']) == list
    for t in [config['saved_caches_directory'], config['commitlog_directory'],
              config['flush_directory'], config['log_dir']] + config['data_file_directories']:
        assert type(t) in (str, unicode) and len(t) > 1, '{t} doesn\'t look like a directory'.format(t=t)

    if not leave_data:
        for d in config['data_file_directories']:
            fab.run('rm -rf {data}/*'.format(data=d))
        fab.run('rm -rf {saved_caches_directory}/*'.format(saved_caches_directory=config['saved_caches_directory']))
        fab.run('rm -rf {commitlog}/*'.format(commitlog=config['commitlog_directory']))
        fab.run('rm -rf {flushdir}/*'.format(flushdir=config['flush_directory']))
        if config.get('hints_directory'):
            fab.run('rm -rf {hints_directory}/*'.format(hints_directory=config.get('hints_directory')))
        _clean_up_cdc_directories()
    fab.run('rm -rf {log_dir}/*'.format(log_dir=config['log_dir']))
    fab.run('rm -f /tmp/fincore.stats.log') 
Example #26
Source File: fabfile.py    From ocl_web with Mozilla Public License 2.0 5 votes vote down vote up
def create_api_database():
    """ Helper to create the API mongo database """
    with cd('/opt/deploy/ocl_api/ocl'):
        with prefix('source /opt/virtualenvs/ocl_api/bin/activate'):
            with prefix('export DJANGO_CONFIGURATION="Production"'):
                with prefix('export DJANGO_SECRET_KEY="blah"'):

                    print yellow('creating API database...')
                    # no super user
                    run('./manage.py syncdb --noinput')
                    put(_conf_path('mongo_setup.js'), '~/mongo_setup.js')
                    run('mongo ocl ~/mongo_setup.js')

    # now start the server so that we can create base users
    print yellow('Start up partial API server...')
    run('supervisorctl start ocl_api')

    with cd('/opt/deploy/ocl_api/ocl'):
        with prefix('source /opt/virtualenvs/ocl_api/bin/activate'):
            with prefix('export DJANGO_CONFIGURATION="Production"'):
                with prefix('export DJANGO_SECRET_KEY="blah"'):

                    print yellow('creating internal users: admin and anon ...')
                    run('./manage.py create_tokens --create --password password')

    # now grab the token for the web config
    print yellow('Put tokens into WEB app config...')
    setup_supervisor()
    run('supervisorctl reread')
    run('supervisorctl update')
    # update shell env setup file with new tokens
    files.upload_template(_conf_path(
        'shell_prep.sh'), '~/shell_prep.sh', env)

    # create sysadmin user
    with prefix('source /opt/virtualenvs/ocl_web/bin/activate'):
        print yellow('creating sysadmin user...')
        run('source ~/shell_prep.sh;/opt/deploy/ocl_web/ocl_web/manage.py create_sysadmin') 
Example #27
Source File: fs.py    From boss with MIT License 5 votes vote down vote up
def save_remote_file(path, data):
    ''' Save data to the remote file. '''
    fd = StringIO(data)
    put(fd, path)

    return fd.getvalue() 
Example #28
Source File: fs.py    From boss with MIT License 5 votes vote down vote up
def upload(local_path, remote_path):
    ''' Upload one or more files to a remote host. '''
    return put(local_path, remote_path) 
Example #29
Source File: fab_deploy.py    From cstar_perf with Apache License 2.0 5 votes vote down vote up
def copy_cluster_config(config):
    config = json.dumps(config, sort_keys=True, indent=4, separators=(',', ': '))
    config_file = StringIO(config)
    fab.run('mkdir -p ~/.cstar_perf')
    fab.put(config_file, '~/.cstar_perf/cluster_config.json') 
Example #30
Source File: fab_common.py    From cstar_perf with Apache License 2.0 5 votes vote down vote up
def copy_logs(local_directory):
    # put the whole code in a with block and do not fail immediately in case a logging dir cannot be found
    # E.g. if the C* JVM cannot start because of invalid settings, the C* system.log dir won't be available
    # and this piece of code will fail. However, in this case we want to be able to at least copy
    # the startup log (nohup.out) to see what went wrong
    with fab.settings(warn_only=True):
        cfg = config['hosts'][fab.env.host]
        host_log_dir = os.path.join(local_directory, cfg['hostname'])
        if not os.path.exists(host_log_dir):
            os.makedirs(host_log_dir)
        # copy the node's startup log
        fab.get(CASSANDRA_STARTUP_LOG, host_log_dir)
        # copy the node's system.log
        fab.get(os.path.join(config['log_dir'], '*'), host_log_dir)