Skip to content

Commit bc8ef27

Browse files
committed
PR comments
1 parent ed066d7 commit bc8ef27

File tree

3 files changed

+40
-62
lines changed

3 files changed

+40
-62
lines changed

linode_api4/groups/monitor_service.py

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from typing import Optional
2+
3+
from linode_api4 import (
4+
PaginatedList,
5+
)
16
from linode_api4.errors import UnexpectedResponseError
27
from linode_api4.groups import Group
38
from linode_api4.objects import (
@@ -15,100 +20,75 @@ class MonitorGroup(Group):
1520
This group contains all features beneath the `/monitor` group in the API v4.
1621
"""
1722

18-
def dashboards(self, *filters) -> list[MonitorDashboard]:
23+
def dashboards(
24+
self, service_type: Optional[str] = None, *filters
25+
) -> PaginatedList:
1926
"""
20-
Returns a list of dashboards.
27+
Returns a list of dashboards. If `service_type` is provided, it fetches dashboards
28+
for the specific service type. If None, it fetches all dashboards.
2129
22-
dashboards = client.monitor_service.list_monitor_dashboards()
30+
dashboards = client.monitor_service.dashboards()
2331
dashboard = client.load(MonitorDashboard, 1)
32+
dashboards_by_service = client.monitor_service.dashboards(service_type="dbaas")
2433
2534
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
2635
27-
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-dashboards-all
36+
API Documentation:
37+
- All Dashboards: https://techdocs.akamai.com/linode-api/reference/get-dashboards-all
38+
- Dashboards by Service: https://techdocs.akamai.com/linode-api/reference/get-dashboards
2839
40+
:param service_type: The service type to get dashboards for.
41+
:type service_type: Optional[str]
2942
:param filters: Any number of filters to apply to this query.
3043
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
3144
for more details on filtering.
3245
3346
:returns: A list of Dashboards.
3447
:rtype: PaginatedList of Dashboard
3548
"""
36-
37-
return self.client._get_and_filter(MonitorDashboard, *filters)
38-
39-
def dashboards_by_service(
40-
self, service_type: str, *filters
41-
) -> list[MonitorDashboard]:
42-
"""
43-
Returns a list of dashboards for a particular service.
44-
45-
dashboard_by_service = client.monitor_service.list_dashboards_by_service(service_type="dbaas")
46-
47-
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
48-
49-
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-dashboards
50-
51-
:param service_type: The service type to get dashboards for.
52-
:type service_type: str
53-
:param filters: Any number of filters to apply to this query.
54-
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
55-
for more details on filtering.
56-
57-
:returns: Dashboards filtered by Service Type.
58-
:rtype: PaginatedList of the Dashboards
59-
"""
49+
endpoint = (
50+
f"/monitor/services/{service_type}/dashboards"
51+
if service_type
52+
else "/monitor/dashboards"
53+
)
6054

6155
return self.client._get_and_filter(
6256
MonitorDashboard,
6357
*filters,
64-
endpoint=f"/monitor/services/{service_type}/dashboards",
58+
endpoint=endpoint,
6559
)
6660

67-
def services(self, *filters) -> list[MonitorService]:
68-
"""
69-
Returns a list of services supported by ACLP.
70-
71-
supported_services = client.monitor_service.list_supported_services()
72-
73-
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
74-
75-
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services
76-
77-
:param filters: Any number of filters to apply to this query.
78-
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
79-
for more details on filtering.
80-
81-
:returns: A list of Supported Services
82-
:rtype: PaginatedList of Services
83-
"""
84-
85-
return self.client._get_and_filter(MonitorService, *filters)
86-
87-
def service_by_type(
88-
self, service_type: str, *filters
61+
def services(
62+
self, service_type: Optional[str] = None, *filters
8963
) -> list[MonitorService]:
9064
"""
91-
Lists monitor services by a given service_type
92-
93-
service_details = client.monitor_service.list_service_by_type(service_type="dbaas")
65+
Lists services supported by ACLP.
66+
supported_services = client.monitor_service.services()
67+
service_details = client.monitor_service.services(service_type="dbaas")
9468
9569
.. note:: This endpoint is in beta. This will only function if base_url is set to `https://api.linode.com/v4beta`.
9670
71+
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services
9772
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services-for-service-type
9873
9974
:param service_type: The service type to get details for.
100-
:type service_type: str
75+
:type service_type: Optional[str]
10176
:param filters: Any number of filters to apply to this query.
10277
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
10378
for more details on filtering.
10479
10580
:returns: Lists monitor services by a given service_type
10681
:rtype: PaginatedList of the Services
10782
"""
83+
endpoint = (
84+
f"/monitor/services/{service_type}"
85+
if service_type
86+
else "/monitor/services"
87+
)
10888
return self.client._get_and_filter(
10989
MonitorService,
11090
*filters,
111-
endpoint=f"/monitor/services/{service_type}",
91+
endpoint=endpoint,
11292
)
11393

11494
def metric_definitions(

test/integration/models/monitor/test_monitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_get_all_dashboards(test_linode_client):
3030
assert dashboard_by_id.id == 1
3131

3232
# #Fetch Dashboard by service_type
33-
dashboards_by_svc = client.monitor_service.dashboards_by_service(
33+
dashboards_by_svc = client.monitor_service.dashboards(
3434
service_type=get_service_type
3535
)
3636
assert isinstance(dashboards_by_svc[0], MonitorDashboard)
@@ -46,7 +46,7 @@ def test_get_supported_services(test_linode_client):
4646
get_supported_service = supported_services[0].service_type
4747

4848
# Get details for a particular service
49-
service_details = client.monitor_service.service_by_type(
49+
service_details = client.monitor_service.services(
5050
service_type=get_supported_service
5151
)
5252
assert isinstance(service_details[0], MonitorService)

test/unit/objects/monitor_service_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_dashboard_by_ID(self):
4343
self.assertEqual(dashboard.widgets[0].y_label, "cpu_usage")
4444

4545
def test_dashboard_by_service_type(self):
46-
dashboards = self.client.monitor_service.dashboards_by_service(
46+
dashboards = self.client.monitor_service.dashboards(
4747
service_type="dbaas"
4848
)
4949
self.assertEqual(dashboards[0].type, "standard")
@@ -87,9 +87,7 @@ def test_get_all_dashboards(self):
8787
self.assertEqual(dashboards[0].widgets[0].y_label, "cpu_usage")
8888

8989
def test_specific_service_details(self):
90-
data = self.client.monitor_service.service_by_type(
91-
service_type="dbaas"
92-
)
90+
data = self.client.monitor_service.services(service_type="dbaas")
9391
self.assertEqual(data[0].label, "Databases")
9492
self.assertEqual(data[0].service_type, "dbaas")
9593

0 commit comments

Comments
 (0)