* Updated Cluster->parse_cib() to pull out fencing (stonith) devices and levels.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent 3c2f25a860
commit 61f4dcc41f
  1. 122
      Anvil/Tools/Cluster.pm
  2. 4
      tools/anvil-join-anvil
  3. 2
      tools/test.pl

@ -268,7 +268,7 @@ sub parse_cib
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Cluster->parse_cib()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Cluster->parse_cib()" }});
my $cib = defined $parameters->{cib} ? $parameters->{cib} : ""; my $cib = defined $parameter->{cib} ? $parameter->{cib} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
cib => $cib, cib => $cib,
}}); }});
@ -410,6 +410,18 @@ sub parse_cib
} }
} }
} }
foreach my $fencing_level ($dom->findnodes('/cib/configuration/fencing-topology/fencing-level'))
{
my $id = $fencing_level->{id};
foreach my $variable (sort {$a cmp $b} keys %{$fencing_level})
{
next if $variable eq "id";
$anvil->data->{cib}{parsed}{configuration}{'fencing-topology'}{'fencing-level'}{$id}{$variable} = $fencing_level->{$variable};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"cib::parsed::configuration::fencing-topology::fencing-level::${id}::${variable}" => $anvil->data->{cib}{parsed}{configuration}{'fencing-topology'}{'fencing-level'}{$id}{$variable},
}});
}
}
### TODO: /cib/configuration/constraints ### TODO: /cib/configuration/constraints
foreach my $node_state ($dom->findnodes('/cib/status/node_state')) foreach my $node_state ($dom->findnodes('/cib/status/node_state'))
{ {
@ -467,8 +479,8 @@ sub parse_cib
$anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$id}{type} = $primitive->{type}; $anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$id}{type} = $primitive->{type};
$anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$id}{class} = $primitive->{class}; $anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$id}{class} = $primitive->{class};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"cib::parsed::cib::resources::primitive:${id}::type" => $anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$id}{type}, "cib::parsed::cib::resources::primitive::${id}::type" => $anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$id}{type},
"cib::parsed::cib::resources::primitive:${id}::class" => $anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$id}{class}, "cib::parsed::cib::resources::primitive::${id}::class" => $anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$id}{class},
}}); }});
foreach my $nvpair ($primitive->findnodes('./instance_attributes/nvpair')) foreach my $nvpair ($primitive->findnodes('./instance_attributes/nvpair'))
{ {
@ -552,6 +564,110 @@ sub parse_cib
} }
} }
foreach my $nvpair_id (sort {$a cmp $b} keys %{$anvil->data->{cib}{parsed}{configuration}{crm_config}{cluster_property_set}{nvpair}})
{
my $variable = $anvil->data->{cib}{parsed}{configuration}{crm_config}{cluster_property_set}{nvpair}{$nvpair_id}{name};
my $value = $anvil->data->{cib}{parsed}{configuration}{crm_config}{cluster_property_set}{nvpair}{$nvpair_id}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:nvpair_id' => $nvpair_id,
's2:variable' => $variable,
's3:value' => $value,
}});
if ($variable eq "stonith-max-attempts")
{
$anvil->data->{cib}{parsed}{data}{stonith}{'max-attempts'} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cib::parsed::data::stonith::max-attempts" => $anvil->data->{cib}{parsed}{data}{stonith}{'max-attempts'},
}});
}
if ($variable eq "stonith-enabled")
{
$anvil->data->{cib}{parsed}{data}{stonith}{enabled} = $value eq "true" ? 1 : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cib::parsed::data::stonith::enabled" => $anvil->data->{cib}{parsed}{data}{stonith}{enabled},
}});
}
if ($variable eq "cluster-name")
{
$anvil->data->{cib}{parsed}{data}{cluster}{name} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"cib::parsed::data::cluster::name" => $anvil->data->{cib}{parsed}{data}{cluster}{name},
}});
}
}
# Fencing devices and levels.
foreach my $primitive_id (sort {$a cmp $b} keys %{$anvil->data->{cib}{parsed}{cib}{resources}{primitive}})
{
next if not $anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$primitive_id}{class};
if ($anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$primitive_id}{class} eq "stonith")
{
my $variables = {};
my $node_name = "";
foreach my $fence_id (sort {$a cmp $b} keys %{$anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$primitive_id}{instance_attributes}})
{
my $name = $anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$primitive_id}{instance_attributes}{$fence_id}{name};
my $value = $anvil->data->{cib}{parsed}{cib}{resources}{primitive}{$primitive_id}{instance_attributes}{$fence_id}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
name => $name,
value => $value,
}});
if ($name eq "pcmk_host_list")
{
$node_name = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { node_name => $node_name }});
}
else
{
$variables->{$name} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "variables->{$name}" => $variables->{$name} }});
}
}
if ($node_name)
{
my $argument_string = "";
foreach my $name (sort {$a cmp $b} keys %{$variables})
{
$anvil->data->{cib}{parsed}{data}{node}{$node_name}{fencing}{device}{$primitive_id}{argument}{$name}{value} = $variables->{$name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cib::parsed::data::node::${node_name}::fencing::device::${primitive_id}::argument::${name}::value" => $variables->{$name},
}});
my $value = $variables->{$name};
$value =~ s/"/\\"/g;
$argument_string .= $name."=\"".$value."\" ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
argument_string => $argument_string,
}});
}
$argument_string =~ s/ $//;
$anvil->data->{cib}{parsed}{data}{node}{$node_name}{fencing}{device}{$primitive_id}{arguments} = $argument_string;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cib::parsed::data::node::${node_name}::fencing::device::${primitive_id}::arguments" => $anvil->data->{cib}{parsed}{data}{node}{$node_name}{fencing}{device}{$primitive_id}{arguments},
}});
}
}
}
foreach my $id (sort {$a cmp $b} keys %{$anvil->data->{cib}{parsed}{configuration}{'fencing-topology'}{'fencing-level'}})
{
my $node_name = $anvil->data->{cib}{parsed}{configuration}{'fencing-topology'}{'fencing-level'}{$id}{target};
my $devices = $anvil->data->{cib}{parsed}{configuration}{'fencing-topology'}{'fencing-level'}{$id}{devices};
my $index = $anvil->data->{cib}{parsed}{configuration}{'fencing-topology'}{'fencing-level'}{$id}{'index'};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
node_name => $node_name,
devices => $devices,
'index' => $index,
}});
$anvil->data->{cib}{parsed}{data}{node}{$node_name}{fencing}{order}{$index}{devices} = $devices;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cib::parsed::data::node::${node_name}::fencing::order::${index}::devices" => $anvil->data->{cib}{parsed}{data}{node}{$node_name}{fencing}{order}{$index}{devices},
}});
}
return($problem); return($problem);
} }

@ -401,7 +401,7 @@ sub configure_pacemaker
# Find the variable=value version. # Find the variable=value version.
my $variable = $anvil->data->{fence_data}{$fence_agent}{switch}{$switch}{name}; my $variable = $anvil->data->{fence_data}{$fence_agent}{switch}{$switch}{name};
my $value = $switches->{$switch}; my $value = $switches->{$switch};
$value =~ s/"/\"/g; $value =~ s/"/\\"/g;
$pcs_line .= $variable."=\"".$value."\" "; $pcs_line .= $variable."=\"".$value."\" ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
variable => $variable, variable => $variable,
@ -452,7 +452,7 @@ sub configure_pacemaker
} }
if ($port) if ($port)
{ {
$port =~ s/"/\"/g; $port =~ s/"/\\"/g;
$pcs_line .= "port=\"".$port."\" "; $pcs_line .= "port=\"".$port."\" ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
pcs_line => $pcs_line =~ /passw/ ? $anvil->Log->is_secure($pcs_line) : $pcs_line, pcs_line => $pcs_line =~ /passw/ ? $anvil->Log->is_secure($pcs_line) : $pcs_line,

@ -220,6 +220,6 @@ my $xml = '<cib crm_feature_set="3.3.0" validate-with="pacemaker-3.2" epoch="28"
'; ';
$anvil->Cluster->parse_cib({ $anvil->Cluster->parse_cib({
debug => 2, debug => 3,
cib => $xml, cib => $xml,
}); });

Loading…
Cancel
Save