initial commit
This commit is contained in:
parent
bab6717459
commit
f5f3017731
0
portainer/__init__.py
Normal file
0
portainer/__init__.py
Normal file
15
portainer/base.py
Normal file
15
portainer/base.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import requests
|
||||
|
||||
|
||||
class ApiBase:
|
||||
def __init__(self, base_url, token):
|
||||
self.base_url = f"{base_url}/api"
|
||||
self.headers = {"X-API-Key": token}
|
||||
|
||||
def request(self, method, url):
|
||||
response = requests.request(
|
||||
url=url,
|
||||
method=method,
|
||||
headers=self.headers
|
||||
)
|
||||
|
7
portainer/containers.py
Normal file
7
portainer/containers.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from .base import ApiBase
|
||||
|
||||
|
||||
class ContainersApi(ApiBase):
|
||||
def list_containers_by_endpoint(self, endpoint):
|
||||
url = f"{self.base_url}/docker/{endpoint}/snapshot/containers"
|
||||
return self.request("GET", url).json()
|
7
portainer/endpoints.py
Normal file
7
portainer/endpoints.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from .base import ApiBase
|
||||
|
||||
|
||||
class EndpointApi(ApiBase):
|
||||
def list_endpoints(self):
|
||||
url = f"{self.base_url}/endpoints"
|
||||
return self.request("GET", url).json()
|
16
portainer/stacks.py
Normal file
16
portainer/stacks.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from .base import ApiBase
|
||||
|
||||
|
||||
class StacksApi(ApiBase):
|
||||
def list_stacks(self):
|
||||
url = f"{self.base_url}/stacks"
|
||||
return self.request("GET", url).json()
|
||||
|
||||
def get_stack_by_id(self, stack_id):
|
||||
url = f"{self.base_url}/stacks/{stack_id}"
|
||||
return self.request("GET", url).json()
|
||||
|
||||
def update_stack(self, webhook):
|
||||
url = f"{self.base_url}/stacks/webhooks/{webhook}"
|
||||
return self.request("POST", url)
|
||||
|
Loading…
Reference in a new issue