Skip to content

Commit

Permalink
Generate a random hostname starting with xcp-ng
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume <[email protected]>
  • Loading branch information
gthvn1 committed Aug 17, 2023
1 parent 2fa3e69 commit c328a8c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/install_xcpng.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import atexit
import logging
import os
import random
import requests
import string
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -47,11 +49,13 @@ def generate_answerfile(directory, installer, hostname_or_ip, action, hdd):
cmd = ['openssl', 'passwd', '-6', password]
res = subprocess.run(cmd, stdout=subprocess.PIPE)
encrypted_password = res.stdout.decode().strip()
hostname = "xcp-ng-" + "".join(random.choice(string.ascii_lowercase) for i in range(5))
with open(f'{directory}/answerfile.xml', 'w') as answerfile:
if action == 'install':
answerfile.write(f"""<?xml version="1.0"?>
<installation>
<keymap>fr</keymap>
<hostname>{hostname}</hostname>
<primary-disk>{hdd}</primary-disk>
<guest-disk>{hdd}</guest-disk>
<root-password type="hash">{encrypted_password}</root-password>
Expand Down

0 comments on commit c328a8c

Please sign in to comment.