From afcee3cad5c091e78e909b83f8df49accf1af5b6 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Mon, 11 Oct 2021 22:02:16 +0000 Subject: Prod cobbler hotfixes Signed-off-by: Sawyer Bergeron Change-Id: I092bc6d85a3b2c77bfbe24f3af0d2b7a5f75a8c3 --- src/api/models.py | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'src/api/models.py') diff --git a/src/api/models.py b/src/api/models.py index 1f03deb..3b36b68 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -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: -- cgit 1.2.3-korg