-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dashboard list] Add new endpoints + dog cmd for dashboard lists #252
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e1785bd
[dashboard list] Add new endpoints + dog cmd for dashboard lists
MLaureB 656fd0c
[dash list] Add PUT endpoint to update dashboards
MLaureB 469d395
[dash list] Fix failing check
MLaureB d57c5c7
[dash list] More CRUD endpoints
MLaureB d418810
[dash list] Fix failing check
MLaureB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from datadog.api.resources import ( | ||
ActionAPIResource, | ||
CreateableAPIResource, | ||
DeletableAPIResource, | ||
GetableAPIResource, | ||
ListableAPIResource, | ||
UpdatableAPIResource | ||
) | ||
|
||
|
||
class DashboardList(ActionAPIResource, CreateableAPIResource, DeletableAPIResource, | ||
GetableAPIResource, ListableAPIResource, UpdatableAPIResource): | ||
""" | ||
A wrapper around Dashboard List HTTP API. | ||
""" | ||
_class_url = '/dashboard/lists/manual' | ||
|
||
@classmethod | ||
def get_dashboards(cls, id, **params): | ||
""" | ||
Get dashboards for a dashboard list. | ||
|
||
:returns: Dictionary representing the API's JSON response | ||
""" | ||
return super(DashboardList, cls)._trigger_class_action('GET', 'dashboards', id, params) | ||
|
||
@classmethod | ||
def add_dashboards(cls, id, **body): | ||
""" | ||
Add dashboards to a dashboard list. | ||
|
||
:param dashboards: dashboards to add to the dashboard list | ||
:type dashboards: list of dashboard dicts, e.g. [{"type": "custom_timeboard", "id": 1104}] | ||
|
||
:returns: Dictionary representing the API's JSON response | ||
""" | ||
return super(DashboardList, cls)._trigger_class_action( | ||
'POST', 'dashboards', id, params=None, **body | ||
) | ||
|
||
@classmethod | ||
def update_dashboards(cls, id, **body): | ||
""" | ||
Update dashboards of a dashboard list. | ||
|
||
:param dashboards: dashboards of the dashboard list | ||
:type dashboards: list of dashboard dicts, e.g. [{"type": "custom_timeboard", "id": 1104}] | ||
|
||
:returns: Dictionary representing the API's JSON response | ||
""" | ||
return super(DashboardList, cls)._trigger_class_action( | ||
'PUT', 'dashboards', id, params=None, **body | ||
) | ||
|
||
@classmethod | ||
def delete_dashboards(cls, id, **body): | ||
""" | ||
Delete dashboards from a dashboard list. | ||
|
||
:param dashboards: dashboards to delete from the dashboard list | ||
:type dashboards: list of dashboard dicts, e.g. [{"type": "custom_timeboard", "id": 1234}] | ||
|
||
:returns: Dictionary representing the API's JSON response | ||
""" | ||
return super(DashboardList, cls)._trigger_class_action( | ||
'DELETE', 'dashboards', id, params=None, **body | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ class Host(ActionAPIResource): | |
_class_url = '/host' | ||
|
||
@classmethod | ||
def mute(cls, host_name, **params): | ||
def mute(cls, host_name, **body): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
""" | ||
Mute a host. | ||
|
||
|
@@ -28,7 +28,7 @@ def mute(cls, host_name, **params): | |
:returns: Dictionary representing the API's JSON response | ||
|
||
""" | ||
return super(Host, cls)._trigger_class_action('POST', 'mute', host_name, **params) | ||
return super(Host, cls)._trigger_class_action('POST', 'mute', host_name, **body) | ||
|
||
@classmethod | ||
def unmute(cls, host_name): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,7 +169,7 @@ class ActionAPIResource(object): | |
Actionable API Resource | ||
""" | ||
@classmethod | ||
def _trigger_class_action(cls, method, name, id=None, **params): | ||
def _trigger_class_action(cls, method, name, id=None, params=None, **body): | ||
""" | ||
Trigger an action | ||
|
||
|
@@ -185,15 +185,22 @@ def _trigger_class_action(cls, method, name, id=None, **params): | |
:param params: action parameters | ||
:type params: dictionary | ||
|
||
:param body: action body | ||
:type body: dictionary | ||
|
||
:returns: Dictionary representing the API's JSON response | ||
""" | ||
if params is None: | ||
params = {} | ||
if id is None: | ||
return APIClient.submit(method, cls._class_url + "/" + name, params) | ||
return APIClient.submit(method, cls._class_url + "/" + name, body, **params) | ||
else: | ||
return APIClient.submit(method, cls._class_url + "/" + str(id) + "/" + name, params) | ||
return APIClient.submit( | ||
method, cls._class_url + "/" + str(id) + "/" + name, body, **params | ||
) | ||
|
||
@classmethod | ||
def _trigger_action(cls, method, name, id=None, **params): | ||
def _trigger_action(cls, method, name, id=None, **body): | ||
""" | ||
Trigger an action | ||
|
||
|
@@ -206,12 +213,12 @@ def _trigger_action(cls, method, name, id=None, **params): | |
:param id: trigger the action for the specified resource object | ||
:type id: id | ||
|
||
:param params: action parameters | ||
:type params: dictionary | ||
:param body: action body | ||
:type body: dictionary | ||
|
||
:returns: Dictionary representing the API's JSON response | ||
""" | ||
if id is None: | ||
return APIClient.submit(method, name, params) | ||
return APIClient.submit(method, name, body) | ||
else: | ||
return APIClient.submit(method, name + "/" + str(id), params) | ||
return APIClient.submit(method, name + "/" + str(id), body) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍰 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a
PUT
method (..PATCH
ideally but it's better to be consistent with other api).This would allow people to modify dashboards in a list in an atomic way, without callling delete first. It comes in handy when people have lists stored somewhere in source control and want to make sure Datadog resources are in sync with what they have.