diff --git a/webpanel/admin.py b/webpanel/admin.py index b094af1..be0085f 100644 --- a/webpanel/admin.py +++ b/webpanel/admin.py @@ -16,9 +16,9 @@ def launch_container(modeladmin, request, queryset): container_name = f"{server.game.name}_{server.ip_address}_{server.port}" try: # 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( - server.docker_image, + server.image, detach=True, name=container_name, command=command, @@ -48,7 +48,7 @@ def remove_container(modeladmin, request, queryset): @admin.register(Server) 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') def save_model(self, request, obj, form, change): @@ -62,6 +62,6 @@ class ServerAdmin(admin.ModelAdmin): return queryset list_filter = ('status', 'game') - search_fields = ('ip_address', 'game__name', 'docker_image') + search_fields = ('ip_address', 'game__name', 'image') ordering = ('game', 'ip_address') actions = [launch_container, stop_container, remove_container] diff --git a/webpanel/migrations/0006_rename_docker_image_server_image_and_more.py b/webpanel/migrations/0006_rename_docker_image_server_image_and_more.py new file mode 100644 index 0000000..1c4440f --- /dev/null +++ b/webpanel/migrations/0006_rename_docker_image_server_image_and_more.py @@ -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", + ), + ] diff --git a/webpanel/models.py b/webpanel/models.py index 4ddc928..9a18890 100644 --- a/webpanel/models.py +++ b/webpanel/models.py @@ -18,8 +18,8 @@ class Server(models.Model): name = models.CharField(max_length=100) ip_address = models.GenericIPAddressField(null=True) port = models.PositiveIntegerField(null=True) - docker_image = models.CharField(max_length=200, null=True) - docker_run_command = models.CharField(max_length=500, blank=True, null=True) + image = models.CharField(max_length=200, null=True) + run_command = models.CharField(max_length=500, blank=True, null=True) command_args = models.TextField(blank=True, null=True) 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}" 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") container_name = f"{self.game.name}_{self.ip_address}_{self.port}" try: @@ -42,11 +42,11 @@ class Server(models.Model): self.status = "offline" # Fallback in case of unexpected errors 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.""" - if self.docker_run_command: + if self.run_command: # Return command as a string to be split later - return self.docker_run_command + return self.run_command else: # Default command with image and arguments base_command = f"{self.image}"