You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.0 KiB
46 lines
1.0 KiB
#!/usr/bin/perl -w
|
|
|
|
use Linux::LVM;
|
|
use JSON;
|
|
|
|
my $what = $ARGV[0];
|
|
|
|
open STDERR, '>/dev/null';
|
|
|
|
my $json;
|
|
|
|
if ($what eq "volumes"){
|
|
foreach my $group (get_volume_group_list()){
|
|
my %lvs = get_logical_volume_information($group);
|
|
foreach my $lv (keys %lvs){
|
|
$lv = ($lv =~ m!^/dev/$group!) ? $lv : "/dev/$group/$lv";
|
|
push @{$json->{data}}, { "{#LVMVOL}" => "$lv" };
|
|
}
|
|
}
|
|
}
|
|
elsif ($what eq "snapshots"){
|
|
foreach my $group (get_volume_group_list()){
|
|
my %lvs = get_logical_volume_information($group);
|
|
foreach my $lv (keys %lvs){
|
|
if (defined $lvs{$lv}->{allocated_to_snapshot}){
|
|
$lv = ($lv =~ m!^/dev/$group!) ? $lv : "/dev/$group/$lv";
|
|
push @{$json->{data}}, { "{#LVMSNAP}" => "$lv" };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
elsif ($what eq "groups"){
|
|
foreach my $group (get_volume_group_list()){
|
|
push @{$json->{data}}, { "{#LVMGRP}" => $group };
|
|
}
|
|
}
|
|
else{
|
|
print <<"EOF";
|
|
|
|
Usage: $0 [volumes|snapshots|groups]
|
|
|
|
EOF
|
|
}
|
|
|
|
print to_json($json);
|
|
exit(0);
|
|
|