def raw_cmd(self, cmd, par=[]): warn = [] for server in self.servers: ser = ServerProxy(server, self.ssl) method = getattr(ser, cmd) try: apply(method, par) except xmlrpclib.Fault, inst: warning("RPC on '%s' failed: %s" % (server, str(inst))) warn.append(server) except:
def reload(self): warn = [] for server in self.servers: try: ser = ServerProxy(server, self.ssl) cmds = [ i for i in ser.system.listMethods() if i[-7:] == '.reload' ] except xmlrpclib.Fault, inst: warning("ListMethods on '%s' failed: %s" % (server, str(inst))) warn.append(server) continue except:
def cmd_if_exist(self, cmd, par=[]): warn = [] for server in self.servers: try: ser = ServerProxy(server, self.ssl) if cmd not in ser.system.listMethods(): continue except xmlrpclib.Fault, inst: warning("ListMethods on '%s' failed: %s" % (server, str(inst))) warn.append(server) continue except:
def rm(self, aliases, force=False): ur = Uri(self.dburi, self.db) aliases = uniq(aliases) for a in aliases: if not ur.exist_uri(a) and not force: raise Error (ENOREC, a) for a in aliases: try: ur.rm_uri(a, force=force) except Error, inst: warning(str(inst))
def add(self, uri, aliases, force=False): do = Domain(self.dburi, self.db) ur = Uri(self.dburi, self.db) us = User(self.dburi, self.db) try: uid = ur.get_uid(uri) except: if force: return raise try: user, did = ur.uri2id(uri) except: if force: return raise if not us.exist(uid): if force: return raise Error (ENOUSER, user) aliases = uniq(aliases) try: n = aliases.index(uri) aliases = aliases[:n] + aliases[n+1:] except: pass for a in aliases: if ur.exist_uri(a) and not force: raise Error (EDUPL, a) u, d = split_sip_uri(a) if not do.exist_domain(d) and not force: raise Error (ENODOMAIN, d) for a in aliases: try: ur.add(uid, a, force=force) except Error, inst: warning(str(inst))
def reload(self): try: exists = [ i for i in self.ser.system.listMethods() if i[-7:] == '.reload' ] except xmlrpclib.Fault, inst: warning("ListMethods failed: %s" % str(inst)) return
def _wnote(self, warn): if warn: print "For the change to take effect on all machines in the cluster once available, execute the following command: 'ser_ctl reload'." def raw_cmd(self, cmd, par=[]): warn = [] for server in self.servers: ser = ServerProxy(server, self.ssl) method = getattr(ser, cmd) try: apply(method, par) except xmlrpclib.Fault, inst: warning("RPC on '%s' failed: %s" % (server, str(inst))) warn.append(server) except: warning("RPC on '%s' failed: %s" % (server, str(sys.exc_info()[0]))) warn.append(server) self._wnote(warn) def cmd(self, cmd, *par): return self.raw_cmd(cmd, par) def cmd_if_exist(self, cmd, par=[]): warn = [] for server in self.servers: try: ser = ServerProxy(server, self.ssl) if cmd not in ser.system.listMethods(): continue except xmlrpclib.Fault, inst: warning("ListMethods on '%s' failed: %s" % (server, str(inst))) warn.append(server)
def add(self, uri, aliases, password, idtype=ID_URI, force=False): do = Domain(self.dburi, self.db) da = Domain_attrs(self.dburi, self.db) ur = Uri(self.dburi, self.db) cr = Cred(self.dburi, self.db) us = User(self.dburi, self.db) user, domain = split_sip_uri(uri) aliases = uniq(aliases) try: n = aliases.index(uri) aliases = aliases[:n] + aliases[n+1:] except: pass aliases = [ split_sip_uri(a) for a in aliases ] uid = id(user + '@' + domain, idtype) if us.exist(uid): if not force: raise Error (EDUPL, errstr(uid=uid)) if cr.exist(user, domain): if not force: raise Error (EDUPL, errstr(auth_username=user, domain=domain)) if not do.exist_domain(domain): if force: i = id(domain, idtype) do.add(i, domain, force=force) else: raise Error (ENODOMAIN, domain) did = do.get_did(domain) try: realm = da.get(did, 'digest_realm') except: if force: realm = domain else: raise for u, d in aliases: if not do.exist_domain(d): if force: i = id(d, idtype) do.add(i, d, force=force) else: raise Error (ENODOMAIN, d) did = do.get_did(d) if ur.exist_username_did(u, did) and not force: raise Error (EDUPL, '%s@%s' % (u, d)) did = do.get_did(domain) if ur.exist(uid, user, did): if not force: raise Error(EDUPL, errstr(uid=uid, username=user, did=did)) us.add(uid, force=force) cr.add(uid, user, did, realm, password, force=force) ur.add(uid, uri, force=force) for u, d in aliases: uri = '%s@%s' % (u, d) try: ur.add(uid, uri, force=force) except Error, inst: warning(str(inst))