Rm references to "docker"
Closes #13 Required a change in name of two fields in the Server model. Signed-off-by: Pratyush Desai <pratyush.desai@liberta.casa>
This commit is contained in:
parent
d39e559d24
commit
a13df3aea4
@ -16,9 +16,9 @@ def launch_container(modeladmin, request, queryset):
|
|||||||
container_name = f"{server.game.name}_{server.ip_address}_{server.port}"
|
container_name = f"{server.game.name}_{server.ip_address}_{server.port}"
|
||||||
try:
|
try:
|
||||||
# Ensure the command is passed as a list of strings
|
# Ensure the command is passed as a list of strings
|
||||||
command = server.get_docker_run_command().split() if server.docker_run_command else []
|
command = server.get_podman_run_command().split() if server.run_command else []
|
||||||
container = client.containers.run(
|
container = client.containers.run(
|
||||||
server.docker_image,
|
server.image,
|
||||||
detach=True,
|
detach=True,
|
||||||
name=container_name,
|
name=container_name,
|
||||||
command=command,
|
command=command,
|
||||||
@ -48,7 +48,7 @@ def remove_container(modeladmin, request, queryset):
|
|||||||
|
|
||||||
@admin.register(Server)
|
@admin.register(Server)
|
||||||
class ServerAdmin(admin.ModelAdmin):
|
class ServerAdmin(admin.ModelAdmin):
|
||||||
list_display = ('game', 'name', 'ip_address', 'port', 'status', 'docker_image', 'docker_run_command', 'command_args')
|
list_display = ('game', 'name', 'ip_address', 'port', 'status', 'image', 'run_command', 'command_args')
|
||||||
search_fields = ('game__name', 'ip_address', 'port')
|
search_fields = ('game__name', 'ip_address', 'port')
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
def save_model(self, request, obj, form, change):
|
||||||
@ -62,6 +62,6 @@ class ServerAdmin(admin.ModelAdmin):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
list_filter = ('status', 'game')
|
list_filter = ('status', 'game')
|
||||||
search_fields = ('ip_address', 'game__name', 'docker_image')
|
search_fields = ('ip_address', 'game__name', 'image')
|
||||||
ordering = ('game', 'ip_address')
|
ordering = ('game', 'ip_address')
|
||||||
actions = [launch_container, stop_container, remove_container]
|
actions = [launch_container, stop_container, remove_container]
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.1.5 on 2025-02-09 17:03
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("webpanel", "0005_server_command_args_server_docker_run_command"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="server",
|
||||||
|
old_name="docker_image",
|
||||||
|
new_name="image",
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name="server",
|
||||||
|
old_name="docker_run_command",
|
||||||
|
new_name="run_command",
|
||||||
|
),
|
||||||
|
]
|
@ -18,8 +18,8 @@ class Server(models.Model):
|
|||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
ip_address = models.GenericIPAddressField(null=True)
|
ip_address = models.GenericIPAddressField(null=True)
|
||||||
port = models.PositiveIntegerField(null=True)
|
port = models.PositiveIntegerField(null=True)
|
||||||
docker_image = models.CharField(max_length=200, null=True)
|
image = models.CharField(max_length=200, null=True)
|
||||||
docker_run_command = models.CharField(max_length=500, blank=True, null=True)
|
run_command = models.CharField(max_length=500, blank=True, null=True)
|
||||||
command_args = models.TextField(blank=True, null=True)
|
command_args = models.TextField(blank=True, null=True)
|
||||||
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='offline')
|
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='offline')
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class Server(models.Model):
|
|||||||
return f"{self.game.name} Server at {self.ip_address}:{self.port}"
|
return f"{self.game.name} Server at {self.ip_address}:{self.port}"
|
||||||
|
|
||||||
def sync_status(self):
|
def sync_status(self):
|
||||||
"""Check the real-time status of the Docker container and update the field."""
|
"""Check the real-time status of the container and update the field."""
|
||||||
client = podman.PodmanClient(base_url="unix:///run/user/1000/podman/podman.sock")
|
client = podman.PodmanClient(base_url="unix:///run/user/1000/podman/podman.sock")
|
||||||
container_name = f"{self.game.name}_{self.ip_address}_{self.port}"
|
container_name = f"{self.game.name}_{self.ip_address}_{self.port}"
|
||||||
try:
|
try:
|
||||||
@ -42,11 +42,11 @@ class Server(models.Model):
|
|||||||
self.status = "offline" # Fallback in case of unexpected errors
|
self.status = "offline" # Fallback in case of unexpected errors
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def get_docker_run_command(self):
|
def get_podman_run_command(self):
|
||||||
"""Returns the Podman run command, falling back to default image if not set."""
|
"""Returns the Podman run command, falling back to default image if not set."""
|
||||||
if self.docker_run_command:
|
if self.run_command:
|
||||||
# Return command as a string to be split later
|
# Return command as a string to be split later
|
||||||
return self.docker_run_command
|
return self.run_command
|
||||||
else:
|
else:
|
||||||
# Default command with image and arguments
|
# Default command with image and arguments
|
||||||
base_command = f"{self.image}"
|
base_command = f"{self.image}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user