def attrs(command, uri, *attrs, **opts): cmd = CMD.get(command) if cmd == CMD_SET: attrs = ('user='+uri,) + attrs return _set(attrs, opts) else: raise Error (EINVAL, command)
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)
def alias(command, *uri, **opts): force = opts['FORCE'] cmd = CMD.get(command) if cmd == CMD_ADD: if len(uri) < 1: raise Error (ENOARG, 'uri') if len(uri) < 2: raise Error (ENOARG, 'alias') a = Alias_ctl(opts['DB_URI'], multi_rpc(opts)) a.add(uri[0], uri[1:], force) elif cmd == CMD_RM: if len(uri) < 1: raise Error (ENOARG, 'alias') a = Alias_ctl(opts['DB_URI'], multi_rpc(opts)) a.rm(uri, force) else: raise Error (EINVAL, command)
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)
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)