Beispiel #1
0
    def __call__(self, argv, help):
        """Do stuff on the cluster (using fabric)"""
        parser = argparse.ArgumentParser(
            prog="%s fab" % self.ctrl.progname,
            description=help,
            add_help=False,
        )
        instances = self.ctrl.get_instances(command='init_ssh_key')
        parser.add_argument("instance", nargs=1,
                            metavar="instance",
                            help="Name of the instance from the config.",
                            choices=list(instances))
        parser.add_argument("fabric_opts",
                            metavar="...", nargs=argparse.REMAINDER,
                            help="Fabric options")
        args = parser.parse_args(argv)

        instance = instances[args.instance[0]]
        with fabric_integration(self.ctrl, instance, fabcmd=True):
            from fabric.main import main
            fabfile = get_fabfile(instance)
            newargv = ['fab', '-f', fabfile]
            if args.fabric_opts:
                newargv = newargv + args.fabric_opts
            with sys_argv(newargv):
                main()
Beispiel #2
0
def main():
    from pkg_resources import resource_filename, Requirement
    import os
    cwd = os.path.realpath('.')
    os.environ['FLASKPATH'] = cwd
    from fabric.main import main
    filename = resource_filename(Requirement.parse("filament"), "filament/fabfile")
    main([filename])
Beispiel #3
0
def pypi42_clean():
    from fabric.main import main
    from distutils.sysconfig import get_python_lib

    fabpath = get_python_lib() + "/pypi42/"
    fabfile = fabpath + "fabfile.py"
    fabfile = [fabfile]
    main(fabfile)
Beispiel #4
0
def pypi42_dirty():
    from fabric.main import main
    from distutils.sysconfig import get_python_lib

    savedpath = os.getcwd()
    fabpath = get_python_lib() + "/pypi42/"
    os.chdir(fabpath)
    main()
    os.chdir(savedpath)
Beispiel #5
0
def main():
    """Load our default fabfile, then attempt to load any local fabfiles."""
    our_fab = os.path.join(os.path.dirname(__file__), 'default_tasks.py')
    docstring, callables, default = fab.load_fabfile(our_fab)
    fab.state.commands.update(callables)


    fabfiles = []
    other_fab = fab.find_fabfile()
    if other_fab:
      fabfiles.append(other_fab)

    fabfiles.append(our_fab)


    fab.main(fabfiles)
Beispiel #6
0
def awsfab():
    monkey_patch_get_hosts()
    from optparse import make_option
    from fabric.main import main
    from fabric import state

    state.env_options.append(
        make_option(
            '-E',
            '--ec2names',
            default=None,
            help=('Comma-separated list of AWS hosts identified by their '
                  '``Name`` tag. You can specify region by prefixing the name '
                  'with ``region:`` (e.g.: eu-west-1:ec2test). Default region '
                  'is awsfab_settings.DEFAULT_REGION.')))
    state.env_options.append(
        make_option('-G',
                    '--ec2tags',
                    default='',
                    help=('Comma-separated list of tag=value pairs.')))
    state.env_options.append(
        make_option(
            '--ec2ids',
            default=None,
            help=(
                'Comma-separated list of AWS hosts identified by instance ID. '
                'You can specify region by prefixing the instanceid '
                'with ``region:`` (e.g.: eu-west-1:x-abcdefg). Default region '
                'is awsfab_settings.DEFAULT_REGION.')))
    state.env_options.append(
        make_option(
            '--awsfab-settings',
            dest='awsfab_settings_module',
            default='awsfab_settings',
            help=
            ('Awsfabrictask settings module. Defaults to '
             '``awsfab_settings``. Can NOT be a dotted path (e.g.: '
             'my.settings). If this module is found, it will be merged '
             'with the default settings. Furthermore, this module suffixed with '
             '``_local`` will also be merged into the awsfab settings if it exists.'
             )))

    main()
Beispiel #7
0
def awsfab():
    monkey_patch_get_hosts()
    from optparse import make_option
    from fabric.main import main
    from fabric import state

    state.env_options.append(
            make_option('-E', '--ec2names',
                default=None,
                help=('Comma-separated list of AWS hosts identified by their '
                    '``Name`` tag. You can specify region by prefixing the name '
                    'with ``region:`` (e.g.: eu-west-1:ec2test). Default region '
                    'is awsfab_settings.DEFAULT_REGION.')
                )
            )
    state.env_options.append(
            make_option('-T', '--ec2tags',
                default='',
                help=('Comma-separated list of tag=value pairs.')
                )
            )
    state.env_options.append(
            make_option('--ec2ids',
                default=None,
                help=('Comma-separated list of AWS hosts identified by instance ID. '
                    'You can specify region by prefixing the instanceid '
                    'with ``region:`` (e.g.: eu-west-1:x-abcdefg). Default region '
                    'is awsfab_settings.DEFAULT_REGION.')
                )
            )
    state.env_options.append(
            make_option('--awsfab-settings',
                dest='awsfab_settings_module',
                default='awsfab_settings',
                help=('Awsfabrictask settings module. Defaults to '
                    '``awsfab_settings``. Can NOT be a dotted path (e.g.: '
                    'my.settings). If this module is found, it will be merged '
                    'with the default settings. Furthermore, this module suffixed with '
                    '``_local`` will also be merged into the awsfab settings if it exists.')
                )
            )

    main()
Beispiel #8
0
def main(fabfile_locations=None, file_paths=None):
    # type: (list, list) -> None
    fabfile_local = find_fabfile()
    if fabfile_locations is None and fabfile_local is None:
        fabfile_locations = ['~/fabfile.py']
        print_info('Added $HOME to fabfile locations')

    docstring, new_style, classic, default = load_tasks_from_module(api)
    tasks = new_style if state.env.new_style_tasks else classic
    state.commands.update(tasks)

    print_info('Forwarding execution to Fabric')

    _load_settings_original = fabric_main.load_settings

    def hemp_load_settings(path):
        print_info('Loading hempfiles')
        load_hempfiles(file_paths)
        return _load_settings_original(path)

    fabric_main.load_settings = hemp_load_settings
    fabric_main.main(fabfile_locations)
Beispiel #9
0
def main():
    fab = fabfile.__file__
    if fab.endswith('.pyc'):
        fab = fab[:-1]
    fab_main.main([fab])
Beispiel #10
0

#===============================================================================
# seed jenkins job from xml config file
#===============================================================================
def seed_jenkins_job():
    deployment_handler.seed_jenkins_jobs()
    #print 'Not implemented'


def init(deployment_type):
    global util
    deployment_handler.set_deployment_type(deployment_type)
    env.hosts = deployment_handler.read_config_map(
        'authentication')['ssh_hosts'].split(",")
    env.user = deployment_handler.read_config_map(
        'authentication')['ssh_username']
    env.password = deployment_handler.read_config_map(
        'authentication')['ssh_password']


if __name__ == '__main__':
    import sys
    from fabric.main import main
    sys.argv = [
        'fab',
        '-f',
        __file__,
    ] + sys.argv[1:]
    main()
Beispiel #11
0
import os
#import subprocess
from fabric.operations import run, env
from fabric.main import main


env.user = args.user()
env.password = args.password()


def ssh(task):
    run(task)
    #for machine in target_parser.parse(sys.argv[1]):
        #process = subprocess.Popen([machine] + sys.argv[2:],
                                   #executable='ssh')

if __name__ == '__main__':
    hosts = reduce(lambda x, y: x + ';' + y, args.parse_targets(sys.argv[1]))

    if len(sys.argv) < 3:
        cmdline = reduce(lambda x, y: x.rstrip() + ' && ' + y,
                         sys.stdin.readlines())
    else:
        cmdline = reduce(lambda x, y: x + ' ' + y, sys.argv[2:])
    sys.argv = ['fab',
                '-f', __file__,
                'ssh:{0},hosts={1}'.format(cmdline, hosts)]
    if os.environ.get('SER_PSH') is None:
        sys.argv.append('-P')
    main()
Beispiel #12
0
def restart_uwsgi():
    sudo('supervisorctl restart %s' % config.domain)


def get_project_root():
    return join(config.root, config.domain)

def get_virtualenv():
    return join(get_repo(), '.tox', config.toxenv)

def get_repo():
    return join(get_project_root(), config.repo.split('/')[-1])


def upload_jinja_template(tpl):
    context = {
        'domain': config.domain,
        'uwsgi_sock': '/tmp/%s.sock' % config.domain,
        'virtualenv': get_virtualenv(),
    }
    src = tpl + '.jinja'
    dest = join(get_project_root(), tpl)
    return upload_template(src, dest, context, use_jinja=True,
                           template_dir='templates')


# Make this invocable as  ./deploy
if __name__ == '__main__':
    from fabric.main import main; main()
Beispiel #13
0
def production():
    env.hosts = [os.environ['ENV_PROD_HOSTS']
    env.user = os.environ['ENV_PROD_USER']
    
    env.password = os.environ['ENV_PROD_PASSWORD']
    
    env.projectHome = "/home/stompthemonsternc/stompnc"
    env.gitRemote = "origin"
    env.gitBranch = "master"
    

def staging():
    env.hosts = [os.environ['ENV_STAGING_HOSTS']
    env.user = os.environ['ENV_STAGING_USER']
    
    env.password = os.environ['ENV_STAGING_PASSWORD']

    env.projectHome = "/home/stompthemonsternc/stompnc"
    env.gitRemote = "origin"
    env.gitBranch = "master"
    
    
def pull():    
    execute(git_pull)

def deploy():
    "Deploying..."
    execute(dependencies)
    execute(migrateDB)
    execute(syncDB)
    execute(collectStatic)
    execute(apacheReboot)
    
def git_pull():
    "Updating the code..."
    run("cd %s; git pull %s %s" % (env.projectHome,env.gitRemote,env.gitBranch))

def git_reset():
    "Resets the repository to specified version."
    run("cd %s; git reset --hard %s" % (env.projectHome,env.hash))

def apacheReboot():
    "Reboot Apache2 server..."
    sudo("/etc/init.d/apache2 restart")
    
def updateAptGet():
    sudo("apt-get update; apt-get upgrade;")    

def dependencies():
    "Syncing Dependencies..."
    sudo("cd %s/setup; pip install -r requirements.txt" % (env.projectHome))    
    
def migrateDB():
    "Migrating DB..."
    run("cd %s/app; python manage.py migrate --all --no-initial-data" % (env.projectHome))   
    
def syncDB():
    "Syncing DB..."
    run("cd %s/app; python manage.py syncdb" % (env.projectHome))   

def collectStatic():
	"Collecting static resources..."
	run("cd %s/app; python manage.py collectstatic" % (env.projectHome))   

def test():
    local("python manage.py test", fail='abort')

def reset(hash):
    """
    Reset all git repositories to specified hash.
    Usage:
        fab reset:repo=my_repo,hash=etcetc123
    """
    env.hash = hash
    execute(git_reset)
    
if __name__ == '__main__':
   import sys
   from fabric.main import main
   sys.argv = ['fab', '-f', __file__,] + sys.argv[1:]
   main()    
Beispiel #14
0
def main():
    # if sys.argv[-1] != "--list":
    #     sys.argv.remove("--list")
    main_fabric.main()
Beispiel #15
0
 def execute(self, cwd, root):
     os.chdir(root)
     sys.argv[1:] = sys.argv[2:]
     main()
Beispiel #16
0
def commandline():
    # default to our own fabfile
    if '-f' not in sys.argv:
        sys.argv.extend(['-f', path.join(here, 'fabfile.py')])
    main.main()
Beispiel #17
0
#!/usr/bin/env python2.7

# ignore PyCrypto errors that appear on RHEL6 when loading fabric
try:
    import warnings
    from Crypto.pct_warnings import PowmInsecureWarning
    warnings.filterwarnings("ignore")
    warnings.simplefilter("ignore", PowmInsecureWarning)
except:
    pass

# run Fabric like normal
if __name__ == '__main__':
    import sys
    from fabric.main import main
    sys.exit(main())
Beispiel #18
0
def execute_from_command_line(argv=None):
    fabfile = os.path.join(os.path.dirname(__file__), 'fabfile.py')
    sys.path.append(os.getcwd())
    main([fabfile])