Natalie/portainer_api/stacks.py
2024-11-24 10:28:21 +03:30

45 lines
1.6 KiB
Python

from .base import Portainer
class Stacks(Portainer):
def list_stacks(self):
stacks = self.portainer.stacks.list_stacks()
stacks_list = []
for stack in stacks:
stack_data = {
"id": stack['Id'],
"name": stack['Name'],
"type": stack['Type'],
"endpoint_id": stack['EndpointId'],
"resource_id": stack['ResourceControl']['ResourceId'],
"status": stack['Status'],
"creation_date": stack['CreationDate'],
"created_by": stack['CreatedBy'],
"update_date": stack['UpdateDate'],
"updated_by": stack['UpdatedBy'],
"webhook": stack['Webhook']
}
stacks_list.append(stack_data)
return stacks_list
def get_stack_by_id(self, stack_id):
stack = self.portainer.stacks.get_stack_by_id(stack_id)
stack_data = {
"id": stack['Id'],
"name": stack['Name'],
"type": stack['Type'],
"endpoint_id": stack['EndpointId'],
"resource_id": stack['ResourceControl']['ResourceId'],
"status": stack['Status'],
"creation_date": stack['CreationDate'],
"created_by": stack['CreatedBy'],
"update_date": stack['UpdateDate'],
"updated_by": stack['UpdatedBy'],
"webhook": stack['Webhook']
}
return stack_data
def update_stack(self, webhook):
response = self.portainer.stacks.update_stack(webhook)
return response