# # Copyright (c) 2015 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # =head1 NAME NACL::MTask::SystemNodeSingleton =head1 SYNOPSIS my @Nodes = NACL::MTask::SystemNodeSingleton->find(); =head1 DESCRIPTION C returns a singleton of a NACL::C::SystemNode. This is useful if you want to limit the number of duplicate connections to a filer but are unable to pass references between modules. =head1 METHODS =head2 discover NACL::MTask::SystemNodeSingleton->discover(); Discover all nodes by querying the cluster even if only a few nodes are passed in the testbed. If only NODES=node1 was passed the discover causes all nodes in the cluster to be returned when find is called. If operating in a multi-cluster environment at least one node from each cluster must be passed. This must be called before any Singleton->find is called and does not return any values. After calling discover, any calls to find will return all nodes reachable from the nodes passed in via tharn parameters. =head1 METHODS =head2 discover_nodes_all_clusters NACL::MTask::SystemNodeSingleton->discover_nodes_all_clusters(); Discover all nodes from all clusters in the testbed. This must be called before Singleton->find_clus_A_nodes() or Singleton->find_clus_B_nodes(). After calling discover, any calls to find cluster nodes will return all nodes reachable from the nodes passed in via tharn parameters (NODES). =head1 METHODS =head2 find my @Nodes = NACL::MTask::SystemNodeSingleton->find(); my $Node = NACL::MTask::SystemNodeSingleton->find(); Get a C instance or instances =cut package NACL::MTask::SystemNodeSingleton; use NACL::C::SystemNode; my @Nodes; my @Nodes_7mode; my @Nodes_cmode; our @All_Nodes; our @Clus_A_Nodes; our @Clus_B_Nodes; sub discover { if (@Nodes) { return; } my $node = NACL::C::Node->find(); @Nodes = NACL::C::Node->find(command_interface => $node); return; } sub find { my ($pkg, %args) = @_; if (!@Nodes) { @Nodes = NACL::C::SystemNode->find(%args); } return wantarray ? @Nodes : $Nodes[0]; } sub find_7m_nodes { my ($pkg, %args) = @_; if (!@Nodes_7mode) { @Nodes_7mode = NACL::C::SystemNode->find_7m_nodes(%args); } return wantarray ? @Nodes_7mode : $Nodes_7mode[0]; } sub find_cm_nodes { my ($pkg, %args) = @_; if (!@Nodes_cmode) { @Nodes_cmode = NACL::C::SystemNode->find_cm_nodes(%args); } return wantarray ? @Nodes_cmode : $Nodes_cmode[0]; } sub discover_nodes_all_clusters { if (@All_Nodes) { return; } @All_Nodes = NACL::C::Node->find(); return; } sub find_clus_A_nodes { if (!@Clus_A_Nodes) { my @cluster_states = NACL::CS::Cluster->fetch(command_interface => $All_Nodes[0]); my @node_names = map { $_->node } @cluster_states; foreach my $clus_node (@node_names) { foreach my $node (@All_Nodes) { if($node->node() eq $clus_node){ push (@Clus_A_Nodes,$node); } } } } return wantarray ? @Clus_A_Nodes : $Clus_A_Nodes[0]; } sub find_clus_B_nodes { my ($pkg) = @_; if (!@Clus_B_Nodes) { my @all_nodes = @All_Nodes; my @primary_nodes = @Clus_A_Nodes; if(!@primary_nodes){ @primary_nodes = $pkg->find_clus_A_nodes(); } @Clus_B_Nodes = splice ( @all_nodes, @primary_nodes) ; } return wantarray ? @Clus_B_Nodes : $Clus_B_Nodes[0]; } 1;