def bootstrap_proxy(name, recreate): """ run as: python bootstrap.py note: must be python script, cannot be run via fabfile - as fabric uses global env for ssh-key-setting and we create key here. """ host = base_bootstrap(name, recreate, template_dir=rel_path('proxy', 'templates'), server_yaml=rel_path('proxy', 'server.yaml')) execute(admin.create_user, 'cc_proxy', gen_password(), hosts=new_host_string('admin', host.ip)) execute(proxy.init, hosts=new_host_string('cc_proxy', host.ip))
def create_instance(user_account): """ create account for user and install requirements """ with total_silence(): execute(supervisor.stop_program, 'all') # in case this is re-init, stop all execute(admin.create_user, user_account, password='******', hosts=new_host_string('admin')) execute(system.python, hosts=new_host_string(user_account)) execute(system.nginx, hosts=new_host_string(user_account)) execute(system.uwsgi, hosts=new_host_string(user_account)) execute(supervisor.install, hosts=new_host_string(user_account)) print_successful()
def create_user(user_account, password): setup_env_for_user() execute(root.user_create, user_account, password) user_add_ssh(user_account, pub_key_file=env.key_filename + '.pub', use_sudo=True) dummy_port = 123 # bh sets env variable 'HTTP_LISTENING_PORT' to this one, but we won't use that env var execute(user.init_home_env, dummy_port, hosts=new_host_string(user=user_account)) sudo('mkdir -p ~{}/conf'.format(user_account)) secure_account(user_account) print_successful()
def base_bootstrap(name, recreate, template_dir, server_yaml): if recreate: host = glesys.recreate(name) else: host = glesys.create(name) key_file = os.path.expanduser('~/.ssh/{}'.format(host.admin_ssh_key)) if not os.path.isfile(key_file): os.system('ssh-keygen -q -t rsa -N "" -f {}'.format(key_file)) # must import fabfile only once we are sure the keyfilename exists (fabfile uses global env.key_filename) # and must import fabfile as it sets up the global env which are used in the tasks import fabfile # flake8: noqa execute(server.bootstrap, template_dir=template_dir, server_yaml=server_yaml, pub_key_file=key_file + '.pub', hosts=new_host_string('root', host.ip)) return host
def can_ssh(): host_str = new_host_string('root', host.ip) with total_silence(): class NotReady(Exception): pass with settings(abort_exception=NotReady): try: ret = execute(lambda: run("echo 'OK'"), hosts=host_str) except NotReady: return False else: if host_str in ret: if 'OK' in ret[host_str]: return True return False
def bootstrap_app(name, recreate): host = base_bootstrap(name, recreate, template_dir=rel_path('app', 'templates'), server_yaml=rel_path('app', 'server.yaml')) execute(admin.create_user, 'cc_appmin', gen_password(), hosts=new_host_string('admin', host.ip))