From b48656ee84f74604103b744b524afeb9cebd168d Mon Sep 17 00:00:00 2001 From: Anish Mehta Date: Wed, 19 Aug 2015 11:13:14 -0700 Subject: [PATCH] To handles UVE key that include "/", we need to re-organize the bottle match rules. bottle matches rules according to a priority order. As part of re-organizing these rules, url that have "/analytics/', 'GET', obj.uve_http_get) - bottle.route( - '/analytics/virtual-machine/', 'GET', obj.uve_http_get) - bottle.route( - '/analytics/service-instance/', 'GET', obj.uve_http_get) - bottle.route( - '/analytics/service-chain/', 'GET', obj.uve_http_get) - bottle.route('/analytics/vrouter/', 'GET', obj.uve_http_get) - bottle.route('/analytics/bgp-router/', 'GET', obj.uve_http_get) - bottle.route('/analytics/bgp-peer/', 'GET', obj.uve_http_get) - bottle.route('/analytics/xmpp-peer/', 'GET', obj.uve_http_get) - bottle.route('/analytics/collector/', 'GET', obj.uve_http_get) - bottle.route('/analytics/generator/', 'GET', obj.uve_http_get) - bottle.route('/analytics/config-node/', 'GET', obj.uve_http_get) - bottle.route('/analytics/query', 'POST', obj.query_process) - bottle.route('/analytics/query/', 'GET', obj.query_status_get) - bottle.route('/analytics/query//chunk-final/', - 'GET', obj.query_chunk_get) - bottle.route('/analytics/queries', 'GET', obj.show_queries) - bottle.route('/analytics/tables', 'GET', obj.tables_process) - bottle.route('/analytics/operation/database-purge', - 'POST', obj.process_purge_request) - bottle.route('/analytics/operation/analytics-data-start-time', - 'GET', obj._get_analytics_data_start_time) - bottle.route('/analytics/table/', 'GET', obj.table_process) - bottle.route( - '/analytics/table/
/schema', 'GET', obj.table_schema_process) - for i in range(0, len(_TABLES)): - if len(_TABLES[i].columnvalues) > 0: - bottle.route('/analytics/table/
/column-values', - 'GET', obj.column_values_process) - bottle.route('/analytics/table/
/column-values/', - 'GET', obj.column_process) - bottle.route('/analytics/send-tracebuffer////', - 'GET', obj.send_trace_buffer) - bottle.route('/documentation/', 'GET', - obj.documentation_http_get) - - for uve in UVE_MAP: - bottle.route( - '/analytics/uves/' + uve + 's', 'GET', obj.uve_list_http_get) - bottle.route( - '/analytics/uves/' + uve + '/', 'GET', obj.uve_http_get) - bottle.route( - '/analytics/uves/' + uve, 'POST', obj.uve_http_post) - bottle.route( - '/analytics/alarms/' + uve + 's', 'GET', obj.alarm_list_http_get) - bottle.route( - '/analytics/alarms/' + uve + '/', 'GET', obj.alarm_http_get) - bottle.route( - '/analytics/alarms/' + uve, 'POST', obj.alarm_http_post) - bottle.route( - '/analytics/alarms/' + uve +'s/types', 'GET', obj.alarm_http_types) - - return obj - # end __new__ - def disc_publish(self): try: import discoveryclient.client as client @@ -636,32 +557,6 @@ def __init__(self): bottle.route('/analytics', 'GET', self.analytics_http_get) bottle.route('/analytics/uves', 'GET', self.uves_http_get) bottle.route('/analytics/alarms', 'GET', self.alarms_http_get) - bottle.route( - '/analytics/virtual-networks', 'GET', self.uve_list_http_get) - bottle.route( - '/analytics/virtual-machines', 'GET', self.uve_list_http_get) - bottle.route( - '/analytics/service-instances', 'GET', self.uve_list_http_get) - bottle.route( - '/analytics/service-chains', 'GET', self.uve_list_http_get) - bottle.route('/analytics/vrouters', 'GET', self.uve_list_http_get) - bottle.route('/analytics/bgp-routers', 'GET', self.uve_list_http_get) - bottle.route('/analytics/collectors', 'GET', self.uve_list_http_get) - bottle.route('/analytics/generators', 'GET', self.uve_list_http_get) - bottle.route('/analytics/config-nodes', 'GET', self.uve_list_http_get) - bottle.route( - '/analytics/virtual-network/', 'GET', self.uve_http_get) - bottle.route( - '/analytics/virtual-machine/', 'GET', self.uve_http_get) - bottle.route( - '/analytics/service-instance/', 'GET', self.uve_http_get) - bottle.route( - '/analytics/service-chain/', 'GET', self.uve_http_get) - bottle.route('/analytics/vrouter/', 'GET', self.uve_http_get) - bottle.route('/analytics/bgp-router/', 'GET', self.uve_http_get) - bottle.route('/analytics/collector/', 'GET', self.uve_http_get) - bottle.route('/analytics/generator/', 'GET', self.uve_http_get) - bottle.route('/analytics/config-node/', 'GET', self.uve_http_get) bottle.route('/analytics/query', 'POST', self.query_process) bottle.route( '/analytics/query/', 'GET', self.query_status_get) @@ -687,21 +582,10 @@ def __init__(self): bottle.route('/documentation/', 'GET', self.documentation_http_get) - for uve in UVE_MAP: - bottle.route( - '/analytics/uves/' + uve + 's', 'GET', self.uve_list_http_get) - bottle.route( - '/analytics/uves/' + uve + '/', 'GET', self.uve_http_get) - bottle.route( - '/analytics/uves/' + uve, 'POST', self.uve_http_post) - bottle.route( - '/analytics/alarms/' + uve + 's', 'GET', self.alarm_list_http_get) - bottle.route( - '/analytics/alarms/' + uve + '/', 'GET', self.alarm_http_get) - bottle.route( - '/analytics/alarms/' + uve, 'POST', self.alarm_http_post) - bottle.route( - '/analytics/alarms/' + uve +'s/types', 'GET', self.alarm_http_types) + bottle.route('/analytics//', 'GET', self.dyn_list_http_get) + bottle.route('/analytics//
/', 'GET', self.dyn_http_get) + bottle.route('/analytics//', 'POST', self.dyn_http_post) + bottle.route('/analytics/alarms//types', 'GET', self._uve_alarm_http_types) # start gevent to monitor disk usage and automatically purge if (self._args.auto_db_purge): @@ -709,6 +593,36 @@ def __init__(self): # end __init__ + def dyn_http_get(self, uvealarm, table, name): + is_alarm = None + if uvealarm == "uves": + is_alarm = False + elif uvealarm == "alarms": + is_alarm = True + else: + return {} + return self._uve_alarm_http_get(table, name, is_alarm) + + def dyn_list_http_get(self, uvealarm, tables): + is_alarm = None + if uvealarm == "uves": + is_alarm = False + elif uvealarm == "alarms": + is_alarm = True + else: + return [] + return self._uve_alarm_list_http_get(is_alarm) + + def dyn_http_post(self, uvealarm, tables): + is_alarm = None + if uvealarm == "uves": + is_alarm = False + elif uvealarm == "alarms": + is_alarm = True + else: + return {} + return self._uve_alarm_http_post(is_alarm) + def _parse_args(self, args_str=' '.join(sys.argv[1:])): ''' Eg. python opserver.py --host_ip 127.0.0.1 @@ -1407,71 +1321,47 @@ def _uve_alarm_http_post(self, is_alarm): yield u']}' # end _uve_alarm_http_post - def uve_http_post(self): - return self._uve_alarm_http_post(is_alarm=False) - # end uve_http_post - - def alarm_http_post(self): - return self._uve_alarm_http_post(is_alarm=True) - # end alarm_http_post - - def _uve_alarm_http_get(self, name, is_alarm): + def _uve_alarm_http_get(self, uve_type, name, is_alarm): # common handling for all resource get (ok, result) = self._get_common(bottle.request) if not ok: (code, msg) = result abort(code, msg) - uve_type = bottle.request.url.rsplit('/', 2)[1] - try: + uve_tbl = uve_type + if uve_type in UVE_MAP: uve_tbl = UVE_MAP[uve_type] + + bottle.response.set_header('Content-Type', 'application/json') + uve_name = uve_tbl + ':' + name + req = bottle.request.query + try: + filters = OpServer._uve_filter_set(req) except Exception as e: - yield {} + yield bottle.HTTPError(_ERRORS[errno.EBADMSG], e) + + flat = False + if 'flat' in req.keys() or any(filters.values()): + flat = True + if name.find('*') != -1: + flat = True + yield u'{"value": [' + first = True + if filters['kfilt'] is None: + filters['kfilt'] = [name] + for gen in self._uve_server.multi_uve_get(uve_tbl, flat, + filters, is_alarm): + if first: + yield u'' + json.dumps(gen) + first = False + else: + yield u', ' + json.dumps(gen) + yield u']}' else: - bottle.response.set_header('Content-Type', 'application/json') - uve_name = uve_tbl + ':' + name - req = bottle.request.query - try: - filters = OpServer._uve_filter_set(req) - except Exception as e: - yield bottle.HTTPError(_ERRORS[errno.EBADMSG], e) - - flat = False - if 'flat' in req.keys() or any(filters.values()): - flat = True - - uve_name = uve_tbl + ':' + name - if name.find('*') != -1: - flat = True - yield u'{"value": [' - first = True - if filters['kfilt'] is None: - filters['kfilt'] = [name] - for gen in self._uve_server.multi_uve_get(uve_tbl, flat, - filters, is_alarm): - if first: - yield u'' + json.dumps(gen) - first = False - else: - yield u', ' + json.dumps(gen) - yield u']}' - else: - rsp = self._uve_server.get_uve(uve_name, flat, filters, - is_alarm=is_alarm) - yield json.dumps(rsp) + rsp = self._uve_server.get_uve(uve_name, flat, filters, + is_alarm=is_alarm) + yield json.dumps(rsp) # end _uve_alarm_http_get - def uve_http_get(self, name): - return self._uve_alarm_http_get(name, is_alarm=False) - # end uve_http_get - - def alarm_http_get(self, name): - return self._uve_alarm_http_get(name, is_alarm=True) - # end alarm_http_get - - def alarm_http_types(self): - return self._uve_alarm_http_types() - # end alarm_http_get - def _uve_alarm_http_types(self): # common handling for all resource get (ok, result) = self._get_common(bottle.request) @@ -1536,14 +1426,6 @@ def _uve_alarm_list_http_get(self, is_alarm): return json.dumps(uve_links) # end _uve_alarm_list_http_get - def uve_list_http_get(self): - return self._uve_alarm_list_http_get(is_alarm=False) - # end uve_list_http_get - - def alarm_list_http_get(self): - return self._uve_alarm_list_http_get(is_alarm=True) - # end alarm_list_http_get - def analytics_http_get(self): # common handling for all resource get (ok, result) = self._get_common(bottle.request) diff --git a/src/opserver/test/utils/opserver_introspect_utils.py b/src/opserver/test/utils/opserver_introspect_utils.py index d8a9b46847b..00b51f0eba0 100644 --- a/src/opserver/test/utils/opserver_introspect_utils.py +++ b/src/opserver/test/utils/opserver_introspect_utils.py @@ -22,13 +22,13 @@ def __init__(self, ip, port=8081): super(VerificationOpsSrv, self).__init__(ip, port) def get_ops_vm(self, vm='default-virtual-machine'): - vm_dict = self.dict_get('analytics/virtual-machine/' + vm) + vm_dict = self.dict_get('analytics/uves/virtual-machine/' + vm) return OpVMResult(vm_dict) def get_ops_vn(self, vn='default-virtual-network'): res = None try: - vn_dict = self.dict_get('analytics/virtual-network/' + vn) + vn_dict = self.dict_get('analytics/uves/virtual-network/' + vn) res = OpVNResult(vn_dict) except Exception as e: print e @@ -41,7 +41,7 @@ def get_ops_collector(self, col=None): res = None try: #import pdb; pdb.set_trace() - col_dict = self.dict_get('analytics/collector/' + col) + col_dict = self.dict_get('analytics/uves/analytics-node/' + col) res = OpCollectorResult(col_dict) except Exception as e: print e