def test_list_table(): ''' test list_table() ''' result = du.list_table('locations') assert (result == 'client_loc_list') result = du.list_table('locations', 'clients') assert (result == 'client_asn_client_loc_list')
def get_server_info(self, server_id): ''' Get info for a client server_id = id of server. ''' # we are using a hack from list tables # so grab the first match from a list table faceted by server ids' table_name = du.list_table("clients", "servers") table_config = get_table_config(self.table_configs, None, table_name) key_fields = du.get_key_fields([server_id], table_config) prefix_key = du.BIGTABLE_KEY_DELIM.join(key_fields) results = bt.scan_table(table_config, self.get_pool(), prefix=prefix_key, limit=1, filter=FamilyNameRegexFilter('meta')) result = {} if len(results) > 0: result = results[0] return result
def get_table_name(cls, search_type, search_filter): ''' Returns name of table for provided search type. search_type = type of search. search_filter = optional filter we are searching within. ''' if search_filter['type']: # its a list table we want return du.list_table(search_type, search_filter['type']) else: # its a search table we want return du.search_table(search_type)
def get_table_name(cls, search_type, search_filter): ''' Returns name of table for provided search type. search_type = type of search. search_filter = optional filter we are searching within. ''' if search_filter['type']: # its a list table we want return du.list_table(search_type, search_filter['type']) else: # its a search table we want return du.search_table(search_type)
def get_server_info(self, server_id): ''' Get info for a client server_id = id of server. ''' # we are using a hack from list tables # so grab the first match from a list table faceted by server ids' table_name = du.list_table("clients", "servers") table_config = get_table_config(self.table_configs, None, table_name) key_fields = du.get_key_fields([server_id], table_config) return get_bt_results(key_fields, table_config, self.get_pool())
def get_server_info(self, server_id): ''' Get info for a client server_id = id of server. ''' # we are using a hack from list tables # so grab the first match from a list table faceted by server ids' table_name = du.list_table("clients", "servers") table_config = get_table_config(self.table_configs, None, table_name) key_fields = du.get_key_fields([server_id], table_config) return get_bt_results(key_fields, table_config, self.get_pool())
def get_location_client_isp_info(self, location_id, client_id): ''' Get static information about location_id = id string of location. client_id = id string of client. ''' config_id = du.list_table('clients', 'locations') table_config = get_table_config(self.table_configs, None, config_id) key_fields = du.get_key_fields([location_id, client_id], table_config) row_key = du.BIGTABLE_KEY_DELIM.join(key_fields) results = [] results = bt.get_row(table_config, self.get_pool(), row_key) return results
def get_location_info(self, location_id): ''' Get info about specific location location_id = id string of location. ''' table_config = get_table_config(self.table_configs, None, du.list_table('locations')) # add empty field to get child location in there location_key_fields = du.get_key_fields(["info", location_id], table_config) row_key = du.BIGTABLE_KEY_DELIM.join(location_key_fields) row = "" row = bt.get_row(table_config, self.get_pool(), row_key) return row
def get_list_data(self, entity_id, entity_type, query_type, include_data): ''' Helper method to get out data from a list table. entity_id = id of entity to look for entity_type = [locations, clients, servers] query_type = [locations, clients, servers] - what we are faceting on include_data = boolean to indicate if data should be queried and returned. ''' config_id = du.list_table(query_type, entity_type) metric_name = "_".join([entity_type, query_type]) table_config = get_table_config(self.table_configs, None, config_id) key_fields = du.get_key_fields([entity_id], table_config) results = bt.get_list_table_results(key_fields, self.get_pool(), include_data, table_config, metric_name) return {"results": results}
def get_location_children(self, location_id, type_filter=None): ''' Return information about children regions of a location location_id = id string of location. type_filter = optionally restrict results to a location type. ''' table_config = get_table_config(self.table_configs, None, du.list_table('locations')) location_key_fields = du.get_location_key_fields(location_id, table_config) location_key_field = du.BIGTABLE_KEY_DELIM.join(location_key_fields) results = [] results = bt.scan_table(table_config, self.get_pool(), prefix=location_key_field) if type_filter: results = [r for r in results if r['meta']['type'] == type_filter] return {"results": results}
def get_list_data(self, entity_id, entity_type, query_type, include_data): ''' Helper method to get out data from a list table. entity_id = id of entity to look for entity_type = [locations, clients, servers] query_type = [locations, clients, servers] - what we are faceting on include_data = boolean indicates if data should be queried and returned. ''' config_id = du.list_table(query_type, entity_type) metric_name = "_".join([entity_type, query_type]) table_config = get_table_config(self.table_configs, None, config_id) key_fields = du.get_key_fields([entity_id], table_config) results = bt.get_list_table_results( key_fields, self.get_pool(), include_data, table_config, metric_name) return {"results": results}