def test_generic_report_with_units_fails_well(self, mock_handler): """Test that validation error is thrown for bad unit conversion.""" mock_handler.return_value.execute_query.return_value = self.report # The 'bad' unit here is that the report is in GB-Mo, and can't # convert to seconds params = { 'group_by[account]': '*', 'filter[resolution]': 'monthly', 'filter[time_scope_value]': '-1', 'filter[time_scope_units]': 'month', 'units': 'second' } user = User.objects.filter( username=self.customer_data[0]['owner']['username'] ).first() django_request = HttpRequest() qd = QueryDict(mutable=True) qd.update(params) django_request.GET = qd request = Request(django_request) request.user = user with self.assertRaises(ValidationError): _generic_report(request, 'usage_amount', 'cost_entry_pricing__unit')
def test_generic_report_with_units_fails_well(self, mock_handler): """Test that validation error is thrown for bad unit conversion.""" mock_handler.return_value.execute_query.return_value = self.report # The 'bad' unit here is that the report is in GB-Mo, and can't # convert to seconds params = { 'group_by[account]': '*', 'filter[resolution]': 'monthly', 'filter[time_scope_value]': '-1', 'filter[time_scope_units]': 'month', 'units': 'second' } user = User.objects.get(username=self.user_data['username']) django_request = HttpRequest() qd = QueryDict(mutable=True) qd.update(params) django_request.GET = qd request = Request(django_request) request.user = user with self.assertRaises(ValidationError): extras = {'report_type': 'costs'} _generic_report(request, QueryParamSerializer, mock_handler, **extras)
def test_generic_report_with_units_success(self, mock_handler): """Test unit conversion succeeds in generic report.""" mock_handler.return_value.execute_query.return_value = self.report params = { 'group_by[account]': '*', 'filter[resolution]': 'monthly', 'filter[time_scope_value]': '-1', 'filter[time_scope_units]': 'month', 'units': 'byte' } user = User.objects.filter( username=self.customer_data[0]['owner']['username'] ).first() django_request = HttpRequest() qd = QueryDict(mutable=True) qd.update(params) django_request.GET = qd request = Request(django_request) request.user = user response = _generic_report( request, 'usage_amount', 'cost_entry_pricing__unit' ) self.assertIsInstance(response, Response)
def aws_tags(request): """Get AWS tags. @api {get} /cost-management/v1/tags/aws/ @apiName getAWSTagData @apiGroup Report @apiVersion 1.0.0 @apiDescription Get AWS tag keys. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "filter": { "resolution": "daily", "time_scope_value": "-10", "time_scope_units": "day" }, "data": [ "production", "staging", "test", ] } """ return _generic_report(request, provider='aws', report='tags')
def test_generic_report_ocp_mem_success(self, mock_handler): """Test OCP memory generic report.""" mock_handler.return_value.execute_query.return_value = self.report_ocp_mem params = { 'group_by[account]': '*', 'filter[resolution]': 'monthly', 'filter[time_scope_value]': '-1', 'filter[time_scope_units]': 'month' } user = User.objects.get( username=self.user_data['username'] ) django_request = HttpRequest() qd = QueryDict(mutable=True) qd.update(params) django_request.GET = qd request = Request(django_request) request.user = user response = _generic_report(request, report='memory', provider='ocp') self.assertIsInstance(response, Response)
def test_generic_report_with_units_success(self, mock_handler): """Test unit conversion succeeds in generic report.""" mock_handler.return_value.execute_query.return_value = self.report params = { 'group_by[account]': '*', 'filter[resolution]': 'monthly', 'filter[time_scope_value]': '-1', 'filter[time_scope_units]': 'month', 'units': 'byte', 'SERVER_NAME': '' } user = User.objects.get(username=self.user_data['username']) django_request = HttpRequest() qd = QueryDict(mutable=True) qd.update(params) django_request.GET = qd request = Request(django_request) request.user = user response = _generic_report(request, provider='aws', report='costs') self.assertIsInstance(response, Response)
def test_generic_report_ocp_cpu_success(self, mock_handler): """Test OCP cpu generic report.""" mock_handler.return_value.execute_query.return_value = self.report_ocp_cpu params = { 'group_by[account]': '*', 'filter[resolution]': 'monthly', 'filter[time_scope_value]': '-1', 'filter[time_scope_units]': 'month' } user = User.objects.get(username=self.user_data['username']) django_request = HttpRequest() qd = QueryDict(mutable=True) qd.update(params) django_request.GET = qd request = Request(django_request) request.user = user extras = {'report_type': 'cpu'} response = _generic_report(request, QueryParamSerializer, OCPReportQueryHandler, **extras) self.assertIsInstance(response, Response)
def costs(request): """Get OpenShift on AWS cost usage data. @api {get} /cost-management/v1/reports/openshift/costs/ Get OpenShift cost data @apiName getOpenShiftCostData @apiGroup OpenShift Report @apiVersion 1.0.0 @apiDescription Get OpenShift cost data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[project]=* @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. """ return _generic_report(request, report='costs', provider='ocp_aws')
def ocp_tags(request): """Get OCP tags. @api {get} /api/v1/tags/ocp/ @apiName getOCPTagData @apiGroup Report @apiVersion 1.0.0 @apiDescription Get OCP tag keys. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "filter": { "resolution": "daily", "time_scope_value": "-10", "time_scope_units": "day" }, "data": [ "production", "staging", "test", ] } """ extras = {} return _generic_report(request, OCPTagsQueryParamSerializer, OCPTagQueryHandler, **extras)
def volume(request): """Get OpenShift volume usage data. @api {get} /cost-management/v1/reports/openshift/volume/ Get volume usage data @apiName getOpenShiftVolumeData @apiGroup OpenShift Report @apiVersion 1.0.0 @apiDescription Get OpenShift volume usage data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[project]=* @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP 200 OK Allow: OPTIONS, GET Content-Type: application/json Vary: Accept { "group_by": { "project": [ "*" ] }, "filter": { "resolution": "monthly", "time_scope_value": "-1" }, "data": [ { "date": "2019-02", "projects": [ { "project": "metering-hccm", "values": [ { "date": "2019-02", "project": "metering-hccm", "usage": 283.455815, "request": 14058.333334, "capacity": 13732.252982, "charge": null, "units": "GB-Mo" } ] } ] } ], "total": { "usage": 283.455815, "request": 14058.333334, "capacity": 13732.252982, "charge": null, "units": "GB-Mo" } } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK capacity,charge,date,project,request,units,usage 13732.252982,,2019-02,metering-hccm,14058.333334,GB-Mo,283.455815 """ return _generic_report(request, report='volume', provider='ocp')
def memory(request): """Get OpenShift memory usage data. @api {get} /cost-management/v1/reports/openshift/memory/ Get memory usage data @apiName getOpenshiftMemoryData @apiGroup OpenShift Report @apiVersion 1.0.0 @apiDescription Get OpenShift memory usage data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[project]=* @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "group_by": { "project": [ "*" ] }, "filter": { "resolution": "monthly", "time_scope_value": "-1", "time_scope_units": "month" }, "data": [ { "date": "2018-10", "projects": [ { "project": "default", "values": [ { "date": "2018-10", "project": "default", "memory_usage_gigabytes": 0.162249, "memory_requests_gigabytes": 1.063302 } ] }, { "project": "metering", "values": [ { "date": "2018-10", "project": "metering", "memory_usage_gigabytes": 5.899788, "memory_requests_gigabytes": 7.007081 } ] }, { "project": "monitoring", "values": [ { "date": "2018-10", "project": "monitoring", "memory_usage_gigabytes": 3.178287, "memory_requests_gigabytes": 4.153526 } ] }, { "project": "openshift-web-console", "values": [ { "date": "2018-10", "project": "openshift-web-console", "memory_usage_gigabytes": 0.068988, "memory_requests_gigabytes": 0.207677 } ] } ] } ], "total": { "pod_usage_memory_gigabytes": 9.309312, "pod_request_memory_gigabytes": 12.431585 } } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK cpu_limit,cpu_requests_core_hours,cpu_usage_core_hours,date,project ,9.506666,0.119385,2018-10,default ,53.985832,4.464511,2018-10,metering ,17.920067,7.861343,2018-10,monitoring ,4.753333,0.862687,2018-10,openshift-web-console """ return _generic_report(request, report='memory', provider='ocp')
def costs(request): """Get OpenShift cost data. @api {get} /cost-management/v1/reports/openshift/costs/ Get OpenShift costs data @apiName getOpenShiftCostData @apiGroup OpenShift Report @apiVersion 1.0.0 @apiDescription Get OpenShift cost data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[project]=* @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP 200 OK { "meta": { "count": 1, "group_by": { "project": [ "*" ] }, "filter": { "resolution": "monthly", "time_scope_value": "-1", "time_scope_units": "month" }, "total": { "infrastructure_cost": { "value": 1960.75, "units": "USD" }, "derived_cost": { "value": 0.0, "units": "USD" }, "cost": { "value": 1960.75, "units": "USD" } } }, "links": { "first": "/cost-management/v1/reports/openshift/costs/?filter%5Bresolution%5D=monthly&filter%5Btime_scope_units%5D=month&filter%5Btime_scope_value%5D=-1&group_by%5Bproject%5D=%2A&limit=100&offset=0", # noqa: E501 "next": null, "previous": null, "last": "/local/v1/reports/openshift/costs/?filter%5Bresolution%5D=monthly&filter%5Btime_scope_units%5D=month&filter%5Btime_scope_value%5D=-1&group_by%5Bproject%5D=%2A&limit=100&offset=0" # noqa: E501 }, "data": [ { "date": "2019-03", "projects": [ { "project": "namespace_ci", "values": [ { "date": "2019-03", "project": "namespace_ci", "infrastructure_cost": { "value": 1960.75, "units": "USD" }, "derived_cost": { "value": 0.0, "units": "USD" }, "cost": { "value": 1960.75, "units": "USD" } } ] }, { "project": "namespace_qe", "values": [ { "date": "2019-03", "project": "namespace_qw", "infrastructure_cost": { "value": 0.0, "units": "USD" }, "derived_cost": { "value": 0.0, "units": "USD" }, "cost": { "value": 0.0, "units": "USD" } } ] } ] } ] } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK cost,cost_units,date,derived_cost,infrastructure_cost,project 1960.750000,USD,2019-03,0.000000,1960.750000,namespace_ci 0.000000,USD,2019-03,0.000000,0,namespace_hyper """ return _generic_report(request, report='costs', provider='ocp')
def cpu(request): """Get OpenShift compute usage data. @api {get} /cost-management/v1/reports/openshift/compute/ Get compute usage data @apiName getOpenShiftInventoryCPUData @apiGroup OpenShift Report @apiVersion 1.0.0 @apiDescription Get OpenShift compute usage data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[project]=* @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "group_by": { "project": [ "*" ] }, "filter": { "resolution": "monthly", "time_scope_value": "-1", "time_scope_units": "month" }, "data": [ { "date": "2018-10", "projects": [ { "project": "default", "values": [ { "date": "2018-10", "project": "default", "cpu_limit": null, "cpu_usage_core_hours": 0.119385, "cpu_requests_core_hours": 9.506666 } ] }, { "project": "metering", "values": [ { "date": "2018-10", "project": "metering", "cpu_limit": null, "cpu_usage_core_hours": 4.464511, "cpu_requests_core_hours": 53.985832 } ] }, { "project": "monitoring", "values": [ { "date": "2018-10", "project": "monitoring", "cpu_limit": null, "cpu_usage_core_hours": 7.861343, "cpu_requests_core_hours": 17.920067 } ] }, { "project": "openshift-web-console", "values": [ { "date": "2018-10", "project": "openshift-web-console", "cpu_limit": null, "cpu_usage_core_hours": 0.862687, "cpu_requests_core_hours": 4.753333 } ] } ] } ], "total": { "pod_usage_cpu_core_hours": 13.307928, "pod_request_cpu_core_hours": 86.165898 } } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK cpu_limit,cpu_requests_core_hours,cpu_usage_core_hours,date,project ,9.506666,0.119385,2018-10,default ,53.985832,4.464511,2018-10,metering ,17.920067,7.861343,2018-10,monitoring ,4.753333,0.862687,2018-10,openshift-web-console """ return _generic_report(request, report='cpu', provider='ocp')
def storage(request): """Get inventory storage data. @api {get} /api/v1/reports/inventory/aws/storage Get inventory storage data @apiName getInventoryStorageData @apiGroup Report @apiVersion 1.0.0 @apiDescription Get inventory data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParam (Query Param) {String} units The units used in the report. @apiParamExample {json} Query Param: ?filter[resolution]=daily&filter[time_scope_value]=-10&order_by[cost]=asc&units=byte @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "group_by": { "account": [ "*" ] }, "filter": { "resolution": "monthly", "time_scope_value": "-1", "time_scope_units": "month" }, "data": [ { "date": "2018-08", "accounts": [ { "account": "0840549025238", "values": [ { "date": "2018-08", "units": "GB-Mo", "account": "0840549025238", "total": 4066.923135971 } ] }, { "account": "3082416796941", "values": [ { "date": "2018-08", "units": "GB-Mo", "account": "3082416796941", "total": 3644.58070225345 } ] }, { "account": "8133889256380", "values": [ { "date": "2018-08", "units": "GB-Mo", "account": "8133889256380", "total": 3584.67567749966 } ] }, { "account": "4783090375826", "values": [ { "date": "2018-08", "units": "GB-Mo", "account": "4783090375826", "total": 3096.66740996526 } ] }, { "account": "2415722664993", "values": [ { "date": "2018-08", "units": "GB-Mo", "account": "2415722664993", "total": 2599.75765963921 } ] } ] } ], "total": { "value": 16992.6045853286, "units": "GB-Mo" } } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK account,date,total,units 0840549025238,2018-08,4066.923135971,GB-Mo 3082416796941,2018-08,3644.58070225345,GB-Mo 8133889256380,2018-08,3584.67567749966,GB-Mo 4783090375826,2018-08,3096.66740996526,GB-Mo 2415722664993,2018-08,2599.75765963921,GB-Mo """ extras = {'report_type': 'storage'} return _generic_report(request, QueryParamSerializer, AWSReportQueryHandler, **extras)
def storage(request): """Get OpenShift on AWS storage usage data. @api {get} /cost-management/v1/reports/openshift/infrastructures/aws/storage/ Get OpenShift on AWS storage usage. @apiName getOpenShiftAWSStorageData @apiGroup OpenShift Report @apiVersion 1.0.0 @apiDescription Get OpenShift on AWS storage usage data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[project]=* @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP 200 OK Allow: GET, OPTIONS Content-Type: application/json Vary: Accept { "group_by": { "project": [ "*" ] }, "filter": { "resolution": "monthly", "time_scope_value": "-1", "time_scope_units": "month" }, "data": [ { "date": "2019-01", "projects": [ { "project": "namespace_ci", "values": [ { "date": "2019-01", "units": "GB-Mo", "project": "namespace_ci", "cost": 11.674377, "total": 24.0 } ] } ] } ], "total": { "units": "GB-Mo", "cost": 11.674377, "total": 24.0 } } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK cost,date,project,total,units 11.674377,2019-01,namespace_ci,24.0,GB-Mo """ return _generic_report(request, report='storage', provider='ocp_aws')
def instance_type(request): """Get OpenShift on AWS instance usage data. @api {get} /cost-management/v1/reports/openshift/infrastructures/aws/instance-types/ Get instance data @apiName getOpenShiftAWSInventoryInstanceData @apiGroup OpenShift Report @apiVersion 1.0.0 @apiDescription Get OpenShift on AWS instance usage data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[project]=* @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP 200 OK Allow: OPTIONS, GET Content-Type: application/json Vary: Accept { "group_by": { "project": [ "*" ] }, "filter": { "resolution": "monthly", "time_scope_value": "-2", "time_scope_units": "month" }, "data": [ { "date": "2019-01", "projects": [ { "project": "namespace_ci", "instance_types": [ { "instance_type": "m5.large", "values": [ { "instance_type": "m5.large", "date": "2019-01", "units": "Hrs", "project": "namespace_ci", "cost": 915.889752, "count": 1, "total": 120.0 } ] } ] }, { "project": "namespace_qa", "instance_types": [ { "instance_type": "m5.large", "values": [ { "instance_type": "m5.large", "date": "2019-01", "units": "Hrs", "project": "namespace_qa", "cost": 939.377001, "count": 1, "total": 140.0 } ] } ] } ] } ], "total": { "units": "Hrs", "cost": 1855.266753, "count": 2, "value": 260.0 } } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK cost,count,date,instance_type,project,total,units 915.889752,1,2019-01,m5.large,namespace_ci,1488.0,Hrs 939.377001,1,2019-01,m5.large,namespace_qa,1488.0,Hrs """ return _generic_report(request, report='instance_type', provider='ocp_aws')
def charges(request): """Get OCP cpu usage data. @api {get} /api/v1/reports/charge/ocp/ Get OCP charge data @apiName getOCPChargeData @apiGroup Report @apiVersion 1.0.0 @apiDescription Get OCP charge data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[project]=* @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP 200 OK { "group_by": { "project": [ "*" ] }, "filter": { "resolution": "monthly", "time_scope_value": "-1", "time_scope_units": "month" }, "data": [ { "date": "2018-11", "projects": [ { "project": "monitoring", "values": [ { "date": "2018-11", "project": "monitoring", "charge": 3.2 } ] }, { "project": "metering-hccm", "values": [ { "date": "2018-11", "project": "metering-hccm", "charge": 3.0 } ] } ] } ], "total": { "charge": 6.2 } } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK charge,date,project 3.200000,2018-11,monitoring 3.000000,2018-11,metering-hccm """ tag_keys = get_tag_keys(request) extras = { 'report_type': 'charge', 'tag_keys': tag_keys } return _generic_report(request, OCPChargeQueryParamSerializer, OCPReportQueryHandler, **extras)
def costs(request): """Get cost data. @api {get} /api/v1/reports/costs/aws/ Get cost data @apiName getCostData @apiGroup Report @apiVersion 1.0.0 @apiDescription Get cost data. @apiHeader {String} token User authorization token. @apiHeader {String} accept HTTP Accept header. (See: RFC2616) @apiHeaderExample {json} Header-Example: { "Accept": "text/csv;q=0.8, application/json" } @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[resolution]=daily&filter[time_scope_value]=-10&order_by[cost]=asc @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} order_by The ordering to applied to the report @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "group_by": { "account": [ "*" ] }, "order_by": { "cost": "asc" }, "filter": { "resolution": "daily", "time_scope_value": -10, "time_scope_units": "day", "resource_scope": [] }, "data": [ [ { "date": "2018-05-28", "accounts": [ { "account": "8577742690384", "values": [ { "date": "2018-05-28", "units": "USD", "account": "8577742690384", "total": 1498.92962634 } ] }, { "account": "9420673783214", "values": [ { "date": "2018-05-28", "units": "USD", "account": "9420673783214", "total": 1065.845524241 } ] } ] } ] ] } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK account,date,total,units 6855812392331,2018-07,23008.281583543,USD 3028898336671,2018-07,20826.675630200,USD 7475489704610,2018-07,20305.483875161,USD 2882243055256,2018-07,19474.534357638,USD 6721340654404,2018-07,19356.197856632,USD """ extras = {'report_type': 'costs'} return _generic_report(request, QueryParamSerializer, AWSReportQueryHandler, **extras)
def charges(request): """Get OpenShift charge data. @api {get} /cost-management/v1/reports/openshift/charge/ Get OpenShift charge data @apiName getOpenShiftChargeData @apiGroup OpenShift Report @apiVersion 1.0.0 @apiDescription Get OpenShift charge data. @apiHeader {String} token User authorization token. @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParamExample {json} Query Param: ?filter[time_scope_units]=month&filter[time_scope_value]=-1&filter[resolution]=monthly&group_by[project]=* @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The report data. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP 200 OK { "group_by": { "project": [ "*" ] }, "filter": { "resolution": "monthly", "time_scope_value": "-1", "time_scope_units": "month" }, "data": [ { "date": "2018-11", "projects": [ { "project": "monitoring", "values": [ { "date": "2018-11", "project": "monitoring", "charge": 3.2 } ] }, { "project": "metering-hccm", "values": [ { "date": "2018-11", "project": "metering-hccm", "charge": 3.0 } ] } ] } ], "total": { "charge": 6.2 } } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK charge,date,project 3.200000,2018-11,monitoring 3.000000,2018-11,metering-hccm """ return _generic_report(request, report='charge', provider='ocp')
def instance_type(request): """Get inventory data. @api {get} /api/v1/reports/inventory/aws/instance-type/ Get inventory instance type data @apiName getInventoryInstanceTypeData @apiGroup Report @apiVersion 1.0.0 @apiDescription Get inventory instance type data. @apiHeader {String} token User authorization token. @apiHeader {String} accept HTTP Accept header. (See: RFC2616) @apiHeaderExample {json} Header-Example: { "Accept": "text/csv;q=0.8, application/json" } @apiParam (Query Param) {Object} filter The filter to apply to the report. @apiParam (Query Param) {Object} group_by The grouping to apply to the report. @apiParam (Query Param) {Object} order_by The ordering to apply to the report. @apiParam (Query Param) {String} units The units used in the report. @apiParamExample {json} Query Param: ?filter[resolution]=daily&filter[time_scope_value]=-10&order_by[cost]=asc&group_by[account]=*&units=hours @apiSuccess {Object} group_by The grouping to applied to the report. @apiSuccess {Object} filter The filter to applied to the report. @apiSuccess {Object} data The data including types, usage, and distinct number of instances for a time period. @apiSuccess {Object} total Aggregates statistics for the report range. @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "group_by": { "account": [ "*" ] }, "filter": { "resolution": "daily", "time_scope_value": -10, "time_scope_units": "day", "resource_scope": [] }, "data": [ [ { "date": "2018-05-28", "accounts": [ { "account": 111111111111 , "instance_types": [ { "instance_type": "t2.medium", "values": [ { "date": "2018-05-28", "units": "Hrs", "instance_type": "t2.medium", "total": 5, "count": 1 } ] }, { "instance_type": "m5.2xlarge", "values": [ { "date": "2018-05-28", "units": "Hrs", "instance_type": "m5.2xlarge", "total": 29, "count": 3 } ] } ] } ] }, { "date": "2018-05-29", "accounts": [ { "account": 111111111111 , "instance_types": [ { "instance_type": "m5.2xlarge", "values": [ { "date": "2018-05-28", "units": "Hrs", "instance_type": "m5.2xlarge", "total": 29, "count": 4 } ] } ] } ] } ] ], "total": { "value": 63, "units": "Hrs", "count": 5 } } @apiSuccessExample {text} Success-Response: HTTP/1.1 200 OK account,date,instance_type,total,units 3082416796941,2018-08-05,r4.large,11.0,Hrs 0840549025238,2018-08-05,m5.large,11.0,Hrs 0840549025238,2018-08-05,c5d.2xlarge,9.0,Hrs 8133889256380,2018-08-05,c4.xlarge,8.0,Hrs 3082416796941,2018-08-04,c5d.2xlarge,12.0,Hrs 8133889256380,2018-08-04,c4.xlarge,12.0,Hrs 2415722664993,2018-08-04,r4.large,10.0,Hrs 8133889256380,2018-08-04,r4.large,10.0,Hrs """ annotations = {'instance_type': Concat('cost_entry_product__instance_type', Value(''))} extras = {'annotations': annotations, 'group_by': ['instance_type'], 'report_type': 'instance_type'} return _generic_report(request, QueryParamSerializer, AWSReportQueryHandler, **extras)