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 create_vps(name): vps_util.save_pillar(name) plan = vps_util.dc_by_cm(vps_util.my_cm()) + "_1GB" out = subprocess.check_output(["salt-cloud", "-p", plan, name]) # Uberhack: XXX update with salt version... d = yaml.load(out[out.rfind(name + ":"):].replace("----------", "").replace("|_", "-")).values()[0] return d['name'], d['networks']['v4'][1]['ip_address']
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 create_vps(name): vps_util.save_pillar(name) plan = vps_util.dc_by_cm(vps_util.my_cm()) + "_1GB" out = subprocess.check_output(["salt-cloud", "-p", plan, name]) # Uberhack: XXX update with salt version... d = yaml.load(out[out.rfind(name + ":"):].replace( "----------", "").replace("|_", "-")).values()[0] return d['name'], d['networks']['v4'][1]['ip_address']
def create_vps(name, req={}, plan=None): vps_util.save_pillar(name, req) if plan is None: plan = vps_util.dc_by_cm(vps_util.my_cm()) + "_1GB" out = subprocess.check_output(["salt-cloud", "-p", plan, name]) # Uberhack: XXX update with salt version... d = yaml.load(out[out.rfind(name + ":"):].replace( "----------", "").replace("|_", "-")).values()[0] return {'name': d['name'], 'ip': d['public_ips'][0]}
def create_vps(name, req={}, plan=None): vps_util.save_pillar(name, req) if plan is None: plan = vps_util.dc_by_cm(vps_util.my_cm()) + "_1GB" out = subprocess.check_output(["salt-cloud", "-p", plan, name]) # Uberhack: XXX update with salt version... d = yaml.load(out[out.rfind(name + ":"):].replace("----------", "").replace("|_", "-")).values()[0] return {'name': d['name'], 'ip': d['public_ips'][0]}
def create_vps(label, req): vps_util.save_pillar(label, req) dc = vps_util.dc_by_cm(vps_util.my_cm()) subid = vultr.server_create(vultr_dcid[dc], default_plan[dc], ubuntu14_04_64bit, label=label, sshkeyid=cloudmaster_keyid, enable_ipv6='yes', enable_private_network="yes")['SUBID'] for _ in xrange(30): time.sleep(10) d = try_vultr_cmd(vultr.server_list, subid) ip = d.get('main_ip') if ip and util.ipre.match(ip): d['ip'] = ip return d raise RuntimeError("Couldn't get the new VPS's 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))
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))
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"]