mirror of
git://git.proxmox.com/git/pve-ha-manager.git
synced 2025-01-25 10:03:53 +03:00
FenceConfig: move line parsing out to closure
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
92cfcee1ab
commit
98dca1a462
@ -15,6 +15,64 @@ sub parse_config {
|
||||
my $lineno = 0;
|
||||
my $priority = 0;
|
||||
|
||||
my $parse_line = sub {
|
||||
my ($line) = @_;
|
||||
|
||||
if ($line =~ m/^(device|connect)\s+(\S+)\s+(\S+)\s+(.+)$/) {
|
||||
my ($command, $dev_name, $target) = ($1, $2, $3);
|
||||
|
||||
my $arg_array = PVE::Tools::split_args($4);
|
||||
|
||||
my $dev_number = 1; # default
|
||||
|
||||
# check for parallel devices
|
||||
if ($dev_name =~ m/^(\w+)(:(\d+))?/) {
|
||||
$dev_name = $1;
|
||||
$dev_number = $3 if $3;
|
||||
}
|
||||
|
||||
if ($command eq "device") {
|
||||
|
||||
my $dev = $config->{$dev_name} || {};
|
||||
|
||||
die "device '$dev_name:$dev_number' already declared\n"
|
||||
if $dev && $dev->{sub_devs}->{$dev_number};
|
||||
|
||||
$dev->{sub_devs}->{$dev_number} = {
|
||||
agent => $target,
|
||||
args => $arg_array,
|
||||
};
|
||||
$dev->{priority} = $priority++ if !$dev->{priority};
|
||||
|
||||
$config->{$dev_name} = $dev;
|
||||
|
||||
} else { # connect nodes to devices
|
||||
|
||||
die "device '$dev_name' must be declared before you can connect to it\n"
|
||||
if !$config->{$dev_name};
|
||||
|
||||
die "No parallel device '$dev_name:$dev_number' found\n"
|
||||
if !$config->{$dev_name}->{sub_devs}->{$dev_number};
|
||||
|
||||
my $sdev = $config->{$dev_name}->{sub_devs}->{$dev_number};
|
||||
|
||||
my ($node) = $target =~ /node=(\w+)/;
|
||||
die "node=nodename needed to connect device '$dev_name' to node\n"
|
||||
if !$node;
|
||||
|
||||
die "node '$node' already connected to device '$dev_name:$dev_number'\n"
|
||||
if $sdev->{node_args}->{$node};
|
||||
|
||||
$sdev->{node_args}->{$node} = $arg_array;
|
||||
|
||||
$config->{$dev_name}->{sub_devs}->{$dev_number} = $sdev;
|
||||
}
|
||||
|
||||
} else {
|
||||
warn "$fn ignore line $lineno: $line\n"
|
||||
}
|
||||
};
|
||||
|
||||
eval {
|
||||
while ($raw =~ /^\h*(.*?)\h*$/gm) {
|
||||
my $line = $1;
|
||||
@ -22,59 +80,7 @@ sub parse_config {
|
||||
|
||||
next if !$line || $line =~ /^#/;
|
||||
|
||||
if ($line =~ m/^(device|connect)\s+(\S+)\s+(\S+)\s+(.+)$/) {
|
||||
my ($command, $dev_name, $target) = ($1, $2, $3);
|
||||
|
||||
my $arg_array = PVE::Tools::split_args($4);
|
||||
|
||||
my $dev_number = 1; # default
|
||||
|
||||
# check for parallel devices
|
||||
if ($dev_name =~ m/^(\w+)(:(\d+))?/) {
|
||||
$dev_name = $1;
|
||||
$dev_number = $3 if $3;
|
||||
}
|
||||
|
||||
if ($command eq "device") {
|
||||
|
||||
my $dev = $config->{$dev_name} || {};
|
||||
|
||||
die "device '$dev_name:$dev_number' already declared\n"
|
||||
if $dev && $dev->{sub_devs}->{$dev_number};
|
||||
|
||||
$dev->{sub_devs}->{$dev_number} = {
|
||||
agent => $target,
|
||||
args => $arg_array,
|
||||
};
|
||||
$dev->{priority} = $priority++ if !$dev->{priority};
|
||||
|
||||
$config->{$dev_name} = $dev;
|
||||
|
||||
} else { # connect nodes to devices
|
||||
|
||||
die "device '$dev_name' must be declared before you can connect to it\n"
|
||||
if !$config->{$dev_name};
|
||||
|
||||
die "No parallel device '$dev_name:$dev_number' found\n"
|
||||
if !$config->{$dev_name}->{sub_devs}->{$dev_number};
|
||||
|
||||
my $sdev = $config->{$dev_name}->{sub_devs}->{$dev_number};
|
||||
|
||||
my ($node) = $target =~ /node=(\w+)/;
|
||||
die "node=nodename needed to connect device '$dev_name' to node\n"
|
||||
if !$node;
|
||||
|
||||
die "node '$node' already connected to device '$dev_name:$dev_number'\n"
|
||||
if $sdev->{node_args}->{$node};
|
||||
|
||||
$sdev->{node_args}->{$node} = $arg_array;
|
||||
|
||||
$config->{$dev_name}->{sub_devs}->{$dev_number} = $sdev;
|
||||
}
|
||||
|
||||
} else {
|
||||
warn "$fn ignore line $lineno: $line\n"
|
||||
}
|
||||
$parse_line->($line);
|
||||
}
|
||||
};
|
||||
if (my $err = $@) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user