Example #1
0
def target(*targets):
    """
    Set the deployment target system(s)

    :param *targets: Comma-separated names of YAML config files located in config/targets
    """
    env.targets = _AttributeDict(targets)
Example #2
0
def project(*projects):
    """
    Specify the project(s) to deploy to the target system.

    :param *projects: Comma-separated names of YAML config files located in config/projects
    """
    env.projects = _AttributeDict(projects)
Example #3
0
 def propagate_settings(self):
     for _ in range(len(self.settings)):
         for key, value in self.settings.items():
             if isinstance(value, basestring):
                 new_value = value.format(**self.settings)
                 self.settings[key] = new_value
     self.settings = _AttributeDict(self.settings)
Example #4
0
def load_settings(path):
    if os.path.exists(path):
        parser.read(path)
        return (
            (name, _AttributeDict(section.iteritems()))
            for name, section in parser.iteritems())
    return {}
Example #5
0
def env_mock(fabric_integration, monkeypatch, ployconf):
    from fabric.utils import _AttributeDict
    env = _AttributeDict()
    env.instance = Mock()
    env.instance.config = {}
    env.instance.master.main_config.path = ployconf.directory
    monkeypatch.setattr('bsdploy.bootstrap_utils.env', env)
    return env
Example #6
0
def _parse_config_file(config_path):
    config = None
    env.update({'config': _AttributeDict()})

    if os.path.exists(config_path):
        with open(config_path) as f:
            config = ConfigParser.ConfigParser()
            config.readfp(f)
    else:
        print('ERROR: {} doesn\'t exist on the file system!')
        sys.exit(1)

    return config
Example #7
0
def config_input(defaults=None):
    """Read AWS config options from user input on the command line"""

    if defaults is None:
        defaults = dict()

    access_key_id = raw_input('AWS Access Key Id [{}]: '.format(defaults.setdefault('access_key_id', '')))
    secret_access_key = raw_input('AWS Secret Access Key [{}]: '.format(defaults.setdefault('secret_access_key', '')))
    region = raw_input('AWS Region [{}]: '.format(defaults.setdefault('region', 'eu-west-1')))

    config = _AttributeDict(defaults)
    if len(access_key_id) > 0:
        config.access_key_id = access_key_id

    if len(secret_access_key) > 0:
        config.secret_access_key = secret_access_key

    if len(region) > 0:
        config.region = region

    return config
Example #8
0
    # load the roles and machines
    roledefs = {}
    machinedefs = {}
    for section in [
            x for x in cfg.sections() if x.lower().startswith('role|')
    ]:
        role_name = str(section.lower().replace('role|', '').strip())
        if not role_name in env.roledefs:
            roledefs[role_name] = []

        for host in cfg.options(section):
            machine_section = 'host|' + host
            if cfg.has_section(machine_section):
                machinedefs[str(host)] = {}
                roledefs[str(role_name)].append(str(host.lower()))
                for option in cfg.options(machine_section):
                    machinedefs[host][str(option.upper())] = str(
                        cfg.get(machine_section, option))

    env.roledefs = roledefs
    env.machines = machinedefs

    # ... and the environment sections
    for section in [x for x in cfg.sections() if x.lower().startswith('env|')]:
        env_name = str(section.replace('env|', '').strip())
        if not env_name in env:
            d = {}
            for option in cfg.options(section):
                d[str(option)] = str(cfg.get(section, option))
            env[env_name] = _AttributeDict(d)
from fabric.utils import _AttributeDict

from fabric.api import run

execute = _AttributeDict({
	'func' : run
})

ssh = _AttributeDict({
	'server_name' : {
		'hosts'    : '',
		'user'     : '',
		'password' : '',
	}
})

from fabric import colors

result = _AttributeDict({
	'done'    : colors.green,
	'error'   : colors.red,
	'already' : colors.cyan
})

git = _AttributeDict({
	'branch'  : 'development',
	'message' : 'no message.',
	'by'      : 'John Doe'
})
Example #10
0
options = _AttributeDict({
    # Should yes be assumed for interactive prompts?
    'assume_yes': False,

    # How to compute a file's mime_type?
    'get_mime_type': _get_mime_type,

    # How to determine if a template should be rendered?
    'should_render': _should_render,

    # How to determine if a template is an empty file?
    'is_empty': _is_empty,

    # How do filter available templates within the jinja environment?
    'filter_func': _filter_func,

    # How to determine diffs?
    'diff': _diff,

    # How to get dictionary configuration from module data?
    'module_as_dict': _as_dict,

    # Base directory for template and data directories.
    'get_base_dir': _get_base_dir,

    # What is the name of the template directory?
    'get_templates_dir': lambda: 'templates',

    # What is the name of the data directory?
    'get_data_dir': lambda: 'data',

    # What is the name of the generated directory?
    'get_generated_dir': lambda: 'generated',

    # What is the name of the remotes directory?
    'get_remotes_dir': lambda: 'remotes',
})
Example #11
0
 def _wrap_dict(d):
     d = _AttributeDict(d)
     for k in d:
         if isinstance(d[k], dict):
             d[k] = _wrap_dict(d[k])
     return d
Example #12
0
env = _AttributeDict({
    'again_prompt': 'Sorry, try again.',
    'all_hosts': [],
    'combine_stderr': True,
    'command': None,
    'command_prefixes': [],
    'cwd': '',  # Must be empty string, not None, for concatenation purposes
    'echo_stdin': True,
    'exclude_hosts': [],
    'host': None,
    'host_string': None,
    'lcwd': '',  # Must be empty string, not None, for concatenation purposes
    'local_user': _get_system_username(),
    'output_prefix': True,
    'passwords': {},
    'path': '',
    'path_behavior': 'append',
    'port': None,
    'real_fabfile': None,
    'roles': [],
    'roledefs': {},
    'skip_bad_hosts': False,
    # -S so sudo accepts passwd via stdin, -p with our known-value prompt for
    # later detection (thus %s -- gets filled with env.sudo_prompt at runtime)
    'sudo_prefix': "sudo -S -p '%s' ",
    'sudo_prompt': 'sudo password:'******'use_exceptions_for': {'network': False},
    'use_shell': True,
    'user': None,
    'version': get_version('short')
})
Example #13
0
        sys.exit(1)

    # load the roles and machines
    roledefs = {}
    machinedefs = {}
    for section in [x for x in cfg.sections() if x.lower().startswith('role|')]:
        role_name = str(section.lower().replace('role|', '').strip())
        if not role_name in env.roledefs:
            roledefs[role_name] = []

        for host in cfg.options(section):
            machine_section = 'host|' + host
            if cfg.has_section(machine_section):
                machinedefs[str(host)] = {}
                roledefs[str(role_name)].append(str(host.lower()))
                for option in cfg.options(machine_section):
                    machinedefs[host][str(option.upper())] = str(cfg.get(machine_section, option))

    env.roledefs = roledefs
    env.machines = machinedefs

    # ... and the environment sections
    for section in [x for x in cfg.sections() if x.lower().startswith('env|')]:
        env_name = str(section.replace('env|', '').strip())
        if not env_name in env:
            d = {}
            for option in cfg.options(section):
                d[str(option)] = str(cfg.get(section, option))
            env[env_name] = _AttributeDict(d)

Example #14
0
options = _AttributeDict({
    # Should yes be assumed for interactive prompts?
    'assume_yes': False,

    # How to compute a file's mime_type?
    'get_mime_type': _get_mime_type,

    # How to determine if a template should be rendered?
    'should_render': _should_render,

    # How to determine if a template is an empty file?
    'is_empty': _is_empty,

    # How do filter available templates within the jinja environment?
    'filter_func': _filter_func,

    # How to determine diffs?
    'diff': _diff,

    # How to get dictionary configuration from module data?
    'module_as_dict': _as_dict,

    # What is the name of the template directory?
    'get_templates_dir': lambda: 'templates',

    # What is the name of the data directory?
    'get_data_dir': lambda: 'data',

    # What is the name of the generated directory?
    'get_generated_dir': lambda: 'generated',

    # What is the name of the remotes directory?
    'get_remotes_dir': lambda: 'remotes',
})
Example #15
0
# =========== 

# = GLOBALS =
# ===========
env.project_name = os.path.basename(os.path.dirname(__file__))
env.project_path = '~/Git/{}'.format(env.project_name)
# 其他:
env.repositories = {
    'django': '[email protected]:liaoyunxia/keithxiaoy.git'.format(env),  # SSH部署必须用git不能用http
}
env.server = {
}

cloud = _AttributeDict({
    'name': '',
    'domain_name': '',
    'region': '',
    'bucket_static': ''
})
cloud.name = 'ucloud'  # 可选: aws, aliyun
cloud.region = 'oss-cn-hangzhou'
if cloud.name == 'ucloud':
    env.user = '******'
    cloud.domain_name = 'ucloud.cn'
elif cloud.name == 'aliyun':
    env.user = '******'
    cloud.domain_name = 'aliyuncs.com'
else:
    puts('没有云')
env.forward_agent = True  # GitHub的代理转发部署方式需要开启这项, GitLab不要开启, 有SSH Key的时候会无效
env.colorize_errors = True
Example #16
0
from fabric.api import run, sudo
from fabric.utils import _AttributeDict
from fabric.contrib.files import upload_template
from fiber.api import grant_admin_permissions

conf = {
    "version": "1.4.1",
    "path": "/home/ombu/redmine",
    "repo": "git://github.com/redmine/redmine.git",
    "site_name": "t.ombuweb.com",
}
conf = _AttributeDict(conf)


def install(server):
    """ Install redmine on a server
    Keyword arguments:
    server -- a boto.ec2.instance
    conf   -- redmine configuration
    """

    # Dependencies
    sudo("apt-get update")
    sudo("apt-get -y install libapache2-mod-passenger ruby1.8-dev libmagickwand-dev libopenssl-ruby")
    sudo("a2enmod passenger")
    _upgrade_rubygems()
    sudo("gem install --no-ri --no-rdoc bundler")

    # Setup environment
    upload_template(
        "fiber/profiles/redmine/templates/passenger.conf", "/etc/apache2/mods-available/passenger.conf", use_sudo=True
Example #17
0
from fabric.api import env
from fabric.utils import _AttributeDict

env.settings = _AttributeDict()
Example #18
0
 def construct_mapping(self, node, deep=False):
     """
     Constructs a mapping from a node, returning a Fabric _AttributeDict
     """
     return _AttributeDict(
         super(DeployerLoader, self).construct_mapping(node, deep))
Example #19
0
from fabric.utils import _AttributeDict

from fabric.api import run

execute = _AttributeDict({'func': run})

ssh = _AttributeDict(
    {'server_name': {
        'hosts': '',
        'user': '',
        'password': '',
    }})

from fabric import colors

result = _AttributeDict({
    'done': colors.green,
    'error': colors.red,
    'already': colors.cyan
})

git = _AttributeDict({
    'branch': 'development',
    'message': 'no message.',
    'by': 'John Doe'
})
Example #20
0
# -*- coding: utf-8 -*-

import os
from fabric.api import *
from fabric.utils import _AttributeDict

import time

ez_env = _AttributeDict({
    'group': None,
    'roles': None,
    'cloud': None,
    'cloud_processor': None,
    'cloud_handler': None,
    'cloud_active': None,
    'debug': None,
})


def _pssh(file):
    """
    Parse pssh-like file
    :param file:
    """
    file = os.path.realpath(os.path.expanduser(file))

    with open(file, 'r') as fp:
        buffer = fp.read()

    host_list = buffer.strip("\n").split("\n")
    machines = []
Example #21
0
        jenv = Environment(loader=FileSystemLoader(template_dir or '.'))
        return jenv.get_template(filename).render(**context or {})
    except ImportError:
        import traceback
        tb = traceback.format_exc()
        abort(tb + "\nUnable to import Jinja2 -- see above.")


def get_template_dir():
    return os.path.join(satellite.__path__[0], 'templates')


parser = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())

def load_settings(path):
    if os.path.exists(path):
        parser.read(path)
        return (
            (name, _AttributeDict(section.iteritems()))
            for name, section in parser.iteritems())
    return {}

settings = _AttributeDict({
    'fabric': _AttributeDict(dict(
        store_true=False,
        list_commands=False,
        env_settings="",
        shortlist=False,
        show_version=False,
    )),
})
Example #22
0
import os

env.project = _AttributeDict({
    'name':
    'name',
    'username':
    '******',  # group assumed to be the same
    'reqs':
    'requirements.txt',
    'src_dir':
    'source_tmp',  # rel from home
    'src_web':
    'host',  # rel from home
    'src_branch':
    'master',
    'pip_cache':
    '.pip-cache',  # rel path from home
    'venv':
    '.venv',
    'persistent_dirs': [
        {
            'media': [
                'cache',
                'ckeditor',
            ]
        },
    ],
    'links': [('media', 'media')]
})

env.project.home = os.path.join('/home', env.project.username)
Example #23
0
        except KeyError:
            print 'WARNING: no certificates directory specified in config file...'

        try:
            env.user = str(cfg.get('auth', 'user'))
        except KeyError:
            print 'WARNING: no default username specified in config file...'

        try:
            env.password = str(cfg.get('auth', 'password'))
        except KeyError:
            print 'WARNING: no default password specified in config file...'

    # the environment sections
    for section in [x for x in cfg.sections() if x.lower().startswith('env|')]:
        env_name = str(section.replace('env|', '').strip())

        if env_name == 'global':
            env.update(_AttributeDict(from_section(cfg, section)))
        else:
            if not env_name in env:
                d = from_section(cfg, section)
                env[env_name] = _AttributeDict(d)

    ## and some defaults...

    ## do not use the local SSH config files...
    env.no_agent = True
    env.no_keys = True
    env.disable_known_hosts = True
Example #24
0
env.newrelic_key = '7cba721d377c66139fb07c29ecf1bae50e3dbf43'


# ===========
# = GLOBALS =
# ===========
env.project_name = os.path.basename(os.path.dirname(__file__))
env.project_path = '~/Git/{}'.format(env.project_name)
# 其他:
env.repositories = {
    'django': 'git@{0.git_host}:{0.organization}/{0.project_name}.git'.format(env),  # SSH部署必须用git不能用http
    'java': 'git@{0.git_host}:{0.organization}/{0.project_name}_java.git'.format(env)
}
cloud = _AttributeDict({
    'name': '',
    'domain': '',
    'region': '',
    'bucket_static': ''
})
cloud.name = 'aliyun'  # 可选: aws, aliyun
cloud.region = 'oss-cn-hangzhou'
if cloud.name == 'aws':
    env.user = '******'
    cloud.domain = 'amazonaws.com'
elif cloud.name == 'aliyun':
    env.user = '******'
    cloud.domain = 'aliyuncs.com'
else:
    puts('没有云')
# env.forward_agent = True  # GitHub的代理转发部署方式需要开启这项, GitLab不要开启, 有SSH Key的时候会无效
env.colorize_errors = True
Example #25
0
options = _AttributeDict({
    # Should yes be assumed for interactive prompts?
    'assume_yes': False,

    # Should sudo be used with put and in lieu of run?
    'use_sudo': False,

    # How do compute a file's mime_type?
    'get_mime_type': _get_mime_type,

    # How to determine if a template should be rendered?
    'should_render': _should_render,

    # How to determine if a template is an empty file?
    'is_empty': _is_empty,

    # How to determine the current host name?
    'get_hostname': _get_hostname,

    # How to determine the current role name?
    'get_rolename': _get_rolename,

    # How to determine the current environment name?
    'get_environmentname': _get_environmentname,

    # How do filter available templates within the jinja environment?
    'filter_func': _is_not_temporary,

    # How to determine diffs?
    'diff': _diff
})
Example #26
0
File: env.py Project: nextoa/cabric
from fabric.api import *
from fabric.main import list_commands
from fabric.utils import _AttributeDict

ez_env = _AttributeDict({
    'debug': None,
    'group': None,
    'roles': None,
    'cloud': None,

    # cloud
    'cc': {
        'cloud_class': None,
        'processor': None,
        'connection': None,
        'sleep_time': None,
        'config': None,
        'actions': {},
    },
    'cloud_processor': None,
    'cloud_class': None,
    'cloud_handler': None,  # current cloud handle
    'cloud_hold_recyle': 3,  # sleep time when request jobs
    'debug': None,
})


def _pssh(file):
    """
    Parse pssh-like file
# The directory where the log files will be written
log_dir = '%s/logs' % app_dir
# The directory where the new release will be uploaded to
release_dir = '%s/releases' % app_dir
# The directory where releases will  be uploaded to
upload_dir = '%s/release' % release_dir
# The directory where the current release can be found
current_dir = '%s/current' % release_dir

# -----------------------------------------------------------------------------
# Section 4. Configure the various project components.

# Settings for configuring the Apache2 web server
configure_apache = _AttributeDict({
    # path to the template used for the apache2 configuration file
    'source': '%s/templates/apache2/httpd.conf' % fabric_dir,
    # path on the server where the filled out template will be uploaded to
    'dest': '%s/apache2/conf/httpd.conf' % app_dir,
})

# Settings for configuring the WSGI application
configure_wsgi = _AttributeDict({
    # path to the template used for the WSGI configuration file
    'source': '%s/templates/wsgi/script.py' % fabric_dir,
    # path on the server where the filled out template will be uploaded to
    'dest': '%s/wsgi/script.py' % app_dir,
})

# Settings for the Django app.
configure_django = _AttributeDict({
    'source': '%s/%s' % (source_dir, django_settings_file),
    'dest': '%s/%s' % (upload_dir, django_settings_file),
Example #28
0
File: env.py Project: nextoa/cabric
from fabric.api import *
from fabric.main import list_commands
from fabric.utils import _AttributeDict

ez_env = _AttributeDict({
    'debug': None,
    'group': None,
    'roles': None,
    'cloud': None,

    # cloud
    'cc': {
        'cloud_class': None,
        'processor': None,
        'connection': None,
        'sleep_time': None,
        'config': None,
        'actions': {},
    },
    'cloud_processor': None,
    'cloud_class': None,
    'cloud_handler': None,  # current cloud handle
    'cloud_hold_recyle': 3,  # sleep time when request jobs
    'debug': None,
})


def _pssh(file):
    """
    Parse pssh-like file
Example #29
0
 def construct_mapping(self, node, deep=False):
     """
     Constructs a mapping from a node, returning a Fabric _AttributeDict
     """
     return _AttributeDict(super(DeployerLoader, self).construct_mapping(node, deep))
Example #30
0
env = _AttributeDict({
    'again_prompt': 'Sorry, try again.',
    'all_hosts': [],
    'combine_stderr': True,
    'command': None,
    'command_prefixes': [],
    'cwd': '',  # Must be empty string, not None, for concatenation purposes
    'default_port': default_port,
    'echo_stdin': True,
    'exclude_hosts': [],
    'host': None,
    'host_string': None,
    'lcwd': '',  # Must be empty string, not None, for concatenation purposes
    'local_user': _get_system_username(),
    'output_prefix': True,
    'passwords': {},
    'path': '',
    'path_behavior': 'append',
    'port': default_port,
    'real_fabfile': None,
    'roles': [],
    'roledefs': {},
    'skip_bad_hosts': False,
    'ssh_config_path': default_ssh_config_path,
    # -S so sudo accepts passwd via stdin, -p with our known-value prompt for
    # later detection (thus %s -- gets filled with env.sudo_prompt at runtime)
    'sudo_prefix': "sudo -S -p '%s' ",
    'sudo_prompt': 'sudo password:'******'use_exceptions_for': {
        'network': False
    },
    'use_shell': True,
    'use_ssh_config': False,
    'user': None,
    'version': get_version('short')
})
Example #31
0
env = _AttributeDict({
    'abort_exception': None,
    'again_prompt': 'Sorry, try again.',
    'all_hosts': [],
    'combine_stderr': True,
    'colorize_errors': False,
    'command': None,
    'command_prefixes': [],
    'cwd': '',  # Must be empty string, not None, for concatenation purposes
    'dedupe_hosts': True,
    'default_port': default_port,
    'eagerly_disconnect': False,
    'echo_stdin': True,
    'exclude_hosts': [],
    'gateway': None,
    'host': None,
    'host_string': None,
    'lcwd': '',  # Must be empty string, not None, for concatenation purposes
    'local_user': _get_system_username(),
    'output_prefix': True,
    'passwords': {},
    'path': '',
    'path_behavior': 'append',
    'port': default_port,
    'real_fabfile': None,
    'remote_interrupt': None,
    'roles': [],
    'roledefs': {},
    'shell_env': {},
    'skip_bad_hosts': False,
    'ssh_config_path': default_ssh_config_path,
    'ok_ret_codes': [0],     # a list of return codes that indicate success
    # -S so sudo accepts passwd via stdin, -p with our known-value prompt for
    # later detection (thus %s -- gets filled with env.sudo_prompt at runtime)
    'sudo_prefix': "sudo -S -p '%(sudo_prompt)s' ",
    'sudo_prompt': 'sudo password:'******'sudo_user': None,
    'tasks': [],
    'prompts': {},
    'use_exceptions_for': {'network': False},
    'use_shell': True,
    'use_ssh_config': False,
    'user': None,
    'version': get_version('short')
})
Example #32
0
env = _AttributeDict(
    {
        "again_prompt": "Sorry, try again.",
        "all_hosts": [],
        "combine_stderr": True,
        "command": None,
        "command_prefixes": [],
        "cwd": "",  # Must be empty string, not None, for concatenation purposes
        "dedupe_hosts": True,
        "default_port": default_port,
        "echo_stdin": True,
        "exclude_hosts": [],
        "host": None,
        "host_string": None,
        "lcwd": "",  # Must be empty string, not None, for concatenation purposes
        "local_user": _get_system_username(),
        "output_prefix": True,
        "passwords": {},
        "path": "",
        "path_behavior": "append",
        "port": default_port,
        "real_fabfile": None,
        "roles": [],
        "roledefs": {},
        "skip_bad_hosts": False,
        "ssh_config_path": default_ssh_config_path,
        # -S so sudo accepts passwd via stdin, -p with our known-value prompt for
        # later detection (thus %s -- gets filled with env.sudo_prompt at runtime)
        "sudo_prefix": "sudo -S -p '%(sudo_prompt)s' ",
        "sudo_prompt": "sudo password:"******"sudo_user": None,
        "use_exceptions_for": {"network": False},
        "use_shell": True,
        "use_ssh_config": False,
        "user": None,
        "version": get_version("short"),
    }
)
Example #33
0
env = _AttributeDict({
    'abort_exception': None,
    'again_prompt': 'Sorry, try again.',
    'all_hosts': [],
    'combine_stderr': True,
    'colorize_errors': False,
    'command': None,
    'command_prefixes': [],
    'cwd': '',  # Must be empty string, not None, for concatenation purposes
    'dedupe_hosts': True,
    'default_port': default_port,
    'eagerly_disconnect': False,
    'echo_stdin': True,
    'exclude_hosts': [],
    'gateway': None,
    'host': None,
    'host_string': None,
    'lcwd': '',  # Must be empty string, not None, for concatenation purposes
    'local_user': _get_system_username(),
    'output_prefix': True,
    'passwords': {},
    'path': '',
    'path_behavior': 'append',
    'port': default_port,
    'real_fabfile': None,
    'remote_interrupt': None,
    'roles': [],
    'roledefs': {},
    'shell_env': {},
    'skip_bad_hosts': False,
    'ssh_config_path': default_ssh_config_path,
    'ok_ret_codes': [0],  # a list of return codes that indicate success
    # -S so sudo accepts passwd via stdin, -p with our known-value prompt for
    # later detection (thus %s -- gets filled with env.sudo_prompt at runtime)
    'sudo_prefix': "sudo -S -p '%(sudo_prompt)s' ",
    'sudo_prompt': 'sudo password:'******'sudo_user': None,
    'tasks': [],
    'prompts': {},
    'use_exceptions_for': {
        'network': False
    },
    'use_shell': True,
    'use_ssh_config': False,
    'user': None,
    'version': get_version('short')
})
Example #34
0
File: state.py Project: ombu/fiber
"""
Internal shared-state variables such as config settings
The top level is Fabric's env. Fiber adds its own key `fiber` to this dict
"""

import os, ConfigParser
from fabric.api import env
from fabric.utils import _AttributeDict

# Read config
config = ConfigParser.ConfigParser()
config.read('config.ini')

# AWS Credentials
os.environ['AWS_ACCESS_KEY_ID'] = config.get('ec2', 'access_key')
os.environ['AWS_SECRET_ACCESS_KEY'] = config.get('ec2', 'secret_key')

if not env.has_key('fiber'):
    env.fiber = _AttributeDict()

_ec2 = _AttributeDict(config.items('ec2'))
# type adjustments
_ec2.security_groups = _ec2.security_groups.split(',')
_ec2.region = int(_ec2.region)
env.fiber.ec2 = _ec2