Exemple #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)
Exemple #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)
Exemple #3
0
def show(uri=None, **opts):
	cols, fformat, limit, rsep, lsep, astab = show_opts(opts)

	u = Uri(opts['DB_URI'])
	uri_list, desc = u.show(uri, cols, fformat, limit)

	tabprint(uri_list, desc, rsep, lsep, astab)
Exemple #4
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)
Exemple #5
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)
Exemple #6
0
def show(realm=None, auth_username=None, **opts):

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

	u = Cred(opts['DB_URI'])
	clist, desc = u.show(realm, auth_username, cols, fformat, limit)

	tabprint(clist, desc, rsep, lsep, astab)
Exemple #7
0
def show(table_name, *args, **opts):
	clist = _columns(args)[1]
	cols, fformat, limit, rsep, lsep,  astab = show_opts(opts)

	u = Db(opts['DB_URI'])
	data, desc = u.show(table_name, cols, clist, limit)

	tabprint(data, desc, rsep, lsep, astab)
Exemple #8
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)
Exemple #9
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)
Exemple #10
0
def main(argv):
	set_excepthook(True)
	args, opts, defaults = parse_cmdline(argv)
	set_excepthook(opts.get('DEBUG', defaults.get('DEBUG')))
	conf_opts = handle_config(opts.get('CONFIG', defaults.get('CONFIG')))
	defaults.update(conf_opts)
	defaults.update(opts)
	opts = defaults
	del defaults
	set_excepthook(opts['DEBUG'])
	if len(args) < 1:
		raise Error (EINVAL)

	opts['VERSION'] = handle_version(opts)

	opts['DB_URI']  = handle_db_uri(opts)
	opts['SER_URI'] = handle_ser_uri(opts)
	opts['SERVERS'] = handle_servers(opts)

	modname = handle_module_name(args[0])
	mod = module(modname)

	errarg = None
	try:
		funcname = mod._handler_
		args = args[1:]
	except:
		try:
			errarg = args[1]
			funcname = opt.CMD.get(args[1])
		except IndexError:
			funcname = 'help'
		if opts['HELP']:
			funcname = 'help'
		args = args[2:]

	try:
		func = getattr(mod, funcname)
	except:
		if errarg:
			raise Error (EINVAL, errarg)
		else:
			raise Error (EINVAL,)

	if opts['DBG_ARGS']:
		vals = [('MOD', repr(modname)), ('FUN', repr(funcname))]
		i = 0
		for a in args:
			vals.append((str(i),  repr(a)))
			i += 1
		tabprint(vals, [('ARG',),('VALUE',)], tab=True)
		vals, desc = var2tab(opts, ('OPT', 'VALUE'))
		vals = [ (k, repr(v)) for k, v in vals ]
		tabprint(vals, desc, tab=True)

	return call(func, args, opts)
Exemple #11
0
def show(domain=None, **opts):
	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)
Exemple #12
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)
Exemple #13
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)
Exemple #14
0
def user(command, uri, *aliases, **opts):
	force = opts['FORCE']
	cmd = CMD.get(command)
	idtype = get_idtype(opts)
	if cmd == CMD_ADD:
		prompt='Please, enter password for the new subscriber.\nPassword: '******'DB_URI'], multi_rpc(opts))
		u.add(uri, aliases, password, idtype, force)
	elif cmd == CMD_RM:
		u = User_ctl(opts['DB_URI'], multi_rpc(opts))
		u.rm(uri, idtype, force)
	elif cmd == CMD_SHOW:
		cols, fformat, limit, rsep, lsep, astab = show_opts(opts)
		u = User_ctl(opts['DB_URI'], multi_rpc(opts))
		ret, desc = u.show(uri, cols, fformat, limit)
		tabprint(ret, desc, rsep, lsep, astab)
	else:
		raise Error (EINVAL, command)
Exemple #15
0
def show(identificator=None, **opts):
	if identificator is None:
		return show_all(opts)
#	COLS = ['name', 'type', 'value', 'flags']
	cols, fformat, limit, rsep, lsep, astab = show_opts(opts)

	obj, id, x = _attr_id(identificator, opts)

	if x == 'g':
		alist, desc = obj.show(None, cols, fformat, limit)
	elif x == 'u':
		alist, desc = obj.show_uid(id, cols, fformat, limit)
	elif x == 'd':
		alist, desc = obj.show_did(id, cols, fformat, limit)
	elif x == 't':
		alist, desc = obj.show(None, cols, fformat, limit)
	else:
		raise Error (EINVAL, identificator)

	tabprint(alist, desc, rsep, lsep, astab)	
Exemple #16
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)
Exemple #17
0
def show_all(opts):
	cols, fformat, limit, rsep, lsep, astab = show_opts(opts)

	COLS = ['name', 'type', 'value', 'flags']
	if not cols:
		cols = ['did', 'uid'] + COLS
	CIDX = idx_dict(['did', 'uid'] + COLS)
	cidx = col_idx(CIDX, cols)

	lst = []

	a = User_attrs(opts['DB_URI'])
	ulist, desc = a.show(None, ['uid']+COLS, fformat, limit)
	for l in ulist:
		lst.append([''] + l) 

	a = Domain_attrs(opts['DB_URI'])
	dlist, desc = a.show(None, ['did']+COLS, fformat, limit)
	for l in dlist:
		lst.append([l[0], ''] + l[1:]) 

	a = Global_attrs(opts['DB_URI'])
	glist, desc = a.show(None, COLS, fformat, limit)
	for l in glist:
		lst.append(['GLOBAL', 'GLOBAL'] + l) 
	
	alist = []
	for row in lst:
		nr = []
		for i in cidx:
			nr.append(row[i])
		alist.append(nr)

	desc = [('did', ), ('uid', )] + list(desc)
	dsc = []
	for i in cidx:
		dsc.append(desc[i])
	tabprint(alist, dsc, rsep, lsep, astab)	
Exemple #18
0
def rpc(cmd, args, opts):

	rpc = any_rpc(opts)

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

	# quote unquoted string that not appear as number
	args = list(args)
	for i in range(len(args)):
		try:
			tmp = float(args[i])
		except:
			if args[i][:1] not in ('"', "'"):
				args[i] = '"' + str(args[i]) + '"'

	ret = rpc.shell_cmd(cmd, args)
	if astab:
		ret, desc = var2tab(ret)
	        tabprint(ret, desc, rsep, lsep, astab)
	else:
		if ret == '':      # ignore empty string it's default
			return     # value if nothing returns
		print repr(ret)