Skip to content

Commit 0ee7810

Browse files
committed
Add update_datasource_by_uid to the datasource API
1 parent 3bbfacf commit 0ee7810

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Update the `update_folder` method of the folder API to allow changing
66
the UID of the folder. Thanks, @iNoahNothing.
7+
* Add `update_datasource_by_uid` to the datasource API. Thanks, @mgreen-sm.
78

89

910
## 3.0.0 (2022-07-02)

grafana_client/elements/datasource.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ def update_datasource(self, datasource_id, datasource):
124124
r = self.client.PUT(update_datasource, json=datasource)
125125
return r
126126

127+
def update_datasource_by_uid(self, datasource_uid, datasource):
128+
"""
129+
130+
:param datasource_uid:
131+
:param datasource:
132+
:return:
133+
"""
134+
update_datasource = "/datasources/uid/%s" % datasource_uid
135+
r = self.client.PUT(update_datasource, json=datasource)
136+
return r
137+
127138
def list_datasources(self):
128139
"""
129140

test/elements/test_datasource_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ def test_update_datasource(self, m):
8787
result = self.grafana.datasource.update_datasource(42, PROMETHEUS_DATASOURCE)
8888
self.assertEqual(result["type"], "prometheus")
8989

90+
@requests_mock.Mocker()
91+
def test_update_datasource_by_uid(self, m):
92+
m.put(
93+
"http://localhost/api/datasources/uid/foo42",
94+
json=PROMETHEUS_DATASOURCE,
95+
)
96+
97+
result = self.grafana.datasource.update_datasource_by_uid("foo42", PROMETHEUS_DATASOURCE)
98+
self.assertEqual(result["type"], "prometheus")
99+
90100
@requests_mock.Mocker()
91101
def test_delete_datasource_by_id(self, m):
92102
m.delete("http://localhost/api/datasources/42", json={"message": "Data source deleted"})

0 commit comments

Comments
 (0)