# $Id: //depot/prod/test/main/lib/NACL/MTask/NetworkInterfaceFailoverGroups.pm#1 $ # # Copyright (c) 2011 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary NetworkInterfaceFailoverGroups Task Module ## @author Sivakumar T(sivakum1@netapp.com), dl-nacl-dev ## @status shared ## @pod here package NACL::MTask::NetworkInterfaceFailoverGroups; use strict; use warnings; use base qw(NACL::STask::NetworkInterfaceFailoverGroups NACL::MTask::MTask); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Params::Validate qw(validate SCALAR BOOLEAN SCALARREF ARRAYREF); use NATE::Exceptions::Argument qw(:try); use NACL::APISet::Exceptions::ResponseException (); use NACL::C::Component; use Class::MethodMaker [ new => [ '-hash', 'new' ], scalar => 'NetworkInterfaceFailoverGroups', ]; =head1 NAME NACL::MTask::NetworkInterfaceFailoverGroups =head1 DESCRIPTION C provide methods to create, rename and destroy network interface failover-groups in ONTAP. It is created on top of C component. Since it is derived class of C, we can use all the methods of C from the object of this task. =head1 ATTRIBUTES =head2 command_interface (Required) A component object that represents the host to which to send commands. See L. =head2 NetworkInterfaceFailoverGroups Reference to an array of NetworkInterfaceFailoverGroups Mtask objects =head1 METHODS =head2 create my $NetworkInterfaceFailoverGroups_obj = NACL::MTask::NetworkInterfaceFailoverGroups->create( command_interface => $command_interface, 'failover-group' => $failover_group, node => $node_name, port => $port, nacltask_if_exists => $action ); (Class Method) It will create a failover group with specified ports. It also check if failover-group with specified ports is already exists or not. If failover-group already exists it will perform the action based on C parameter. Default behavior would be to to reuse the existing failover-group. Uses CMode CLI. =over =item Options =over =item C<< "ports" => $ports >> (Required) Array of ports to be used for failover-group. This takes reference to an array of ports. =item C<< "node" => $node_name >> (Required) node to be used for failover-group =item C<< "failover-group" => $failover_group >> (Required) Name of the failover-group. =item C<< nacltask_if_exists => $action >> (Optional) What to do if the failover-group with specified port already exists. If $action is "die" (the default), then fail with an exception. If action is "reuse", then it should be using the already existing failover-group. If action is "purge", then call the purge method of failover-group (see the C method, below) before creating a new one. =item C<< _was_created => \$scalar >> (Optional) When this option is provided a reference to a scalar variable, the variable gets filled in with a boolean value describing whether the failover-group was found (value will be 0; this scenario is possible when if_exists => "reuse") or whether the failover-group was created (value will be 1). This is necessary to determine whether the failover-group needs to be cleaned up later. my $was_created; my $FailoverGroup_obj = NACL::MTask::NetworkInterfaceFailoverGroups->create( if_exists => 'reuse', _was_created => \$was_created, %other_opts ); # Operate on $FailoverGroup_obj here # ... # Now determine whether to clean up the failover-group, since we're not sure # whether we reused an existing failover-group or created a new one if ($was_created) { # New failover-group was created. Clean it up. $FailoverGroup_obj->purge(); } =item C<< nacltask_verify => $nacltask_verify_boolean >> (Optional) If '0' (default), verification will not be performed. If '1', verification will be performed to ensure that the creation did happen successfully. =item command_interface, apiset_must, apiset_should, node,port etc. All of the other various options to L<< NACL::C::NetworkInterfaceFailoverGroups->create | lib-NACL-C-NetworkInterfaceFailoverGroups-pm/create >>. =back =back =cut sub create { $Log->enter() if $may_enter; my $pkg = shift; my %opts = $pkg->_common_validate_with( params => \@_, additional_spec => { nacltask_if_exists => NACL::STask::STask->_if_exists_validate_spec(), _was_created => { type => SCALARREF, optional => 1 }, nacltask_verify => { type => BOOLEAN, default => 0 }, }, allow_extra => 1, ignore_primary_keys => 1, ); # Transform %opts from the options we received into the options to # pass to the base class method. my $was_created = delete $opts{_was_created}; my $ports = delete $opts{ports}; $$was_created = 0; my $obj = $pkg->new(); my $NetworkInterfaceFailoverGroups; foreach my $port (@$ports) { $opts{port} = $port; my $fg = $pkg->SUPER::create(%opts); push @$NetworkInterfaceFailoverGroups, $fg; } $obj->NetworkInterfaceFailoverGroups($NetworkInterfaceFailoverGroups); $Log->exit() if $may_exit; return $obj; } ## end sub create =head2 purge $NetworkInterfaceFailoverGroups->purge(); NACL::MTask::NetworkInterfaceFailoverGroups->purge( 'command_interface' => $ci, 'failover-group' => $failover_group, 'node' => $node_name, 'ports' => $ports ); (Class or Instance method) Deletes the given failover group from Node. If the given failover group doesn't exists, it will perform the action based on C parameter. First Deassociate the failover group associated with the user defined lif, then delete all the ports in the failover group one by one using NetworkInterfaceFailoverGroups component. Throw an exception if someother lif is using the failover group. Once the failover group is deleted, it verifies whether the failover group is deleted or not using the NetworkInterfaceFailoverGroups Component states using nacltask_verify option. Uses a CMode CLI. =over =item Options =over =item C<< command_interface => $ci >> (Required) A component object that represents the host which to send commands. See NACL::C::Component::command_interface =item C<< "ports" => $ports >> (Required) Array of ports to be used for failover-group. This takes reference to an array of ports. =item C<< "node" => $node_name >> (Required) node to be used for failover-group =item C<< "failover-group" => $failover_group >> (Required) Name of the failover-group. =item C<< nacltask_verify => $nacltask_verify_boolean >> (Optional) If '0' (default), verification will not be performed. If '1', verification will be performed to ensure that the deletion did happen successfully. =item C<< nacltask_if_purged=>$nacltask_if_purged_value >> (Optional) If "die" (default), exception is thrown when failover groups to be deleted does not exist If "pass", exits quietly when failover groups to be deleted does not exist =back =back =cut sub purge { $Log->enter() if $may_enter; my $pkg_or_obj = shift; my %opts = $pkg_or_obj->_common_validate_with( params => \@_, additional_spec => { command_interface => { type => SCALAR, optional => 1 }, nacltask_verify => { type => BOOLEAN, default => 0 }, nacltask_if_purged => NACL::STask::STask->_if_action_completed_already_validate_spec() }, allow_extra => 1, ignore_primary_keys => 1, ); my $ports = delete $opts{ports}; if (ref($pkg_or_obj)) { my $obj = $pkg_or_obj->NetworkInterfaceFailoverGroups(); # Check for array of MTask objects, If exists means purge called right after create been called # Otherwise purge called from object which find() returns if ($obj) { foreach my $fg_obj (@$obj) { $fg_obj->SUPER::purge(%opts); } } else { $pkg_or_obj->SUPER::purge(); } } else { # package call with ports arrayref passed if ($ports) { foreach my $port (@$ports) { $opts{port} = $port; $pkg_or_obj->SUPER::purge(%opts); } } else { # Called from _element_exists_handler $pkg_or_obj->SUPER::purge(%opts); } } $Log->exit() if $may_exit; } ## end sub purge 1;