Prod cobbler hotfixes 67/72967/1
authorSawyer Bergeron <sbergeron@iol.unh.edu>
Mon, 11 Oct 2021 22:02:16 +0000 (22:02 +0000)
committerSawyer Bergeron <sbergeron@iol.unh.edu>
Mon, 11 Oct 2021 22:02:16 +0000 (22:02 +0000)
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Change-Id: I092bc6d85a3b2c77bfbe24f3af0d2b7a5f75a8c3

src/api/models.py
src/api/views.py
src/booking/quick_deployer.py
src/templates/base/dashboard/searchable_select_multiple.html
src/templates/lfedge/booking/quick_deploy.html

index 1f03deb..3b36b68 100644 (file)
@@ -376,7 +376,9 @@ class GeneratedCloudConfig(models.Model):
         """
         returns the dictionary to be placed behind the `users` field of the toplevel c-i dict
         """
+        # conserves distro default user
         user_array = ["default"]
+
         users = list(self.booking.collaborators.all())
         users.append(self.booking.owner)
         for collaborator in users:
@@ -392,16 +394,39 @@ class GeneratedCloudConfig(models.Model):
 
             user_array.append(userdict)
 
-        user_array.append({
-            "name": "opnfv",
-            "plain_text_passwd": "OPNFV_HOST",
-            "ssh_redirect_user": True,
-            "sudo": "ALL=(ALL) NOPASSWD:ALL",
-            "groups": "sudo",
-            })
+        #user_array.append({
+        #    "name": "opnfv",
+        #    "passwd": "$6$k54L.vim1cLaEc4$5AyUIrufGlbtVBzuCWOlA1yV6QdD7Gr2MzwIs/WhuYR9ebSfh3Qlb7djkqzjwjxpnSAonK1YOabPP6NxUDccu.",
+        #    "ssh_redirect_user": True,
+        #    "sudo": "ALL=(ALL) NOPASSWD:ALL",
+        #    "groups": "sudo",
+        #    })
 
         return user_array
 
+    # TODO: make this configurable
+    def _serialize_sysinfo(self):
+        defuser = {}
+        defuser['name'] = 'opnfv'
+        defuser['plain_text_passwd'] = 'OPNFV_HOST'
+        defuser['home'] = '/home/opnfv'
+        defuser['shell'] = '/bin/bash'
+        defuser['lock_passwd'] = True
+        defuser['gecos'] = 'Lab Manager User'
+        defuser['groups'] = 'sudo'
+
+        return { 'default_user': defuser }
+
+    # TODO: make this configurable
+    def _serialize_runcmds(self):
+        cmdlist = [ ]
+
+        # have hosts run dhcp on boot
+        cmdlist.append(['sudo', 'dhclient', '-r'])
+        cmdlist.append(['sudo', 'dhclient'])
+
+        return cmdlist
+
     def _serialize_netconf_v1(self):
         interfaces = {} # map from iface_name => dhcp_config
         #vlans = {} # map from vlan_id => dhcp_config
@@ -468,6 +493,12 @@ class GeneratedCloudConfig(models.Model):
         main_dict['network'] = self._serialize_netconf_v1()
         main_dict['hostname'] = self.rconfig.name
 
+        # add first startup commands
+        main_dict['runcmd'] = self._serialize_runcmds()
+
+        # configure distro default user
+        main_dict['system_info'] = self._serialize_sysinfo()
+
         return main_dict
 
     def serialize(self) -> str:
index 5af3d69..13bf1dd 100644 (file)
@@ -37,6 +37,8 @@ from resource_inventory.models import (
 )
 
 import json
+import yaml
+import uuid
 from deepmerge import Merger
 
 """
@@ -309,19 +311,19 @@ def resource_ci_userdata_directory(request, lab_name="", job_id="", resource_id=
             ["override"], # if types conflict (shouldn't happen in CI, but handle case)
         )
 
-    for file in files.order_by("priority").all():
+    for f in resource.config.cloud_init_files.order_by("priority").all():
         try:
-            other_dict = yaml.load(file.text)
+            other_dict = yaml.load(f.text)
             if not (type(d) is dict):
                 raise Exception("CI file was valid yaml but was not a dict")
 
             merger.merge(d, other_dict)
         except Exception as e:
             # if fail to merge, then just skip
-            print("Failed to merge file in, as it had invalid content:", file.id)
+            print("Failed to merge file in, as it had invalid content:", f.id)
             print("File text was:")
-            print(file.text)
-            d['merge_failures'].append({file.id: str(e)})
+            print(f.text)
+            d['merge_failures'].append({f.id: str(e)})
 
     file = CloudInitFile.create(text=yaml.dump(d), priority=0)
 
index 261b095..2eb9fba 100644 (file)
@@ -9,6 +9,7 @@
 
 
 import json
+import yaml
 from django.db.models import Q
 from datetime import timedelta
 from django.utils import timezone
index 4d996e5..2b77fa3 100644 (file)
@@ -40,7 +40,9 @@
         let field_initial = {{ initial|safe }};
 
         //global
+       console.log("makes search widget");
         searchable_select_multiple_widget = new SearchableSelectMultipleWidget(format_vars, field_dataset, field_initial);
+       console.log("made search widget");
     }
 
     searchableSelectMultipleWidgetEntry();
index dac3815..ccafd90 100644 (file)
@@ -11,7 +11,7 @@
 </p>
 {% endblock form-text %}
 {% block collab %}
-<div class="col-12 col-lg-4 my-2">
+<div class="col-12 col-lg-6 my-2">
     <div class="col border rounded py-2 h-100">
         <label>Collaborators</label>
         {{ form.users }}
@@ -21,8 +21,8 @@
 
 {% block image_script %}
     <script type="text/javascript">
-        document.getElementById("id_image").disabled = true;
-        document.getElementById("id_image").style.display = 'none';
-        document.getElementById("id_image").previousElementSibling.style.display = 'none';
+//        document.getElementById("id_image").disabled = true;
+//        document.getElementById("id_image").style.display = 'none';
+//        document.getElementById("id_image").previousElementSibling.style.display = 'none';
     </script>
 {% endblock image_script %}