Skip to content

Commit 5daaa93

Browse files
committed
install_xcpng: setup admin iface as static if name has an IP in data.py
Uses the HOSTS_IP_CONFIG struct already usable to set this config for automated install tests. Signed-off-by: Yann Dirson <[email protected]>
1 parent 067411f commit 5daaa93

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

Diff for: lib/host.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,21 @@
2424

2525
def host_data(hostname_or_ip):
2626
# read from data.py
27-
from data import HOST_DEFAULT_USER, HOST_DEFAULT_PASSWORD, HOSTS
27+
from data import HOST_DEFAULT_USER, HOST_DEFAULT_PASSWORD, HOSTS, HOSTS_IP_CONFIG
2828
if hostname_or_ip in HOSTS:
2929
h_data = HOSTS[hostname_or_ip]
30-
return h_data
30+
ret = h_data
3131
else:
32-
return {'user': HOST_DEFAULT_USER, 'password': HOST_DEFAULT_PASSWORD}
32+
ret = {'user': HOST_DEFAULT_USER, 'password': HOST_DEFAULT_PASSWORD}
33+
#
34+
ip = HOSTS_IP_CONFIG.get('ip', None)
35+
if ip:
36+
ret.update(ip=ip,
37+
netmask=HOSTS_IP_CONFIG['NETMASK'],
38+
gw=HOSTS_IP_CONFIG['GATEWAY'],
39+
dns=HOSTS_IP_CONFIG['DNS'])
40+
41+
return ret
3342

3443
class Host:
3544
xe_prefix = "host"

Diff for: scripts/install_xcpng.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@
2525
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)
2626

2727
def generate_answerfile(directory, installer, hostname_or_ip, target_hostname, action, hdd, netinstall_gpg_check):
28-
password = host_data(hostname_or_ip)['password']
28+
h_data = host_data(hostname_or_ip)
29+
password = h_data['password']
30+
if 'ip' in h_data:
31+
iface = f"""
32+
<admin-interface name="eth0" proto="static">
33+
<ipaddr>{h_data['ip']}</ipaddr>
34+
<subnet>{h_data['netmask']}</subnet>
35+
<gateway>{h_data['gw']}</gateway>
36+
</admin-interface>
37+
<name-server>{h_data['dns']}</name-server>
38+
"""
39+
else:
40+
iface = '<admin-interface name="eth0" proto="dhcp" />'
2941
cmd = ['openssl', 'passwd', '-6', password]
3042
res = subprocess.run(cmd, stdout=subprocess.PIPE)
3143
encrypted_password = res.stdout.decode().strip()
@@ -42,7 +54,7 @@ def generate_answerfile(directory, installer, hostname_or_ip, target_hostname, a
4254
<guest-disk>{hdd}</guest-disk>
4355
<root-password type="hash">{encrypted_password}</root-password>
4456
<source type="url">{installer}</source>
45-
<admin-interface name="eth0" proto="dhcp" />
57+
{iface}
4658
<timezone>Europe/Paris</timezone>
4759
<hostname>{target_hostname}</hostname>
4860
<script stage="filesystem-populated" type="url">

0 commit comments

Comments
 (0)