diff options
-rw-r--r-- | src/api/models.py | 40 | ||||
-rw-r--r-- | src/api/urls.py | 6 | ||||
-rw-r--r-- | src/api/views.py | 6 |
3 files changed, 42 insertions, 10 deletions
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/<slug:lab_name>/booking/<int:booking_id>/idf', get_idf, name="get-idf"), path('labs/<slug:lab_name>/jobs/<int:job_id>', specific_job), path('labs/<slug:lab_name>/jobs/<int:job_id>/<slug:task_id>', specific_task), - path('labs/<slug:lab_name>/jobs/<int:job_id>/cidata/<slug:resource_id>', resource_cidata), + path('labs/<slug:lab_name>/jobs/<int:job_id>/cidata/<slug:resource_id>/user-data', resource_ci_userdata), + path('labs/<slug:lab_name>/jobs/<int:job_id>/cidata/<slug:resource_id>/meta-data', resource_ci_metadata), path('labs/<slug:lab_name>/jobs/new', new_jobs), path('labs/<slug:lab_name>/jobs/current', current_jobs), path('labs/<slug:lab_name>/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') |