aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking
diff options
context:
space:
mode:
Diffstat (limited to 'src/booking')
-rw-r--r--src/booking/forms.py1
-rw-r--r--src/booking/migrations/0009_booking_complete.py18
-rw-r--r--src/booking/models.py2
-rw-r--r--src/booking/quick_deployer.py30
4 files changed, 48 insertions, 3 deletions
diff --git a/src/booking/forms.py b/src/booking/forms.py
index cbc3407..ff829b2 100644
--- a/src/booking/forms.py
+++ b/src/booking/forms.py
@@ -22,6 +22,7 @@ class QuickBookingForm(forms.Form):
purpose = forms.CharField(max_length=1000)
project = forms.CharField(max_length=400)
hostname = forms.CharField(required=False, max_length=400)
+ global_cloud_config = forms.CharField(widget=forms.Textarea, required=False)
installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=False)
scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=False)
diff --git a/src/booking/migrations/0009_booking_complete.py b/src/booking/migrations/0009_booking_complete.py
new file mode 100644
index 0000000..e291a83
--- /dev/null
+++ b/src/booking/migrations/0009_booking_complete.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.2 on 2021-09-07 15:14
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('booking', '0008_auto_20201109_1947'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='booking',
+ name='complete',
+ field=models.BooleanField(default=False),
+ ),
+ ]
diff --git a/src/booking/models.py b/src/booking/models.py
index cfdf7bc..966f1c2 100644
--- a/src/booking/models.py
+++ b/src/booking/models.py
@@ -39,6 +39,8 @@ class Booking(models.Model):
pdf = models.TextField(blank=True, default="")
idf = models.TextField(blank=True, default="")
+ complete = models.BooleanField(default=False)
+
class Meta:
db_table = 'booking'
diff --git a/src/booking/quick_deployer.py b/src/booking/quick_deployer.py
index 9e53da5..9bdebc2 100644
--- a/src/booking/quick_deployer.py
+++ b/src/booking/quick_deployer.py
@@ -26,6 +26,7 @@ from resource_inventory.models import (
NetworkConnection,
InterfaceConfiguration,
Network,
+ CloudInitFile,
)
from resource_inventory.resource_manager import ResourceManager
from resource_inventory.pdf_templater import PDFTemplater
@@ -60,7 +61,7 @@ def parse_resource_field(resource_json):
return lab, template
-def update_template(old_template, image, hostname, user):
+def update_template(old_template, image, hostname, user, global_cloud_config=None):
"""
Duplicate a template to the users account and update configured fields.
@@ -112,9 +113,17 @@ def update_template(old_template, image, hostname, user):
image=image_to_set,
template=template,
is_head_node=old_config.is_head_node,
- name=hostname if len(old_template.getConfigs()) == 1 else old_config.name
+ name=hostname if len(old_template.getConfigs()) == 1 else old_config.name,
+ #cloud_init_files=old_config.cloud_init_files.set()
)
+ for file in old_config.cloud_init_files.all():
+ config.cloud_init_files.add(file);
+
+ if global_cloud_config:
+ config.cloud_init_files.add(global_cloud_config)
+ config.save()
+
for old_iface_config in old_config.interface_configs.all():
iface_config = InterfaceConfiguration.objects.create(
profile=old_iface_config.profile,
@@ -186,6 +195,13 @@ def check_invariants(request, **kwargs):
if length < 1 or length > 21:
raise BookingLengthException("Booking must be between 1 and 21 days long")
+# global_cloud_config is Option<str> forming a valid yaml file if Some
+def generate_cloud_configs(resource_bundle, global_cloud_config):
+ c_file = CloudInitFile.objects.new(priority=1) # apply after the internal
+ for host in resource_bundle.get_resources():
+ #cfile = CloudInitFile::from_text(
+ pass
+ # TODO
def create_from_form(form, request):
"""
@@ -200,6 +216,12 @@ def create_from_form(form, request):
users_field = form.cleaned_data['users']
hostname = 'opnfv_host' if not form.cleaned_data['hostname'] else form.cleaned_data['hostname']
length = form.cleaned_data['length']
+ global_cloud_config = None if not form.cleaned_data['global_cloud_config'] else form.cleaned_data['global_cloud_config']
+
+ if global_cloud_config:
+ print("about to create global cloud config")
+ global_cloud_config = CloudInitFile.create(text=global_cloud_config, priority=CloudInitFile.objects.count())
+ print("made global cloud config")
image = form.cleaned_data['image']
scenario = form.cleaned_data['scenario']
@@ -219,7 +241,7 @@ def create_from_form(form, request):
ResourceManager.getInstance().templateIsReservable(resource_template)
- resource_template = update_template(resource_template, image, hostname, request.user)
+ resource_template = update_template(resource_template, image, hostname, request.user, global_cloud_config=global_cloud_config)
# if no installer provided, just create blank host
opnfv_config = None
@@ -231,6 +253,8 @@ def create_from_form(form, request):
# generate resource bundle
resource_bundle = generate_resource_bundle(resource_template)
+ #generate_cloud_configs(resource_bundle)
+
# generate booking
booking = Booking.objects.create(
purpose=purpose_field,