def init_vps(subid): # VPSs often (always?) report themselves as OK before stopping and # completing setup. Trying to initialize them at this early stage seems to # cause trouble. wait_for_status_ok(subid) print "Status OK for the first time. I don't buy it. Lemme wait again..." time.sleep(10) while True: d = wait_for_status_ok(subid) print "Status OK again; bootstrapping..." ip = d['main_ip'] name = d['label'] passw = d['default_password'] if os.system(bootstrap_tmpl % (passw, ip, name)): print "Error trying to bootstrap; retrying..." else: break time.sleep(10) print "Generating and copying keys..." with vps_util.tempdir(subid): trycmd('salt-key --gen-keys=%s' % name) for suffix in ['.pem', '.pub']: os.rename(name + suffix, 'minion' + suffix) trycmd(scpkeys_tmpl % (passw, ip)) os.rename('minion.pub', os.path.join('/etc/salt/pki/master/minions', name)) print "Starting salt-minion..." trycmd(start_tmpl % (passw, ip)) vps_util.save_pillar(name) print "Calling highstate..." time.sleep(10) trycmd("salt -t 1800 %s state.highstate" % name) return vps_util.hammer_the_damn_thing_until_it_proxies( name, ssh_tmpl('%%s') % (passw, ip), fetchaccessdata_tmpl % (passw, ip))
def init_vps(d): subid = d['SUBID'] wait_for_status_ok(subid) # VPSs often (always?) report themselves as OK before stopping and # completing setup. Trying to initialize them at this early stage seems to # cause trouble. I don't know of any way to determine programatically when # it's OK to start pounding on these machines, but empirically some 400 # seconds after status first reported OK should be fine most of the time. print("Status OK for the first time. I don't buy it. Lemme sleep some...") time.sleep(400) while True: d = wait_for_status_ok(subid) print("Status OK again; bootstrapping...") ip = d['main_ip'] name = d['label'] passw = d['default_password'] if os.system(bootstrap_tmpl % (ip, name)): print("Error trying to bootstrap; retrying...") else: break time.sleep(10) print("Generating and copying keys...") with vps_util.tempdir(subid): trycmd('salt-key --gen-keys=%s' % name) for suffix in ['.pem', '.pub']: os.rename(name + suffix, 'minion' + suffix) trycmd(scpkeys_tmpl % ip) os.rename('minion.pub', os.path.join('/etc/salt/pki/master/minions', name)) print("Starting salt-minion...") trycmd(start_tmpl % ip) print("Calling highstate...") time.sleep(10) trycmd("salt -t 1800 %s state.highstate" % name) return vps_util.hammer_the_damn_thing_until_it_proxies(name)
def init_vps(d): name = d['name'] ip = d['ip'] if not vps_util.highstate_pid(name): print("Highstate not running yet; waiting for a bit just in case...") time.sleep(10) while vps_util.highstate_pid(name): print("Highstate still running...") time.sleep(10) print("Highstate done!") return vps_util.hammer_the_damn_thing_until_it_proxies(name)
def init_vps(name_and_ip): name, ip = name_and_ip if not vps_util.highstate_pid(name): print("Highstate not running yet; waiting for a bit just in case...") time.sleep(10) while vps_util.highstate_pid(name): print("Highstate still running...") time.sleep(10) print("Highstate done!") return vps_util.hammer_the_damn_thing_until_it_proxies( name, ssh_tmpl % ip, fetchaccessdata_tmpl % ip)
def init_vps(d): name = d['name'] ip = d['ip'] if not vps_util.highstate_pid(name): print("Highstate not running yet; waiting for a bit just in case...") time.sleep(10) while vps_util.highstate_pid(name): print("Highstate still running...") time.sleep(10) print("Highstate done!") return vps_util.hammer_the_damn_thing_until_it_proxies(name)
def init_vps(name_and_ip): name, ip = name_and_ip if not vps_util.highstate_pid(name): print("Highstate not running yet; waiting for a bit just in case...") time.sleep(10) while vps_util.highstate_pid(name): print("Highstate still running...") time.sleep(10) print("Highstate done!") return vps_util.hammer_the_damn_thing_until_it_proxies( name, ssh_tmpl % ip, fetchaccessdata_tmpl % ip)
def init_vps(subid): wait_for_status_ok(subid) # VPSs often (always?) report themselves as OK before stopping and # completing setup. Trying to initialize them at this early stage seems to # cause trouble. I don't know of any way to determine programatically when # it's OK to start pounding on these machines, but empirically some 400 # seconds after status first reported OK should be fine most of the time. print( "Status OK for the first time. I don't buy it. Lemme sleep some...") time.sleep(400) while True: d = wait_for_status_ok(subid) print("Status OK again; bootstrapping...") ip = d['main_ip'] name = d['label'] passw = d['default_password'] if os.system(bootstrap_tmpl % (passw, ip, name)): print("Error trying to bootstrap; retrying...") else: break time.sleep(10) print("Generating and copying keys...") with vps_util.tempdir(subid): trycmd('salt-key --gen-keys=%s' % name) for suffix in ['.pem', '.pub']: os.rename(name + suffix, 'minion' + suffix) trycmd(scpkeys_tmpl % (passw, ip)) os.rename('minion.pub', os.path.join('/etc/salt/pki/master/minions', name)) print("Starting salt-minion...") trycmd(start_tmpl % (passw, ip)) vps_util.save_pillar(name) print("Calling highstate...") time.sleep(10) trycmd("salt -t 1800 %s state.highstate" % name) return vps_util.hammer_the_damn_thing_until_it_proxies( name, ssh_tmpl('%%s') % (passw, ip), fetchaccessdata_tmpl % (passw, ip))
do_token = os.getenv("DO_TOKEN") do = digitalocean.Manager(token=do_token) def create_vps(name): vps_util.save_pillar(name) out = subprocess.check_output(["salt-cloud", "-p", "do_nl_1GB", name]) # Uberhack; It'll get better with newer salt-cloud versions. d = yaml.load(out[out.rfind(name + ":"):].replace("----------", "")).values()[0] return d['name'], d['ip_address'] def init_vps((name, ip), wait_for_hs=True): if wait_for_hs: while not vps_util.highstate_pid(name): print "Highstate not running yet..." time.sleep(10) while vps_util.highstate_pid(name): print "Highstate still running..." time.sleep(10) print "Highstate done!" return vps_util.hammer_the_damn_thing_until_it_proxies( name, ssh_tmpl % ip, fetchaccessdata_tmpl % ip) def destroy_vps(name): os.system('salt-cloud -yd ' + name) os.system('salt-key -yd' + name)
"scp -o StrictHostKeyChecking=no -i /etc/salt/cloudmaster.id_rsa root@%s:/home/lantern/access_data.json ." ) do_token = os.getenv("DO_TOKEN") do = digitalocean.Manager(token=do_token) def create_vps(name): vps_util.save_pillar(name) out = subprocess.check_output(["salt-cloud", "-p", "do_nl_1GB", name]) # Uberhack; It'll get better with newer salt-cloud versions. d = yaml.load(out[out.rfind(name + ":") :].replace("----------", "")).values()[0] return d["name"], d["ip_address"] def init_vps((name, ip), wait_for_hs=True): if wait_for_hs: while not vps_util.highstate_pid(name): print "Highstate not running yet..." time.sleep(10) while vps_util.highstate_pid(name): print "Highstate still running..." time.sleep(10) print "Highstate done!" return vps_util.hammer_the_damn_thing_until_it_proxies(name, ssh_tmpl % ip, fetchaccessdata_tmpl % ip) def destroy_vps(name): os.system("salt-cloud -yd " + name) os.system("salt-key -yd" + name)