# # Copyright (c) 2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary VG ComponentState Module ## @author praveent@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here ################################################################################ =head1 NAME NACL::CS::Client::VG =head1 DESCRIPTION C is a derived class of L. It represents the state of VG element. A related class is L, which represents access to a VG element. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the VG element are the individual attributes of the VG ComponentState =over =item C<< "cur_pv" >> Filled in for Linux CLI. =item C<< "system_id" >> Filled in for Linux CLI. =item C<< "act_pv" >> Filled in for Linux CLI. =item C<< "vg_name" >> Filled in for Linux CLI. =item C<< "alloc_pe_size" >> Filled in for Linux CLI. =item C<< "max_pv" >> Filled in for Linux CLI. =item C<< "vg_status" >> Filled in for Linux CLI. =item C<< "alloc_pe" >> Filled in for Linux CLI. =item C<< "vg_size" >> Filled in for Linux CLI. =item C<< "cur_lv" >> Filled in for Linux CLI. =item C<< "vg_uuid" >> Filled in for Linux CLI. =item C<< "total_pe" >> Filled in for Linux CLI. =item C<< "pe_size" >> Filled in for Linux CLI. =item C<< "free_pe" >> Filled in for Linux CLI. =item C<< "vg_access" >> Filled in for Linux CLI. =item C<< "metadata_areas" >> Filled in for Linux CLI. =item C<< "metadata_sequence_no" >> Filled in for Linux CLI. =item C<< "format" >> Filled in for Linux CLI. =item C<< "free_pe_size" >> Filled in for Linux CLI. =item C<< "max_lv" >> Filled in for Linux CLI. =item C<< "open_lv" >> Filled in for Linux CLI. =item C<< "vg_mode" >> Filled in for Linux CLI. =item C<< "internal_vg_number" >> Filled in for Linux CLI. =item C<< "max_lv_size" >> Filled in for Linux CLI. =item C<< "pe_size_kb" >> Filled in for Linux CLI. =item C<< "vg_size_kb" >> Filled in for Linux CLI. =item C<< "free_space" >> Filled in for Linux CLI. =item C<< "used_space" >> Filled in for Linux CLI. =item C<< "library_version" >> Filled in for Linux CLI. =item C<< "driver_version" >> Filled in for Linux CLI. =item C<< "lvm_version" >> Filled in for Linux CLI. =item C<< "lv_size" >> Filled in for Linux CLI. =item C<< "time" >> Filled in for Linux CLI. =item C<< "lv_creation_host" >> Filled in for Linux CLI. =item C<< "segments" >> Filled in for Linux CLI. =item C<< "read_ahead_sectors" >> Filled in for Linux CLI. =item C<< "currently_set_to" >> Filled in for Linux CLI. =item C<< "lv_name" >> Filled in for Linux CLI. =item C<< "lv_uuid" >> Filled in for Linux CLI. =item C<< "allocation" >> Filled in for Linux CLI. =item C<< "lv_write_access" >> Filled in for Linux CLI. =item C<< "lv_status" >> Filled in for Linux CLI. =item C<< "open" >> Filled in for Linux CLI. =item C<< "lv_path" >> Filled in for Linux CLI. =item C<< "current_le" >> Filled in for Linux CLI. =item C<< "block_device" >> Filled in for Linux CLI. =item C<< "pv_status" >> Filled in for Linux CLI. =item C<< "pv_uuid" >> Filled in for Linux CLI. =item C<< "pv_name" >> Filled in for Linux CLI. =item C<< "sn" >> Filled in for Linux CLI. =item C<< "vg_free" >> Filled in for Linux CLI. =item C<< "attr" >> Filled in for Linux CLI. =item C<< "logical_volume" >> (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $logical_volume = $obj->logical_volume(); $logical_volume contains a reference to the array of values my @logical_volume = $obj->logical_volume(); @logical_volume contains the array of values Filled in for Linux CLI. =item C<< "physical_volumes" >> (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $physical_volumes = $obj->physical_volumes(); $physical_volumes contains a reference to the array of values my @physical_volumes = $obj->physical_volumes(); @physical_volumes contains the array of values Filled in for Linux CLI. =item C<< "volume_group" >> (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $volume_group = $obj->volume_group(); $volume_group contains a reference to the array of values my @volume_group = $obj->volume_group(); @volume_group contains the array of values Filled in for Linux CLI. =back =cut ################### # Package package NACL::CS::Client::VG; ################### # Everytime use strict; use warnings; ################### # Module includes use Params::Validate qw (validate validate_with HASHREF ARRAYREF OBJECT); use NACL::ComponentUtils qw (_optional_scalars Dumper); use NACL::APISet::Exceptions::UnexpectedOutputException qw(:try); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use base 'NACL::CS::ComponentState::Client'; use Class::MethodMaker [ scalar => "cur_pv", scalar => "system_id", scalar => "act_pv", scalar => "vg_name", scalar => "alloc_pe_size", scalar => "max_pv", scalar => "vg_status", scalar => "alloc_pe", scalar => "vg_size", scalar => "cur_lv", scalar => "vg_uuid", scalar => "total_pe", scalar => "pe_size", scalar => "free_pe", scalar => "vg_access", scalar => "metadata_areas", scalar => "metadata_sequence_no", scalar => "format", scalar => "free_pe_size", scalar => "max_lv", scalar => "open_lv", scalar => "vg_mode", scalar => "internal_vg_number", scalar => "max_lv_size", scalar => "pe_size_kb", scalar => "vg_size_kb", scalar => "free_space", scalar => "used_space", scalar => "library_version", scalar => "driver_version", scalar => "lvm_version", scalar => "lv_size", scalar => "time", scalar => "lv_creation_host", scalar => "segments", scalar => "read_ahead_sectors", scalar => "currently_set_to", scalar => "lv_name", scalar => "lv_uuid", scalar => "allocation", scalar => "lv_write_access", scalar => "lv_status", scalar => "open", scalar => "lv_path", scalar => "current_le", scalar => "block_device", scalar => "pv_status", scalar => "pv_uuid", scalar => "pv_name", scalar => "sn", scalar => "vg_free", scalar => "attr", array => "logical_volume", array => "physical_volumes", array => "volume_group", ]; =head1 METHODS =head2 fetch my $volume_groups = NACL::CS::Client::VG->fetch(command_interface=>$ci,...); my @volume_groups = NACL::CS::Client::VG->fetch(command_interface=>$ci,...); see L Supports Linux CLI. Invokes "vgdisplay" command for Linux CLI. =cut sub fetch { $Log->enter(); my ($pkg, @opts) = @_; my @state_objs = $pkg->SUPER::fetch( @opts, choices => [ { method => "_fetch_linux_cli", interface => "CLI", set => 'Linux' }, ], exception_text => 'No volume groups found' ); $Log->exit(); return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_linux_cli { $Log->enter(); my ( $pkg, @opts ) = @_; my %opts = validate @opts, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my ( @vgdisplay_args, @state_objs ); # Provide a large timeout so that the command will not timeout if there is # a lot of output to display my $timeout = $opts{'timeout'} || 1200; push @vgdisplay_args, ( 'connectrec-timeout' => $timeout ); my @orig_requested_fields = @{ $opts{requested_fields} }; my %orig_filter = %{ $opts{filter} }; $pkg->_remove_relational_regex_filters( filter => \%orig_filter, requested_fields => \@orig_requested_fields ); $requested_fields = \@orig_requested_fields; $filter = \%orig_filter; if ( defined $filter->{vg_name} ) { push @vgdisplay_args, ( "volume-group-name" => $filter->{vg_name} ); } my ( $response, $caught_exception, $obj ); my %temp_hash; try { $response = $apiset->vgdisplay(@vgdisplay_args); } catch NACL::APISet::Exceptions::UnexpectedOutputException with { # A caught exception indicates that the device being looked for # does not exist. We catch the exception and return immediately. The # 'fetch' frontend decides whether to throw a NoElementsFound # exception based on the value of 'allow_empty' $caught_exception = 1; }; if ($caught_exception) { $Log->exit(); return; } my $output = $response->get_parsed_output(); foreach my $row (@$output) { my $state_base_field_settings = $pkg->_hash_copy( source => $row, copy => [qw( cur_pv system_id act_pv vg_name alloc_pe_size max_pv vg_status alloc_pe vg_size cur_lv vg_uuid total_pe pe_size free_pe vg_access metadata_areas metadata_sequence_no format free_pe_size max_lv open_lv )], ); $obj = $pkg->new(command_interface => $opts{command_interface}); $obj->_set_fields(row => $state_base_field_settings); push @state_objs, $obj; } ## end foreach my $row (@$output) my %commands = $pkg->_handle_commands_returning_common_fields( common_fields => [qw( cur_pv system_id act_pv vg_name alloc_pe_size max_pv vg_status alloc_pe vg_size cur_lv vg_uuid total_pe pe_size free_pe vg_access metadata_areas metadata_sequence_no format free_pe_size max_lv open_lv )], commands => { 'vgdisplay_version' => [ qw( library_version driver_version lvm_version ) ], 'vgdisplay_colon' => [ qw( vg_mode internal_vg_number max_lv_size pe_size_kb vg_size_kb ) ], 'vgdisplay_columns' => [ qw( sn vg_free attr ) ], 'vgdisplay_short' => [ qw( free_space used_space ) ], 'vgdisplay_verbose' => [ qw( logical_volume lv_size time lv_creation_host segments read_ahead_sectors currently_set_to lv_name lv_uuid allocation lv_write_access lv_status open lv_path current_le block_device physical_volumes pv_status pv_uuid pv_name volume_group ) ], }, preferred_command => 'vgdisplay', requested_fields => $requested_fields, filter => $filter ); if ( exists $commands{'vgdisplay_version'} ) { my @show_args; push @show_args, ('version' => 1); my $vgdisplay_response = $apiset->vgdisplay(@show_args); my $vgdisplay_show_output = $vgdisplay_response->get_parsed_output(); foreach my $show_info (@{$vgdisplay_show_output}) { my $device_info = $pkg->_hash_copy( source => $show_info, copy => [qw( library_version driver_version lvm_version )], ); $obj->_set_fields(row => $device_info); push @state_objs, $obj; } } if ( exists $commands{'vgdisplay_colon'} ) { my @show_args; push @show_args, ( 'colon' => 1); if (defined $filter->{vg_name}) { push @show_args, ( "volume-group-name" => $filter->{vg_name}); } my $vgdisplay_response = $apiset->vgdisplay(@show_args); my $vgdisplay_show_output = $vgdisplay_response->get_parsed_output(); foreach my $show_info (@{$vgdisplay_show_output}) { my $device_info = $pkg->_hash_copy( source => $show_info, copy => [qw( vg_mode internal_vg_number max_lv_size pe_size_kb vg_size_kb )], ); $obj->_set_fields(row => $device_info); push @state_objs, $obj; } } if ( exists $commands{'vgdisplay_columns'} ) { my @show_args; push @show_args, ( 'columns' => 1); if (defined $filter->{vg_name}) { push @show_args, ( "volume-group-name" => $filter->{vg_name}); } my $vgdisplay_response = $apiset->vgdisplay(@show_args); my $vgdisplay_show_output = $vgdisplay_response->get_parsed_output(); foreach my $show_info (@{$vgdisplay_show_output}) { my $device_info = $pkg->_hash_copy( source => $show_info, copy => [qw( sn vg_free attr )], ); $obj->_set_fields(row => $device_info); push @state_objs, $obj; } } if ( exists $commands{'vgdisplay_short'} ) { my @show_args; push @show_args, ('short' => 1); if (defined $filter->{vg_name}) { push @show_args, ( "volume-group-name" => $filter->{vg_name}); } my $vgdisplay_response = $apiset->vgdisplay(@show_args); my $vgdisplay_show_output = $vgdisplay_response->get_parsed_output(); foreach my $show_info (@{$vgdisplay_show_output}) { my $device_info = $pkg->_hash_copy( source => $show_info, copy => [qw( free_space used_space )], ); $obj->_set_fields(row => $device_info); push @state_objs, $obj; } } if ( exists $commands{'vgdisplay_verbose'} ) { my @show_args; push @show_args, ('verbose' => 1); if (defined $filter->{vg_name}) { push @show_args, ( "volume-group-name" => $filter->{vg_name}); } my $vgdisplay_response = $apiset->vgdisplay(@show_args); my $vgdisplay_show_output = $vgdisplay_response->get_parsed_output(); foreach my $show_info (@{$vgdisplay_show_output}) { my $device_info = $pkg->_hash_copy( source => $show_info, copy => [qw( logical_volume lv_size time lv_creation_host segments read_ahead_sectors currently_set_to lv_name lv_uuid allocation lv_write_access lv_status open lv_path current_le block_device physical_volumes pv_status pv_uuid pv_name volume_group )], ); $obj->_set_fields(row => $device_info); push @state_objs, $obj; } } $Log->exit(); return @state_objs; } 1;