mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 16:36:06 +00:00
fix(instances): a VM name of any length libvirt takes is kept
libvirt names a VM by its <name>.xml file, so a name can have up to 251 bytes. The panel's VM, removed-VM and log records held 120 characters: on PostgreSQL one longer name made the host's sync fail and the VM list answer with an error. They now hold 255. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
e83bdcbd44
commit
373760f2c5
8 changed files with 68 additions and 8 deletions
|
|
@ -17,7 +17,7 @@ def write(user, host, instance, message, success=None, ip=None, uuid=""):
|
|||
Save one Logs row. A failure is written to the log file instead and never
|
||||
raised, so an audit write cannot break the action it records.
|
||||
"""
|
||||
user, host, instance, uuid = user[:150], host[:255], instance[:120], uuid[:36]
|
||||
user, host, instance, uuid = user[:150], host[:255], instance[:255], uuid[:36]
|
||||
try:
|
||||
with transaction.atomic():
|
||||
Logs.objects.create(user=user, host=host, instance=instance, instance_uuid=uuid, message=message,
|
||||
|
|
|
|||
18
logs/migrations/0006_instance_name_length.py
Normal file
18
logs/migrations/0006_instance_name_length.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 5.2.18 on 2026-11-09 18:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('logs', '0005_instance_uuid'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='logs',
|
||||
name='instance',
|
||||
field=models.CharField(max_length=255, verbose_name='instance'),
|
||||
),
|
||||
]
|
||||
|
|
@ -4,7 +4,7 @@ from django.utils.translation import gettext_lazy as _
|
|||
class Logs(Model):
|
||||
user = CharField(_("user"), max_length=150)
|
||||
host = CharField(_("host"), max_length=255, default="-")
|
||||
instance = CharField(_("instance"), max_length=120)
|
||||
instance = CharField(_("instance"), max_length=255)
|
||||
instance_uuid = CharField(_("instance UUID"), max_length=36, blank=True, default="", db_index=True)
|
||||
message = TextField(_("message"))
|
||||
date = DateTimeField(_("date"), auto_now_add=True, db_index=True)
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ class WriteTests(TestCase):
|
|||
self.assertEqual(row.ip, "192.0.2.7")
|
||||
|
||||
def test_long_values_are_cut(self):
|
||||
write("u" * 200, "h" * 300, "i" * 200, "m" * 5000)
|
||||
write("u" * 200, "h" * 300, "i" * 300, "m" * 5000)
|
||||
row = Logs.objects.get()
|
||||
self.assertEqual(len(row.user), 150)
|
||||
self.assertEqual(len(row.host), 255)
|
||||
self.assertEqual(len(row.instance), 120)
|
||||
self.assertEqual(len(row.instance), 255)
|
||||
self.assertEqual(len(row.message), 5000)
|
||||
|
||||
def test_a_failed_write_inside_a_transaction_leaves_it_usable(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue