From d93346a716bde5237b7cfef5c10ea56e4922b59a Mon Sep 17 00:00:00 2001 From: Adam Hassick Date: Tue, 27 Jul 2021 13:05:16 +0000 Subject: Make C-I serialization work with current netconf rules Signed-off-by: Sawyer Bergeron Change-Id: If967e5e1f268c5bee3ad4496847662cf4de1187c Signed-off-by: Sawyer Bergeron --- src/api/models.py | 40 +++++++++++++++++++++++++++++++++------- src/api/urls.py | 6 ++++-- src/api/views.py | 6 +++++- 3 files changed, 42 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/api/models.py b/src/api/models.py index a207044..3098111 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -390,24 +390,50 @@ class CloudInitFile(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", + }) + return user_array def _serialize_netconf_v1(self): + interfaces = {} # map from iface_name => dhcp_config + #vlans = {} # map from vlan_id => dhcp_config + config_arr = [] for interface in self._resource().interfaces.all(): interface_name = interface.profile.name interface_mac = interface.mac_address + iface_dict_entry = { + "type": "physical", + "name": interface_name, + "mac_address": interface_mac, + } + + for vlan in interface.config.all(): - vlan_dict_entry = {'type': 'vlan'} - vlan_dict_entry['name'] = str(interface_name) + "." + str(vlan.vlan_id) - vlan_dict_entry['link'] = str(interface_name) - vlan_dict_entry['vlan_id'] = int(vlan.vlan_id) - vlan_dict_entry['mac_address'] = str(interface_mac) + if vlan.tagged: + vlan_dict_entry = {'type': 'vlan'} + vlan_dict_entry['name'] = str(interface_name) + "." + str(vlan.vlan_id) + vlan_dict_entry['vlan_link'] = str(interface_name) + vlan_dict_entry['vlan_id'] = int(vlan.vlan_id) + vlan_dict_entry['mac_address'] = str(interface_mac) + if vlan.public: + vlan_dict_entry["subnets"] = [ { "type": "dhcp" } ] + config_arr.append(vlan_dict_entry) + if (not vlan.tagged) and vlan.public: + iface_dict_entry["subnets"] = [ { "type": "dhcp" } ] + #vlan_dict_entry['mtu'] = # TODO, determine override MTU if needed - config_arr.append(vlan_dict_entry) + config_arr.append(iface_dict_entry) + ns_dict = { 'type': 'nameserver', @@ -443,7 +469,7 @@ class CloudInitFile(models.Model): return main_dict def serialize(self) -> str: - return yaml.dump(self._to_dict()) + return str("#cloud-config\n") + yaml.dump(self._to_dict()) class Job(models.Model): """ diff --git a/src/api/urls.py b/src/api/urls.py index e5ddd97..970ecf2 100644 --- a/src/api/urls.py +++ b/src/api/urls.py @@ -46,7 +46,8 @@ from api.views import ( lab_user, GenerateTokenView, analytics_job, - resource_cidata, + resource_ci_metadata, + resource_ci_userdata, all_images, all_opsyss, single_image, @@ -68,7 +69,8 @@ urlpatterns = [ path('labs//booking//idf', get_idf, name="get-idf"), path('labs//jobs/', specific_job), path('labs//jobs//', specific_task), - path('labs//jobs//cidata/', resource_cidata), + path('labs//jobs//cidata//user-data', resource_ci_userdata), + path('labs//jobs//cidata//meta-data', resource_ci_metadata), path('labs//jobs/new', new_jobs), path('labs//jobs/current', current_jobs), path('labs//jobs/done', done_jobs), diff --git a/src/api/views.py b/src/api/views.py index 4b887e6..7add23e 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -248,7 +248,7 @@ def specific_job(request, lab_name="", job_id=""): return JsonResponse(lab_manager.get_job(job_id), safe=False) @csrf_exempt -def resource_cidata(request, lab_name="", job_id="", resource_id=""): +def resource_ci_userdata(request, lab_name="", job_id="", resource_id=""): #lab_token = request.META.get('HTTP_AUTH_TOKEN') #lab_manager = LabManagerTracker.get(lab_name, lab_token) @@ -263,6 +263,10 @@ def resource_cidata(request, lab_name="", job_id="", resource_id=""): return HttpResponse(cifile.serialize(), status=200) +@csrf_exempt +def resource_ci_metadata(request, lab_name="", job_id="", resource_id=""): + return HttpResponse("#cloud-config", status=200) + def new_jobs(request, lab_name=""): lab_token = request.META.get('HTTP_AUTH_TOKEN') -- cgit 1.2.3-korg