diff --git a/.gitignore b/.gitignore index 57b83ab..06d660d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ dhcpd.conf vm.conf *-orig +dpl.pl diff --git a/_deploy.conf b/_deploy.conf index 1bec0f4..8608034 100644 --- a/_deploy.conf +++ b/_deploy.conf @@ -18,8 +18,8 @@ MEMORY="512M" DISKSIZE="50G" FORMAT="qcow2" VMDUSERS="vmdusers" -SWITCH="uplink_vlan931" -INTERFACE="bridge931" +SWITCH="uplink_vlan931 uplink_vlan910" +INTERFACE="veb931 veb910" # dhcpd.conf ROUTER="46.23.93.1" DNS="46.23.80.26" diff --git a/deploy.pl b/deploy.pl index 224e88e..e570a84 100755 --- a/deploy.pl +++ b/deploy.pl @@ -34,6 +34,7 @@ # 2022/12/01 added: boot device net, move away from expect() # 2023/05/02 added: enable flag, allow for VMs to auto-start # 2023/05/03 added: predefined IPv6 address, gw +# 2023/05/04 added: added ability to run without dhcp and only predfined IPs # use 5.024; use strict; @@ -85,6 +86,7 @@ sub render_vm_conf { my %vms = %{$_[1]}; my $_etc = $conf{'conf'}{'ETC'}; my $_VERSION = qx(uname -r); + my %switches; open my $fh_vm, ">", "$_etc/vm.conf"; printf $fh_vm "#\n# File generated by deploy.pl\n#\n"; @@ -93,16 +95,16 @@ sub render_vm_conf { if ($_VERSION > 7.2) { printf $fh_vm "agentx\n"; } - printf $fh_vm "\n"; - printf $fh_vm "switch \"%s\" {\n", $conf{'conf'}{'SWITCH'}; - printf $fh_vm "\tinterface %s\n", $conf{'conf'}{'INTERFACE'}; - printf $fh_vm "}\n\n"; - if ($conf{'conf'}{'SWITCH2'}) { - printf $fh_vm "switch \"%s\" {\n", $conf{'conf'}{'SWITCH2'}; - printf $fh_vm "\tinterface %s\n", $conf{'conf'}{'INTERFACE2'}; - printf $fh_vm "}\n\n"; + @switches{split / /, $conf{'conf'}{'SWITCH'}} = split / /, $conf{'conf'}{'INTERFACE'}; + my $default_switch = (sort keys %switches)[0]; + foreach my $switch (sort keys %switches) { + printf $fh_vm "\n"; + printf $fh_vm "switch \"%s\" {\n", $switch; + printf $fh_vm "\tinterface %s\n", $switches{$switch}; + printf $fh_vm "}\n"; } + print $fh_vm "\n"; for my $vm_name (sort keys %vms) { my $_instance = $vms{$vm_name}{'instance'} || $vm_name; @@ -114,8 +116,7 @@ sub render_vm_conf { my $_owner = $vms{$vm_name}{'username'}; my $_memory = $vms{$vm_name}{'memory'} || $conf{'conf'}{'MEMORY'}; my $_boot = $conf{'conf'}{'IMAGES'} . "/bsd.rd"; - my $_switch = $vms{$vm_name}{'switch'} || $conf{'conf'}{'SWITCH'}; - my $_switch2 = $vms{$vm_name}{'switch2'}; + my $_switch = $vms{$vm_name}{'switch'} || $default_switch; my $_mac = $vms{$vm_name}{'mac'} || $conf{'conf'}{'MAC_PREFIX'} . ":" . $vms{$vm_name}{'vm_number'}; printf $fh_vm "vm \"%s\" {\n", $_instance; @@ -130,7 +131,6 @@ sub render_vm_conf { printf $fh_vm "\t\tswitch \"%s\"\n", $_switch; printf $fh_vm "\t\tlladdr %s\n", $_mac; printf $fh_vm "\t}\n"; - printf $fh_vm "\tinterface tap { switch \"%s\" }\n", $_switch2 if $_switch2; printf $fh_vm "}\n"; } close $fh_vm; @@ -157,13 +157,13 @@ 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 $_ip = $vms{$vm_name}{'ip'} || $conf{'conf'}{'IP_PREFIX'} . "." . ($conf{'conf'}{'IP_START'} + $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 $_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'}; printf $fh_dhcpd "\thost %s {\n", $_instance; printf $fh_dhcpd "\t\thardware ethernet %s;\n", $_mac; - printf $fh_dhcpd "\t\tfixed-address %s;\n", $_ip; + printf $fh_dhcpd "\t\tfixed-address %s;\n", $_ipv4; printf $fh_dhcpd "\t\t#fixed-address-ipv6 %s;\n", $_ipv6; if (! -e $_disk) { printf $fh_dhcpd "\t\tfilename \"auto_install\";\n"; @@ -196,6 +196,8 @@ sub render_install_conf { my $_hostname = $vms{$vm_name}{'hostname'}; 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 $_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'}; @@ -207,8 +209,9 @@ sub render_install_conf { printf $fh_install "Password for root = %s\n", $jot_pass; printf $fh_install "Which speed should com0 = 115200\n"; printf $fh_install "Network interfaces = vio0\n"; - printf $fh_install "IPv4 address for vio0 = autoconf\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 "IPv6 default router = %s\n", $_ipv6_gateway; printf $fh_install "Setup a user = %s\n", $_username; printf $fh_install "Password for user = %s\n", $jot_pass; @@ -354,10 +357,12 @@ my %vms; my @files = glob "$conf{'conf'}{'VMS'}/*.txt"; %vms = get_variables('vms', @files); +my $DHCP = $conf{'conf'}{'DHCP'} || "yes"; + # run all functions #debug_parse(\%conf, \%vms); render_vm_conf(\%conf, \%vms); -render_dhcpd_conf(\%conf, \%vms); +render_dhcpd_conf(\%conf, \%vms) if $DHCP eq "yes"; render_install_conf(\%conf, \%vms); create_accounts(\%conf, \%vms); create_img_files(\%conf, \%vms); diff --git a/vms/vm01.txt b/vms/vm01.txt index bf37453..7cd6d81 100644 --- a/vms/vm01.txt +++ b/vms/vm01.txt @@ -1,7 +1,4 @@ mac="fe:e1:ab:dd:73:a4" -ip="192.168.1.112" -ipv6="2a03:6000:1::112" -ipv6_gw="2a03:6000:1::1" owner="testuser1" date="2018/04/02" payment="74" @@ -13,4 +10,3 @@ hostname="deploytest1" username="deploytest1" memory="1G" note="" -enable="yes"