-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
revol.cai
committed
Mar 5, 2018
1 parent
d01aca9
commit 2b8f455
Showing
13 changed files
with
203 additions
and
63 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test_version_api(client): | ||
print(client.version()) |
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 |
---|---|---|
@@ -1,3 +1,16 @@ | ||
class BaseAPI(object): | ||
@staticmethod | ||
def _raise_for_status(resp): | ||
raise NotImplementedError | ||
|
||
def _url(self, method): | ||
raise NotImplementedError | ||
|
||
def _get(self, url, **kwargs): | ||
raise NotImplementedError | ||
|
||
def _post(self, url, data=None, json=None, **kwargs): | ||
raise NotImplementedError | ||
|
||
def call_rpc(self, method, data=None, stream=False, **kwargs): | ||
raise NotImplementedError |
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,33 @@ | ||
from collections import namedtuple | ||
|
||
from .base import BaseAPI | ||
|
||
EtcdVersion = namedtuple('EtcdVersion', ['etcdserver', 'etcdcluster']) | ||
|
||
|
||
class ExtraAPI(BaseAPI): | ||
def version(self): | ||
""" | ||
get the version of etcdserver and etcdcluster | ||
:return: EtcdVersion | ||
""" | ||
resp = self._get(self._url('/version')) | ||
self._raise_for_status(resp) | ||
return EtcdVersion(**resp.json()) | ||
|
||
def metrics_raw(self): | ||
""" | ||
get the raw /metrics text | ||
:return: str | ||
""" | ||
resp = self._get(self._url('/metrics')) | ||
self._raise_for_status(resp) | ||
return resp.content | ||
|
||
def metrics(self): | ||
""" | ||
get the modelized metrics parsed by prometheus_client | ||
""" | ||
from prometheus_client.parser import text_string_to_metric_families | ||
|
||
return text_string_to_metric_families(self.metrics_raw()) |
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
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
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.