From a819fc1df86721eda36eee89d0235c89b3159d6b Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Tue, 7 Sep 2021 11:28:35 -0400 Subject: Add user specified CI file entry Signed-off-by: Sawyer Bergeron Change-Id: Ia920130612da8fcde9d1a0d5dde7861904857162 Signed-off-by: Sawyer Bergeron --- src/booking/quick_deployer.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/booking/quick_deployer.py') 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 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, -- cgit 1.2.3-korg