# # Copyright (c) 2001-2010 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary DFM Role ComponentState Module ## @author deepthis@netapp.com, dl-sm-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::DFM::Role =head1 DESCRIPTION C is a derived class of L. It represents the state of a role on DFM. A related class is L, which represents access to a role on DFM. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Role element are the attributes of the Role ComponentState. =over =item C<< role >> The name of the role element whose state is being represented. =item C<< Role_Id >> The Id associated with the role element whose state is being represented. =item C<< Description >> Description of the role whose state is being represented. =item C<< Inherited_Roles >> List of roles inherited by the role whose state is being represented. =item C<< Capabilities >> List of capabilities i.e operations that can be performed on resources by the role whose state is being represented. =back =cut package NACL::CS::DFM::Role; use strict; use warnings; use Data::Dumper; use Params::Validate qw(validate); use NACL::ComponentUtils qw(_dump_one); use NACL::APISet::Exceptions::InvalidParamException 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 Data::Dumper; use base 'NACL::CS::ComponentState::DFM'; use Class::MethodMaker [ new => [ '-hash', 'new' ], scalar => 'Role_Id', scalar => 'role', scalar => 'Description', scalar => 'Inherited_Roles', scalar => 'Capabilities', ]; =head1 METHODS =head2 fetch my $role_state = NACL::CS::DFM::Role->fetch(command_interface=>$ci,...); my @role_states = NACL::CS::DFM::Role->fetch(command_interface=>$ci,...); see L =cut sub fetch { $Log->enter() if $may_enter; my $pkg = shift; $Log->debug("Opts to 'fetch' front end are:\n".Dumper(\@_)); my %opts = validate @_, $pkg->_fetch_validate_spec(); my $allow_empty = delete $opts{allow_empty}; my @state_objs = $pkg->call_on_apiset( %opts, choices => [ { method => "_fetch_dfm_cli", interface => "CLI", set => "DFM", } ], ); # Apply the filter @state_objs = $pkg->_apply_filter(state_objs => \@state_objs, filter => $opts{filter}); $Log->exit() if $may_exit; if ( !@state_objs && !$allow_empty ) { NACL::Exceptions::NoElementsFound->throw( "No matching roles found\n" . " Filter: " . _dump_one( $opts{filter} ) . "\n" ); } ## end if ( !@state_objs && !... return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_dfm_cli { $Log->enter() if $may_enter; my $pkg = shift; $Log->debug("Opts to 'fetch'backend are:\n".Dumper(\@_)); my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my ( $response, $output, %args ); if ( $filter->{"role"} || $filter->{"Role Id"} ) { $args{"role-name"} = $filter->{"role"} || $filter->{"Role Id"}; } try { $response = $apiset->dfm_role_list(%args); $output = $response->get_parsed_output(); } catch NACL::APISet::Exceptions::InvalidParamValueException with { # Do nothing. # $response is empty. Results in @state_objs being empty at the end. }; my @state_objs; foreach my $row (@$output) { # Important to do this, because the parsed output of dfm_role_list has different keys # They have keys with spaces. If spaces are used here, Perl throws an exception $pkg->_hash_move( source => $row, target => $row, map => { "Role Name" => "role", # For the output of "dfm role list" "Role-name" => "role", # For the output of "dfm role list " "Role-id" => "Role_Id", "Inherited Roles" => "Inherited_Roles", }, ); my $obj = $pkg->new(); while ( my ( $key, $value ) = each %$row ) { # Set only known columns; columns without accessors are # assumed to be newer than what the test code knows about if ( $obj->can($key) ) { $obj->$key($value); } } ## end while ( my ( $key, $value... push @state_objs, $obj; } ## end foreach my $row (@$output) $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_dfm_cli 1;