@ -1127,13 +1127,11 @@ sub check_stonith_config
### NOTE: This was copied from 'anvil-join-anvil' and modified.
### NOTE: This was copied from 'anvil-join-anvil' and modified.
# Now I know what I have, lets see what I should have.
# Now I know what I have, lets see what I should have.
my $ host_name = $ anvil - > Get - > host_name ;
my $ host_name = $ anvil - > Get - > host_name ;
my $ new_password = $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { anvil_password } ;
my $ new_password = $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { anvil_password } ;
my $ escaped_password = shell_quote ( $ new_password ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
host_name = > $ host_name ,
host_name = > $ host_name ,
new_password = > $ anvil - > Log - > is_secure ( $ new_password ) ,
new_password = > $ anvil - > Log - > is_secure ( $ new_password ) ,
escaped_password = > $ anvil - > Log - > is_secure ( $ escaped_password ) ,
} } ) ;
} } ) ;
$ anvil - > data - > { machine } { node1 } { host_name } = "" ;
$ anvil - > data - > { machine } { node1 } { host_name } = "" ;
@ -1184,9 +1182,6 @@ sub check_stonith_config
# This will store the fence level order. If something changes
# This will store the fence level order. If something changes
$ fence_order - > { $ node_name } = [] ;
$ fence_order - > { $ node_name } = [] ;
# This will switch to '1' if something changed, triggering a reconfig of the fencing levels.
$ something_changed - > { $ node_name } = 0 ;
# Does this stonith method already exist?
# Does this stonith method already exist?
my $ create_entry = 0 ;
my $ create_entry = 0 ;
my $ delete_old = 0 ;
my $ delete_old = 0 ;
@ -1352,9 +1347,6 @@ sub check_stonith_config
} } ) ;
} } ) ;
return ( 1 ) ;
return ( 1 ) ;
}
}
$ something_changed - > { $ node_name } = 1 ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { "something_changed->{$node_name}" = > $ something_changed - > { $ node_name } } } ) ;
}
}
if ( $ create_entry )
if ( $ create_entry )
{
{
@ -1379,12 +1371,8 @@ sub check_stonith_config
} } ) ;
} } ) ;
return ( 1 ) ;
return ( 1 ) ;
}
}
$ something_changed - > { $ node_name } = 1 ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { "something_changed->{$node_name}" = > $ something_changed - > { $ node_name } } } ) ;
}
}
### Now any other fence devices.
### Now any other fence devices.
foreach my $ device ( sort { $ a cmp $ b } keys % { $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ node } { fence } } )
foreach my $ device ( sort { $ a cmp $ b } keys % { $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ node } { fence } } )
{
{
@ -1592,9 +1580,6 @@ sub check_stonith_config
} } ) ;
} } ) ;
return ( 1 ) ;
return ( 1 ) ;
}
}
$ something_changed - > { $ node_name } = 1 if not $ delete_old ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { "something_changed->{$node_name}" = > $ something_changed - > { $ node_name } } } ) ;
}
}
if ( ( $ create_entry ) && ( not $ dont_create ) )
if ( ( $ create_entry ) && ( not $ dont_create ) )
{
{
@ -1619,9 +1604,6 @@ sub check_stonith_config
} } ) ;
} } ) ;
return ( 1 ) ;
return ( 1 ) ;
}
}
$ something_changed - > { $ node_name } = 1 if not $ delete_old ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { "something_changed->{$node_name}" = > $ something_changed - > { $ node_name } } } ) ;
}
}
}
}
@ -1664,78 +1646,109 @@ sub check_stonith_config
# Setup fence levels.
# Setup fence levels.
foreach my $ node_name ( sort { $ a cmp $ b } keys % { $ fence_order } )
foreach my $ node_name ( sort { $ a cmp $ b } keys % { $ fence_order } )
{
{
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { "something_changed->{$node_name}" = > $ something_changed - > { $ node_name } } } ) ;
# Update our view of the cluster.
if ( $ something_changed - > { $ node_name } )
my $ problem = $ anvil - > Cluster - > parse_cib ( { debug = > 2 } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { problem = > $ problem } } ) ;
# Check our current levels and update if needed.
my $ index = 1 ;
foreach my $ fence_agent ( @ { $ fence_order - > { $ node_name } } )
{
{
# Update our view of the cluster.
my $ key_name = "fl-" . $ node_name . "-" . $ index ;
my $ problem = $ anvil - > Cluster - > parse_cib ( { debug = > 2 } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { problem = > $ problem } } ) ;
fence_agent = > $ fence_agent ,
key_name = > $ key_name ,
} } ) ;
# Delete any existing fence levels
# Does the fence level exist, and is it for the right fence agent?
if ( exists $ anvil - > data - > { cib } { parsed } { data } { node } { $ node _name} )
if ( exists $ anvil - > data - > { cib } { parsed } { configuration } { 'fencing-topology' } { 'fencing-level' } { $ key _name} )
{
{
foreach my $ index ( sort { $ a cmp $ b } keys % { $ anvil - > data - > { cib } { parsed } { data } { node } { $ node_name } { fencing } { order } } )
# If there's multiple fence devices in this method, crop off the extra ones.
my $ old_fence_name = $ anvil - > data - > { cib } { parsed } { configuration } { 'fencing-topology' } { 'fencing-level' } { $ key_name } { devices } ;
$ old_fence_name =~ s/,.*// ;
my $ old_fence_agent = exists $ anvil - > data - > { crm_mon } { parsed } { 'pacemaker-result' } { resources } { stonith } { $ old_fence_name } ?
$ anvil - > data - > { crm_mon } { parsed } { 'pacemaker-result' } { resources } { stonith } { $ old_fence_name } { variables } { resource_agent } : "" ;
$ old_fence_agent =~ s/^stonith:// ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
old_fence_name = > $ old_fence_name ,
old_fence_agent = > $ old_fence_agent ,
} } ) ;
if ( $ fence_agent eq $ old_fence_agent )
{
{
# pcs stonith level delete <index> <target>
# The fence level exists and it's the same fence agent, nothing to do.
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , key = > "log_0848" } ) ;
$ index + + ;
next ;
}
else
{
# The fence level exists, but it's for a different fence agent, deleting it
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , 'print' = > 1 , level = > 1 , key = > "log_0849" , variables = > {
old_fence_name = > $ old_fence_name ,
old_fence_agent = > $ old_fence_agent ,
} } ) ;
my $ shell_call = $ anvil - > data - > { path } { exe } { pcs } . " stonith level delete " . $ index . " " . $ node_name ;
my $ shell_call = $ anvil - > data - > { path } { exe } { pcs } . " stonith level delete " . $ index . " " . $ node_name ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { shell_call = > $ shell_call } } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { shell_call = > $ shell_call } } ) ;
my ( $ output , $ return_code ) = $ anvil - > System - > call ( { debug = > 3 , shell_call = > $ shell_call } ) ;
my ( $ output , $ return_code ) = $ anvil - > System - > call ( { debug = > $ debug , shell_call = > $ shell_call } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
output = > $ output ,
output = > $ output ,
return_code = > $ return_code ,
return_code = > $ return_code ,
} } ) ;
} } ) ;
if ( $ return_code )
if ( $ return_code )
{
{
# Something went wrong.
# Something went wrong. We'll not exit, but this is probably not going to end well.
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , 'print' = > 1 , level = > 0 , priority = > "err" , key = > "error_0138" , variables = > {
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , 'print' = > 1 , level = > 0 , priority = > "err" , key = > "error_0138" , variables = > {
shell_call = > $ shell_call ,
shell_call = > $ shell_call ,
output = > $ output ,
output = > $ output ,
return_code = > $ return_code ,
return_code = > $ return_code ,
} } ) ;
} } ) ;
return ( 1 ) ;
}
}
}
}
}
}
else
{
# The fence level doesn't exist.
}
# Create the new fence levels
# Create the fence level now.
my $ i = 1 ;
my $ devices = "" ;
foreach my $ fence_agent ( @ { $ fence_order - > { $ node_name } } )
foreach my $ device ( sort { $ a cmp $ b } @ { $ fence_devices - > { $ node_name } { $ fence_agent } } )
{
{
my $ devices = "" ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { device = > $ device } } ) ;
foreach my $ device ( sort { $ a cmp $ b } @ { $ fence_devices - > { $ node_name } { $ fence_agent } } )
$ devices . = $ device . "," ;
{
}
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { device = > $ device } } ) ;
$ devices =~ s/,$// ;
$ devices . = $ device . "," ;
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , 'print' = > 1 , level = > 1 , key = > "log_0850" , variables = > {
}
key_name = > $ key_name ,
$ devices =~ s/,$// ;
fence_agent = > $ fence_agent ,
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { devices = > $ devices } } ) ;
devices = > $ devices ,
} } ) ;
my $ shell_call = $ anvil - > data - > { path } { exe } { pcs } . " stonith level add " . $ i . " " . $ node_name . " " . $ devices ;
my $ shell_call = $ anvil - > data - > { path } { exe } { pcs } . " stonith level add " . $ index . " " . $ node_name . " " . $ devices ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { shell_call = > $ shell_call } } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { shell_call = > $ shell_call } } ) ;
my ( $ output , $ return_code ) = $ anvil - > System - > call ( { debug = > 3 , shell_call = > $ shell_call } ) ;
my ( $ output , $ return_code ) = $ anvil - > System - > call ( { debug = > 3 , shell_call = > $ shell_call } ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
output = > $ output ,
return_code = > $ return_code ,
} } ) ;
if ( $ return_code )
{
# Something went wrong.
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , 'print' = > 1 , level = > 0 , priority = > "err" , key = > "error_0138" , variables = > {
shell_call = > $ shell_call ,
output = > $ output ,
output = > $ output ,
return_code = > $ return_code ,
return_code = > $ return_code ,
} } ) ;
} } ) ;
if ( $ return_code )
return ( 1 ) ;
{
# Something went wrong.
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , 'print' = > 1 , level = > 0 , priority = > "err" , key = > "error_0138" , variables = > {
shell_call = > $ shell_call ,
output = > $ output ,
return_code = > $ return_code ,
} } ) ;
return ( 1 ) ;
}
$ i + + ;
}
}
$ index + + ;
}
}
}
}
return ( 0 ) ;
return ( 0 ) ;
}
}