Skip to content

Commit

Permalink
Use random hostname starting with xcp-ng-
Browse files Browse the repository at this point in the history
This allows to have different hostname when installing new VM.

Signed-off-by: Guillaume <[email protected]>
  • Loading branch information
gthvn1 committed Aug 23, 2023
1 parent 2fa3e69 commit deb96b5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 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,6 +49,9 @@ 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"?>
Expand All @@ -58,6 +63,7 @@ def generate_answerfile(directory, installer, hostname_or_ip, action, hdd):
<source type="url">{installer}</source>
<admin-interface name="eth0" proto="dhcp" />
<timezone>Europe/Paris</timezone>
<hostname>{hostname}</hostname>
<script stage="filesystem-populated" type="url">
http://{pxe}/configs/presets/scripts/filesystem-populated.py
</script>
Expand Down

0 comments on commit deb96b5

Please sign in to comment.