Skip to content

Commit c066912

Browse files
committed
Rename module names and references
1 parent f171787 commit c066912

31 files changed

+324
-324
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ Install the package from PyPI.
3434
pip install grafana-client --upgrade
3535
```
3636

37-
Connect to your Grafana API endpoint using the `GrafanaFace` interface.
37+
Connect to your Grafana API endpoint using the `GrafanaApi` class.
3838

3939
```python
40-
from grafana_client.grafana_face import GrafanaFace
40+
from grafana_client import GrafanaApi
4141

42-
grafana = GrafanaFace(auth='abcde....', host='grafana.example.org')
42+
grafana = GrafanaApi(auth='abcde....', host='grafana.example.org')
4343

4444
# Create user
45-
user = grafana.admin.create_user({"name": "User", "email": "[email protected]", "login": "user", "password": "userpassword", "OrgId": 1})
45+
user = grafana.admin.create_user(
46+
{"name": "User", "email": "[email protected]", "login": "user", "password": "userpassword", "OrgId": 1})
4647

4748
# Change user password
4849
user = grafana.admin.change_user_password(2, "newpassword")
@@ -63,7 +64,7 @@ grafana.dashboard.update_dashboard(dashboard={'dashboard': {...}, 'folderId': 0,
6364
grafana.dashboard.delete_dashboard(dashboard_uid='abcdefgh')
6465

6566
# Create organization
66-
grafana.organization.create_organization({"name":"new_organization"})
67+
grafana.organization.create_organization({"name": "new_organization"})
6768
```
6869

6970

@@ -75,18 +76,17 @@ or HTTP basic auth.
7576
To use the admin API, you need to use HTTP basic auth, as stated at the
7677
[Grafana Admin API documentation].
7778

78-
7979
```python
80-
from grafana_client.grafana_face import GrafanaFace
80+
from grafana_client import GrafanaApi
8181

8282
# Use HTTP basic authentication
83-
grafana = GrafanaFace(
83+
grafana = GrafanaApi(
8484
auth=("username", "password"),
8585
host='grafana.example.org'
8686
)
8787

8888
# Use Grafana API token
89-
grafana = GrafanaFace(
89+
grafana = GrafanaApi(
9090
auth='eyJrIjoiWHg...dGJpZCI6MX0=',
9191
host='grafana.example.org'
9292
)

conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ requirements:
2424
test:
2525
imports:
2626
- grafana_client
27-
- grafana_client.api
27+
- grafana_client.elements
2828

2929
about:
3030
home: https://panodata.github.io/grafana-client/

grafana_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .grafana_face import GrafanaFace
1+
from .api import GrafanaApi

grafana_client/api.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from .client import GrafanaClient
2+
from .elements import (
3+
Admin,
4+
Dashboard,
5+
Datasource,
6+
Folder,
7+
Organization,
8+
Organizations,
9+
Search,
10+
User,
11+
Users,
12+
Teams,
13+
Snapshots,
14+
Annotations,
15+
Notifications
16+
)
17+
18+
19+
class GrafanaApi:
20+
def __init__(
21+
self,
22+
auth,
23+
host="localhost",
24+
port=None,
25+
url_path_prefix="",
26+
protocol="http",
27+
verify=True,
28+
timeout=5.0,
29+
):
30+
self.client = GrafanaClient(
31+
auth,
32+
host=host,
33+
port=port,
34+
url_path_prefix=url_path_prefix,
35+
protocol=protocol,
36+
verify=verify,
37+
timeout=timeout,
38+
)
39+
self.admin = Admin(self.client)
40+
self.dashboard = Dashboard(self.client)
41+
self.datasource = Datasource(self.client)
42+
self.folder = Folder(self.client)
43+
self.organization = Organization(self.client)
44+
self.organizations = Organizations(self.client)
45+
self.search = Search(self.client)
46+
self.user = User(self.client)
47+
self.users = Users(self.client)
48+
self.teams = Teams(self.client)
49+
self.annotations = Annotations(self.client)
50+
self.snapshots = Snapshots(self.client)
51+
self.notifications = Notifications(self.client)

grafana_client/api/base.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

grafana_client/grafana_api.py renamed to grafana_client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __call__(self, request):
5656
return request
5757

5858

59-
class GrafanaAPI:
59+
class GrafanaClient:
6060
def __init__(
6161
self,
6262
auth,
File renamed without changes.

grafana_client/api/admin.py renamed to grafana_client/elements/admin.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33

44
class Admin(Base):
5-
def __init__(self, api):
6-
super(Admin, self).__init__(api)
7-
self.api = api
5+
def __init__(self, client):
6+
super(Admin, self).__init__(client)
7+
self.client = client
88

99
def settings(self):
1010
"""
1111
1212
:return:
1313
"""
1414
path = "/admin/settings"
15-
r = self.api.GET(path)
15+
r = self.client.GET(path)
1616
return r
1717

1818
def stats(self):
@@ -21,7 +21,7 @@ def stats(self):
2121
:return:
2222
"""
2323
path = "/admin/stats"
24-
r = self.api.GET(path)
24+
r = self.client.GET(path)
2525
return r
2626

2727
def create_user(self, user):
@@ -31,7 +31,7 @@ def create_user(self, user):
3131
:return:
3232
"""
3333
create_user_path = "/admin/users"
34-
r = self.api.POST(create_user_path, json=user)
34+
r = self.client.POST(create_user_path, json=user)
3535
return r
3636

3737
def change_user_password(self, user_id, password):
@@ -42,7 +42,7 @@ def change_user_password(self, user_id, password):
4242
:return:
4343
"""
4444
change_user_password_path = "/admin/users/%s/password" % user_id
45-
r = self.api.PUT(change_user_password_path, json={"password": password})
45+
r = self.client.PUT(change_user_password_path, json={"password": password})
4646
return r
4747

4848
def change_user_permissions(self, user_id, is_grafana_admin):
@@ -53,7 +53,7 @@ def change_user_permissions(self, user_id, is_grafana_admin):
5353
:return:
5454
"""
5555
change_user_permissions = "/admin/users/%s/permissions" % user_id
56-
r = self.api.PUT(
56+
r = self.client.PUT(
5757
change_user_permissions, json={"isGrafanaAdmin": is_grafana_admin}
5858
)
5959
return r
@@ -65,7 +65,7 @@ def delete_user(self, user_id):
6565
:return:
6666
"""
6767
delete_user_path = "/admin/users/%s" % user_id
68-
r = self.api.DELETE(delete_user_path)
68+
r = self.client.DELETE(delete_user_path)
6969
return r
7070

7171
def pause_all_alerts(self, pause):
@@ -75,5 +75,5 @@ def pause_all_alerts(self, pause):
7575
:return:
7676
"""
7777
change_user_permissions = "/admin/pause-all-alerts"
78-
r = self.api.POST(change_user_permissions, json={"paused": pause})
78+
r = self.client.POST(change_user_permissions, json={"paused": pause})
7979
return r

grafana_client/api/annotations.py renamed to grafana_client/elements/annotations.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33

44
class Annotations(Base):
5-
def __init__(self, api):
6-
super(Annotations, self).__init__(api)
7-
self.api = api
5+
def __init__(self, client):
6+
super(Annotations, self).__init__(client)
7+
self.client = client
88

99
def get_annotation(
1010
self,
@@ -67,7 +67,7 @@ def get_annotation(
6767
list_annotations_path += "?"
6868
list_annotations_path += "&".join(params)
6969

70-
r = self.api.GET(list_annotations_path)
70+
r = self.client.GET(list_annotations_path)
7171

7272
return r
7373

@@ -103,7 +103,7 @@ def add_annotation(
103103
"text": text,
104104
}
105105

106-
r = self.api.POST(annotations_path, json=payload)
106+
r = self.client.POST(annotations_path, json=payload)
107107

108108
return r
109109

@@ -132,7 +132,7 @@ def add_annotation_graphite(
132132
"data": data
133133
}
134134

135-
r = self.api.POST(annotations_path, json=payload)
135+
r = self.client.POST(annotations_path, json=payload)
136136

137137
return r
138138

@@ -161,7 +161,7 @@ def update_annotation(
161161
"text": text
162162
}
163163

164-
r = self.api.PUT(annotations_path, json=payload)
164+
r = self.client.PUT(annotations_path, json=payload)
165165

166166
return r
167167

@@ -193,7 +193,7 @@ def partial_update_annotation(
193193
"text": text
194194
}
195195

196-
r = self.api.PATCH(annotations_path, json=payload)
196+
r = self.client.PATCH(annotations_path, json=payload)
197197

198198
return r
199199

@@ -209,6 +209,6 @@ def delete_annotations_by_id(
209209
:return:
210210
"""
211211
annotations_path = "/annotations/{}".format(annotations_id)
212-
r = self.api.DELETE(annotations_path)
212+
r = self.client.DELETE(annotations_path)
213213

214214
return r

grafana_client/elements/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Base(object):
2+
def __init__(self, client):
3+
self.client = client

0 commit comments

Comments
 (0)