예제 #1
0
def domain(command, *domain, **opts):
	force = opts['FORCE']
	cmd = CMD.get(command)
	idtype = get_idtype(opts)
	if cmd == CMD_ADD:
		if len(domain) < 1:
			raise Error (ENOARG, 'domain')
		d = Domain_ctl(opts['DB_URI'], any_rpc(opts))
		d.add(domain[0], domain[1:], idtype, force)
	elif cmd == CMD_RM:
		d = Domain_ctl(opts['DB_URI'], any_rpc(opts))
		d.rm(domain, force)
	elif cmd == CMD_SHOW:
		if not domain:
			domain = None
		else:
			domain = domain[0]
		cols, fformat, limit, rsep, lsep, astab = show_opts(opts)
		u = Domain(opts['DB_URI'])
		if opts['DID']:
			uri_list, desc = u.show_did(domain, cols=cols, fformat=fformat, limit=limit)
		elif opts['DEPTH']:
			uri_list, desc = u.show_did_for_domain(domain, cols=cols, fformat=fformat, limit=limit)
		else:
			uri_list, desc = u.show_domain(domain, cols=cols, fformat=fformat, limit=limit)
		tabprint(uri_list, desc, rsep, lsep, astab)
	else:
		raise Error (EINVAL, command)
예제 #2
0
def stat(*modules, **opts):
	cols, numeric, limit, rsep, lsep, astab = show_opts(opts)

	rpc = any_rpc(opts)

	estats = [ i for i in rpc.ser.system.listMethods() if i[-6:] == '.stats' ]
	display = [ i for i in rpc.ser.system.listMethods() if i in STATS ] + estats

	if modules:
		display = [ i for i in display if i.split('.')[0] in modules ]

	st = []
	for fn in display:
		ret = rpc.cmd(fn)
		if fn == 'usrloc.stats':	# FIX: Is this usrloc.stats processing correct?
			d = {}
			for x in ret:
				name = x['domain']
				for k, v in x.items():
					if k == 'domain': continue
					d[name + ' : ' + k] = v
			ret = d
		if type(ret) is dict:
			for k, v in ret.items():
				st.append([fn, str(k), str(v).strip()])
		elif type(ret) in [tuple, list]:
			for v in ret:
				st.append([fn, '', str(v).strip()])
		else:
			st.append([fn,'',str(ret).strip()])
	dsc = [('function', None, ''), ('name', None, ''), ('value', None, '')]
	tabprint(st, dsc, rsep, lsep, astab)
예제 #3
0
def methods(**opts):
	cols, numeric, limit, rsep, lsep, astab = show_opts(opts)

	rpc = any_rpc(opts)
	ret = rpc.system_listmethods()

	ret, desc = var2tab(ret, 'methods')
	tabprint(ret, desc, rsep, lsep, astab)
예제 #4
0
def uptime(**opts):
	cols, numeric, limit, rsep, lsep, astab = show_opts(opts)

	rpc = any_rpc(opts)
	ret = rpc.core_uptime()

	ret, desc = dict2tab(ret, ('uptime', 'up_since', 'now'))
	tabprint(ret, desc, rsep, lsep, astab)
예제 #5
0
def version(**opts):
	cols, numeric, limit, rsep, lsep, astab = show_opts(opts)

	rpc = any_rpc(opts)
	ret = rpc.core_version()

	ret, desc = var2tab(ret, 'version')
	tabprint(ret, desc, rsep, lsep, astab)
예제 #6
0
def ps(**opts):
	cols, numeric, limit, rsep, lsep, astab = show_opts(opts)

	rpc = any_rpc(opts)
	ret = rpc.core_ps()

	desc = [ ('id', None, ''), ('process description', None, '') ]
	ret = [ (str(a), b) for a, b in ret ]
	tabprint(ret, desc, rsep, lsep, astab)
예제 #7
0
def usrloc(command, uri, contact=None, *args, **opts):
	ad, al = arg_attrs(args)
	table = opts['UL_TABLE']
	q = float(ad.get('q', 1))
	expires = ad.get('expires')
	if expires is not None:
		expires = int(expires)
	flags = ad.get('flags')
	if flags is not None:
		flags = int(flags)

	# LB hack
	if opts['SER_URI'][:4] == 'http':
		ur = Uri(opts['DB_URI'])
		curi = ur.canonize(uri)
		del(ur)
		if opts['SER_URI'][-1:] != '/':
			opts['SER_URI'] = opts['SER_URI'] + '/'
		opts['SER_URI'] = opts['SER_URI'] + 'sip:' + curi

	cmd = CMD.get(command)
	if cmd == CMD_ADD:
		if contact is None:
			raise Error (ENOARG, 'contact')
		u = Usrloc_ctl(opts['DB_URI'], any_rpc(opts))
		u.add(uri, contact, table, expires, q, flags)
	elif cmd == CMD_RM:
		u = Usrloc_ctl(opts['DB_URI'], any_rpc(opts))
		u.rm(uri, contact, table)
	elif cmd == CMD_SHOW:
		cols, numeric, limit, rsep, lsep, astab = show_opts(opts)
		u = Usrloc_ctl(opts['DB_URI'], any_rpc(opts))
		ret = u.show(uri, table)
		if type(ret) == dict:	# FIX: Is this a bug in usrloc SER code?
			ret = [ret]
		ret = [ (str(i['contact']), str(i['expires']), str(i['q'])) for i in ret ]
		desc = (('contact',), ('expires',), ('q',))
		tabprint(ret, desc, rsep, lsep, astab)
	else:
		raise Error (EINVAL, command)
예제 #8
0
def list_tls(**opts):
	cols, numeric, limit, rsep, lsep, astab = show_opts(opts)

	rpc = any_rpc(opts)
	ret = rpc.tls_list()

	desc = [ ('ID', None, ''),     ('Timeout', None, ''), \
	         ('Source', None, ''), ('Destination', None, ''), \
	         ('TLS', None, '') ]
	ret = [ (str(s['id']), str(s['timeout']), \
	        s['src_ip'] + ':' + str(s['src_port']), \
	        s['dst_ip'] + ':' + str(s['dst_port']), s['tls']) for s in ret ]
	tabprint(ret, desc, rsep, lsep, astab)
예제 #9
0
def publish(uid, file_with_PIDF_doc, expires_in_sec, etag=None, **opts):
	expires = int(expires_in_sec)

	cols, numeric, limit, rsep, lsep, astab = show_opts(opts)

	rpc = any_rpc(opts)
	fh = open(file_with_PIDF_doc)
	doc = fh.read()
	fh.close()
	if etag:
		ret = rpc.ser.pa.publish('registrar', uid, doc, expires, etag)
	else:
		ret = rpc.ser.pa.publish('registrar', uid, doc, expires)
	if astab:
		ret, desc = var2tab(ret)
		tabprint(ret, desc, rsep, lsep, astab)
	else:
		print repr(ret)
예제 #10
0
def kill(sig=15, **opts):
	sig = int(sig)

	rpc = any_rpc(opts)
	return rpc.core_kill(sig)