from flask_restplus import fields from mlab_api.rest_api import API from mlab_api.format_utils import meta_results_to_csv, meta_data_to_csv, \ meta_data_in_row_to_csv, meta_in_row_to_csv from mlab_api.models.base_models import LOCATION_META_FIELDS, \ METRIC_META_FIELDS, LOCATION_CLIENT_META_FIELDS, \ LOCATION_CLIENT_SERVER_META_FIELDS, LOCATION_SEARCH_META_FIELDS, \ SEARCH_DATA_FIELDS, LOCATION_INFO_DATA_FIELDS, LOCATION_SERVER_META_FIELDS # ------------------------------------------- # Locations: search # ------------------------------------------- LOCATION_SEARCH_RESULT_FIELDS = API.model('Search Result', { 'meta': fields.Nested(LOCATION_SEARCH_META_FIELDS, required=True), 'data': fields.Nested(SEARCH_DATA_FIELDS, required=False) }) LOCATION_SEARCH_MODEL = API.model('Location Search Model', { 'results': fields.List(fields.Nested(LOCATION_SEARCH_RESULT_FIELDS), required=True) }) def location_search_to_csv(data): ''' Convert location search results to CSV ''' return meta_data_in_row_to_csv(data, LOCATION_SEARCH_META_FIELDS, SEARCH_DATA_FIELDS)
''' from flask_restplus import fields from mlab_api.rest_api import API from mlab_api.format_utils import meta_results_to_csv, \ meta_data_in_row_to_csv, meta_data_to_csv from mlab_api.models.base_models import SEARCH_DATA_FIELDS, \ METRIC_META_FIELDS, SERVER_SEARCH_META_FIELDS, SERVER_META_FIELDS # ------------------------------------------- # Servers: search # ------------------------------------------- SERVER_SEARCH_RESULTS_FIELD = API.model('Server ASN Search Result', { 'meta': fields.Nested(SERVER_SEARCH_META_FIELDS, required=True), 'data': fields.Nested(SEARCH_DATA_FIELDS, required=True) }) SERVER_SEARCH_MODEL = API.model('Server ASN Search Results', { 'results': fields.List(fields.Nested(SERVER_SEARCH_RESULTS_FIELD), required=True) }) def server_search_to_csv(data): ''' Converts server search results into a CSV ''' return meta_data_in_row_to_csv(data, SERVER_SEARCH_META_FIELDS, SEARCH_DATA_FIELDS)
from flask_restplus import fields from mlab_api.rest_api import API from mlab_api.id_utils import location_id, location_client_id, \ location_server_id, location_client_server_id, client_id, server_id, \ client_server_id # ---------------------------------------------------- # Generic Data Fields # ---------------------------------------------------- SEARCH_DATA_FIELDS = API.model( 'Search Data', { 'last_three_months_test_count': fields.Integer(description="Test counts over last 3 months."), 'last_six_months_test_count': fields.Integer(description="Test counts in last six months"), 'last_year_test_count': fields.Integer(description="Test counts in last year"), 'test_count': fields.Integer(description="Test counts over entire MLab dataset"), }) # Unfortunately, currently some models include test count in meta and some do # it in data (e.g., see location info vs location+client info). # Ideally this gets fixed at some point. SEARCH_META_FIELDS = API.model( 'Search Meta', { 'last_three_months_test_count': fields.Integer(description="Test counts over last 3 months."), 'last_six_months_test_count': fields.Integer(description="Test counts in last six months"),
from flask_restplus import fields from mlab_api.rest_api import API from mlab_api.format_utils import meta_results_to_csv, meta_data_to_csv, \ meta_data_in_row_to_csv, meta_in_row_to_csv from mlab_api.models.base_models import SEARCH_DATA_FIELDS, \ METRIC_META_FIELDS, CLIENT_SEARCH_META_FIELDS, CLIENT_META_FIELDS, \ CLIENT_SERVER_META_FIELDS # ------------------------------------------- # Clients: search # ------------------------------------------- CLIENT_SEARCH_RESULT_FIELDS = API.model('Client ASN Search Result', { 'meta': fields.Nested(CLIENT_SEARCH_META_FIELDS, required=True), 'data': fields.Nested(SEARCH_DATA_FIELDS, required=True) }) CLIENT_SEARCH_MODEL = API.model('Client ASN Search Results', { 'results': fields.List(fields.Nested(CLIENT_SEARCH_RESULT_FIELDS), required=True) }) def client_search_to_csv(data): ''' Convert client search results to CSV ''' return meta_data_in_row_to_csv(data, CLIENT_SEARCH_META_FIELDS, SEARCH_DATA_FIELDS)
from flask_restplus import fields from mlab_api.rest_api import API from mlab_api.id_utils import location_id, location_client_id, \ location_server_id, location_client_server_id, client_id, server_id, \ client_server_id # ---------------------------------------------------- # Generic Data Fields # ---------------------------------------------------- SEARCH_DATA_FIELDS = API.model('Search Data', { 'last_three_months_test_count': fields.Integer( description="Test counts over last 3 months."), 'last_six_months_test_count': fields.Integer( description="Test counts in last six months"), 'last_year_test_count': fields.Integer( description="Test counts in last year"), 'test_count': fields.Integer( description="Test counts over entire MLab dataset"), }) # Unfortunately, currently some models include test count in meta and some do # it in data (e.g., see location info vs location+client info). # Ideally this gets fixed at some point. SEARCH_META_FIELDS = API.model('Search Meta', { 'last_three_months_test_count': fields.Integer( description="Test counts over last 3 months."), 'last_six_months_test_count': fields.Integer( description="Test counts in last six months"), 'last_year_test_count': fields.Integer( description="Test counts in last year"),
from flask_restplus import fields from mlab_api.rest_api import API from mlab_api.format_utils import meta_results_to_csv, meta_data_to_csv, \ meta_data_in_row_to_csv, meta_in_row_to_csv from mlab_api.models.base_models import LOCATION_META_FIELDS, \ METRIC_META_FIELDS, LOCATION_CLIENT_META_FIELDS, \ LOCATION_CLIENT_SERVER_META_FIELDS, LOCATION_SEARCH_META_FIELDS, \ SEARCH_DATA_FIELDS, LOCATION_INFO_DATA_FIELDS, LOCATION_SERVER_META_FIELDS # ------------------------------------------- # Locations: search # ------------------------------------------- LOCATION_SEARCH_RESULT_FIELDS = API.model( 'Search Result', { 'meta': fields.Nested(LOCATION_SEARCH_META_FIELDS, required=True), 'data': fields.Nested(SEARCH_DATA_FIELDS, required=False) }) LOCATION_SEARCH_MODEL = API.model( 'Location Search Model', { 'results': fields.List(fields.Nested(LOCATION_SEARCH_RESULT_FIELDS), required=True) }) def location_search_to_csv(data): ''' Convert location search results to CSV '''