From f0de2c0e31bfe8d0bbaf4fe00b1ea009daae31e4 Mon Sep 17 00:00:00 2001 From: mischa Date: Thu, 4 May 2023 14:32:41 +0200 Subject: [PATCH] strip cidr from IP when dhcpd is in play --- deploy.pl | 11 ++++++++--- vms/vm01.txt | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/deploy.pl b/deploy.pl index e570a84..2017da8 100755 --- a/deploy.pl +++ b/deploy.pl @@ -157,7 +157,8 @@ sub render_dhcpd_conf { my $_disk_format = $vms{$vm_name}{'format'} || $conf{'conf'}{'FORMAT'}; my $_disk = $conf{'conf'}{'IMAGES'} . "/" . $_instance . "." . $_disk_format; my $_mac = $vms{$vm_name}{'mac'} || $conf{'conf'}{'MAC_PREFIX'} . ":" . $vms{$vm_name}{'vm_number'}; - my $_ipv4 = $vms{$vm_name}{'ipv4'} || $conf{'conf'}{'IP_PREFIX'} . "." . ($conf{'conf'}{'IP_START'} + $vms{$vm_name}{'vm_number'}); + my ($_ipv4_address, $_ipv4_subnet) = split(/\//, $vms{$vm_name}{'ipv4'}, 2) if $vms{$vm_name}{'ipv4'}; + my $_ipv4 = $_ipv4_address || $conf{'conf'}{'IP_PREFIX'} . "." . ($conf{'conf'}{'IP_START'} + $vms{$vm_name}{'vm_number'}); my $_ipv6 = $vms{$vm_name}{'ipv6'} || $conf{'conf'}{'IPV6_PREFIX'} . ":" . ($conf{'conf'}{'IPV6_START'} + $vms{$vm_name}{'vm_number'}) . "::" . ($conf{'conf'}{'IP_START'} + $vms{$vm_name}{'vm_number'}); my $_hostname = $vms{$vm_name}{'hostname'}; @@ -197,7 +198,7 @@ sub render_install_conf { my $jot_pass = qx(jot -rcs '' 20 46 125); chomp($jot_pass); my $_ipv4 = $vms{$vm_name}{'ipv4'} || "autoconf"; - my $_ipv4_gateway = $vms{$vm_name}{'ipv4_gw'} || ""; + my $_ipv4_gateway = $vms{$vm_name}{'ipv4_gw'} || $conf{'conf'}{'ROUTER'}; my $_ipv6 = $vms{$vm_name}{'ipv6'} || $conf{'conf'}{'IPV6_PREFIX'} . ":" . ($conf{'conf'}{'IPV6_START'} + $vms{$vm_name}{'vm_number'}) . "::" . ($conf{'conf'}{'IP_START'} + $vms{$vm_name}{'vm_number'}); my $_ipv6_gateway = $vms{$vm_name}{'ipv6_gw'} || $conf{'conf'}{'IPV6_PREFIX'} . ":" . ($conf{'conf'}{'IPV6_START'} + $vms{$vm_name}{'vm_number'}) . "::1"; my $_username = $vms{$vm_name}{'username'}; @@ -211,8 +212,12 @@ sub render_install_conf { printf $fh_install "Network interfaces = vio0\n"; printf $fh_install "IPv4 address for vio0 = %s\n", $_ipv4; printf $fh_install "IPv6 address for vio0 = %s\n", $_ipv6; - printf $fh_install "Default IPv4 route = %s\n", $_ipv4_gateway if $_ipv4_gateway; + printf $fh_install "Default IPv4 route = %s\n", $_ipv4_gateway if $_ipv4 ne "autoconf"; printf $fh_install "IPv6 default router = %s\n", $_ipv6_gateway; + + printf $fh_install "DNS domain name = %s\n", "high5.nl" if $_ipv4 ne "autoconf"; + printf $fh_install "DNS nameservers = %s\n", $conf{'conf'}{'DNS'} if $_ipv4 ne "autoconf"; + printf $fh_install "Setup a user = %s\n", $_username; printf $fh_install "Password for user = %s\n", $jot_pass; printf $fh_install "Public ssh key for user = %s %s\n", $_sshkey, $jot_pass; diff --git a/vms/vm01.txt b/vms/vm01.txt index 7cd6d81..f99990a 100644 --- a/vms/vm01.txt +++ b/vms/vm01.txt @@ -1,4 +1,5 @@ mac="fe:e1:ab:dd:73:a4" +ipv4="192.168.1.1/23" owner="testuser1" date="2018/04/02" payment="74"