def load_json_api_confs(api_path, select=[]): result = "" if os.path.isdir(api_path): api_path = "%s%s%s" % (api_path, '' if api_path.endswith(os.sep) else os.sep, "api_conf.json") if not os.path.exists(api_path): result = rstformater.jsonError(101, "Path Not Found :'%s'" % api_path) else: #load json file json_obj = json.loads(open(api_path).read()) #create api conf list result = {} for conf in json_obj['api_list']: if conf['load']: if conf['tax'] not in result: result[conf['tax']] = {} result[conf['tax']][conf['name']] = { u'enable': conf.get('enable'), u'method': conf.get('method'), u'handler': ''.join([ appendBackSlash(conf.get('url')), conf.get('handler') ]), u'level': conf.get('level'), u'support_result': conf.get('support_result'), u'url': conf.get('url') } result = rstformater.jsonRst(result) return result
def execapi(self, api_url, api_params): ''' execute the execution function in api handler then return a api result ''' api_conf = self.search_api_conf(api_url) print 'api_conf => ', api_conf api_handler = api_conf.get('handler') api_rst = self.invok_api_execfunc(api_handler) return rstformater.jsonRst(api_rst)
def search_api_conf(self, url='', name=''): '''Search api conf in api list''' if self.__apilist == None: self.__apilist = self.preload_apilst() rst_val = None if len(url) > 0: for api in self.__apilist: for apiurl in api.get('resources').get('urls'): if apiurl == url: rst_val = rstformater.jsonRst(api) break if rst_val != None: break elif len(name) > 0: for api in self.__apilist: if api.get('name') == name: rst_val = rstformater.jsonRst(api) break else: rst_val = rstformater.jsonError(301, 'Api not found!') return rst_val
def search_api_conf(self, url='', name=''): '''Search api conf in api list''' if self.__apilist == None : self.__apilist = self.preload_apilst() rst_val = None if len(url) > 0: for api in self.__apilist : for apiurl in api.get('resources').get('urls'): if apiurl == url: rst_val = rstformater.jsonRst(api) break if rst_val != None: break elif len(name) > 0: for api in self.__apilist: if api.get('name') == name: rst_val = rstformater.jsonRst(api) break else: rst_val = rstformater.jsonError(301, 'Api not found!') return rst_val
def load_xml_api_confs(api_path, select=[]): result = "" if os.path.isdir(api_path) : api_path = "%s%s%s" % (api_path, '' if api_path.endswith(os.sep) else os.sep, "api_module_configs.xml") if not os.path.exists(api_path) : result = rstformater.jsonError(101, "Path Not Found :'%s'" % api_path) else : #import from xml.sax import make_parser parser = make_parser() handler = __make_confxml_handler() parser.setContentHandler(handler) try: parser.parse(open(api_path, "r")) except Exception: result = rstformater.jsonError(101, "Exception :'%s'" % Exception.message) result = rstformater.jsonRst(handler.apimodlelist) return result
def load_server_confs(sevrRoot, confPath): """load OpenStorage Server Configurations""" filePath = "" fileName = "server.setting" if isEndWithSlash(confPath): filePath = confPath + fileName else: filePath = appendBackSlash(sevrRoot) + confPath if os.path.exists(filePath): jsonStr = open(filePath).read() jsonData = json.loads(jsonStr) #处理相对路径 jsonData['api_dir'] = parsePath(jsonData['api_dir'], sevrRoot) jsonData['logs_path'] = parsePath(jsonData['logs_path'], sevrRoot) result = rstformater.jsonRst(jsonData) else: result = rstformater.jsonError(101, "Server Configuration File Not Found path:'%s'" % confPath) return result
def load_json_api_confs(api_path, select=[]): result = "" if os.path.isdir(api_path) : api_path = "%s%s%s" % (api_path, '' if api_path.endswith(os.sep) else os.sep, "api_conf.json") if not os.path.exists(api_path) : result = rstformater.jsonError(101, "Path Not Found :'%s'" % api_path) else : #load json file json_obj = json.loads(open(api_path).read()) #create api conf list result = {} for conf in json_obj['api_list'] : if conf['load'] : if conf['tax'] not in result : result[conf['tax']] = {} result[conf['tax']][conf['name']] = {u'enable':conf.get('enable'), u'method':conf.get('method'), u'handler':''.join([appendBackSlash(conf.get('url')), conf.get('handler')]), u'level':conf.get('level'), u'support_result':conf.get('support_result'), u'url':conf.get('url') } result = rstformater.jsonRst(result) return result
def load_xml_api_confs(api_path, select=[]): result = "" if os.path.isdir(api_path): api_path = "%s%s%s" % (api_path, '' if api_path.endswith(os.sep) else os.sep, "api_module_configs.xml") if not os.path.exists(api_path): result = rstformater.jsonError(101, "Path Not Found :'%s'" % api_path) else: #import from xml.sax import make_parser parser = make_parser() handler = __make_confxml_handler() parser.setContentHandler(handler) try: parser.parse(open(api_path, "r")) except Exception: result = rstformater.jsonError( 101, "Exception :'%s'" % Exception.message) result = rstformater.jsonRst(handler.apimodlelist) return result
def load_server_confs(sevrRoot, confPath): """load OpenStorage Server Configurations""" filePath = "" fileName = "server.setting" if isEndWithSlash(confPath): filePath = confPath + fileName else: filePath = appendBackSlash(sevrRoot) + confPath if os.path.exists(filePath): jsonStr = open(filePath).read() jsonData = json.loads(jsonStr) #处理相对路径 jsonData['api_dir'] = parsePath(jsonData['api_dir'], sevrRoot) jsonData['logs_path'] = parsePath(jsonData['logs_path'], sevrRoot) result = rstformater.jsonRst(jsonData) else: result = rstformater.jsonError( 101, "Server Configuration File Not Found path:'%s'" % confPath) return result