def __init__(self, host=edog_host, port=edog_port, sql_url=sql_url, misc_url=misc_url): self.rs = RestSql(host=host, who='service', port=port, url=sql_url) self.rc = RestCtrl(host=host, port=port, url=misc_url)
class SrvcOpt(): def __init__(self, host=edog_host, port=edog_port, sql_url=sql_url, misc_url=misc_url): self.rs = RestSql(host=host, who='service', port=port, url=sql_url) self.rc = RestCtrl(host=host, port=port, url=misc_url) def __call__(self): return self def select(self, what='*', where=None, limit=None, orderby=None, headers={}): rslt = self.rs.select(what=what, where=where, limit=limit, orderby=orderby, headers=headers) if rslt == {'result': 'empty'} or not rslt: return [] return rslt def start(self, ip=None, service=None, serviceId=None): ''' ''' return self.rc.start(ip=ip, service=service, serviceId=serviceId) def stop(self, ip=None, service=None, serviceId=None): ''' ''' return self.rc.stop(ip=ip, service=servcie, serviceId=serviceId)
class YlvmOpt(): def __init__(self): self.rc = RestCtrl(host=edog_host, port=edog_port) def create(self, name, size): """ <type 'dict'> {u'result': True} """ ns = self.rc.set_ylvm("create", name, size) print "lvm create:", ns if not type(ns) == type({}): raise Exception("%s lvm create error." % (edog_host)) if "result" in ns.keys() and ns["result"] == True: pass else: raise Exception("%s lvm create error." % (edog_host)) def resize(self, name, size): """ <type 'dict'> {u'result': True} """ ns = self.rc.set_ylvm("resize", name, size) # print type(ns) print "lvm resize:", ns if not type(ns) == type({}): raise Exception("%s lvm resize error." % (edog_host)) if "result" in ns.keys() and ns["result"] == True: pass else: raise Exception("%s lvm resize error." % (edog_host)) def list(self): """ """ ns = self.rc.set_ylvm("list") l = 4 ##下面对返回的结果进行约束检查是否满足 if not type(ns) == type([]): raise Exception("%s lvm list返回数据格式操作,format error." % (edog_host)) for i in ns: if not type(i) == type({}): raise Exception("%s lvm list返回数据格式操作,format error." % (edog_host)) if not len(i) == 4: raise Exception("%s lvm list返回数据格式操作,format error." % (edog_host)) keys = i.keys() if "id" not in keys or "name" not in keys \ or "fileid" not in keys or "size" not in keys: raise Exception("%s lvm list返回数据格式操作,format error." % (edog_host)) return ns
class YlvmOpt(): def __init__(self): self.rc = RestCtrl(host=edog_host, port=edog_port) def create(self, name, size): """ <type 'dict'> {u'result': True} """ ns = self.rc.set_ylvm("create", name, size) print "lvm create:", ns if not type(ns) == type({}): raise Exception("%s lvm create error."%(edog_host)) if "result" in ns.keys() and ns["result"] == True: pass else: raise Exception("%s lvm create error."%(edog_host)) def resize(self, name, size): """ <type 'dict'> {u'result': True} """ ns = self.rc.set_ylvm("resize", name, size) # print type(ns) print "lvm resize:", ns if not type(ns) == type({}): raise Exception("%s lvm resize error."%(edog_host)) if "result" in ns.keys() and ns["result"] == True: pass else: raise Exception("%s lvm resize error."%(edog_host)) def list(self): """ """ ns = self.rc.set_ylvm("list") l = 4 ##下面对返回的结果进行约束检查是否满足 if not type(ns) == type([]): raise Exception("%s lvm list返回数据格式操作,format error."%(edog_host)) for i in ns: if not type(i) == type({}): raise Exception("%s lvm list返回数据格式操作,format error."%(edog_host)) if not len(i) == 4: raise Exception("%s lvm list返回数据格式操作,format error."%(edog_host)) keys = i.keys() if "id" not in keys or "name" not in keys \ or "fileid" not in keys or "size" not in keys: raise Exception("%s lvm list返回数据格式操作,format error."%(edog_host)) return ns
class YlogOpt(): def __init__(self): self.rc = RestCtrl(host=edog_host, port=edog_port) def get_log(self, ip, stype, n, level=None, lines=None): """ """ rest = self.rc.get_log(ip, stype, n, level, lines) if not type(rest) == type({}): raise Exception("%s response error.get log" % (ip)) if "result" in rest.keys() and len(rest) == 1: pass else: raise Exception("%s response error.get log" % (ip)) return rest["result"].split("\n") def clean_log_all(self): """ """ rest = self.rc.clean_log_all() if not type(rest) == type({}): raise Exception("%s response error.get log" % (ip)) if "result" in rest.keys() and len(rest) == 1: pass else: raise Exception("%s response error.get log" % (ip)) return rest pass def dump_log_all(self): """ """ rest = self.rc.dump_log_all() if not type(rest) == type({}): raise Exception("%s response error.get log" % (ip)) if "result" in rest.keys() and len(rest) == 1: pass else: raise Exception("%s response error.get log" % (ip)) return rest def get_log_all(self, ip, stype, n, level=None, lines=None): """ """ rest = self.rc.get_log("192.168.1.201", "mds", 1, level, lines) return "log_all"
class YlogOpt(): def __init__(self): self.rc = RestCtrl(host=edog_host, port=edog_port) def get_log(self, ip, stype, n, level = None, lines = None): """ """ rest = self.rc.get_log(ip, stype, n, level, lines) if not type(rest) == type({}): raise Exception("%s response error.get log"%(ip)) if "result" in rest.keys() and len(rest) == 1: pass else: raise Exception("%s response error.get log"%(ip)) return rest["result"].split("\n") def clean_log_all(self): """ """ rest = self.rc.clean_log_all() if not type(rest) == type({}): raise Exception("%s response error.get log"%(ip)) if "result" in rest.keys() and len(rest) == 1: pass else: raise Exception("%s response error.get log"%(ip)) return rest pass def dump_log_all(self): """ """ rest = self.rc.dump_log_all() if not type(rest) == type({}): raise Exception("%s response error.get log"%(ip)) if "result" in rest.keys() and len(rest) == 1: pass else: raise Exception("%s response error.get log"%(ip)) return rest def get_log_all(self, ip, stype, n, level = None, lines = None): """ """ rest = self.rc.get_log("192.168.1.201", "mds", 1, level, lines) return "log_all"
class SrvcOpt(): def __init__(self, host=edog_host, port=edog_port, sql_url=sql_url, misc_url=misc_url): self.rs = RestSql(host=host, who='service', port=port, url=sql_url) self.rc = RestCtrl(host=host, port=port, url=misc_url) def __call__(self): return self def select(self, what='*', where=None, limit=None, orderby=None, headers={}): rslt = self.rs.select(what=what, where=where, limit=limit, orderby=orderby, headers=headers) if rslt == {'result':'empty'} or not rslt: return [] return rslt def start(self, ip=None, service=None, serviceId=None): ''' ''' return self.rc.start(ip=ip, service=service, serviceId=serviceId) def stop(self, ip=None, service=None, serviceId=None): ''' ''' return self.rc.stop(ip=ip, service=servcie, serviceId=serviceId)
class ConfOpt(): def __init__(self): self.rc = RestCtrl(host=edog_host, port=edog_port) def get_conf(self): """ """ ns = self.rc.get_conf() ##下面对返回的结果进行约束检查是否满足 l = 6 wantkeys = ["doc", "value", "catagory", "mode", "key", "type"] if not type(ns) == type([]): raise Exception("edog get_conf返回数据格式操作,format error.") for i in ns: if not type(i) == type({}): raise Exception("edog get_conf 返回数据格式操作,format error.") if not len(i) == 6: raise Exception("edog get_conf 返回数据格式操作,format error.") keys = i.keys() for key in keys: if key not in wantkeys: raise Exception("edog get_conf 返回数据格式操作,format error.") return ns
def __init__(self): self.rc = RestCtrl(host=edog_host, port=edog_port)
def __init__(self, host=edog_host, port=edog_port, misc_url=misc_url): RestCtrl.__init__(self, host=host, port=port, url=misc_url)