Skip to content

Commit

Permalink
install_xcpng: setup admin iface as static if name has an IP in data.py
Browse files Browse the repository at this point in the history
Uses the HOSTS_IP_CONFIG struct already usable to set this config for
automated install tests.

Signed-off-by: Yann Dirson <[email protected]>
  • Loading branch information
ydirson committed Oct 18, 2024
1 parent 9b67a2e commit 3b9e66b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
15 changes: 12 additions & 3 deletions lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@

def host_data(hostname_or_ip):
# read from data.py
from data import HOST_DEFAULT_USER, HOST_DEFAULT_PASSWORD, HOSTS
from data import HOST_DEFAULT_USER, HOST_DEFAULT_PASSWORD, HOSTS, HOSTS_IP_CONFIG
if hostname_or_ip in HOSTS:
h_data = HOSTS[hostname_or_ip]
return h_data
ret = h_data
else:
return {'user': HOST_DEFAULT_USER, 'password': HOST_DEFAULT_PASSWORD}
ret = {'user': HOST_DEFAULT_USER, 'password': HOST_DEFAULT_PASSWORD}
#
ip = HOSTS_IP_CONFIG.get('ip', None)
if ip:
ret.update(ip=ip,
netmask=HOSTS_IP_CONFIG['NETMASK'],
gw=HOSTS_IP_CONFIG['GATEWAY'],
dns=HOSTS_IP_CONFIG['DNS'])

return ret

class Host:
xe_prefix = "host"
Expand Down
16 changes: 14 additions & 2 deletions scripts/install_xcpng.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)

def generate_answerfile(directory, installer, hostname_or_ip, target_hostname, action, hdd, netinstall_gpg_check):
password = host_data(hostname_or_ip)['password']
h_data = host_data(hostname_or_ip)
password = h_data['password']
if 'ip' in h_data:
iface = f"""
<admin-interface name="eth0" proto="static">
<ipaddr>{h_data['ip']}</ipaddr>
<subnet>{h_data['netmask']}</subnet>
<gateway>{h_data['gw']}</gateway>
</admin-interface>
<name-server>{h_data['dns']}</name-server>
"""
else:
iface = '<admin-interface name="eth0" proto="dhcp" />'
cmd = ['openssl', 'passwd', '-6', password]
res = subprocess.run(cmd, stdout=subprocess.PIPE)
encrypted_password = res.stdout.decode().strip()
Expand All @@ -42,7 +54,7 @@ def generate_answerfile(directory, installer, hostname_or_ip, target_hostname, a
<guest-disk>{hdd}</guest-disk>
<root-password type="hash">{encrypted_password}</root-password>
<source type="url">{installer}</source>
<admin-interface name="eth0" proto="dhcp" />
{iface}
<timezone>Europe/Paris</timezone>
<hostname>{target_hostname}</hostname>
<script stage="filesystem-populated" type="url">
Expand Down

0 comments on commit 3b9e66b

Please sign in to comment.