Пример #1
0
def test_find_template():
    from burlap import common
    common.set_verbose(True)
    fn = 'burlap/gitignore.template'
    ret = common.find_template(fn)
    print('ret:', ret)
    assert ret and ret.endswith(fn) 
Пример #2
0
def install_apt(fn=None, update=0):
    """
    Installs system packages listed in apt-requirements.txt.
    """
    print 'Installing apt requirements...'
    assert env[ROLE]
    env.apt_fqfn = fn or find_template(env.apt_fn)
    if not env.apt_fqfn:
        return
    assert os.path.isfile(env.apt_fqfn)
    fd, tmp_fn = tempfile.mkstemp()
    lines = [
        _ for _ in open(env.apt_fqfn).readlines()
        if _.strip() and not _.strip().startswith('#')
    ]
    fout = open(tmp_fn, 'w')
    fout.write('\n'.join(lines))
    fout.close()
    env.apt_fqfn = tmp_fn
    if not env.is_local:
        put(local_path=tmp_fn)
        env.apt_fqfn = env.put_remote_path
    if int(update):
        sudo('apt-get update -y')
    sudo('apt-get install -y `cat "%(apt_fqfn)s" | tr "\\n" " "`' % env)
Пример #3
0
def test_find_template():
    from burlap import common
    common.set_verbose(True)
    fn = 'burlap/gitignore.template'
    ret = common.find_template(fn)
    print('ret:', ret)
    assert ret and ret.endswith(fn)
Пример #4
0
def install_apt(fn=None, update=0):
    """
    Installs system packages listed in apt-requirements.txt.
    """
    print 'Installing apt requirements...'
    assert env[ROLE]
    env.apt_fqfn = fn or find_template(env.apt_fn)
    if not env.apt_fqfn:
        return
    assert os.path.isfile(env.apt_fqfn)
    fd, tmp_fn = tempfile.mkstemp()
    lines = [
        _ for _ in open(env.apt_fqfn).readlines()
        if _.strip() and not _.strip().startswith('#')
    ]
    fout = open(tmp_fn, 'w')
    fout.write('\n'.join(lines))
    fout.close()
    env.apt_fqfn = tmp_fn
    if not env.is_local:
        put(local_path=tmp_fn)
        env.apt_fqfn = env.put_remote_path
    if int(update):
        sudo('apt-get update -y')
    sudo('apt-get install -y `cat "%(apt_fqfn)s" | tr "\\n" " "`' % env)
Пример #5
0
def get_desired_package_versions(preserve_order=False):
    versions_lst = []
    versions = {}
    for line in open(find_template(
            env.pip_requirements_fn)).read().split('\n'):
        line = line or ''
        if '#' in line:
            line = line.split('#')[0].strip()
        if not line.strip() or line.startswith('#'):
            continue
        #print line
        matches = re.findall('([a-zA-Z0-9\-_]+)[\=\<\>]{2}(.*)', line)
        if matches:
            if matches[0][0] not in versions_lst:
                versions_lst.append((matches[0][0], (matches[0][1], line)))
            versions[matches[0][0]] = (matches[0][1], line)
        else:
            matches = re.findall('([a-zA-Z0-9\-]+)\-([0-9\.]+)(?:$|\.)', line)
            if matches:
                if matches[0][0] not in versions_lst:
                    versions_lst.append((matches[0][0], (matches[0][1], line)))
                versions[matches[0][0]] = (matches[0][1], line)
            else:
                if line not in versions_lst:
                    versions_lst.append((line, ('current', line)))
                versions[line] = ('current', line)
    if preserve_order:
        return versions_lst
    return versions
Пример #6
0
def iter_certificates():
    print 'apache_ssl_domain:',env.apache_ssl_domain
    for cert_type, cert_file_template in env.apache_ssl_certificates_templates:
        print 'cert_type, cert_file_template:',cert_type, cert_file_template
        _local_cert_file = os.path.join(env.apache_ssl_dir_local, cert_file_template % env)
        local_cert_file = find_template(_local_cert_file)
        assert local_cert_file, 'Unable to find local certificate file: %s' % (_local_cert_file,)
        remote_cert_file = os.path.join(env.apache_ssl_dir, cert_file_template % env)
        yield cert_type, local_cert_file, remote_cert_file
Пример #7
0
def iter_certificates():
    print 'apache_ssl_domain:', env.apache_ssl_domain
    for cert_type, cert_file_template in env.apache_ssl_certificates_templates:
        print 'cert_type, cert_file_template:', cert_type, cert_file_template
        _local_cert_file = os.path.join(env.apache_ssl_dir_local,
                                        cert_file_template % env)
        local_cert_file = find_template(_local_cert_file)
        assert local_cert_file, 'Unable to find local certificate file: %s' % (
            _local_cert_file, )
        remote_cert_file = os.path.join(env.apache_ssl_dir,
                                        cert_file_template % env)
        yield cert_type, local_cert_file, remote_cert_file
Пример #8
0
def create(name, config):
    require('vm_type', 'vm_group')
    config_fn = common.find_template(config)
    config = yaml.load(open(config_fn))
    env.update(config)
    env.vm_type = (env.vm_type or '').lower()
    assert env.vm_type, 'No VM type specified.'
    assert env.vm_group, 'No VM group specified.'
    if env.vm_type == EC2:
        _create_ec2_instance(name=name, group=env.vm_group)
    else:
        raise NotImplementedError
Пример #9
0
def get_or_create(name=None,
                  group=None,
                  config=None,
                  extra=0,
                  verbose=0,
                  backend_opts=None):
    """
    Creates a virtual machine instance.
    """
    require('vm_type', 'vm_group')

    backend_opts = backend_opts or {}

    verbose = int(verbose)
    extra = int(extra)

    if config:
        config_fn = common.find_template(config)
        config = yaml.load(open(config_fn))
        env.update(config)

    env.vm_type = (env.vm_type or '').lower()
    assert env.vm_type, 'No VM type specified.'

    group = group or env.vm_group
    assert group, 'No VM group specified.'

    ret = exists(name=name, group=group)
    if not extra and ret:
        if verbose:
            print('VM %s:%s exists.' % (name, group))
        return ret

    today = datetime.date.today()
    release = int('%i%02i%02i' % (today.year, today.month, today.day))

    if not name:
        existing_instances = list_instances(group=group,
                                            release=release,
                                            verbose=verbose)
        name = env.vm_name_template.format(index=len(existing_instances) + 1)

    if env.vm_type == EC2:
        return get_or_create_ec2_instance(name=name,
                                          group=group,
                                          release=release,
                                          verbose=verbose,
                                          backend_opts=backend_opts)
    else:
        raise NotImplementedError
Пример #10
0
def update_install(clean=0,
                   pip_requirements_fn=None,
                   virtualenv_dir=None,
                   user=None,
                   group=None,
                   perms=None):
    try:
        from burlap.dj import render_remote_paths
    except ImportError:
        render_remote_paths = None

    _env = type(env)(env)

    pip_requirements_fn = pip_requirements_fn or env.pip_requirements_fn

    bootstrap(force=clean)

    init(clean=clean, virtualenv_dir=virtualenv_dir, check_permissions=False)

    req_fn = find_template(pip_requirements_fn)
    assert req_fn, 'Could not find file: %s' % pip_requirements_fn
    _env.pip_remote_requirements_fn = '/tmp/pip-requirements.txt'
    put_or_dryrun(
        local_path=req_fn,
        remote_path=_env.pip_remote_requirements_fn,
    )

    if render_remote_paths:
        render_remote_paths()

    if virtualenv_dir:
        _env.virtualenv_dir = virtualenv_dir
    elif _env.pip_virtual_env_dir_template:
        _env.virtualenv_dir = _env.pip_virtual_env_dir_template % _env

    _env.pip_update_install_command = "%(virtualenv_dir)s/bin/pip install -r %(pip_remote_requirements_fn)s"
    if _env.is_local:
        run_or_dryrun(_env.pip_update_install_command % _env)
    else:
        sudo_or_dryrun(_env.pip_update_install_command % _env)

    if not _env.is_local and (_env.pip_check_permissions or user or group
                              or perms):
        set_virtualenv_permissions(
            user=user,
            group=group,
            perms=perms,
            virtualenv_dir=virtualenv_dir,
        )
Пример #11
0
def install_yum(fn=None, update=0):
    """
    Installs system packages listed in yum-requirements.txt.
    """
    print 'Installing yum requirements...'
    assert env[ROLE]
    env.yum_fn = fn or find_template(env.yum_fn)
    assert os.path.isfile(env.yum_fn)
    update = int(update)
    if env.is_local:
        put(local_path=env.yum_fn)
        env.yum_fn = env.put_remote_fn
    if update:
        sudo('yum update --assumeyes')
    sudo('yum install --assumeyes $(cat %(yum_fn)s)' % env)
Пример #12
0
def install_yum(fn=None, update=0):
    """
    Installs system packages listed in yum-requirements.txt.
    """
    print 'Installing yum requirements...'
    assert env[ROLE]
    env.yum_fn = fn or find_template(env.yum_fn)
    assert os.path.isfile(env.yum_fn)
    update = int(update)
    if env.is_local:
        put(local_path=env.yum_fn)
        env.yum_fn = env.put_remote_fn
    if update:
        sudo('yum update --assumeyes')
    sudo('yum install --assumeyes $(cat %(yum_fn)s)' % env)
Пример #13
0
def get_desired_package_versions():
    versions = {}
    for line in open(find_template(env.pip_requirements_fn)).read().split('\n'):
        if not line.strip() or line.startswith('#'):
            continue
        #print line
        matches = re.findall('([a-zA-Z0-9\-_]+)[\=\<\>]{2}(.*)', line)
        if matches:
            #print line,matches[0]
            versions[matches[0][0]] = (matches[0][1], line)
        else:
            matches = re.findall('([a-zA-Z\-]+)\-([0-9\.]+)(?:$|\.)', line)
            if matches:
                versions[matches[0][0]] = (matches[0][1], line)
            else:
                versions[line] = ('current', line)
    return versions
Пример #14
0
def get_or_create(name=None, group=None, config=None, extra=0, verbose=0, backend_opts={}):
    """
    Creates a virtual machine instance.
    """
    require('vm_type', 'vm_group')
    
    verbose = int(verbose)
    extra = int(extra)
    
    if config:
        config_fn = common.find_template(config)
        config = yaml.load(open(config_fn))
        env.update(config)
        
    env.vm_type = (env.vm_type or '').lower()
    assert env.vm_type, 'No VM type specified.'
    
    group = group or env.vm_group
    assert group, 'No VM group specified.'
    
    ret = exists(name=name, group=group)
    if not extra and ret:
        if verbose:
            print('VM %s:%s exists.' % (name, group))
        return ret
    
    today = datetime.date.today()
    release = int('%i%02i%02i' % (today.year, today.month, today.day))
    
    if not name:
        existing_instances = list_instances(
            group=group,
            release=release,
            verbose=verbose)
        name = env.vm_name_template.format(index=len(existing_instances)+1)
    
    if env.vm_type == EC2:
        return get_or_create_ec2_instance(
            name=name,
            group=group,
            release=release,
            verbose=verbose,
            backend_opts=backend_opts)
    else:
        raise NotImplementedError
Пример #15
0
def iter_pip_requirements():
    for line in open(find_template(env.pip_requirements_fn)):
        line = line.strip()
        if not line or line.startswith('#'):
            continue
        yield line.split('#')[0]
Пример #16
0
def iter_pip_requirements():
    for line in open(find_template(env.pip_requirements_fn)):
        line = line.strip()
        if not line or line.startswith('#'):
            continue
        yield line
Пример #17
0
 def test_find_template(self):
     fn = 'burlap/gitignore.template'
     ret = find_template(fn)
     print('ret:', ret)
     assert ret and ret.endswith(fn)