/usr/share/perl5/NetApp/Volume.pm is in libnetapp-perl 500.002-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | package NetApp::Volume;
our $VERSION = '500.002';
$VERSION = eval $VERSION; ## no critic: StringyEval
use strict;
use warnings;
use English;
use Carp;
use Class::Std;
use Params::Validate qw( :all );
use Regexp::Common;
use NetApp::Volume::Source;
{
my %filer_of :ATTR( get => 'filer' );
my %name_of :ATTR( get => 'name' );
my %state_of :ATTR;
my %status_of :ATTR;
my %options_of :ATTR;
my %source_of :ATTR( get => 'source' );
my %plex_of :ATTR( get => 'plex' );
my %aggregate_name_of :ATTR( get => 'aggregate_name' );
my %clone_names_of :ATTR;
my %parent_name_of :ATTR( get => 'parent_name' );
my %snapshot_name_of :ATTR( get => 'snapshot_name' );
my %path_of :ATTR( get => 'path' );
sub BUILD {
my ($self,$ident,$args_ref) = @_;
my @args = %$args_ref;
my (%args) = validate( @args, {
filer => { isa => 'NetApp::Filer' },
name => { type => SCALAR },
state => { type => HASHREF },
status => { type => HASHREF },
options => { type => HASHREF },
plex => { type => HASHREF },
aggregate_name => { type => SCALAR,
optional => 1 },
source => { type => HASHREF,
optional => 1 },
clone_names => { type => ARRAYREF,
default => [],
optional => 1 },
parent_name => { type => SCALAR,
optional => 1 },
snapshot_name => { type => SCALAR,
optional => 1 },
});
$filer_of{$ident} = $args{filer};
$name_of{$ident} = $args{name};
$state_of{$ident} = $args{state};
$status_of{$ident} = $args{status};
$options_of{$ident} = $args{options};
$plex_of{$ident} =
NetApp::Aggregate::Plex->new( $args{plex} );
if ( $args{aggregate_name} ) {
$aggregate_name_of{$ident} = $args{aggregate_name};
}
if ( $args{source} ) {
$source_of{$ident} =
NetApp::Volume::Source->new( $args{source} );
}
$clone_names_of{$ident} = $args{clone_names};
if ( $args{parent_name} ) {
$parent_name_of{$ident} = $args{parent_name};
}
if ( $args{snapshot_of} ) {
$snapshot_name_of{$ident} = $args{snapshot_name};
}
$path_of{$ident} = "/vol/$args{name}";
}
sub get_states {
return keys %{ $state_of{ident shift} };
}
sub get_state {
my $self = shift;
my $ident = ident $self;
my $state = shift;
return $state_of{$ident}->{$state};
}
sub get_statuses { # Stati? Oh, hell no...
return keys %{ $status_of{ident shift} };
}
sub get_status {
my $self = shift;
my $ident = ident $self;
my $status = shift;
return $status_of{$ident}->{$status};
}
sub get_options {
return keys %{ $options_of{ident shift} };
}
sub get_option {
my $self = shift;
my $ident = ident $self;
my $option = shift;
if ( exists $options_of{$ident}->{$option} ) {
return $options_of{$ident}->{$option};
} else {
return undef;
}
}
sub set_option {
my $self = shift;
my $option = shift;
my $value = $option eq 'root' ? '-f' : shift;
my $ident = ident $self;
my $name = $self->get_name;
my @command = ( qw(vol options), $name, $option, $value );
$self->get_filer->_run_command( command => @command );
if ( $option eq 'root' ) {
$options_of{$ident}->{$option} = 1;
} else {
$options_of{$ident}->{$option} = $value;
}
return 1;
}
sub get_aggregate {
my $self = shift;
return $self->get_filer->get_aggregate( $self->get_aggregate_name );
}
sub get_qtree_names {
my $self = shift;
return map { $_->get_name } $self->get_qtrees;
}
sub get_qtree {
my $self = shift;
my $name = shift || "/vol/" . $self->get_name;
return $self->get_filer->get_qtree( $name );
}
sub get_qtrees {
my $self = shift;
return $self->get_filer->_get_qtree_status( volume => $self );
}
sub get_language {
my $self = shift;
my $name = $self->get_name;
$self->get_filer->_run_command(
command => [qw(vol language), $name],
);
my @stdout = $self->get_filer->_get_command_stdout;
my $language = "";
while ( my $line = shift @stdout ) {
if ( $line =~ /Volume language is (\S+)/ ) {
$language = $1;
}
}
if ( not $language ) {
croak(
"Unable to determine language for volume $name\n",
);
}
return $language;
}
sub set_language {
my $self = shift;
my $language = shift;
my $name = $self->get_name;
return $self->get_filer->_run_command(
command => [qw(vol language), $name, $language],
);
}
sub get_size {
my $self = shift;
my $name = $self->get_name;
$self->get_filer->_run_command(
command => [qw(vol size), $name],
);
my @stdout = $self->get_filer->_get_command_stdout;
my $size = "";
while ( defined(my $line = shift @stdout) ) {
if ( $line =~ /has size (\S+)\./ ) {
$size = $1;
}
}
if ( not $size ) {
croak("Unable to determine size of volume $name\n");
}
return $size;
}
sub set_size {
my $self = shift;
my $size = shift;
return $self->get_filer->_run_command(
command => [qw(vol size), $self->get_name, $size],
);
}
sub get_maxfiles {
my $self = shift;
my $name = $self->get_name;
$self->get_filer->_run_command(
command => ['maxfiles', $name],
);
my @stdout = $self->get_filer->_get_command_stdout;
my $maxfiles = "";
while ( my $line = shift @stdout ) {
if ( $line =~ /is currently (\d+)/ ) {
$maxfiles = $1;
}
}
if ( not $maxfiles ) {
croak("Unable to determine maxfiles of volume $name\n");
}
return $maxfiles;
}
sub set_maxfiles {
my $self = shift;
my $maxfiles = shift;
return $self->get_filer->_run_command(
command => ['maxfiles', $self->get_name, $maxfiles],
);
}
sub get_clone_names {
my $self = shift;
my $ident = ident $self;
return @{ $clone_names_of{$ident} };
}
sub get_clones {
my $self = shift;
my @clones = ();
foreach my $clone_name ( $self->get_clone_names ) {
push @clones, $self->get_filer->get_volume( $clone_name );
}
return @clones;
}
sub is_clone {
my $self = shift;
return ( $self->get_parent_name ? 1 : 0 );
}
sub get_parent {
my $self = shift;
if ( $self->is_clone ) {
return $self->get_filer->get_volume( $self->get_parent_name );
} else {
return;
}
}
sub get_snapmirrors {
my $self = shift;
return $self->get_filer->_get_snapmirrors( volume => $self );
}
sub get_snapshots {
return NetApp::Snapshot->_get_snapshots( parent => shift );
}
sub get_snapshot {
my $self = shift;
my ($name) = validate_pos( @_, { type => SCALAR } );
return grep { $_->get_name eq $name } $self->get_snapshots;
}
sub create_snapshot {
my $self = shift;
my ($name) = validate_pos( @_, { type => SCALAR } );
return NetApp::Snapshot->_create_snapshot(
parent => $self,
name => $name,
);
}
sub delete_snapshot {
my $self = shift;
my ($name) = validate_pos( @_, { type => SCALAR } );
return NetApp::Snapshot->_delete_snapshot(
parent => $self,
name => $name,
);
}
sub delete_all_snapshots {
croak(__PACKAGE__ . "->delete_all_snapshots not yet implemented\n");
# XXX: This one's tricky to implement. Should we parse the
# output, and attempt to return a list of what was delete, and
# what was busy? Probably too ugly.
my $self = shift;
return $self->get_filer->_run_command(
command => [ qw( snap delete -a -f -q ), $self->get_name ],
);
}
sub get_snapshot_deltas {
return NetApp::Snapshot->_get_snapshot_deltas( parent => shift );
}
sub get_snapshot_reserved {
return NetApp::Snapshot->_get_snapshot_reserved( parent => shift );
}
sub set_snapshot_reserved {
my $self = shift;
my ($reserved) = validate_pos( @_, { type => SCALAR } );
return NetApp::Snapshot->_set_snapshot_reserved(
parent => $self,
reserved => $reserved,
);
}
sub get_snapshot_schedule {
return NetApp::Snapshot->_get_snapshot_schedule(
parent => shift,
@_
);
}
sub set_snapshot_schedule {
return NetApp::Snapshot->_set_snapshot_schedule(
parent => shift,
@_
);
}
sub enable_snapshot_autodelete {
my $self = shift;
return $self->get_filer->_run_command(
command => [ qw(snap autodelete), $self->get_name, qw(on) ],
);
}
sub disable_snapshot_autodelete {
my $self = shift;
return $self->get_filer->_run_command(
command => [ qw(snap autodelete), $self->get_name, qw(off) ],
);
}
sub reset_snapshot_autodelete {
my $self = shift;
return $self->get_filer->_run_command(
command => [ qw(snap autodelete), $self->get_name, qw(reset) ],
);
}
sub set_snapshot_autodelete_option {
my $self = shift;
my ($name,$value) = validate_pos(
@_,
{ type => SCALAR },
{ type => SCALAR },
);
my @command = (
qw( snap autodelete ),
$self->get_name, $name, $value,
);
return $self->get_filer->_run_command(
command => \@command,
);
}
sub get_snapshot_autodelete_option {
my $self = shift;
my ($name) = validate_pos(
@_,
{ type => SCALAR },
);
my @command = ( qw( snap autodelete ), $self->get_name );
$self->get_filer->_run_command(
command => \@command,
);
my @stdout = $self->get_filer->_get_command_stdout;
my $found = 0;
my $value = "";
while ( defined (my $line = shift @stdout) ) {
if ( $line =~ /^$name\s*:\s*(.*)/ ) {
$found = 1;
$value = $1;
$value = "" if $value eq '(not specified)';
}
}
if ( not $found ) {
croak("Invalid autodelete option name '$name'\n");
}
return $value;
}
sub get_temporary_exports {
return grep { $_->get_type eq 'temporary' } shift->get_exports;
}
sub get_permanent_exports {
return grep { $_->get_type eq 'permanent' } shift->get_exports;
}
sub get_active_exports {
return grep { $_->get_active } shift->get_exports;
}
sub get_inactive_exports {
return grep { not $_->get_active } shift->get_exports;
}
sub get_export {
my $self = shift;
my ($path) = validate_pos( @_, { type => SCALAR } );
return grep { $_->get_path eq $path } $self->get_exports;
}
sub get_exports {
my $self = shift;
return
grep { $_->get_path eq $self->get_path ||
$_->get_actual eq $self->get_path }
$self->get_filer->get_exports;
}
sub create_export {
my $self = shift;
my (%args) = validate( @_, {
exportas => { type => SCALAR,
optional => 1 },
type => { type => SCALAR,
optional => 1 },
nosuid => { type => SCALAR,
optional => 1 },
anon => { type => SCALAR,
optional => 1 },
sec => { type => ARRAYREF,
optional => 1 },
root => { type => ARRAYREF,
optional => 1 },
rw => { type => ARRAYREF,
optional => 1 },
ro => { type => ARRAYREF,
optional => 1 },
rw_all => { type => SCALAR,
optional => 1 },
ro_all => { type => SCALAR,
optional => 1 },
});
if ( $args{exportas} ) {
$args{actual} = $self->get_path,
$args{path} = delete $args{exportas},
} else {
$args{path} = $self->get_path;
}
my $export = NetApp::Filer::Export->new( \%args );
return $export->update;
}
sub destroy_export {
my $self = shift;
# XXX: Hmm....
}
sub offline {
my $self = shift;
my $ident = ident $self;
my (%args) = validate( @_, {
cifsdelaytime => { type => SCALAR,
optional => 1 },
});
my @command = ( qw(vol offline), $self->get_name );
if ( $args{cifsdelaytime} ) {
push @command, '-t', $args{cifsdelaytime};
}
$self->get_filer->_run_command(
command => \@command,
);
delete $state_of{$ident}->{online};
delete $state_of{$ident}->{restricted};
$state_of{$ident}->{offline} = 1;
return 1;
}
sub online {
my $self = shift;
my $ident = ident $self;
my (%args) = validate( @_, {
force => { type => SCALAR,
optional => 1 },
});
my @command = ( qw( vol online ), $self->get_name );
if ( $args{force} ) {
push @command, '-f';
}
$self->get_filer->_run_command(
command => \@command,
);
delete $state_of{$ident}->{offline};
delete $state_of{$ident}->{restricted};
$state_of{$ident}->{online} = 1;
return 1;
}
sub rename {
my $self = shift;
my $ident = ident shift;
my (%args) = validate( @_, {
newname => { type => SCALAR },
});
my $oldname = $self->get_name;
$self->get_filer->_run_command(
command =>[qw(vol rename), $oldname, $args{newname}],
);
$name_of{$ident} = $args{newname};
return 1;
}
sub restrict {
my $self = shift;
my $ident = ident shift;
my (%args) = validate( @_, {
cifsdelaytime => { type => SCALAR,
optional => 1 },
});
my @command = ( qw(vol restrict), $self->get_name );
if ( $args{cifsdelaytime} ) {
push @command, '-t', $args{cifsdelaytime};
}
$self->get_filer->_run_command(
command => \@command,
);
delete $state_of{$ident}->{offline};
delete $state_of{$ident}->{online};
$state_of{$ident}->{restricted} = 1;
return 1;
}
}
sub _parse_vol_status_headers {
my $class = shift;
my $header = shift;
my $indices = {};
my $index = 0;
my ($volume) = ( $header =~ /(^\s+Volume\s+)/ ) or
croak(
"Unable to match 'Volume' column header\n"
);
$indices->{volume} = [ 0, length($volume) ];
$index += length($volume);
my ($state) = ( $header =~ /(State\s+)/ ) or
croak(
"Unable to match 'State' column header\n"
);
$indices->{state} = [ $index, length($state) ];
$index += length($state);
my ($status) = ( $header =~ /(Status\s+)/ ) or
croak(
"Unable to match 'Status' column header\n"
);
$indices->{status} = [ $index, length($status) ];
$index += length($status);
my ($options) = ( $header =~ /(Options\s*)/ ) or
croak(
"Unable to match 'Options' column header\n"
);
$indices->{options} = [ $index ];
if ( $header =~ /Source/ ) {
$indices->{options}->[1] = length($options);
$index += length($options);
$indices->{source} = [ $index ];
}
$indices->{length} = $index + 1;
return $indices;
}
sub _parse_vol_status_volume {
my $class = shift;
my %args = validate( @_, {
indices => { type => HASHREF },
line => { type => SCALAR },
volume => { type => HASHREF,
default => {},
optional => 1 },
});
my $indices = $args{indices};
my $volume = $args{volume};
my $line = $args{line};
if ( $line =~ /Clone, backed by volume '(.*)', snapshot '(.*)'/ ) {
$volume->{parent_name} = $1;
$volume->{snapshot_name} = $2;
return $volume;
} elsif ( $line =~ /Volume has clones: (.*)/ ) {
my $clones = $1;
$volume->{clone_names} = [ split( /[,\s]+/, $clones ) ];
return $volume;
} elsif ( $line =~ /Containing aggregate: (\S+)/ ) {
my $aggrname = $1;
$aggrname =~ s/'//g;
if ( $aggrname ne '<N/A>' ) {
$volume->{aggregate_name} = $aggrname;
}
return $volume;
}
if ( length($line) < $indices->{length} ) {
$line .= " " x ( $indices->{length} - length($line) );
}
foreach my $column ( qw( volume state status options source ) ) {
my $value = "";
next unless $indices->{$column};
if ( defined $indices->{$column}->[1] ) {
$value = substr( $line,
$indices->{$column}->[0],
$indices->{$column}->[1] );
} else {
$value = substr( $line,
$indices->{$column}->[0] );
}
$value =~ s/$RE{ws}{crop}//g;
if ( $column eq 'volume' ) {
if ( $value ) {
$volume->{name} = $value;
my ($name) = split( /\s+/, $line );
if ( length($name) > length($value) ) {
$volume->{name} = $name;
$line =~ s/^$name/$value/;
}
}
} elsif ( $column eq 'source' ) {
my ($hostname,$source) = split( /:/, $value );
$volume->{source} = {
hostname => $hostname,
volume => $source,
};
$indices->{options}->[1] = undef;
delete $indices->{source};
} else {
foreach my $entry ( split( /[,\s]+/, $value ) ) {
my ($key,$value);
if ( $entry =~ /=/ ) {
($key,$value) = split( /=/, $entry, 2 );
} else {
($key,$value) = ($entry,1);
}
$volume->{$column}->{$key} = $value;
}
}
}
return $volume;
}
1;
|