Skip to content
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 5 commits into from
Mar 16, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[dash list] Fix failing check
  • Loading branch information
MLaureB committed Feb 22, 2018
commit 469d395ab93261b4dce152c9f8f3bea9dbcda290
17 changes: 12 additions & 5 deletions datadog/api/dashboard_lists.py
Original file line number Diff line number Diff line change
@@ -7,8 +7,9 @@
UpdatableAPIResource
)

class DashboardList(ActionAPIResource, CreateableAPIResource, DeletableAPIResource, GetableAPIResource,
ListableAPIResource, UpdatableAPIResource):

class DashboardList(ActionAPIResource, CreateableAPIResource, DeletableAPIResource,
GetableAPIResource, ListableAPIResource, UpdatableAPIResource):
"""
A wrapper around Dashboard List HTTP API.
"""
@@ -33,7 +34,9 @@ def add_dashboards(cls, id, **body):

:returns: Dictionary representing the API's JSON response
"""
return super(DashboardList, cls)._trigger_class_action('POST', 'dashboards', id, params=None, **body)
return super(DashboardList, cls)._trigger_class_action(
'POST', 'dashboards', id, params=None, **body
)

@classmethod
def update_dashboards(cls, id, **body):
@@ -45,7 +48,9 @@ def update_dashboards(cls, id, **body):

:returns: Dictionary representing the API's JSON response
"""
return super(DashboardList, cls)._trigger_class_action('PUT', 'dashboards', id, params=None, **body)
return super(DashboardList, cls)._trigger_class_action(
'PUT', 'dashboards', id, params=None, **body
)

@classmethod
def delete_dashboards(cls, id, **body):
@@ -57,4 +62,6 @@ def delete_dashboards(cls, id, **body):

:returns: Dictionary representing the API's JSON response
"""
return super(DashboardList, cls)._trigger_class_action('DELETE', 'dashboards', id, params=None, **body)
return super(DashboardList, cls)._trigger_class_action(
'DELETE', 'dashboards', id, params=None, **body
)
4 changes: 3 additions & 1 deletion datadog/api/resources.py
Original file line number Diff line number Diff line change
@@ -195,7 +195,9 @@ def _trigger_class_action(cls, method, name, id=None, params=None, **body):
if id is None:
return APIClient.submit(method, cls._class_url + "/" + name, body, **params)
else:
return APIClient.submit(method, cls._class_url + "/" + str(id) + "/" + name, body, **params)
return APIClient.submit(
method, cls._class_url + "/" + str(id) + "/" + name, body, **params
)

@classmethod
def _trigger_action(cls, method, name, id=None, **body):
71 changes: 49 additions & 22 deletions datadog/dogshell/dashboard_list.py
Original file line number Diff line number Diff line change
@@ -6,11 +6,14 @@
from datadog.dogshell.common import report_errors, report_warnings
from datadog.util.compat import json


class DashboardListClient(object):

@classmethod
def setup_parser(cls, subparsers):
parser = subparsers.add_parser('dashboard_list', help="Create, edit, and delete dashboard lists")
parser = subparsers.add_parser(
'dashboard_list', help="Create, edit, and delete dashboard lists"
)
verb_parsers = parser.add_subparsers(title='Verbs', dest='verb')
verb_parsers.required = True

@@ -21,7 +24,9 @@ def setup_parser(cls, subparsers):

# Update Dashboard List parser
update_parser = verb_parsers.add_parser('update', help="Update existing dashboard list")
update_parser.add_argument('dashboard_list_id', help="Dashboard list to replace with the new definition")
update_parser.add_argument(
'dashboard_list_id', help="Dashboard list to replace with the new definition"
)
update_parser.add_argument('name', help="Name for the dashboard list")
update_parser.set_defaults(func=cls._update)

@@ -31,7 +36,9 @@ def setup_parser(cls, subparsers):
show_parser.set_defaults(func=cls._show)

# Show All Dashboard Lists parser
show_all_parser = verb_parsers.add_parser('show_all', help="Show a list of all dashboard lists")
show_all_parser = verb_parsers.add_parser(
'show_all', help="Show a list of all dashboard lists"
)
show_all_parser.set_defaults(func=cls._show_all)

# Delete Dashboard List parser
@@ -40,36 +47,57 @@ def setup_parser(cls, subparsers):
delete_parser.set_defaults(func=cls._delete)

# Get Dashboards for Dashboard List parser
get_dashboards_parser = verb_parsers.add_parser('show_dashboards',
help="Show a list of all dashboards for an existing dashboard list")
get_dashboards_parser.add_argument('dashboard_list_id', help="Dashboard list to show dashboards from")
get_dashboards_parser = verb_parsers.add_parser(
'show_dashboards', help="Show a list of all dashboards for an existing dashboard list"
)
get_dashboards_parser.add_argument(
'dashboard_list_id', help="Dashboard list to show dashboards from"
)
get_dashboards_parser.set_defaults(func=cls._show_dashboards)

# Add Dashboards to Dashboard List parser
add_dashboards_parser = verb_parsers.add_parser('add_dashboards',
help="Add dashboards to an existing dashboard list")
add_dashboards_parser.add_argument('dashboard_list_id', help="Dashboard list to add dashboards to")
add_dashboards_parser.add_argument('dashboards',
add_dashboards_parser = verb_parsers.add_parser(
'add_dashboards', help="Add dashboards to an existing dashboard list"
)
add_dashboards_parser.add_argument(
'dashboard_list_id', help="Dashboard list to add dashboards to"
)
add_dashboards_parser.add_argument(
'dashboards',
help='A JSON list of dashboard dicts, e.g. ' +
'[{"type": "custom_timeboard", "id": 1234}, {"type": "custom_screenboard", "id": 123}]')
'[{"type": "custom_timeboard", "id": 1234}, ' +
'{"type": "custom_screenboard", "id": 123}]'
)
add_dashboards_parser.set_defaults(func=cls._add_dashboards)

# Update Dashboards of Dashboard List parser
update_dashboards_parser = verb_parsers.add_parser('update_dashboards',
help="Update dashboards of an existing dashboard list")
update_dashboards_parser.add_argument('dashboard_list_id', help="Dashboard list to update with dashboards")
update_dashboards_parser.add_argument('dashboards',
update_dashboards_parser = verb_parsers.add_parser(
'update_dashboards', help="Update dashboards of an existing dashboard list"
)
update_dashboards_parser.add_argument(
'dashboard_list_id', help="Dashboard list to update with dashboards"
)
update_dashboards_parser.add_argument(
'dashboards',
help='A JSON list of dashboard dicts, e.g. ' +
'[{"type": "custom_timeboard", "id": 1234}, {"type": "custom_screenboard", "id": 123}]')
'[{"type": "custom_timeboard", "id": 1234}, ' +
'{"type": "custom_screenboard", "id": 123}]'
)
update_dashboards_parser.set_defaults(func=cls._update_dashboards)

# Delete Dashboards from Dashboard List parser
delete_dashboards_parser = verb_parsers.add_parser('delete_dashboards',
help="Delete dashboards from an existing dashboard list")
delete_dashboards_parser.add_argument('dashboard_list_id', help="Dashboard list to delete dashboards from")
delete_dashboards_parser.add_argument('dashboards',
delete_dashboards_parser = verb_parsers.add_parser(
'delete_dashboards', help="Delete dashboards from an existing dashboard list"
)
delete_dashboards_parser.add_argument(
'dashboard_list_id', help="Dashboard list to delete dashboards from"
)
delete_dashboards_parser.add_argument(
'dashboards',
help='A JSON list of dashboard dicts, e.g. ' +
'[{"type": "custom_timeboard", "id": 1234}, {"type": "custom_screenboard", "id": 123}]')
'[{"type": "custom_timeboard", "id": 1234}, ' +
'{"type": "custom_screenboard", "id": 123}]'
)
delete_dashboards_parser.set_defaults(func=cls._delete_dashboards)

@classmethod
@@ -209,4 +237,3 @@ def _delete_dashboards(cls, args):
print(pretty_json(res))
else:
print(json.dumps(res))