Fix autoinstalls to work around a modern d-i bug
[invirt/packages/invirt-xen-config.git] / templatize-xend-config
1 #!/usr/bin/perl -0n
2 print <<'EOF';
3 <%
4 from invirt.config import structs as cfg
5 import os
6 fqdn = os.uname()[1]
7 internal_ip = None
8 # This hack is necessary because cfg.hosts is an array rather than a dict.
9 for host in cfg.hosts:
10   if host.hostname == fqdn:
11     internal_ip = host.internal_ips[0]
12     break
13
14 class xend_template_exception(Exception): pass
15 if internal_ip is None:
16   raise xend_template_exception('Could not find an internal IP in the configuration for host %s' % fqdn)
17 %>
18 EOF
19
20 s/^\#?\(xend-relocation-server [a-z]*\)/(xend-relocation-server yes)/m or die;
21 s/^\#?\(xend-relocation-address ''\)/(xend-relocation-address '\${internal_ip}')/m or die;
22 s/^\#?\(xend-relocation-hosts-allow '[^']*'\)/(xend-relocation-hosts-allow '')/m or die;
23 # s/^(\# )?\(network-script network-bridge\)/(network-script 'network-bridge')/m or die;
24 s/^\(dom0-min-mem [0-9]*\)/(dom0-min-mem 1536)/m or die;
25 s/\$(\{XEN_CONFIG_DIR\})/$1/m or die;
26 print;