added ability to run without dhcpd
This commit is contained in:
parent
3edb629bd2
commit
ef79927dc2
|
@ -2,3 +2,4 @@
|
||||||
dhcpd.conf
|
dhcpd.conf
|
||||||
vm.conf
|
vm.conf
|
||||||
*-orig
|
*-orig
|
||||||
|
dpl.pl
|
||||||
|
|
|
@ -18,8 +18,8 @@ MEMORY="512M"
|
||||||
DISKSIZE="50G"
|
DISKSIZE="50G"
|
||||||
FORMAT="qcow2"
|
FORMAT="qcow2"
|
||||||
VMDUSERS="vmdusers"
|
VMDUSERS="vmdusers"
|
||||||
SWITCH="uplink_vlan931"
|
SWITCH="uplink_vlan931 uplink_vlan910"
|
||||||
INTERFACE="bridge931"
|
INTERFACE="veb931 veb910"
|
||||||
# dhcpd.conf
|
# dhcpd.conf
|
||||||
ROUTER="46.23.93.1"
|
ROUTER="46.23.93.1"
|
||||||
DNS="46.23.80.26"
|
DNS="46.23.80.26"
|
||||||
|
|
35
deploy.pl
35
deploy.pl
|
@ -34,6 +34,7 @@
|
||||||
# 2022/12/01 added: boot device net, move away from expect()
|
# 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/02 added: enable flag, allow for VMs to auto-start
|
||||||
# 2023/05/03 added: predefined IPv6 address, gw
|
# 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 5.024;
|
||||||
use strict;
|
use strict;
|
||||||
|
@ -85,6 +86,7 @@ sub render_vm_conf {
|
||||||
my %vms = %{$_[1]};
|
my %vms = %{$_[1]};
|
||||||
my $_etc = $conf{'conf'}{'ETC'};
|
my $_etc = $conf{'conf'}{'ETC'};
|
||||||
my $_VERSION = qx(uname -r);
|
my $_VERSION = qx(uname -r);
|
||||||
|
my %switches;
|
||||||
|
|
||||||
open my $fh_vm, ">", "$_etc/vm.conf";
|
open my $fh_vm, ">", "$_etc/vm.conf";
|
||||||
printf $fh_vm "#\n# File generated by deploy.pl\n#\n";
|
printf $fh_vm "#\n# File generated by deploy.pl\n#\n";
|
||||||
|
@ -93,16 +95,16 @@ sub render_vm_conf {
|
||||||
if ($_VERSION > 7.2) {
|
if ($_VERSION > 7.2) {
|
||||||
printf $fh_vm "agentx\n";
|
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'}) {
|
@switches{split / /, $conf{'conf'}{'SWITCH'}} = split / /, $conf{'conf'}{'INTERFACE'};
|
||||||
printf $fh_vm "switch \"%s\" {\n", $conf{'conf'}{'SWITCH2'};
|
my $default_switch = (sort keys %switches)[0];
|
||||||
printf $fh_vm "\tinterface %s\n", $conf{'conf'}{'INTERFACE2'};
|
foreach my $switch (sort keys %switches) {
|
||||||
printf $fh_vm "}\n\n";
|
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) {
|
for my $vm_name (sort keys %vms) {
|
||||||
my $_instance = $vms{$vm_name}{'instance'} || $vm_name;
|
my $_instance = $vms{$vm_name}{'instance'} || $vm_name;
|
||||||
|
@ -114,8 +116,7 @@ sub render_vm_conf {
|
||||||
my $_owner = $vms{$vm_name}{'username'};
|
my $_owner = $vms{$vm_name}{'username'};
|
||||||
my $_memory = $vms{$vm_name}{'memory'} || $conf{'conf'}{'MEMORY'};
|
my $_memory = $vms{$vm_name}{'memory'} || $conf{'conf'}{'MEMORY'};
|
||||||
my $_boot = $conf{'conf'}{'IMAGES'} . "/bsd.rd";
|
my $_boot = $conf{'conf'}{'IMAGES'} . "/bsd.rd";
|
||||||
my $_switch = $vms{$vm_name}{'switch'} || $conf{'conf'}{'SWITCH'};
|
my $_switch = $vms{$vm_name}{'switch'} || $default_switch;
|
||||||
my $_switch2 = $vms{$vm_name}{'switch2'};
|
|
||||||
my $_mac = $vms{$vm_name}{'mac'} || $conf{'conf'}{'MAC_PREFIX'} . ":" . $vms{$vm_name}{'vm_number'};
|
my $_mac = $vms{$vm_name}{'mac'} || $conf{'conf'}{'MAC_PREFIX'} . ":" . $vms{$vm_name}{'vm_number'};
|
||||||
|
|
||||||
printf $fh_vm "vm \"%s\" {\n", $_instance;
|
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\tswitch \"%s\"\n", $_switch;
|
||||||
printf $fh_vm "\t\tlladdr %s\n", $_mac;
|
printf $fh_vm "\t\tlladdr %s\n", $_mac;
|
||||||
printf $fh_vm "\t}\n";
|
printf $fh_vm "\t}\n";
|
||||||
printf $fh_vm "\tinterface tap { switch \"%s\" }\n", $_switch2 if $_switch2;
|
|
||||||
printf $fh_vm "}\n";
|
printf $fh_vm "}\n";
|
||||||
}
|
}
|
||||||
close $fh_vm;
|
close $fh_vm;
|
||||||
|
@ -157,13 +157,13 @@ sub render_dhcpd_conf {
|
||||||
my $_disk_format = $vms{$vm_name}{'format'} || $conf{'conf'}{'FORMAT'};
|
my $_disk_format = $vms{$vm_name}{'format'} || $conf{'conf'}{'FORMAT'};
|
||||||
my $_disk = $conf{'conf'}{'IMAGES'} . "/" . $_instance . "." . $_disk_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 $_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 $_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'};
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
|
|
||||||
printf $fh_dhcpd "\thost %s {\n", $_instance;
|
printf $fh_dhcpd "\thost %s {\n", $_instance;
|
||||||
printf $fh_dhcpd "\t\thardware ethernet %s;\n", $_mac;
|
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;
|
printf $fh_dhcpd "\t\t#fixed-address-ipv6 %s;\n", $_ipv6;
|
||||||
if (! -e $_disk) {
|
if (! -e $_disk) {
|
||||||
printf $fh_dhcpd "\t\tfilename \"auto_install\";\n";
|
printf $fh_dhcpd "\t\tfilename \"auto_install\";\n";
|
||||||
|
@ -196,6 +196,8 @@ sub render_install_conf {
|
||||||
my $_hostname = $vms{$vm_name}{'hostname'};
|
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||||
my $jot_pass = qx(jot -rcs '' 20 46 125);
|
my $jot_pass = qx(jot -rcs '' 20 46 125);
|
||||||
chomp($jot_pass);
|
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 = $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 $_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'};
|
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 "Password for root = %s\n", $jot_pass;
|
||||||
printf $fh_install "Which speed should com0 = 115200\n";
|
printf $fh_install "Which speed should com0 = 115200\n";
|
||||||
printf $fh_install "Network interfaces = vio0\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 "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 "IPv6 default router = %s\n", $_ipv6_gateway;
|
||||||
printf $fh_install "Setup a user = %s\n", $_username;
|
printf $fh_install "Setup a user = %s\n", $_username;
|
||||||
printf $fh_install "Password for user = %s\n", $jot_pass;
|
printf $fh_install "Password for user = %s\n", $jot_pass;
|
||||||
|
@ -354,10 +357,12 @@ my %vms;
|
||||||
my @files = glob "$conf{'conf'}{'VMS'}/*.txt";
|
my @files = glob "$conf{'conf'}{'VMS'}/*.txt";
|
||||||
%vms = get_variables('vms', @files);
|
%vms = get_variables('vms', @files);
|
||||||
|
|
||||||
|
my $DHCP = $conf{'conf'}{'DHCP'} || "yes";
|
||||||
|
|
||||||
# run all functions
|
# run all functions
|
||||||
#debug_parse(\%conf, \%vms);
|
#debug_parse(\%conf, \%vms);
|
||||||
render_vm_conf(\%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);
|
render_install_conf(\%conf, \%vms);
|
||||||
create_accounts(\%conf, \%vms);
|
create_accounts(\%conf, \%vms);
|
||||||
create_img_files(\%conf, \%vms);
|
create_img_files(\%conf, \%vms);
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
mac="fe:e1:ab:dd:73:a4"
|
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"
|
owner="testuser1"
|
||||||
date="2018/04/02"
|
date="2018/04/02"
|
||||||
payment="74"
|
payment="74"
|
||||||
|
@ -13,4 +10,3 @@ hostname="deploytest1"
|
||||||
username="deploytest1"
|
username="deploytest1"
|
||||||
memory="1G"
|
memory="1G"
|
||||||
note=""
|
note=""
|
||||||
enable="yes"
|
|
||||||
|
|
Loading…
Reference in New Issue