# $Id$ # # Copyright (c) 2001-2011 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary CifsDomain ComponentState Module ## @author Vikas.p@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::SysManager::CifsDomain =head1 DESCRIPTION C is a derived class of L. It represents the state of an CifsDomain server configuration present on the System Manger GUI Screen. A related class is L, which represents access to an cifs setup =head1 ATTRIBUTES The individual pieces of data that are part of the state of the cifs domain element are the attributes of the cifs ComponentState. =over =item C<< vserver >> Filled in for CMode. =item C<< fqdn >> Filled in for CMode. Filled in for CMode. =item C<< dc_interface >> Filled in for CMode. =item C<< dc_fqdn >> Filled in for CMode. =item C<< dc_preferreddc >> Filled in for CMode. =item C<< domaincontroller >> Filled in for 7Mode. =item C<< domain_controller >> Filled in for 7Mode. =item C<< dc_status >> Filled in for 7Mode. =item C<< ldapserver >> Filled in for 7Mode. =item C<< ldap_server >> Filled in for 7Mode. =item C<< ldap_status >> Filled in for 7Mode. =back =cut package NACL::CS::SysManager::CifsDomain; use strict; use warnings; 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 Params::Validate qw(validate); use base 'NACL::CS::ComponentState::SysManager'; use NACL::C::SysManager::CifsDomain; use NACL::Exceptions::NoElementsFound qw(:try); # Import Exception class use NACL::APISet::Exceptions::ResponseException qw(:try); use NACL::APISet::Exceptions::CommandFailedException; use Class::MethodMaker [ #7mode Only scalar => 'domaincontroller', scalar => 'domain_controller', scalar => 'dc_status', scalar => 'ldapserver', scalar => 'ldap_server', scalar => 'ldap_status', #Cmode Only scalar => 'vserver', scalar => 'fqdn', scalar => 'dc_interface', scalar => 'dc_fqdn', scalar => 'dc_preferreddc', ]; =head1 METHODS =head2 fetch my $cifs_state = NACL::CS::SysManager::CifsDomain->fetch(command_interface=>$ci,...); my @cifs_states = NACL::CS::SysManager::CifsDomain->fetch(command_interface=>$ci,...); see L. Uses a CMode GUI or a 7Mode GUI APISet. =cut sub fetch { $Log->enter() if $may_enter; my ( $pkg, @args ) = @_; my @state_objs = $pkg->SUPER::fetch( @args, choices => [ { method => "_fetch_cmode_gui", set => "SysManager_CMode", }, { method => '_fetch_7mode_gui', set => 'SysManager_7Mode', }, ], exception_text => 'CIFS not licensed/Configured', ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_7mode_gui { $Log->enter() if $may_enter; my ( $pkg, @args ) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $domain_controllers = 0; my $domain_ldapservers = 0; my $parsed_output_dc; my $parsed_output_ldap; my $domain_args; my $ldap_args; my $response; my $caught_exception = 0; my $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my $command_interface = $opts{command_interface}; if ( exists( $filter->{'domaincontroller'} ) ) { $domain_args = $pkg->_hash_copy( source => $filter, map => { 'domaincontroller' => '-domaincontroller', }, ); try { # caling the gui api to get cifs domain controller status $response = $apiset->get_cifs_domaincontrollers_info(%$domain_args); $parsed_output_dc = $response->get_parsed_output(); $domain_controllers = 1; } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the domain Controller 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' $Log->debug( 'CommandFailedException caught. Requested Domain Controller does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } } ## end if ( exists( $filter->...)) if ( exists( $filter->{'ldapserver'} ) ) { $ldap_args = $pkg->_hash_copy( source => $filter, map => { 'ldapserver' => '-ldapserver', }, ); try { # caling the gui api to get cifs ldap server status $response = $apiset->get_cifs_domainldapservers_info(%$ldap_args); $parsed_output_ldap = $response->get_parsed_output(); $domain_ldapservers = 1; } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the ldap server 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' $Log->debug( 'CommandFailedException caught. Requested LDAP server does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } } ## end if ( exists( $filter->...)) my %final_attributes; my %state_base_field_settings; if ( $domain_controllers == 1 ) { $state_base_field_settings{'domaincontroller'} = $domain_args->{'-domaincontroller'}; %final_attributes = ( %final_attributes, %$parsed_output_dc ); } elsif ( $domain_ldapservers == 1 ) { $state_base_field_settings{'ldapserver'} = $ldap_args->{'-ldapserver'}; %final_attributes = ( %final_attributes, %$parsed_output_ldap ); } %final_attributes = ( %final_attributes, %state_base_field_settings ); my $obj = $pkg->new( command_interface => $command_interface ); $obj->_set_fields( row => \%final_attributes ); $Log->exit() if $may_exit; return $obj; } ## end sub _fetch_7mode_gui sub _fetch_cmode_gui { $Log->enter() if $may_enter; my ( $pkg, @args ) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $parsed_output_dc; my $response; my $caught_exception = 0; my $apiset = $opts{apiset}; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my $command_interface = $opts{command_interface}; my $cifs_args = $pkg->_hash_copy( source => $filter, map => { 'fqdn' => '-fqdn' }, ); $pkg->_check_for_required_filter_fields( filter => $filter, required_fields => [qw(fqdn)], ); try { # caling the gui api to get cifs domain controller status $response = $apiset->get_cifs_domaincontrollers_info(%$cifs_args); $parsed_output_dc = $response->get_parsed_output(); } ## end try catch NACL::APISet::Exceptions::CommandFailedException with { # A caught exception indicates that the domain Controller 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' $Log->debug( 'CommandFailedException caught. Requested Domain Controller does ' . 'not exist' ); $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my %state_base_field_settings; $state_base_field_settings{'fqdn'} = $cifs_args->{'-fqdn'}; my %final_attributes = ( %state_base_field_settings, %$parsed_output_dc ); my $obj = $pkg->new( command_interface => $command_interface ); $obj->_set_fields( row => \%final_attributes ); $Log->exit() if $may_exit; return $obj; } ## end sub _fetch_cmode_gui 1;