forked from m0nhawk/grafana_api
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from RusherRG/master
Add API calls for APA Pipeline Model and Handler
- Loading branch information
Showing
7 changed files
with
241 additions
and
3 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
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,75 @@ | ||
from .base import Base | ||
|
||
|
||
class Handler(Base): | ||
def __init__(self, api): | ||
super(Handler, self).__init__(api) | ||
self.api = api | ||
self.path = '/org/handlers' | ||
|
||
def create_handler(self, name, handler_type, data, description=""): | ||
if type(name) != str or not name: | ||
raise ValueError("Handler name is required!") | ||
if type(description) != str: | ||
raise ValueError("Handler description has to be string!") | ||
if handler_type not in ("fetch", "batch", "step"): | ||
raise ValueError("Handler type '%s' is invalid!" % str(handler_type)) | ||
if type(data) != str or not data: | ||
raise ValueError("Handler data is required!") | ||
|
||
response = self.api.POST(self.path, json=dict( | ||
name=name, | ||
description=description, | ||
type=handler_type, | ||
data=data, | ||
)) | ||
return response | ||
|
||
def update_handler(self, id, name, data, description="", **kwargs): | ||
if type(id) != int or not id: | ||
raise ValueError("Handler id is invalid!") | ||
if type(name) != str or not name: | ||
raise ValueError("Handler name is invalid!") | ||
if type(description) != str: | ||
raise ValueError("Handler description has to be string!") | ||
if type(data) != str or not data: | ||
raise ValueError("Handler data is invalid!") | ||
|
||
response = self.api.PUT(self.path + "/%d" % id, json=dict( | ||
name=name, | ||
description=description, | ||
data=data, | ||
)) | ||
return response | ||
|
||
|
||
def list_handlers(self, handler_type="", limit=100, page=0): | ||
if handler_type not in ("fetch", "batch", "step", ""): | ||
raise ValueError("Handler type '%s' is invalid!" % str(handler_type)) | ||
if type(limit) != int or limit < 0: | ||
raise ValueError("limit is invalid!") | ||
if type(page) != int or page < 0: | ||
raise ValueError("page is invalid!") | ||
|
||
response = self.api.GET(self.path, json=dict( | ||
type=handler_type, | ||
limit=limit, | ||
page=page | ||
)) | ||
return response | ||
|
||
def get_handler(self, id, depends=False): | ||
if type(id) != int or not id: | ||
raise ValueError("Handler id is invalid!") | ||
|
||
response = self.api.GET(self.path + "/%d" % id, json=dict( | ||
depends=depends | ||
)) | ||
return response | ||
|
||
def delete_handler(self, id): | ||
if type(id) != int or not id: | ||
raise ValueError("Handler id is invalid!") | ||
|
||
response = self.api.DELETE(self.path + "/%d" % id) | ||
return response |
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,62 @@ | ||
from .base import Base | ||
|
||
|
||
class Model(Base): | ||
def __init__(self, api): | ||
super(Model, self).__init__(api) | ||
self.api = api | ||
self.path = '/org/models' | ||
|
||
def create_model(self, name, description=""): | ||
if type(name) != str or not name: | ||
raise ValueError("Model name is required!") | ||
if type(description) != str: | ||
raise ValueError("Model description has to be string!") | ||
|
||
response = self.api.POST(self.path, json=dict( | ||
name=name, | ||
description=description | ||
)) | ||
return response | ||
|
||
def update_model(self, id, name, description="", **kwargs): | ||
if type(id) != int or not id: | ||
raise ValueError("Model id is invalid!") | ||
if type(name) != str or not name: | ||
raise ValueError("Model name is invalid!") | ||
if type(description) != str: | ||
raise ValueError("Model description has to be string!") | ||
|
||
response = self.api.PUT(self.path + "/%d" % id, json=dict( | ||
name=name, | ||
description=description | ||
)) | ||
return response | ||
|
||
def list_models(self, limit=100, page=0): | ||
if type(limit) != int or limit < 0: | ||
raise ValueError("limit is invalid!") | ||
if type(page) != int or page < 0: | ||
raise ValueError("page is invalid!") | ||
|
||
response = self.api.GET(self.path, json=dict( | ||
limit=limit, | ||
page=page | ||
)) | ||
return response | ||
|
||
def get_model(self, id, depends=False): | ||
if type(id) != int or not id: | ||
raise ValueError("Model id is invalid!") | ||
|
||
response = self.api.GET(self.path + "/%d" % id, json=dict( | ||
depends=depends | ||
)) | ||
return response | ||
|
||
def delete_model(self, id): | ||
if type(id) != int or not id: | ||
raise ValueError("Model id is invalid!") | ||
|
||
response = self.api.DELETE(self.path + "/%d" % id) | ||
return response |
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,74 @@ | ||
from .base import Base | ||
|
||
|
||
class Pipeline(Base): | ||
def __init__(self, api): | ||
super(Pipeline, self).__init__(api) | ||
self.api = api | ||
self.path = '/org/pipelines' | ||
|
||
def create_pipeline(self, name, pipeline_type, data, description=""): | ||
if type(name) != str or not name: | ||
raise ValueError("Pipeline name is required!") | ||
if type(description) != str: | ||
raise ValueError("Pipeline description has to be string!") | ||
if pipeline_type not in ("fetch", "analyse", "tune", "fit", "predict"): | ||
raise ValueError("Pipeline type '%s' is invalid!" % str(pipeline_type)) | ||
if type(data) != str or not data: | ||
raise ValueError("Pipeline data is required!") | ||
|
||
response = self.api.POST(self.path, json=dict( | ||
name=name, | ||
description=description, | ||
type=pipeline_type, | ||
data=data, | ||
)) | ||
return response | ||
|
||
def update_pipeline(self, id, name, data, description="", **kwargs): | ||
if type(id) != int or not id: | ||
raise ValueError("Pipeline id is invalid!") | ||
if type(name) != str or not name: | ||
raise ValueError("Pipeline name is invalid!") | ||
if type(description) != str: | ||
raise ValueError("Pipeline description has to be string!") | ||
if type(data) != str or not data: | ||
raise ValueError("Pipeline data is invalid!") | ||
|
||
response = self.api.PUT(self.path + "/%d" % id, json=dict( | ||
name=name, | ||
description=description, | ||
data=data, | ||
)) | ||
return response | ||
|
||
def list_pipelines(self, pipeline_type="", limit=100, page=0): | ||
if pipeline_type not in ("fetch", "analyse", "tune", "fit", "predict", ""): | ||
raise ValueError("Pipeline type '%s' is invalid!" % str(pipeline_type)) | ||
if type(limit) != int or limit < 0: | ||
raise ValueError("limit is invalid!") | ||
if type(page) != int or page < 0: | ||
raise ValueError("page is invalid!") | ||
|
||
response = self.api.GET(self.path, json=dict( | ||
type=pipeline_type, | ||
limit=limit, | ||
page=page | ||
)) | ||
return response | ||
|
||
def get_pipeline(self, id, depends=False): | ||
if type(id) != int or not id: | ||
raise ValueError("Pipeline id is invalid!") | ||
|
||
response = self.api.GET(self.path + "/%d" % id, json=dict( | ||
depends=depends, | ||
)) | ||
return response | ||
|
||
def delete_pipeline(self, id): | ||
if type(id) != int or not id: | ||
raise ValueError("Pipeline id is invalid!") | ||
|
||
response = self.api.DELETE(self.path + "/%d" % id) | ||
return response |
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