Skip to content

Commit e4bd962

Browse files
authored
Merge pull request #644 from ClusterLabs/upgrade-tools
Upgrade tools
2 parents 84e321f + 5c3d186 commit e4bd962

File tree

12 files changed

+612
-38
lines changed

12 files changed

+612
-38
lines changed

Anvil/Tools.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ sub _set_paths
10611061
'autoindex.conf' => "/etc/httpd/conf.d/autoindex.conf",
10621062
'cib.xml' => "/var/lib/pacemaker/cib/cib.xml",
10631063
'corosync.conf' => "/etc/corosync/corosync.conf",
1064+
'corosync-authkey' => "/etc/corosync/authkey",
10641065
'dhcpd.conf' => "/etc/dhcp/dhcpd.conf",
10651066
'dnf.conf' => "/etc/dnf/dnf.conf",
10661067
'drbd-proxy.license' => "/etc/drbd-proxy.license",

Anvil/Tools/Database.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3687,7 +3687,7 @@ WHERE
36873687
;";
36883688
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
36893689
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
3690-
my $count = @{$results};
3690+
my $count = ref($results) eq "ARRAY" ? @{$results} : 0;
36913691
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
36923692
results => $results,
36933693
count => $count,

Anvil/Tools/Network.pm

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3237,6 +3237,8 @@ This method loads and stores the same data as the C<< get_ips >> method, but doe
32373237
32383238
C<< Note >>: IP addresses that have been deleted will be marked so by C<< ip >> being set to C<< DELETED >>.
32393239
3240+
C<< Note >>: If there network has a device name, from network manager, that is the name used for C<< <iface_name> >>.
3241+
32403242
The loaded data will be stored as:
32413243
32423244
* C<< network::<host>::interface::<iface_name>::ip >> - If an IP address is set
@@ -3343,6 +3345,7 @@ AND
33433345
my $bridge_name = "";
33443346
my $bond_name = "";
33453347
my $interface_name = "";
3348+
my $interface_device = "";
33463349
my $interface_mac = "";
33473350
my $network_interface_uuid = "";
33483351
if ($ip_address_on_type eq "interface")
@@ -3381,11 +3384,24 @@ AND
33813384

33823385
if ($active_interface)
33833386
{
3384-
my $query = "SELECT network_interface_uuid FROM network_interfaces WHERE network_interface_host_uuid = ".$anvil->Database->quote($host_uuid)." AND network_interface_name = ".$anvil->Database->quote($active_interface).";";
3387+
my $query = "
3388+
SELECT
3389+
network_interface_uuid
3390+
FROM
3391+
network_interfaces
3392+
WHERE
3393+
network_interface_host_uuid = ".$anvil->Database->quote($host_uuid)."
3394+
AND
3395+
(
3396+
network_interface_name = ".$anvil->Database->quote($active_interface)."
3397+
OR
3398+
network_interface_device = ".$anvil->Database->quote($active_interface)."
3399+
)
3400+
;";
33853401
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
33863402

33873403
$network_interface_uuid = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
3388-
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { active_interface => $active_interface }});
3404+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { network_interface_uuid => $network_interface_uuid }});
33893405
}
33903406
}
33913407

@@ -3407,6 +3423,7 @@ AND
34073423
SELECT
34083424
network_interface_uuid,
34093425
network_interface_name,
3426+
network_interface_device,
34103427
network_interface_mac_address,
34113428
network_interface_speed,
34123429
network_interface_mtu,
@@ -3432,31 +3449,44 @@ AND
34323449
}});
34333450
next if not $count;
34343451

3435-
$interface_name = $results->[0]->[1];
3436-
$interface_mac = $results->[0]->[2];
3452+
$interface_name = $results->[0]->[1];
3453+
$interface_device = $results->[0]->[2];
3454+
$interface_mac = $results->[0]->[3];
34373455
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
3438-
interface_name => $interface_name,
3439-
interface_mac => $interface_mac,
3456+
interface_name => $interface_name,
3457+
interface_device => $interface_device,
3458+
interface_mac => $interface_mac,
34403459
}});
34413460

3461+
# If we've got an interface device, use that for the hash.
3462+
if ($interface_device)
3463+
{
3464+
$interface_name = $interface_device;
3465+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { interface_name => $interface_name }});
3466+
}
3467+
34423468
$anvil->data->{network}{$host}{interface}{$interface_name}{network_interface_uuid} = $results->[0]->[0];
3469+
$anvil->data->{network}{$host}{interface}{$interface_name}{interface_name} = $results->[0]->[1];
3470+
$anvil->data->{network}{$host}{interface}{$interface_name}{interface_device} = $results->[0]->[2];
34433471
$anvil->data->{network}{$host}{interface}{$interface_name}{mac_address} = $interface_mac;
34443472
$anvil->data->{network}{$host}{interface}{$interface_name}{ip} = $ip_address_address;
34453473
$anvil->data->{network}{$host}{interface}{$interface_name}{subnet_mask} = $ip_address_subnet_mask;
34463474
$anvil->data->{network}{$host}{interface}{$interface_name}{default_gateway} = $ip_address_default_gateway;
34473475
$anvil->data->{network}{$host}{interface}{$interface_name}{gateway} = $ip_address_gateway;
34483476
$anvil->data->{network}{$host}{interface}{$interface_name}{dns} = $ip_address_dns;
34493477
$anvil->data->{network}{$host}{interface}{$interface_name}{type} = "interface";
3450-
$anvil->data->{network}{$host}{interface}{$interface_name}{speed} = $results->[0]->[3];
3451-
$anvil->data->{network}{$host}{interface}{$interface_name}{mtu} = $results->[0]->[4];
3452-
$anvil->data->{network}{$host}{interface}{$interface_name}{link_state} = $results->[0]->[5];
3453-
$anvil->data->{network}{$host}{interface}{$interface_name}{operational} = $results->[0]->[6];
3454-
$anvil->data->{network}{$host}{interface}{$interface_name}{duplex} = $results->[0]->[7];
3455-
$anvil->data->{network}{$host}{interface}{$interface_name}{medium} = $results->[0]->[8];
3456-
$anvil->data->{network}{$host}{interface}{$interface_name}{bond_uuid} = defined $results->[0]->[9] ? $results->[0]->[9] : "";
3457-
$anvil->data->{network}{$host}{interface}{$interface_name}{bridge_uuid} = defined $results->[0]->[10] ? $results->[0]->[10] : "";
3478+
$anvil->data->{network}{$host}{interface}{$interface_name}{speed} = $results->[0]->[4];
3479+
$anvil->data->{network}{$host}{interface}{$interface_name}{mtu} = $results->[0]->[5];
3480+
$anvil->data->{network}{$host}{interface}{$interface_name}{link_state} = $results->[0]->[6];
3481+
$anvil->data->{network}{$host}{interface}{$interface_name}{operational} = $results->[0]->[7];
3482+
$anvil->data->{network}{$host}{interface}{$interface_name}{duplex} = $results->[0]->[8];
3483+
$anvil->data->{network}{$host}{interface}{$interface_name}{medium} = $results->[0]->[9];
3484+
$anvil->data->{network}{$host}{interface}{$interface_name}{bond_uuid} = defined $results->[0]->[10] ? $results->[0]->[10] : "";
3485+
$anvil->data->{network}{$host}{interface}{$interface_name}{bridge_uuid} = defined $results->[0]->[11] ? $results->[0]->[11] : "";
34583486
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
34593487
"network::${host}::interface::${interface_name}::network_interface_uuid" => $anvil->data->{network}{$host}{interface}{$interface_name}{network_interface_uuid},
3488+
"network::${host}::interface::${interface_name}::interface_name" => $anvil->data->{network}{$host}{interface}{$interface_name}{interface_name},
3489+
"network::${host}::interface::${interface_name}::interface_device" => $anvil->data->{network}{$host}{interface}{$interface_name}{interface_device},
34603490
"network::${host}::interface::${interface_name}::mac_address" => $anvil->data->{network}{$host}{interface}{$interface_name}{mac_address},
34613491
"network::${host}::interface::${interface_name}::ip" => $anvil->data->{network}{$host}{interface}{$interface_name}{ip},
34623492
"network::${host}::interface::${interface_name}::subnet_mask" => $anvil->data->{network}{$host}{interface}{$interface_name}{subnet_mask},
@@ -3578,7 +3608,6 @@ AND
35783608
}
35793609

35803610

3581-
35823611
=head2 manage_firewall
35833612
35843613
B<< NOTE >>: So far, only C<< check >> is implemented.

Anvil/Tools/Remote.pm

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ sub add_target_to_known_hosts
130130
}});
131131

132132
# Get the local user's home
133-
my $users_home = $anvil->Get->users_home({debug => ($debug + 1), user => $user});
133+
my $users_home = $anvil->Get->users_home({debug => 3, user => $user});
134134
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { users_home => $users_home }});
135135
if (not $users_home)
136136
{
@@ -148,7 +148,7 @@ sub add_target_to_known_hosts
148148
{
149149
# Yup, see if the target is there already,
150150
$known_machine = $anvil->Remote->_check_known_hosts_for_target({
151-
debug => ($debug + 1),
151+
debug => $debug,
152152
target => $target,
153153
port => $port,
154154
known_hosts => $known_hosts,
@@ -163,7 +163,7 @@ sub add_target_to_known_hosts
163163
{
164164
# We don't know about this machine yet, so scan it.
165165
my $added = $anvil->Remote->_call_ssh_keyscan({
166-
debug => ($debug + 1),
166+
debug => $debug,
167167
target => $target,
168168
port => $port,
169169
user => $user,
@@ -172,7 +172,6 @@ sub add_target_to_known_hosts
172172
if (not $added)
173173
{
174174
# Failed to add. :(
175-
176175
my $say_user = $user;
177176
if (($say_user =~ /^\d+$/) && (getpwuid($user)))
178177
{
@@ -1219,6 +1218,13 @@ sub _check_known_hosts_for_target
12191218
return($known_machine)
12201219
}
12211220

1221+
### NOTE: This is called by ocf:alteeve:server, so there might not be a database available.
1222+
# Make sure we've loaded hosts.
1223+
if (($anvil->data->{sys}{database}{read_uuid}) && (not exists $anvil->data->{hosts}{host_uuid}))
1224+
{
1225+
$anvil->Database->get_hosts({debug => $debug});
1226+
}
1227+
12221228
# read it in and search.
12231229
my $body = $anvil->Storage->read_file({debug => $debug, file => $known_hosts});
12241230
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { body => $body }});
@@ -1227,12 +1233,84 @@ sub _check_known_hosts_for_target
12271233
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { line => $line }});
12281234

12291235
# This is wider scope now to catch hosts using other hashes than 'ssh-rsa'
1230-
if (($line =~ /$target /) or ($line =~ /\[$target\]:$port /))
1236+
if (($line =~ /$target (.*)$/) or ($line =~ /\[$target\]:$port (.*)$/))
12311237
{
12321238
# We already know this machine (or rather, we already have a fingerprint for
12331239
# this machine).
1234-
$known_machine = 1;
1235-
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { known_machine => $known_machine }});
1240+
my $current_key = $anvil->Words->clean_spaces({string => $1});
1241+
my $is_host_name = $anvil->Validate->host_name({debug => 3, name => $target});
1242+
my $is_ip = $anvil->Validate->ipv4({debug => 3, ip => $target});
1243+
$known_machine = 1;
1244+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => {
1245+
current_key => $current_key,
1246+
is_host_name => $is_host_name,
1247+
is_ip => $is_ip,
1248+
known_machine => $known_machine,
1249+
}});
1250+
1251+
# If we're already planning to delete
1252+
next if $delete_if_found;
1253+
1254+
# If we don't have any DBs to read from, we're also done.
1255+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => {
1256+
'sys::database::read_uuid' => $anvil->data->{sys}{database}{read_uuid},
1257+
}});
1258+
next if not $anvil->data->{sys}{database}{read_uuid};
1259+
1260+
my $target_host_uuid = "";
1261+
my $target_host_name = "";
1262+
if ($is_ip)
1263+
{
1264+
($target_host_uuid, $target_host_name) = $anvil->Get->host_from_ip_address({debug => 2, ip_address => $target});
1265+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => {
1266+
target_host_uuid => $target_host_uuid,
1267+
target_host_name => $target_host_name,
1268+
}});
1269+
}
1270+
elsif ($is_host_name)
1271+
{
1272+
$target_host_name = $target;
1273+
$target_host_uuid = $anvil->Get->host_uuid_from_name({debug => 3, host_name => $target});
1274+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => {
1275+
target_host_uuid => $target_host_uuid,
1276+
target_host_name => $target_host_name,
1277+
}});
1278+
}
1279+
1280+
if ($target_host_uuid)
1281+
{
1282+
# If we have a host_key and it doesn't match the one we just read, delete it.
1283+
my $host_key = $anvil->Words->clean_spaces({string => $anvil->data->{hosts}{host_uuid}{$target_host_uuid}{host_key}});
1284+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => {
1285+
's1:host_key' => $host_key,
1286+
's2:current_key' => $current_key,
1287+
}});
1288+
1289+
my ($current_key_type, $current_key_string) = ($current_key =~ /(.*?)\s+(.*)$/);
1290+
my ($host_key_type, $host_key_string) = ($host_key =~ /(.*?)\s+(.*)$/);
1291+
$host_key_string =~ s/\s.*$//;
1292+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => {
1293+
's1:current_key_type' => $current_key_type,
1294+
's2:host_key_type' => $host_key_type,
1295+
's3:current_key_string' => $current_key_string,
1296+
's4:host_key_string' => $host_key_string,
1297+
}});
1298+
1299+
# If the key type is the same, but the string is not, delete the old key.
1300+
if (($current_key_type eq $host_key_type) && ($current_key_string ne $host_key_string))
1301+
{
1302+
# It's changed, clear the old one.
1303+
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0851", variables => {
1304+
known_hosts => $known_hosts,
1305+
target => $target,
1306+
key_type => $current_key_type,
1307+
old_key => $current_key_string,
1308+
new_key => $host_key_string,
1309+
}});
1310+
$delete_if_found = 1;
1311+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { delete_if_found => $delete_if_found }});
1312+
}
1313+
}
12361314
}
12371315
}
12381316

Anvil/Tools/Validate.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,6 @@ sub ip
526526

527527
my $ip = defined $parameter->{ip} ? $parameter->{ip} : "";
528528
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }});
529-
530529

531530
my $ipv4 = $anvil->Validate->ipv4({ip => $ip, debug => $debug});
532531
my $ipv6 = not $ipv4 ? $anvil->Validate->ipv6({ip => $ip, debug => $debug}) : 0;

man/anvil-join-anvil.8

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Manpage for the Anvil! node assembly tool
22
.\" Contact [email protected] to report issues, concerns or suggestions.
3-
.TH anvil-join-anvil "8" "August 10 2023" "Anvil! Intelligent Availability™ Platform"
3+
.TH anvil-join-anvil "8" "April 11 2024" "Anvil! Intelligent Availability™ Platform"
44
.SH NAME
55
anvil-join-anvil \- This tool assembles two subnodes into a node.
66
.SH SYNOPSIS
@@ -9,10 +9,6 @@ anvil-join-anvil \- This tool assembles two subnodes into a node.
99
.SH DESCRIPTION
1010
This program takes two subnodes and merges them into an Anvil! node. This can be two new subnodes, or an existing subnode with a replacement subnode after a subnode failure.
1111
.TP
12-
.B Note:
13-
.TP
14-
As if this time, this tool only runs from a job registered in the database. As such, the job must be recorded using the Striker web interface
15-
.TP
1612
.SH OPTIONS
1713
.TP
1814
\-?, \-h, \fB\-\-help\fR
@@ -25,9 +21,25 @@ When logging, record sensitive data, like passwords.
2521
Set the log level to 1, 2 or 3 respectively. Be aware that level 3 generates a significant amount of log data.
2622
.SS "Commands:"
2723
.TP
24+
\fB\-\-as\-machine\fR <'node1' or 'node2'>
25+
.TP
26+
When using \fB\-\-rejoin\fR, this is the subnode role that this host will take.
27+
.TP
28+
.B NOTE:
29+
.TP
30+
The previous subnode that held this position will be purged! All data associated with the previous subnode will be deleted from the Anvil! database.
31+
.TP
2832
\fB\-\-job\-uuid\fR
2933
.TP
3034
This is the job UUID that will be run.
35+
.TP
36+
\fB\-\-manifest\fR <name or uuid>
37+
.TP
38+
If this is given, then this host will be joined to the manifest. This is required if \fB\-\-rejoin\fR is used.
39+
.TP
40+
\fB\-\-rejoin\fR
41+
.TP
42+
If this is set, the host will be (re)joined to an existing Anvil! node. This is used to bring this host into an Anvil! subnode, typically after a subnode failure / rebuild.
3143
.IP
3244
.SH AUTHOR
3345
Written by Madison Kelly, Alteeve staff and the Anvil! project contributors.

man/striker-purge-target.8

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.\" Manpage for the Striker purge tool
2+
.\" Contact [email protected] to report issues, concerns or suggestions.
3+
.TH striker-purge-target "8" "April 11 2024" "Anvil! Intelligent Availability™ Platform"
4+
.SH NAME
5+
striker-purge-target \- This tool purges the target from all Anvil! databases.
6+
.SH SYNOPSIS
7+
.B striker-purge-target
8+
\fI\,<command> \/\fR[\fI\,options\/\fR]
9+
.SH DESCRIPTION
10+
This tool can be used to purge a host or an Anvil! node (and both subnodes) from the Anvil! database.
11+
.TP
12+
.SH OPTIONS
13+
.TP
14+
\-?, \-h, \fB\-\-help\fR
15+
Show this man page.
16+
.TP
17+
\fB\-\-log-secure\fR
18+
When logging, record sensitive data, like passwords.
19+
.TP
20+
\-v, \-vv, \-vvv
21+
Set the log level to 1, 2 or 3 respectively. Be aware that level 3 generates a significant amount of log data.
22+
.SS "Commands:"
23+
.TP
24+
\fB\-\-anvil\fR
25+
.TP
26+
This purges the Anvil! node (and both subnodes) from the Anvil! database.
27+
.TP
28+
\fB\-\-host\fR <host name or UUID>
29+
.TP
30+
This purges a specific host from the Anvil! databases.
31+
.IP
32+
.SH AUTHOR
33+
Written by Madison Kelly, Alteeve staff and the Anvil! project contributors.
34+
.SH "REPORTING BUGS"
35+
Report bugs to [email protected]

scancore-agents/scan-server/scan-server

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@ sub connect_to_virsh
115115
target => $target,
116116
});
117117

118+
# Also convert the target to an IP, if needed, and make sure that's added also.
119+
my $is_ip = $anvil->Validate->ipv4({debug => 2, ip => $target});
120+
my $check_ip = 0;
121+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { is_ip => $is_ip }});
122+
if (not $is_ip)
123+
{
124+
$check_ip = $anvil->Convert->host_name_to_ip({debug => 2, host_name => $target});
125+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { check_ip => $check_ip }});
126+
127+
if ($check_ip)
128+
{
129+
$anvil->Remote->test_access({
130+
debug => 2,
131+
target => $check_ip,
132+
});
133+
}
134+
}
135+
118136
my $record_locator = "scan_server::qemu::".$target."::no_access";
119137
my $is_local = $anvil->Network->is_local({host => $target });
120138
$anvil->data->{qemu}{$target}{connection} = "";

0 commit comments

Comments
 (0)