$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { storage_group_uuid => $storage_group_uuid }});
print "The storage group: [".$storage_group_name."] on the Anvil! node: [".$anvil_name."] has been created with the UUID: [".$storage_group_uuid."].\n";
$anvil->nice_exit({exit_code => 0});
}
elsif ($anvil->data->{switches}{remove})
{
# Does it exist?
if (not $storage_group_uuid)
{
print "The storage group: [".$group."] wasn't found on the Anvil! node: [".$anvil_name."], nothing to do.\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { storage_group_uuid => $storage_group_uuid }});
print "The storage group: [".$storage_group_name."] on the Anvil! node: [".$anvil_name."] has been deleted.\n";
$anvil->nice_exit({exit_code => 0});
}
elsif ($anvil->data->{switches}{'rename'})
{
# Do we have a new name?
if (not $new_name)
{
print "The storage group: [".$storage_group_name."] exists on the Anvil! node: [".$anvil_name."], but no new name was given via '--new-name <name>' nothing to do.\n";
$anvil->nice_exit({exit_code => 1});
}
# Has the name changed?
if (($storage_group_name) eq ($new_name))
{
print "The storage group: [".$new_name."] already has the desired name on the: [".$anvil_name."], nothing to do.\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { storage_group_uuid => $storage_group_uuid }});
print "The storage group: [".$storage_group_name."] on the Anvil! node: [".$anvil_name."] has been renamed to: [".$new_name."].\n";
$anvil->nice_exit({exit_code => 0});
}
return(0);
}
sub manage_group_member
{
my ($anvil) = @_;
my $group = $anvil->data->{switches}{group};
my $anvil_uuid = $anvil->Database->get_anvil_uuid_from_string({string => $anvil->data->{switches}{anvil}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }});
if (not $anvil_uuid)
{
if ($anvil->data->{switches}{anvil})
{
print "The Anvil! node: [".$anvil->data->{switches}{anvil}."] was not found.\n";
}
else
{
print "When managing a storage group members, '--anvil <name or UUID>' is required as storage group names are not globally unique.\n";
}
$anvil->nice_exit({exit_code => 1});
}
my $anvil_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_name => $anvil_name }});
my $storage_group_uuid = "";
my $storage_group_name = "";
foreach my $this_storage_group_name (sort {$a cmp $b} keys %{$anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_name}})
{
my $this_storage_group_uuid = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_name}{$this_storage_group_name}{storage_group_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
internal_vg_uuid => $internal_vg_uuid,
lvm_vg_name => $lvm_vg_name,
host_uuid => $host_uuid,
host_type => $host_type,
short_host_name => $short_host_name,
host_key => $host_key,
host_anvil_name => $host_anvil_name,
host_anvil_uuid => $host_anvil_uuid,
}});
if ($host_key eq "DELETED")
{
print "The volume group: [".$lvm_vg_name."] is on the deleted host: [".$host_name."]\n";
print "Call with '--show' to see Anvil! nodes, DR hosts and existing storage groups.\n";
$anvil->nice_exit({exit_code => 1});
}
if ($host_type eq "striker")
{
print "The volume group: [".$lvm_vg_name."] is on the Striker dashboard: [".$host_name."].\n";
print "There's no point in a Striker being part of a storage group.\n";
print "Call with '--show' to see Anvil! nodes, DR hosts and existing storage groups.\n";
$anvil->nice_exit({exit_code => 1});
}
if (($host_type eq "node") && ($anvil_uuid ne $host_anvil_uuid))
{
print "The volume group: [".$lvm_vg_name."] is on the sub node: [".$host_name."]. This is part of\n";
print "the Anvil! node: [".$host_anvil_name."], but: [".$anvil_name."] was specified with '--anvil'.\n";
$anvil->nice_exit({exit_code => 1});
}
}
# Add needs to be the internal UUID
if ($anvil->data->{switches}{add})
{
# Add the VG, if needed.
if (exists $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{host_uuid}{$host_uuid})
{
# If the note is not 'DELETED', we don't need to add it.
my $storage_group_member_note = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{host_uuid}{$host_uuid}{storage_group_member_note};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { storage_group_member_note => $storage_group_member_note }});
if ($storage_group_member_note ne "DELETED")
{
# Nothing to do.
print "The volume group: [".$lvm_vg_name."] on the host: [".$short_host_name."] is already a member of the storage group: [".$storage_group_name."]. Nothing to do.\n";
$anvil->nice_exit({exit_code => 0});
}
}
# Still here? Add or update!
my $storage_group_member_uuid = $anvil->Database->insert_or_update_storage_group_members({
print "Added the volume group: [".$lvm_vg_name."] on the host: [".$short_host_name."] to the storage group: [".$storage_group_name."]. The new member UUID is: [".$storage_group_member_uuid."].\n";
}
else
{
# If there's no existing entry, there's nothing to remove.
if (not exists $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{host_uuid}{$host_uuid})
{
# Nothing to do.
print "The volume group: [".$lvm_vg_name."] on the host: [".$short_host_name."] has never been a member of the storage group: [".$storage_group_name."]. Nothing to do.\n";
$anvil->nice_exit({exit_code => 0});
}
# If the note is not 'DELETED', we don't need to add it.
if ($anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{host_uuid}{$host_uuid}{storage_group_member_note} eq "DELETED")
{
# Nothing to do.
print "The volume group: [".$lvm_vg_name."] on the host: [".$short_host_name."] has already been removed from the storage group: [".$storage_group_name."]. Nothing to do.\n";
$anvil->nice_exit({exit_code => 0});
}
# Still here? update!
my $storage_group_member_uuid = $anvil->Database->insert_or_update_storage_group_members({
print "Added the volume group: [".$lvm_vg_name."] on the host: [".$short_host_name."] has been removed from storage group: [".$storage_group_name."].\n";
}
return(0);
}
sub show_data
{
my ($anvil) = @_;
my $show_anvil_uuid = $anvil->Database->get_anvil_uuid_from_string({string => $anvil->data->{switches}{anvil}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { show_anvil_uuid => $show_anvil_uuid }});
foreach my $anvil_name (sort {$a cmp $b} keys %{$anvil->data->{anvils}{anvil_name}})
{
my $anvil_uuid = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_uuid};
my $anvil_description = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_description};
my $anvil_node1_host_uuid = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_node1_host_uuid};
my $anvil_node2_host_uuid = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_node2_host_uuid};
if (($show_anvil_uuid) && ($anvil_uuid ne $show_anvil_uuid))
foreach my $member_short_host_name (sort {$a cmp $b} keys %{$anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{short_host_name}})
{
my $member_host_uuid = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{short_host_name}{$member_short_host_name}{host_uuid};
my $storage_group_member_uuid = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{host_uuid}{$member_host_uuid}{storage_group_member_uuid};
my $vg_internal_uuid = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{host_uuid}{$member_host_uuid}{vg_internal_uuid};
my $vg_name = $anvil->data->{vgs}{host_uuid}{$member_host_uuid}{scan_lvm_vg_internal_uuid}{$vg_internal_uuid}{scan_lvm_vg_name};