Commit fdb826d5 authored by Nikolai R Kristiansen's avatar Nikolai R Kristiansen
Browse files

Clear out pxe_key on validation

parent bcb4b2e7
Pipeline #9 skipped
from mdb.models import Host
from __future__ import unicode_literals
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from mdb.models import Host
class HostPXEValidateSerializer(serializers.Serializer):
certname = serializers.CharField(required=True)
......@@ -41,6 +43,7 @@ class HostPXEValidateSerializer(serializers.Serializer):
def create(self, validated_data):
# Make requests kind of idempotent by only allowing 1 request / installation = False = ''
......@@ -98,6 +98,7 @@ def create_pxe_key_and_write_pxe_files_when_host_changes(sender, instance, creat
for pxe_file_name, pxe_file in host.as_pxe_files():
path = os.path.join(settings.MDB_PXE_TFTP_ROOT, pxe_file_name)
if host.pxe_installable:
# Write pxeconfig file to disk
with open(path, 'w+') as f:
f.write(pxe_file)"Created or updated {}".format(path))
......@@ -120,6 +121,7 @@ def create_pxe_key_and_write_pxe_files_when_host_changes(sender, instance, creat
if os.path.exists(path):
# Delete pxeconfig file from disk
os.unlink(path)"deleted {}".format(path))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment