54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
# coding: utf-8
|
|
|
|
from SWSCloudCore import models
|
|
|
|
|
|
class ControllerContainersServer:
|
|
def status_set(self, container_id, status):
|
|
return self.set_container_status(container_id, status)
|
|
|
|
def set_container_status(self, container_id, status):
|
|
ns = models.Containers.update(status=status).where(
|
|
models.Containers.id == container_id
|
|
)
|
|
ns.execute()
|
|
return True
|
|
|
|
def exists(self, container_id):
|
|
if models.Containers.select().where(
|
|
models.Containers.id == container_id
|
|
).count() == 0:
|
|
return False
|
|
return True
|
|
|
|
def get_container(self, container_id):
|
|
x = models.Containers.select().where(
|
|
models.Containers.id == container_id
|
|
).get()
|
|
|
|
return {
|
|
'id': str(x.id),
|
|
'datacenter_id': str(x.datacenter.id),
|
|
'server_id': str(x.server.id),
|
|
'ipv4': x.ipv4,
|
|
'ipv6': x.ipv6,
|
|
'status': x.status
|
|
}
|
|
|
|
def get_containers_by_server(self, server_id):
|
|
x = models.Containers.select().where(
|
|
models.Containers.server == server_id
|
|
).execute()
|
|
containers = list()
|
|
for i in x:
|
|
containers.append({
|
|
'id': str(i.id),
|
|
'datacenter_id': str(i.datacenter.id),
|
|
'server_id': str(i.server.id),
|
|
'ipv4': i.ipv4,
|
|
'ipv6': i.ipv6,
|
|
'status': i.status
|
|
})
|
|
return containers
|
|
|
|
|