def retire_lcs(name, ip, byip=util.Cache(timeout=60*60, update_fn=srv_cfg_by_ip)): cm = cm_by_name(name) region = region_by_name(name) srvs = byip.get().get(ip, (None, []))[1] txn = redis_shell.pipeline() if srvs: scores = [redis_shell.zscore(region + ':slices', srv) for srv in srvs] pairs = {"<empty:%s>" % int(score): score for score in scores if score} if pairs: txn.zadd(region + ":slices", **pairs) txn.zrem(region + ":slices", *srvs) txn.hdel('srv->cfg', *srvs) txn.incr('srvcount') else: print "No configs left to delete for %s." % name # Check whether this server is in the queue (because of recycling). for cfg in redis_shell.lrange(region + ':srvq', 0, -1): if cfg.split('|')[0] == ip: txn.lrem(region + ':srvq', cfg) txn.lrem(cm + ':vpss', name) txn.incr(cm + ':vpss:version') txn.execute()
def retire_lcs(name, ip, # It's safe to cache this because a proxy will take at least 24h # since the time it's recycled (and thus new server IDs can be # entered for it) and the time it's destroyed. To be more # precise, 24h must elapse since the time it's been _split_. For # this to work, it's crucial to remove the # /home/lantern/server_split flag file whenever we recycle # proxies. byip=util.Cache(timeout=60*60, update_fn=srv_cfg_by_ip)): cm = cm_by_name(name) region = region_by_name(name) srvs = byip.get().get(ip, (None, []))[1] txn = redis_shell.pipeline() if srvs: scores = [redis_shell.zscore(region + ':slices', srv) for srv in srvs] pairs = {"<empty:%s>" % int(score): score for score in scores if score} if pairs: txn.zadd(region + ":slices", **pairs) txn.zrem(region + ":slices", *srvs) txn.hdel('srv->cfg', *srvs) txn.incr('srvcount') else: print "No configs left to delete for %s." % name # Check whether this server is in the queue (because of recycling). for cfg in redis_shell.lrange(region + ':srvq', 0, -1): if cfg.split('|')[0] == ip: txn.lrem(region + ':srvq', cfg) txn.lrem(cm + ':vpss', name) txn.incr(cm + ':vpss:version') txn.execute()
def remove_if_there(k): score = redis_shell.zscore(slices_key, k) if score is None: return False else: txn.zrem(slices_key, k) txn.zadd(slices_key, "<empty:%s>" % int(score), score) return True
def proxy_status(name=None, ip=None, srv=None): name, _, srv = nameipsrv(name, ip, srv) if srv is None: return 'baked-in' elif redis_shell.zscore(region_by_name(name) + ':slices', srv) is None: return 'closed' else: return 'open'
def am_I_closed(): srv = redis_shell.hget('name->srv', instance_id) if srv is None: print "I'm retired or a baked in proxy" return False if redis_shell.zscore(region + ':slices', srv) is not None: print "I'm open" return False print "I'm closed" return True
def proxy_status(name=None, ip=None, srv=None): name, _, srv = nameipsrv(name, ip, srv) if srv is None: if name is not None: region = region_by_name(name) for qentry in redis_shell.lrange(region + ':srvq', 0, -1): if qentry.split('|')[1] == name: return 'enqueued' return 'baked-in' elif redis_shell.zscore(region_by_name(name) + ':slices', srv) is None: return 'closed' else: return 'open'
def fp_status(name): if not name.startswith('fp-'): return "n/a" ip = ip_by_name().get(name) if not ip: return "destroyed" if ip in bakedin(): return "baked-in" cfgs = srv_cfg_by_name(name) if not cfgs: return "???" region = vps_util.region_by_name(name) for cfg in cfgs[1]: if redis_shell.zscore(region + ':slices', cfg): return "open" else: return "full"
def fp_status(name): if not name.startswith('fp-'): return "n/a" ip = ip_by_name().get(name) if not ip: return "destroyed" if ip in bakedin(): return "baked-in" cfg = srv_cfg_by_name(name) if not cfg: return "???" region = vps_util.region_by_name(name) for srv in cfg[1]: for suffix in ["", "|0"]: if redis_shell.zscore(region + ':slices', "%s%s" % (srv, suffix)): return "open" else: return "full"
def retire_lcs(name, ip, byip=util.Cache(timeout=60 * 60, update_fn=srv_cfg_by_ip)): cm = cm_by_name(name) region = region_by_name(name) srvs = byip.get().get(ip, (None, []))[1] txn = redis_shell.pipeline() if srvs: scores = [redis_shell.zscore(region + ':slices', srv) for srv in srvs] pairs = {"<empty:%s>" % int(score): score for score in scores if score} if pairs: txn.zadd(region + ":slices", **pairs) txn.zrem(region + ":slices", *srvs) txn.hdel('srv->cfg', *srvs) txn.incr('srvcount') else: print "No configs left to delete for %s." % name # Check whether this server is in the queue (because of recycling). for cfg in redis_shell.lrange(region + ':srvq', 0, -1): if cfg.split('|')[0] == ip: txn.lrem(region + ':srvq', cfg) txn.lrem(cm + ':vpss', name) txn.incr(cm + ':vpss:version') txn.execute()