@ -18,6 +18,7 @@ my $THIS_FILE = "Striker.pm";
# get_local_repo
# get_local_repo
# get_peer_data
# get_peer_data
# get_ups_data
# get_ups_data
# load_manifest
# parse_all_status_json
# parse_all_status_json
= pod
= pod
@ -448,7 +449,7 @@ sub get_local_repo
my $ parameter = shift ;
my $ parameter = shift ;
my $ anvil = $ self - > parent ;
my $ anvil = $ self - > parent ;
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 = > "Striker->get_peer_data ()" } } ) ;
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , key = > "log_0125" , variables = > { method = > "Striker->get_local_repo ()" } } ) ;
# What is the repo directory?
# What is the repo directory?
my $ document_root = "" ;
my $ document_root = "" ;
@ -749,6 +750,244 @@ sub get_ups_data
return ( 0 ) ;
return ( 0 ) ;
}
}
= head2 load_manifest
This takes a manifest UUID and loads and parses it . If the manifest is loaded , C << 0 >> is returned . C << 1 >> is returned on error .
The loaded data is stored in a hash as:
manifests::manifest_uuid:: <manifest_uuid> :: manifest_name = <name>
manifests::manifest_uuid:: <manifest_uuid> :: manifest_last_ran = < unix time >
manifests::manifest_uuid:: <manifest_uuid> :: manifest_xml = <raw_xml>
manifests::manifest_uuid:: <manifest_uuid> :: manifest_note = < user note >
manifests::manifest_uuid:: <manifest_uuid> :: modified_date = < unix time >
The following hash is used to facilitate manifest name to UUID look up .
manifests::name_to_uuid:: <manifest_name> = <manifest_uuid>
The parsed manifest XML is stored as:
manifests::manifest_uuid:: <manifest_uuid> :: parsed:: name = < Anvil ! name >
manifests::manifest_uuid:: <manifest_uuid> :: parsed:: domain = < Anvil ! domain name >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::upses:: <ups_name> :: uuid = < upses - > ups_uuid of named UPS >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::fences:: <fence_name> :: uuid = < fences - > fence_uuid of named fence device >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::networks:: dns = < DNS to use , default is '8.8.8.8,8.8.4.4' >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::networks:: ntp = < NTP to use , if any >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::networks:: mtu = < MTU of network >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::networks::name:: <network_name> :: network = < base network ip , ie: 10.255 .0 .0 >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::networks::name:: <network_name> :: subnet = < subnet mask >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::networks::name:: <network_name> :: gateway = < gateway ip , if any >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::machine:: <host_name> :: type = < node1 , node2 or dr1 >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::machine:: <host_name> :: ipmi_ip = < ip of IPMI BMC , if any >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::machine:: <host_name> :: fence:: <fence_name> :: port = < 'port' name / number ( see fence agent man page )
manifests::manifest_uuid:: <manifest_uuid> :: parsed::machine:: <host_name> :: ups:: <ups_name> :: used = < 1 if powered by USB , 0 if not >
manifests::manifest_uuid:: <manifest_uuid> :: parsed::machine:: <host_name> :: network:: <network_name> :: ip = < ip used on network >
B <Note> : The machines to use in each role is selected when the manifest is run . Unlike in M2 , the manifest does not store machine - specific information ( like MAC addresses , etc ) . The chosen machines at run time contain that information . Similarly , passwords are NOT stored in the manifest , and passed when the manifest is run .
Parameters ;
= head3 manifest_uuid ( required )
This is the manifest UUID to load .
= cut
sub load_manifest
{
my $ self = shift ;
my $ parameter = shift ;
my $ anvil = $ self - > parent ;
my $ debug = defined $ parameter - > { debug } ? $ parameter - > { debug } : 3 ;
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , key = > "log_0125" , variables = > { method = > "Striker->get_ups_data()" } } ) ;
my $ manifest_uuid = defined $ parameter - > { manifest_uuid } ? $ parameter - > { manifest_uuid } : "" ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
manifest_uuid = > $ manifest_uuid ,
} } ) ;
if ( not $ manifest_uuid )
{
# Didn't get a UUID
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > 0 , priority = > "err" , key = > "log_0020" , variables = > { method = > "Striker->load_manifest()" , parameter = > "manifest_uuid" } } ) ;
return ( 1 ) ;
}
elsif ( not $ anvil - > Validate - > is_uuid ( { uuid = > $ manifest_uuid } ) )
{
# UUID isn't valid
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > 0 , priority = > "err" , key = > "log_0130" , variables = > { method = > "Striker->load_manifest()" , parameter = > "manifest_uuid" , uuid = > $ manifest_uuid } } ) ;
return ( 1 ) ;
}
my $ query = "
SELECT
manifest_name ,
manifest_last_ran ,
manifest_xml ,
manifest_note ,
ROUND ( extract ( epoch FROM modified_date ) )
FROM
manifests
WHERE
manifest_uuid = ".$anvil->Database->quote($manifest_uuid)."
; " ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { query = > $ query } } ) ;
my $ results = $ anvil - > Database - > query ( { query = > $ query , source = > $ THIS_FILE , line = > __LINE__ } ) ;
my $ count = @ { $ results } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
results = > $ results ,
count = > $ count ,
} } ) ;
my $ manifest_template = "" ;
if ( $ count )
{
my $ manifest_name = $ results - > [ 0 ] - > [ 0 ] ;
my $ manifest_last_ran = $ results - > [ 0 ] - > [ 1 ] ;
my $ manifest_xml = $ results - > [ 0 ] - > [ 2 ] ;
my $ manifest_note = $ results - > [ 0 ] - > [ 3 ] ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
manifest_name = > $ manifest_name ,
manifest_last_ran = > $ manifest_last_ran ,
manifest_xml = > $ manifest_xml ,
manifest_note = > $ manifest_note ,
} } ) ;
# Record the data.
$ anvil - > data - > { manifests } { $ manifest_uuid } { manifest_name } = $ manifest_name ;
$ anvil - > data - > { manifests } { $ manifest_uuid } { manifest_last_ran } = $ manifest_last_ran ;
$ anvil - > data - > { manifests } { $ manifest_uuid } { manifest_xml } = $ manifest_xml ;
$ anvil - > data - > { manifests } { $ manifest_uuid } { manifest_note } = $ manifest_note ;
$ anvil - > data - > { manifests } { name_to_uuid } { $ manifest_name } = $ manifest_uuid ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::${manifest_uuid}::manifest_name" = > $ anvil - > data - > { manifests } { $ manifest_uuid } { manifest_name } ,
"manifests::${manifest_uuid}::manifest_last_ran" = > $ anvil - > data - > { manifests } { $ manifest_uuid } { manifest_last_ran } ,
"manifests::${manifest_uuid}::manifest_xml" = > $ anvil - > data - > { manifests } { $ manifest_uuid } { manifest_xml } ,
"manifests::${manifest_uuid}::manifest_note" = > $ anvil - > data - > { manifests } { $ manifest_uuid } { manifest_note } ,
"manifests::name_to_uuid::${manifest_name}" = > $ anvil - > data - > { manifests } { name_to_uuid } { $ manifest_name } ,
} } ) ;
# Parse the XML.
my $ parsed_xml = "" ;
my $ xml = XML::Simple - > new ( ) ;
eval { $ parsed_xml = $ xml - > XMLin ( $ manifest_xml , KeyAttr = > { key = > 'name' } , ForceArray = > [] ) } ;
if ( $@ )
{
chomp $@ ;
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , 'print' = > 1 , level = > 0 , priority = > "err" , key = > "error_0111" , variables = > {
xml_body = > $ manifest_xml ,
eval_error = > $@ ,
} } ) ;
return ( 1 ) ;
}
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { domain } = $ parsed_xml - > { domain } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { name } = $ parsed_xml - > { name } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::domain" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { domain } ,
"manifests::manifest_uuid::${manifest_uuid}::parsed::name" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { name } ,
} } ) ;
foreach my $ hash_ref ( @ { $ parsed_xml - > { upses } { ups } } )
{
my $ ups_name = $ hash_ref - > { name } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { upses } { $ ups_name } { uuid } = $ hash_ref - > { uuid } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::upses::${ups_name}::uuid" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { upses } { $ ups_name } { uuid } ,
} } ) ;
}
foreach my $ hash_ref ( @ { $ parsed_xml - > { fences } { fence } } )
{
my $ fence_name = $ hash_ref - > { name } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { fences } { $ fence_name } { uuid } = $ hash_ref - > { uuid } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::fences::${fence_name}::uuid" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { fences } { $ fence_name } { uuid } ,
} } ) ;
}
foreach my $ hash_ref ( @ { $ parsed_xml - > { fences } { fence } } )
{
my $ fence_name = $ hash_ref - > { name } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { fences } { $ fence_name } = $ hash_ref - > { uuid } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::fences::${fence_name}" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { fences } { $ fence_name } ,
} } ) ;
}
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { dns } = $ parsed_xml - > { networks } { dns } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { ntp } = $ parsed_xml - > { networks } { ntp } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { mtu } = $ parsed_xml - > { networks } { mtu } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::networks::dns" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { dns } ,
"manifests::manifest_uuid::${manifest_uuid}::parsed::networks::ntp" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { ntp } ,
"manifests::manifest_uuid::${manifest_uuid}::parsed::networks::mtu" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { mtu } ,
} } ) ;
foreach my $ hash_ref ( @ { $ parsed_xml - > { networks } { network } } )
{
my $ network_name = $ hash_ref - > { name } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { name } { $ network_name } { network } = $ hash_ref - > { network } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { name } { $ network_name } { subnet } = $ hash_ref - > { subnet } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { name } { $ network_name } { gateway } = $ hash_ref - > { gateway } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::networks::name::${network_name}::network" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { name } { $ network_name } { network } ,
"manifests::manifest_uuid::${manifest_uuid}::parsed::networks::name::${network_name}::subnet" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { name } { $ network_name } { subnet } ,
"manifests::manifest_uuid::${manifest_uuid}::parsed::networks::name::${network_name}::gateway" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { networks } { name } { $ network_name } { gateway } ,
} } ) ;
}
foreach my $ machine ( sort { $ a cmp $ b } keys % { $ parsed_xml - > { machines } } )
{
my $ host_name = $ parsed_xml - > { machines } { $ machine } { name } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { type } = $ machine ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { ipmi_ip } = $ parsed_xml - > { machines } { $ machine } { ipmi_ip } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::machine::${host_name}::type" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { type } ,
"manifests::manifest_uuid::${manifest_uuid}::parsed::machine::${host_name}::ipmi_ip" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { ipmi_ip } ,
} } ) ;
foreach my $ hash_ref ( @ { $ parsed_xml - > { machines } { $ machine } { fences } { fence } } )
{
my $ fence_name = $ hash_ref - > { name } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { fence } { $ fence_name } { port } = $ hash_ref - > { port } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::machine::${host_name}::fence::${fence_name}::port" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { fence } { $ fence_name } { port } ,
} } ) ;
}
foreach my $ hash_ref ( @ { $ parsed_xml - > { machines } { $ machine } { upses } { ups } } )
{
my $ ups_name = $ hash_ref - > { name } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { ups } { $ ups_name } { used } = $ hash_ref - > { used } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::machine::${host_name}::ups::${ups_name}::used" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { ups } { $ ups_name } { used } ,
} } ) ;
}
foreach my $ hash_ref ( @ { $ parsed_xml - > { machines } { $ machine } { networks } { network } } )
{
my $ network_name = $ hash_ref - > { name } ;
$ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { network } { $ network_name } { ip } = $ hash_ref - > { ip } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"manifests::manifest_uuid::${manifest_uuid}::parsed::machine::${host_name}::network::${network_name}::ip" = > $ anvil - > data - > { manifests } { manifest_uuid } { $ manifest_uuid } { parsed } { machine } { $ host_name } { network } { $ network_name } { ip } ,
} } ) ;
}
}
}
else
{
# Not found.
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > 0 , priority = > "err" , key = > "warning_0042" , variables = > {
table = > "manifests" ,
column = > "manifest_uuid" ,
value = > $ manifest_uuid ,
} } ) ;
return ( 1 ) ;
}
return ( 0 ) ;
}
= head2 parse_all_status_json
= head2 parse_all_status_json
This parses the c << all_status . json >> file is a way that Striker can more readily use . If the read or parse failes , C << 1 >> is returned . Otherwise C << 0 >> is returned .
This parses the c << all_status . json >> file is a way that Striker can more readily use . If the read or parse failes , C << 1 >> is returned . Otherwise C << 0 >> is returned .