コード例 #1
0
ファイル: build.py プロジェクト: barraq/docker-deployer
def process_shared(version='master'):
    """Process shared files for given `version` and copy them to cache"""
    local('rm -rf %s' % get_project_shared_cache_for_version(env, version))
    for root, dirs, files in os.walk(env['project']['project_shared_path']):
        rel_root = os.path.relpath(root, env['project']['project_shared_path'])
        if rel_root == os.curdir:
            rel_root = ''

        # setup context for template
        context = env.copy()
        context.update({
            'branch': version
        })

        for dir in dirs:
            local('mkdir -p %s/%s' % (
                get_project_shared_cache_for_version(env, version),
                os.path.join(rel_root, dir)))

        for file in files:
            src = '%s/%s' % (root, file)
            dest = '%s/%s' % (get_project_shared_cache_for_version(env, version), os.path.join(rel_root, file))
            if file.endswith('.tpl'):
                copy_template(src, dest[:-4], context=context)
                os.chmod(dest[:-4], os.stat(src).st_mode)
            else:
                local('cp %s %s' % (src, dest))
コード例 #2
0
ファイル: libvirt.py プロジェクト: jeffmccune/seedBank
def create_pool(name):
    """ Creates a new directory or LVM based storage pool

        Requires:
        * name -> string, name of the new pool

        Returns:
        * None
    """
    if env['storage_pool'] == 'default':
        return
    else:
        values = env.copy()
        with settings(hide('stdout')):
            values['storage_owner_uid'] = run('id -u %s' % env['storage_owner'])
            values['storage_owner_gid'] = run('id -g %s' % env['storage_owner'])
        values['name'] = name
    if env['storage_type'] == 'qcow2':
        _apply_template(values, \
                        'ingredients/libvirt/pool-qcow2.xml', \
                        '/tmp/%s.xml' % name)
        local('virsh --connect %s pool-define /tmp/%s.xml' % (env['connect'], \
                                                              name))
        local('virsh --connect %s pool-build %s' % (env['connect'], name))
    elif values['storage_type'] == 'lvm':
        run('sudo /sbin/vgcreate %s /dev/%s/%s' % (name, env['volumegroup'], \
                                                   name))
        local('virsh --connect %s pool-define-as %s logical --target \
              /dev/%s/%s' % (env['connect'], name, env['volumegroup'], name))
    local('rm -f /tmp/%s.xml' % name)
    local('virsh --connect %s pool-autostart %s' % (env['connect'], name))
    local('virsh --connect %s pool-start %s' % (env['connect'], name))
コード例 #3
0
ファイル: __init__.py プロジェクト: epcim/fabfile
def setenv(name):
    """ Load environment configuration
    """

    cli = env.copy()
    env.update(fabcfg.environments[name])

    #print cli

    # IF ... SPECIFIED ON CLI THEN OVERRIDE
    # gateway
    if cli.has_key('gateway') and cli['gateway'] != None:
        env.gateway = cli['gateway']
    # hosts
    if len(cli['hosts']) > 0:
        env.hosts = cli['hosts']
        #TODO, allow glob* pattern on host name
    else:
      for l in env.roledefs.values():
        env.hosts.extend(l)

    if env.ssh_config_path and os.path.isfile(os.path.expanduser(env.ssh_config_path)):
        env.use_ssh_config = True
        _annotate_hosts_with_ssh_config_info(os.path.expanduser(env.ssh_config_path))

    _populateRoledevsFromHosts()
コード例 #4
0
def upload_template(filename, destination, context=None,
                    use_sudo=False, backup=True, mode=None):
    print filename
    print destination
    func = use_sudo and sudo or run
    # Normalize destination to be an actual filename, due to using StringIO
    with settings(hide('everything'), warn_only=True):
        if func('test -d %s' % destination).succeeded:
            sep = "" if destination.endswith('/') else "/"
            destination += sep + os.path.basename(filename)
    # Process template
    context = context or {}
    env_context = env.copy()
    env_context.update(context)
    filepath = os.path.join(CONF_ROOT, 'templates', filename)
    # TODO use jinja?
    text = pystache.render(open(filepath).read(), env_context)
    # Back up original file
    if backup and files.exists(destination):
        func("cp %s{,.bak}" % destination)
    # Upload the file.
    put(
        local_path=StringIO(text),
        remote_path=destination,
        use_sudo=use_sudo,
        mode=mode
    )
コード例 #5
0
ファイル: project.py プロジェクト: RedTurtle/rt.commands
def supervisor(action='status'):
    """Run remotely ``bin/supervisorctl ${action}"""
    opts = env.copy()
    opts['action'] = action

    with cd('%(code_dir)s' % opts):
        run('./bin/supervisorctl %(action)s' % opts)
コード例 #6
0
ファイル: base.py プロジェクト: dpoirier/argyle
def upload_template(filename, destination, context=None,
    use_sudo=False, backup=True, mode=None):
    func = use_sudo and sudo or run
    # Process template
    loaders = []
    template_dirs = getattr(env, 'ARGYLE_TEMPLATE_DIRS', ())
    if template_dirs:
        loaders.append(FileSystemLoader(template_dirs))
    loaders.append(PackageLoader('argyle'))
    jenv = Environment(loader=ChoiceLoader(loaders))
    context = context or {}
    env_context = env.copy()
    env_context.update(context)
    template = jenv.get_or_select_template(filename)
    text = template.render(env_context)
    # Normalize destination to be an actual filename, due to using StringIO
    with settings(hide('everything'), warn_only=True):
        if func('test -d %s' % destination).succeeded:
            sep = "" if destination.endswith('/') else "/"
            if hasattr(filename, '__iter__'):
                # Use selected filename for destination
                final = template.filename
            else:
                final = filename
            destination += sep + os.path.basename(final)
    # Back up original file
    if backup and files.exists(destination):
        func("cp %s{,.bak}" % destination)
    # Upload the file.
    put(
        local_path=StringIO(text),
        remote_path=destination,
        use_sudo=use_sudo,
        mode=mode
    )
コード例 #7
0
ファイル: fabtools.py プロジェクト: strogo/djpcms
def info():
    '''Information regarding installation parameters'''
    from static import server_types
    utils.get_directories(release = False)
    data = env.copy()
    server = server_types[env.server_type]
    server.info(data)
    for k in sorted(data):
        print('%20s: %s' % (k,data[k]))
コード例 #8
0
def run_buildout(buildout_cfg='buildout.cfg', component='plone'):
    """Run remotely ``bin/buildout -c ${buildout_cfg}`` in component folder.
    """
    opts = env.copy()
    opts['buildout_cfg'] = buildout_cfg
    opts['component'] = 'components/%s/' % component

    with cd('%(code_dir)s/%(component)s' % opts):
        run('svn up')
        run('./bin/buildout -NUc %(buildout_cfg)s' % opts)
コード例 #9
0
def tail_log(component='', glob='*.log'):
    """Tail the log in the component folder
    """
    opts = env.copy()
    opts['glob'] = glob
    if component:
        opts['component'] = 'components/%s' % component
    else:
        opts['component'] = component

    cmd = ("tail -f %(code_dir)s/%(component)s/var/log/%(glob)s" % opts)
    run(cmd)
コード例 #10
0
ファイル: fabfile.py プロジェクト: grangerp/test_presentation
def load_db():
    """
    import dumpfile into database target
    """
    _dynamic_env()
    tmp_file = os.path.join(env.tmp_folder, env.project_fullname)
    data = env.copy()
    data.update({
        'tmp_file': tmp_file,
    })
    put(env.dump_file_name, tmp_file)
    env.run("PGPASSWORD=%(db_password)s psql %(project_fullname)s -U %(project_fullname)s < %(tmp_file)s" % data)  # NOQA
    env.run("rm -f %(tmp_file)s" % data)
コード例 #11
0
ファイル: test_base.py プロジェクト: waytai/argyle
 def test_additional_template_context(self):
     "Additional template context should be passed to the template render."
     with patch('argyle.base.Environment') as mock_environment:
         mock_env = Mock()
         mock_template = Mock()
         mock_env.get_or_select_template.return_value = mock_template
         mock_environment.return_value = mock_env
         extra = {'foo': 'bar'}
         upload_template('foo.txt', '/tmp/', context=extra)
         self.assertTrue(mock_template.render.called)
         args, kwargs = mock_template.render.call_args
         context = args[0]
         expected = env.copy()
         expected.update(extra)
         self.assertEqual(context, expected)
コード例 #12
0
ファイル: libvirt.py プロジェクト: jeffmccune/seedBank
def create_volume(name, ext='img'):
    """ Create a new volume within the default configured storage pool

        Required:
        * name -> string, name of the volume

        Optional:
        * ext -> string, 'img' or 'iso'. Defaults to 'img'

        Returns:
        * None
    """
    values = env.copy()
    values['name'] = name
    values['disk_size'] = int(env['disk_size']) * 1024 * 1024 * 1024
    with settings(hide('stdout')):
        values['storage_owner_uid'] = run('id -u %s' % env['storage_owner'])
        values['storage_owner_gid'] = run('id -g %s' % env['storage_owner'])
    if values['storage_pool'] == 'default':
        values['storage_path'] = '%s/%s.%s' % (env['storage_dir'], name, ext)
    else:
        values['storage_path'] = '%s/%s/%s.%s' % (env['storage_dir'], \
                                                  env['storage_pool'], \
                                                  name, ext)
    if env['storage_type'] == 'qcow2':
        if ext == 'img':
            _apply_template(values, \
                            'ingredients/libvirt/vol-qcow2.xml', \
                            '/tmp/%s.xml' % name)
        else:
            _apply_template(values, \
                            'ingredients/libvirt/vol-iso.xml', \
                            '/tmp/%s.xml' % name)
        local('virsh --connect %s vol-create %s /tmp/%s.xml' % \
                (env['connect'], env['storage_pool'], name))
    elif values['storage_type'] == 'lvm':
        # BROKEN, see https://bugzilla.redhat.com/show_bug.cgi?id=714986
        #local('virsh --connect %(connect)s vol-create-as %(storage_pool)s \
        #       %(name)s %(disk_size)sG ' % values)
        if env['host'] == 'localhost':
            local('sudo /sbin/lvcreate --name %s -L %sG %s' % \
                    (name, env['disk_size'], env['volumegroup']))
        else:
            run('sudo /sbin/lvcreate --name %s -L %sG %s' % \
                    (name, env['disk_size'], env['volumegroup']))
    local('rm -f /tmp/%s.xml' % name)
コード例 #13
0
def sync_var(component='plone'):
    """Sync component's buildout var folder

    :params component: a string specify the component or ".." to sync the var
                       at the root of the buildout
    """
    user, host, port = normalize(env.host_string)
    opts = env.copy()
    with quiet():
        opts['local_buildout'] = local('pwd', capture=True) + '/var/'

    opts['component'] = os.path.normpath('components/%s/var/' % component)
    opts['short_options'] = '-Pthrvz'
    opts['exclude'] = ' '.join(["--exclude='%s'" % x
                                for x in ('log', '*.old', '.svn')])
    cmd = ("rsync %(exclude)s %(short_options)s "
           "%(user)s@%(host)s:%(code_dir)s/%(component)s %(local_buildout)s"
           ) % opts
    local(cmd)
コード例 #14
0
ファイル: libvirt.py プロジェクト: jeffmccune/seedBank
def remove_volume(name, ext='img'):
    """ Remove a volume from the default configured storage pool

        Requires:
        * name -> string, name of the volume

        Optional:
        * ext -> string, 'img' or 'iso'. Defaults to 'img'

        Returns:
        * None
    """
    if not name:
        return
    values = env.copy()
    values['name'] = name
    values['ext'] = ext
    local('virsh --connect %s vol-delete %s.%s --pool %s' % \
            (env['connect'], name, ext, env['storage_pool']))
コード例 #15
0
ファイル: base.py プロジェクト: waytai/argyle
def upload_template(filename,
                    destination,
                    context=None,
                    use_sudo=False,
                    backup=True,
                    mode=None):
    func = use_sudo and sudo or run
    # Process template
    loaders = []
    template_dirs = getattr(env, 'ARGYLE_TEMPLATE_DIRS', ())
    if template_dirs:
        loaders.append(FileSystemLoader(template_dirs))
    loaders.append(PackageLoader('argyle'))
    jenv = Environment(loader=ChoiceLoader(loaders))
    context = context or {}
    env_context = env.copy()
    env_context.update(context)
    template = jenv.get_or_select_template(filename)
    text = template.render(env_context)
    # Normalize destination to be an actual filename, due to using StringIO
    with settings(hide('everything'), warn_only=True):
        if func('test -d %s' % destination).succeeded:
            sep = "" if destination.endswith('/') else "/"
            if hasattr(filename, '__iter__'):
                # Use selected filename for destination
                final = template.filename
            else:
                final = filename
            destination += sep + os.path.basename(final)
    # Back up original file
    if backup and files.exists(destination):
        func("cp %s{,.bak}" % destination)
    # Upload the file.
    put(local_path=StringIO(text),
        remote_path=destination,
        use_sudo=use_sudo,
        mode=mode)