diff options
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/migrations/0022_merge_20211102_2136.py | 14 | ||||
-rw-r--r-- | src/api/migrations/0023_add_cifile_generated_field.py | 14 | ||||
-rw-r--r-- | src/api/models.py | 4 | ||||
-rw-r--r-- | src/api/views.py | 15 |
4 files changed, 40 insertions, 7 deletions
diff --git a/src/api/migrations/0022_merge_20211102_2136.py b/src/api/migrations/0022_merge_20211102_2136.py new file mode 100644 index 0000000..bb27ae4 --- /dev/null +++ b/src/api/migrations/0022_merge_20211102_2136.py @@ -0,0 +1,14 @@ +# Generated by Django 2.2 on 2021-11-02 21:36 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0019_auto_20210907_1448'), + ('api', '0021_auto_20210405_1943'), + ] + + operations = [ + ] diff --git a/src/api/migrations/0023_add_cifile_generated_field.py b/src/api/migrations/0023_add_cifile_generated_field.py new file mode 100644 index 0000000..df2b6d7 --- /dev/null +++ b/src/api/migrations/0023_add_cifile_generated_field.py @@ -0,0 +1,14 @@ +from django.db import migrations, models + +class Migration(migrations.Migration): + dependencies = [ + ('api', '0022_merge_20211102_2136'), + ] + + operations = [ + migrations.AddField( + model_name="CloudInitFile", + name="generated", + field=models.BooleanField(default=False) + ), + ] diff --git a/src/api/models.py b/src/api/models.py index 8cce5d5..93168f5 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -20,6 +20,7 @@ from django.utils import timezone import json import uuid import yaml +import re from booking.models import Booking from resource_inventory.models import ( @@ -362,7 +363,8 @@ class GeneratedCloudConfig(models.Model): def _normalize_username(self, username: str) -> str: # TODO: make usernames posix compliant - return username + s = re.sub(r'\W+', '', username) + return s def _get_ssh_string(self, username: str) -> str: user = User.objects.get(username=username) diff --git a/src/api/views.py b/src/api/views.py index 3a82b96..1516374 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -295,7 +295,7 @@ def resource_ci_userdata(request, lab_name="", job_id="", resource_id="", file_i "datasource_list": ["None"], } - return HttpResponse(yaml.dump(cloud_dict), status=200) + return HttpResponse(yaml.dump(cloud_dict, width=float("inf")), status=200) @csrf_exempt @@ -310,9 +310,9 @@ def resource_ci_userdata_directory(request, lab_name="", job_id="", resource_id= files = resource.config.cloud_init_files files = [{"id": file.id, "priority": file.priority} for file in files.order_by("priority").all()] - d = { - 'merge_failures': [] - } + d = {} + + merge_failures = [] merger = Merger( [ @@ -335,9 +335,12 @@ def resource_ci_userdata_directory(request, lab_name="", job_id="", resource_id= print("Failed to merge file in, as it had invalid content:", f.id) print("File text was:") print(f.text) - d['merge_failures'].append({f.id: str(e)}) + merge_failures.append({f.id: str(e)}) + + if len(merge_failures) > 0: + d['merge_failures'] = merge_failures - file = CloudInitFile.create(text=yaml.dump(d), priority=0) + file = CloudInitFile.create(text=yaml.dump(d, width=float("inf")), priority=0) return HttpResponse(json.dumps([{"id": file.id, "priority": file.priority}]), status=200) |