def wait_until_available(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 with total_silence(): local('ping -o {}'.format(host.ip)) while True: if can_ssh(): break else: secs = 1 print(red("ssh may not be up and running yet, retrying in {}s".format(secs))) time.sleep(secs)
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 init(): """ sets-up reverse-proxy """ with total_silence(): execute(supervisor.stop_program, "all") # in case this is re-init, stop all execute(system.python) execute(system.nginx) execute(supervisor.install) execute(configure) print(yellow("generating self signed ssl for now (you should have yours signed and use proxy.update_ssl!)")) keys = dict(ssl_key=rel_path("dummy_ssl.key"), ssl_cert=rel_path("dummy_ssl.cert")) local("openssl req -nodes -new -x509 -keyout {ssl_key} -out {ssl_cert}".format(**keys)) update_ssl(**keys) print_successful()
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 recreate(name): try: print "waiting for server to be destroyed...", sys.stdout.flush() destroy(name) with total_silence(): while True: ip = read_conf('.glesys')['servers'][name]['ip'] result = local('ping -o -t 1 {}'.format(ip)) if result.return_code != 0: break except ApiError: pass print(green("OK.")) sys.stdout.flush() host = create(name) return host