Clear out pxe_key on validation
This commit is contained in:
1 parent
bcb4b2e713
commit
fdb826d5ac
2 files changed
+6
-1
No files matched your search
@@ -1,7 +1,9 @@
|
||||
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
|
||||
self.host.pxe_installable = False
|
||||
self.host.pxe_key = ''
|
||||
self.host.save()
|
||||
|
||||
return self.host
|
||||
@@ -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)
|
||||
logger.info("Created or updated {}".format(path))
|
||||
@@ -120,6 +121,7 @@ def create_pxe_key_and_write_pxe_files_when_host_changes(sender, instance, creat
|
||||
|
||||
else:
|
||||
if os.path.exists(path):
|
||||
# Delete pxeconfig file from disk
|
||||
os.unlink(path)
|
||||
logger.info("deleted {}".format(path))
|
||||
|
||||
|
||||
Reference in new issue
Block a user