Control-CLI-Extreme

 view release on metacpan or  search on metacpan

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

	my $self = shift;
	my %args;
	if (@_ == 1) { # Method invoked in the shorthand form
		$args{host} = shift;
		if ($args{host} =~ /^(.+?)\s+(\d+)$/) {
			($args{host}, $args{port}) = ($1, $2);
		}
	}
	else {
		my @validArgs = ('host', 'port', 'username', 'password', 'publickey', 'privatekey', 'passphrase',
				 'prompt_credentials', 'baudrate', 'parity', 'databits', 'stopbits', 'handshake',
				 'errmode', 'connection_timeout', 'timeout', 'read_attempts', 'wake_console',
				 'return_reference', 'blocking', 'data_with_error', 'terminal_type', 'window_size',
				 'callback', 'forcebaud', 'atomic_connect', 'non_recognized_login', 'generic_login');
		%args = parseMethodArgs($pkgsub, \@_, \@validArgs);
	}

	# Initialize the base POLL structure
	$self->poll_struct( # $methodName, $codeRef, $blocking, $timeout, $errmode, $outputType, $outputRequested, $returnReference, $returnList
				$pkgsub,
				__PACKAGE__->can('connect_poll'),

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

		username		=>	$args{username},
		password		=>	$args{password},
		publickey		=>	$args{publickey},
		privatekey		=>	$args{privatekey},
		passphrase		=>	$args{passphrase},
		baudrate		=>	$args{baudrate},
		parity			=>	$args{parity},
		databits		=>	$args{databits},
		stopbits		=>	$args{stopbits},
		handshake		=>	$args{handshake},
		prompt_credentials	=>	defined $args{prompt_credentials} ? $args{prompt_credentials} : $self->{prompt_credentials},
		terminal_type		=>	$args{terminal_type},
		window_size		=>	$args{window_size},
		callback		=>	$args{callback},
		forcebaud		=>	$args{forcebaud},
		atomic_connect		=>	$args{atomic_connect},
		login_timeout		=>	defined $args{timeout} ? $args{timeout} : $self->{timeout},
		read_attempts		=>	defined $args{read_attempts} ? $args{read_attempts} : $LoginReadAttempts,
		data_with_error		=>	defined $args{data_with_error} ? $args{data_with_error} : $self->{data_with_error},
		wake_console		=>	defined $args{wake_console} ? $args{wake_console} : $self->{$Package}{wake_console},
		non_recognized_login	=>	defined $args{non_recognized_login} ? $args{non_recognized_login} : $NonRecognizedLogin,

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

sub disconnect { # Perform check on restoring buadrate on device before doing Control::CLI's disconnect
	my $self = shift;
	$self->_restoreDeviceBaudrate if $self->connection_type eq 'SERIAL';
	return $self->SUPER::disconnect(@_);
}


sub login { # Handles steps necessary to get to CLI session, including menu, banner and Telnet/Serial login
	my $pkgsub = "${Package}::login";
	my $self =shift;
	my @validArgs = ('username', 'password', 'prompt_credentials', 'timeout', 'errmode', 'return_reference',
			 'read_attempts', 'wake_console', 'blocking', 'data_with_error', 'non_recognized_login', 'generic_login');
	my %args = parseMethodArgs($pkgsub, \@_, \@validArgs);

	# Initialize the base POLL structure
	$self->poll_struct( # $methodName, $codeRef, $blocking, $timeout, $errmode, $outputType, $outputRequested, $returnReference, $returnList
				$pkgsub,
				__PACKAGE__->can('login_poll'),
				defined $args{blocking} ? $args{blocking} : $self->{blocking},
				defined $args{timeout} ? $args{timeout} : $self->{timeout},
				defined $args{errmode} ? parse_errmode($pkgsub, $args{errmode}) : undef,
				1,
				wantarray,
				defined $args{return_reference} ? $args{return_reference} : $self->{return_reference},
				undef,	# n/a
			);
	$self->{POLL}{$pkgsub} = { # Populate structure with method arguments/storage
		# Set method argument keys
		username		=>	$args{username},
		password		=>	$args{password},
		prompt_credentials	=>	defined $args{prompt_credentials} ? $args{prompt_credentials} : $self->{prompt_credentials},
		read_attempts		=>	defined $args{read_attempts} ? $args{read_attempts} : $LoginReadAttempts,
		data_with_error		=>	defined $args{data_with_error} ? $args{data_with_error} : $self->{data_with_error},
		wake_console		=>	defined $args{wake_console} ? $args{wake_console} : $self->{$Package}{wake_console},
		non_recognized_login	=>	defined $args{non_recognized_login} ? $args{non_recognized_login} : $NonRecognizedLogin,
		generic_login		=>	defined $args{generic_login} ? $args{generic_login} : $GenericLogin,
		# Declare method storage keys which will be used
		stage			=>	0,
		login_attempted		=>	undef,
		password_sent		=>	undef,
		login_error		=>	'',

lib/Control/CLI/Extreme.pm  view on Meta::CPAN



sub enable { # Enter PrivExec mode (handle enable password for WLAN2300)
	my $pkgsub = "${Package}::enable";
	my $self = shift;
	my %args;
	if (@_ == 1) { # Method invoked with just the command argument
		$args{password} = shift;
	}
	else {
		my @validArgs = ('password', 'prompt_credentials', 'timeout', 'errmode', 'blocking');
		%args = parseMethodArgs($pkgsub, \@_, \@validArgs);
	}

	# Initialize the base POLL structure
	$self->poll_struct( # $methodName, $codeRef, $blocking, $timeout, $errmode, $outputType, $outputRequested, $returnReference, $returnList
				$pkgsub,
				__PACKAGE__->can('enable_poll'),
				defined $args{blocking} ? $args{blocking} : $self->{blocking},
				defined $args{timeout} ? $args{timeout} : $self->{timeout},
				defined $args{errmode} ? parse_errmode($pkgsub, $args{errmode}) : undef,
				0,	# no output
				0,	# no output
				undef,	# n/a
				undef,	# n/a
			);
	$self->{POLL}{$pkgsub} = { # Populate structure with method arguments/storage
		# Set method argument keys
		enable_password		=>	defined $args{password} ? $args{password} : $self->{$Package}{ENABLEPWD},
		prompt_credentials	=>	defined $args{prompt_credentials} ? $args{prompt_credentials} : $self->{prompt_credentials},
		# Declare method storage keys which will be used
		stage			=>	0,
		login_attempted		=>	undef,
		password_sent		=>	undef,
		login_failed		=>	undef,
	};
	local $self->{POLLING} = 1; # True until we come out of this polling-capable method
	local $self->{errmode} = $self->{POLL}{errmode} if defined $self->{POLL}{errmode};
	return __PACKAGE__->can('poll_enable')->($self, $pkgsub); # Do not call a sub-classed version
}

lib/Control/CLI/Extreme.pm  view on Meta::CPAN


	# We get here only if we are not complete: $self->{POLL}{complete} == 0
	return __PACKAGE__->can('poll_device_more_paging')->($self, $pkgsub); # Do not call a sub-classed version
}


sub device_peer_cpu { # Connect to peer CPU on ERS8x00 / VSP9000
	my $pkgsub = "${Package}::device_peer_cpu";
	my $self = shift;
	my $familyType;
	my @validArgs = ('username', 'password', 'prompt_credentials', 'timeout', 'errmode', 'blocking');
	my %args = parseMethodArgs($pkgsub, \@_, \@validArgs);

	# Initialize the base POLL structure
	$self->poll_struct( # $methodName, $codeRef, $blocking, $timeout, $errmode, $outputType, $outputRequested, $returnReference, $returnList
				$pkgsub,
				__PACKAGE__->can('device_peer_cpu_poll'),
				defined $args{blocking} ? $args{blocking} : $self->{blocking},
				defined $args{timeout} ? $args{timeout} : $self->{timeout},
				defined $args{errmode} ? parse_errmode($pkgsub, $args{errmode}) : undef,
				0,	# no output
				0,	# no output
				undef,	# n/a
				undef,	# n/a
			);
	$self->{POLL}{$pkgsub} = { # Populate structure with method arguments/storage
		# Set method argument keys
		username		=>	defined $args{username} ? $args{username} : $self->username,
		password		=>	defined $args{password} ? $args{password} : $self->password,
		prompt_credentials	=>	defined $args{prompt_credentials} ? $args{prompt_credentials} : $self->{prompt_credentials},
		# Declare method storage keys which will be used
		stage			=>	0,
	};
	local $self->{POLLING} = 1; # True until we come out of this polling-capable method
	local $self->{errmode} = $self->{POLL}{errmode} if defined $self->{POLL}{errmode};
	return __PACKAGE__->can('poll_device_peer_cpu')->($self, $pkgsub); # Do not call a sub-classed version
}


sub device_peer_cpu_poll { # Poll status of device_peer_cpu (non-blocking mode)

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

		open($fh, '>', "$logfile") or return $self->error("$pkgsub: Unable to open output log file: $!");
	}
	$fh->autoflush();
	$self->{$Package}{DEBUGLOGFH} = $fh;
	return $fh;
}


#################################### Methods to set/read Object variables ####################################

sub flush_credentials { # Clear the stored username, password, passphrases, and enable password, if any
	my $self = shift;
	$self->SUPER::flush_credentials;
	$self->{$Package}{ENABLEPWD} = undef;
	return 1;
}


sub prompt { # Read/Set object prompt
	my ($self, $newSetting) = @_;
	my $currentSetting = $self->{$Package}{prompt};
	if (defined $newSetting) {
		$self->debugMsg(4, "\nPrompt Regex set to:\n$newSetting\n");

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

	my $pkgsub = shift;
	my $pollsub = "${Package}::connect";

	unless ($self->{POLLING}) { # Sanity check
		my (undef, $fileName, $lineNumber) = caller;
		croak "$pollsub (called from $fileName line $lineNumber) can only be used within polled methods";
	}

	unless (defined $self->{POLL}{$pollsub}) { # Only applicable if called from another method already in polling mode
		my @validArgs = ('host', 'port', 'username', 'password', 'publickey', 'privatekey', 'passphrase',
				 'prompt_credentials', 'baudrate', 'parity', 'databits', 'stopbits', 'handshake',
				 'errmode', 'connection_timeout', 'login_timeout', 'read_attempts', 'wake_console',
				 'data_with_error', 'terminal_type', 'window_size', 'callback', 'forcebaud',
				 'atomic_connect', 'non_recognized_login', 'generic_login');
		my %args = parseMethodArgs($pkgsub, \@_, \@validArgs, 1);
		if (@_ && !%args) { # Legacy syntax
			($args{host}, $args{port}, $args{username}, $args{password}, $args{publickey}, $args{privatekey},
			 $args{passphrase}, $args{baudrate}, $args{parity}, $args{databits}, $args{stopbits},
			 $args{handshake}, $args{prompt_credentials}, $args{read_attempts}, $args{wake_console},
			 $args{connection_timeout}, $args{login_timeout}, $args{errmode}) = @_;
		}
		# In which case we need to setup the poll structure for them here (the main poll structure remains unchanged)
		$self->{POLL}{$pollsub} = { # Populate structure with method arguments/storage
			# Set method argument keys
			host			=>	$args{host},
			port			=>	$args{port},
			username		=>	defined $args{username} ? $args{username} : $self->{USERNAME},
			password		=>	defined $args{password} ? $args{password} : $self->{PASSWORD},
			publickey		=>	$args{publickey},
			privatekey		=>	$args{privatekey},
			passphrase		=>	defined $args{passphrase} ? $args{passphrase} : $self->{PASSPHRASE},
			baudrate		=>	$args{baudrate},
			parity			=>	$args{parity},
			databits		=>	$args{databits},
			stopbits		=>	$args{stopbits},
			handshake		=>	$args{handshake},
			prompt_credentials	=>	defined $args{prompt_credentials} ? $args{prompt_credentials} : $self->{prompt_credentials},
			terminal_type		=>	$args{terminal_type},
			window_size		=>	$args{window_size},
			callback		=>	$args{callback},
			forcebaud		=>	$args{forcebaud},
			atomic_connect		=>	$args{atomic_connect},
			login_timeout		=>	defined $args{login_timeout} ? $args{login_timeout} : $self->{timeout},
			read_attempts		=>	defined $args{read_attempts} ? $args{read_attempts} : $LoginReadAttempts,
			data_with_error		=>	defined $args{data_with_error} ? $args{data_with_error} : $self->{data_with_error},
			wake_console		=>	defined $args{wake_console} ? $args{wake_console} : $self->{$Package}{wake_console},
			non_recognized_login	=>	defined $args{non_recognized_login} ? $args{non_recognized_login} : $NonRecognizedLogin,

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

			Password		=> $connect->{password},
			PublicKey		=> $connect->{publickey},
			PrivateKey		=> $connect->{privatekey},
			Passphrase		=> $connect->{passphrase},
			BaudRate		=> $connect->{baudrate},
			ForceBaud		=> $connect->{forcebaud},
			Parity			=> $connect->{parity},
			DataBits		=> $connect->{databits},
			StopBits		=> $connect->{stopbits},
			Handshake		=> $connect->{handshake},
			Prompt_credentials	=> $connect->{prompt_credentials},
			Terminal_type		=> $connect->{terminal_type},
			Window_size		=> $connect->{window_size},
			Callback		=> $connect->{callback},
			Atomic_connect		=> $connect->{atomic_connect},
		);
		return $self->poll_return($ok) unless $ok; # Come out if error (if errmode='return'), or if nothing to read in non-blocking mode
		# Unless console already set, set it now; will determine whether or not wake_console is sent upon login
		$self->console(	 $self->connection_type eq 'SERIAL' ||
				($self->connection_type eq 'TELNET' && $self->port != 23) ||
				($self->connection_type eq 'SSH'    && $self->port != 22) ) unless defined $self->console;

lib/Control/CLI/Extreme.pm  view on Meta::CPAN


	# Login stage
	my ($ok, $outRef) = $self->poll_login($pkgsub,
			Username		=> $connect->{username},
			Password		=> $connect->{password},
			Read_attempts		=> $connect->{read_attempts},
			Wake_console		=> $connect->{wake_console},
			Data_with_error		=> $connect->{data_with_error},
			Non_recognized_login	=> $connect->{non_recognized_login},
			Generic_login		=> $connect->{generic_login},
			Prompt_credentials	=> $connect->{prompt_credentials},
			Timeout			=> $connect->{login_timeout},
	);
	$self->{POLL}{output_buffer} = $$outRef if $ok;
	return $self->poll_return($ok);
}


sub poll_login { # Method to handle login for poll methods (used for both blocking & non-blocking modes)
	my $self = shift;
	my $pkgsub = shift;
	my $pollsub = "${Package}::login";

	unless ($self->{POLLING}) { # Sanity check
		my (undef, $fileName, $lineNumber) = caller;
		croak "$pollsub (called from $fileName line $lineNumber) can only be used within polled methods";
	}

	unless (defined $self->{POLL}{$pollsub}) { # Only applicable if called from another method already in polling mode
		my @validArgs = ('username', 'password', 'prompt_credentials', 'timeout', 'errmode', 'read_attempts', 'wake_console',
				 'data_with_error', 'non_recognized_login', 'generic_login');
		my %args = parseMethodArgs($pkgsub, \@_, \@validArgs, 1);
		if (@_ && !%args) { # Legacy syntax
			($args{username}, $args{password}, $args{read_attempts}, $args{wake_console},
			 $args{prompt_credentials}, $args{data_with_error}, $args{timeout}, $args{errmode}) = @_;
		}
		# In which case we need to setup the poll structure for them here (the main poll structure remains unchanged)
		$self->{POLL}{$pollsub} = { # Populate structure with method arguments/storage
			# Set method argument keys
			username		=>	defined $args{username} ? $args{username} : $self->{USERNAME},
			password		=>	defined $args{password} ? $args{password} : $self->{PASSWORD},
			prompt_credentials	=>	defined $args{prompt_credentials} ? $args{prompt_credentials} : $self->{prompt_credentials},
			read_attempts		=>	defined $args{read_attempts} ? $args{read_attempts} : $LoginReadAttempts,
			data_with_error		=>	defined $args{data_with_error} ? $args{data_with_error} : $self->{data_with_error},
			wake_console		=>	defined $args{wake_console} ? $args{wake_console} : $self->{$Package}{wake_console},
			non_recognized_login	=>	defined $args{non_recognized_login} ? $args{non_recognized_login} : $NonRecognizedLogin,
			generic_login		=>	defined $args{generic_login} ? $args{generic_login} : $GenericLogin,
			# Declare method storage keys which will be used
			stage			=>	0,
			login_attempted		=>	undef,
			password_sent		=>	undef,
			login_error		=>	'',

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

				$self->debugMsg(8,"\nlogin() Processing Login/Username prompt\n\n");
				if ($login->{login_attempted}) {
					$self->{LOGINSTAGE} = 'username';
					return $self->poll_return($self->error("$pkgsub: Incorrect Username or Password"));
				}
				unless ($login->{username}) {
					if ($self->{TYPE} eq 'SSH') { # If an SSH connection, we already have the username
						$login->{username} = $self->{USERNAME};
					}
					else {
						unless ($login->{prompt_credentials}) {
							$self->{LOGINSTAGE} = 'username';
							return $self->poll_return($self->error("$pkgsub: Username required"));
						}
						$login->{username} = promptCredential($login->{prompt_credentials}, 'Clear', 'Username');
					}
				}
				$self->print(line => $login->{username}, errmode => 'return')
					or return $self->poll_return($self->error("$pkgsub: Unable to send username // ".$self->errmsg));
				$self->{LOGINSTAGE} = '';
				$login->{login_attempted} = 1;
				next;
			}
			elsif ($pattern eq 'password') { # Handle password prompt
				$self->debugMsg(8,"\nlogin() Processing Password prompt\n\n");
				if ($login->{password_sent}) {
					$self->{LOGINSTAGE} = 'password';
					return $self->poll_return($self->error("$pkgsub: Incorrect Username or Password"));
				}
				unless (defined $login->{password}) {
					unless ($login->{prompt_credentials}) {
						$self->{LOGINSTAGE} = 'password';
						return $self->poll_return($self->error("$pkgsub: Password required"));
					}
					$login->{password} = promptCredential($login->{prompt_credentials}, 'Hide', 'Password');
				}
				$self->print(line => $login->{password}, errmode => 'return')
					or return $self->poll_return($self->error("$pkgsub: Unable to send password // ".$self->errmsg));
				$self->{LOGINSTAGE} = '';
				$login->{password_sent} = 1;
				next;
			}
			elsif ($pattern =~ /^localfail/) { # Login failure
				return $self->poll_return($self->error("$pkgsub: Incorrect Username or Password"));
			}

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

		$login->{stage} += 2; # Move to final section
	}
	if ($login->{stage} < 4) { # Generic_login OR family type was detected, not just from the prompt (though we do rely on prompt alone for Standby CPUs on PassportERS)
		if ($login->{family_type} eq $Prm{pers} || $login->{family_type} eq $Prm{xlr}) {
			$self->_setAttrib('is_master_cpu', $self->{LASTPROMPT} =~ /^@/ ? 0 : 1);
			$self->_setAttrib('is_dual_cpu', 1) if $self->{LASTPROMPT} =~ /^@/;
		}
		$self->_setFamilyTypeAttrib($login->{family_type}) if $login->{detectionFromPrompt};
	}

	# Store credentials if these were used
	($self->{USERNAME}, $self->{PASSWORD}) = ($login->{username}, $login->{password}) if $login->{login_attempted};
	return $self->poll_return(1);
}


sub poll_cmd { # Method to handle cmd for poll methods (used for both blocking & non-blocking modes)
	my $self = shift;
	my $pkgsub = shift;
	my $pollsub = "${Package}::cmd";

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

	my $self = shift;
	my $pkgsub = shift;
	my $pollsub = "${Package}::enable";

	unless ($self->{POLLING}) { # Sanity check
		my (undef, $fileName, $lineNumber) = caller;
		croak "$pollsub (called from $fileName line $lineNumber) can only be used within polled methods";
	}

	unless (defined $self->{POLL}{$pollsub}) { # Only applicable if called from another method already in polling mode
		my @validArgs = ('password', 'prompt_credentials', 'timeout', 'errmode');
		my %args = parseMethodArgs($pkgsub, \@_, \@validArgs, 1);
		if (@_ && !%args) { # Legacy syntax
			($args{password}, $args{prompt_credentials}, $args{timeout}, $args{errmode}) = @_;
		}
		# In which case we need to setup the poll structure for them here (the main poll structure remains unchanged)
		$self->{POLL}{$pollsub} = { # Populate structure with method arguments/storage
			# Set method argument keys
			enable_password		=>	defined $args{password} ? $args{password} : $self->{$Package}{ENABLEPWD},
			prompt_credentials	=>	defined $args{prompt_credentials} ? $args{prompt_credentials} : $self->{prompt_credentials},
			# Declare method storage keys which will be used
			stage			=>	0,
			login_attempted		=>	undef,
			login_failed		=>	undef,
			# Declare keys to be set if method called from another polled method
			errmode			=>	$args{errmode},
		};
		# Cache poll structure keys which this method will use
		$self->poll_struct_cache($pollsub, $args{timeout});
	}

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

					$self->print(errmode => 'return')
						or return $self->poll_return($self->error("$pkgsub: Unable to send blank password // ".$self->errmsg));
				}
				elsif ($enable->{login_attempted} == 2) {	# Second try; use cached login password
					$enablePwd = $self->password || '';
					$self->debugMsg(4,"enable() Sending login password for enable password\n");
					$self->print(line => $enablePwd, errmode => 'return')
						or return $self->poll_return($self->error("$pkgsub: Unable to send cached password // ".$self->errmsg));
				}
				else {				# Third try; prompt?
					if ($enable->{prompt_credentials}) {
						$enablePwd = promptCredential($enable->{prompt_credentials}, 'Hide', 'Enable Password');
						$self->print(line => $enablePwd, errmode => 'return')
							or return $self->poll_return($self->error("$pkgsub: Unable to send enable password // ".$self->errmsg));
					}
					else {			# Enter blanks
						$enablePwd = '';
						$self->debugMsg(4,"enable() Sending carriage return instead of prompting for password\n");
						$self->print(errmode => 'return')
							or return $self->poll_return($self->error("$pkgsub: Unable to send blank password // ".$self->errmsg));
					}
				}

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

	my $self = shift;
	my $pkgsub = shift;
	my $pollsub = "${Package}::device_peer_cpu";

	unless ($self->{POLLING}) { # Sanity check
		my (undef, $fileName, $lineNumber) = caller;
		croak "$pollsub (called from $fileName line $lineNumber) can only be used within polled methods";
	}

	unless (defined $self->{POLL}{$pollsub}) { # Only applicable if called from another method already in polling mode
		my @validArgs = ('username', 'password', 'prompt_credentials', 'timeout', 'errmode');
		my %args = parseMethodArgs($pkgsub, \@_, \@validArgs, 1);
		if (@_ && !%args) { # Legacy syntax
			($args{username}, $args{password}, $args{prompt_credentials}, $args{timeout}, $args{errmode}) = @_;
		}
		# In which case we need to setup the poll structure for them here (the main poll structure remains unchanged)
		$self->{POLL}{$pollsub} = { # Populate structure with method arguments/storage
			# Set method argument keys
			username		=>	defined $args{username} ? $args{username} : $self->username,
			password		=>	defined $args{password} ? $args{password} : $self->password,
			prompt_credentials	=>	defined $args{prompt_credentials} ? $args{prompt_credentials} : $self->{prompt_credentials},
			# Declare method storage keys which will be used
			stage			=>	0,
			# Declare keys to be set if method called from another polled method
			errmode			=>	$args{errmode},
		};
		# Cache poll structure keys which this method will use
		$self->poll_struct_cache($pollsub, $args{timeout});
	}
	my $devPeerCpu = $self->{POLL}{$pollsub};
	local $self->{errmode} = $devPeerCpu->{errmode} if defined $devPeerCpu->{errmode};
	return $self->poll_return($self->error("$pkgsub: No connection established")) if $self->eof;
	my $familyType = $self->{$Package}{ATTRIB}{'family_type'} || '';

	if ($devPeerCpu->{stage} < 1) { # 1st stage
		unless ($familyType) {
			return $self->poll_return($self->error("$pkgsub: Attribute family_type not set"));
		}
		unless ($familyType eq $Prm{pers}) {
			return $self->poll_return($self->error("$pkgsub: No peer CPU on family_type $familyType"));
		}
		unless (($devPeerCpu->{username} && $devPeerCpu->{password}) || $devPeerCpu->{prompt_credentials}) {
			return $self->poll_return($self->error("$pkgsub: Username & password required"));
		}
		$devPeerCpu->{stage}++; # Move to 2nd stage
	}

	if ($devPeerCpu->{stage} < 2) { # 2nd stage
		my $ok = $self->poll_enable($pkgsub); # If in nncli mode, need to be in PrivExec
		return $self->poll_return($ok) unless $ok;

		$self->print(line => 'peer telnet', errmode => 'return')
			or return $self->poll_return($self->error("$pkgsub: Unable to send peer telnet command // ".$self->errmsg));
		$devPeerCpu->{stage}++; # Move to 3rd stage
	}

	if ($devPeerCpu->{stage} < 3) { # 3rd stage
		my $ok = $self->poll_waitfor($pkgsub, 'Login: $', undef, 'return');
		return $self->poll_return($self->error("$pkgsub: Never got peer login prompt // ".$self->errmsg)) unless defined $ok;
		return $self->poll_return($ok) unless $ok;

		$devPeerCpu->{username} = promptCredential($devPeerCpu->{prompt_credentials}, 'Clear', 'Username') unless defined $devPeerCpu->{username};
		$self->print(line => $devPeerCpu->{username}, errmode => 'return')
			or return $self->poll_return($self->error("$pkgsub: Unable to send username // ".$self->errmsg));
		$devPeerCpu->{stage}++; # Move to 4th stage
	}

	if ($devPeerCpu->{stage} < 4) { # 4th stage
		my $ok = $self->poll_waitfor($pkgsub, 'Password: $', undef, 'return');
		return $self->poll_return($self->error("$pkgsub: Never got peer password prompt // ".$self->errmsg)) unless defined $ok;
		return $self->poll_return($ok) unless $ok;

		$devPeerCpu->{password} = promptCredential($devPeerCpu->{prompt_credentials}, 'Hide', 'Password') unless defined $devPeerCpu->{password};
		$self->print(line => $devPeerCpu->{password}, errmode => 'return')
			or return $self->poll_return($self->error("$pkgsub: Unable to send password // ".$self->errmsg));
		$devPeerCpu->{stage}++; # Move to last stage
	}

	# Use cmd() to expect a new prompt now
	my $ok = $self->poll_cmd($pkgsub, More_pages => 0, Reset_prompt => 1);
	return $self->poll_return($ok) unless $ok;

	$self->{LASTPROMPT} =~ /$InitPrompt{$self->{$Package}{PROMPTTYPE}}/;

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

  	[Errmode		 => $errmode,]
  	[Errmsg_format		 => $msgFormat,]
  	[Return_reference	 => $flag,]
  	[Prompt			 => $prompt,]
  	[Username_prompt	 => $usernamePrompt,]
  	[Password_prompt	 => $passwordPrompt,]
  	[Input_log		 => $fhOrFilename,]
  	[Output_log		 => $fhOrFilename,]
  	[Dump_log		 => $fhOrFilename,]
  	[Blocking		 => $flag,]
  	[Prompt_credentials	 => $flag,]
  	[Read_attempts		 => $numberOfReadAttemps,]
  	[Readwait_timer		 => $millisecs,]
  	[Data_with_error	 => $flag,]
  	[Read_block_size	 => $bytes,]
  	[Output_record_separator => $ors,]
  	[Terminal_type		 => $string,]
  	[Window_size		 => [$width, $height],]
  	[Report_query_status	 => $flag,]
  	[Debug			 => $debugFlag,]

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

  ($ok, $output || $outputRef) = $obj->connect("$host[ $port]");

  $ok = $obj->connect(
  	[Host			=> $host,]
  	[Port			=> $port,]
  	[Username		=> $username,]
  	[Password		=> $password,]
  	[PublicKey		=> $publicKey,]
  	[PrivateKey		=> $privateKey,]
  	[Passphrase		=> $passphrase,]
  	[Prompt_credentials	=> $flag,]
  	[BaudRate		=> $baudRate,]
  	[ForceBaud		=> $flag,]
  	[Parity			=> $parity,]
  	[DataBits		=> $dataBits,]
  	[StopBits		=> $stopBits,]
  	[Handshake		=> $handshake,]
  	[Timeout		=> $secs,]
  	[Connection_timeout	=> $secs,]
  	[Read_attempts		=> $numberOfLoginReadAttemps,]
  	[Data_with_error	=> $flag,]

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

  );

  ($ok, $output || $outputRef) = $obj->connect(
  	[Host			=> $host,]
  	[Port			=> $port,]
  	[Username		=> $username,]
  	[Password		=> $password,]
  	[PublicKey		=> $publicKey,]
  	[PrivateKey		=> $privateKey,]
  	[Passphrase		=> $passphrase,]
  	[Prompt_credentials	=> $flag,]
  	[BaudRate		=> $baudRate,]
  	[ForceBaud		=> $flag,]
  	[Parity			=> $parity,]
  	[DataBits		=> $dataBits,]
  	[StopBits		=> $stopBits,]
  	[Handshake		=> $handshake,]
  	[Timeout		=> $secs,]
  	[Connection_timeout	=> $secs,]
  	[Return_reference	=> $flag,]
  	[Read_attempts		=> $numberOfLoginReadAttemps,]

lib/Control/CLI/Extreme.pm  view on Meta::CPAN


This method connects to the host device. The connection will use either Telnet, SSH or Serial port, depending on how the object was created with the new() constructor.
On success a true (1) value is returned. On time-out or other connection failures the error mode action is performed. See errmode().
In the first & third forms only a success/failure value is returned in scalar context, while in the second & fourth forms, in list context, both the success/failure value is returned as well as any output received from the host device during the conn...

This method overrides Control::CLI::connect() and calls both the Control::CLI::connect() method as well as the login() method from this class. This allows the connect() method to seamlessly handle connection and login for both SSH (which normally han...

In non-blocking mode (blocking disabled) the connect() method will immediately return with a false, but defined, value of 0. You will then need to call the connect_poll() method at regular intervals until it returns a true (1) value indicating that t...

The "host" argument is required by both Telnet and SSH. All the other arguments are optional.
If username/password or SSH Passphrase are not provided but are required and prompt_credentials is true, the method will automatically prompt the user for them; otherwise the error mode action is performed. The "errmode" argument is provided to overr...
The "prompt_credentials" argument is provided to override the global setting of the parameter by the same name which is by default false. See prompt_credentials().
The "read_attempts" argument is simply fed to the login() method. See login().
The "connection_timeout" argument can be used to set a connection timeout when establishing Telnet and SSH TCP connections; this is fed to Control::CLI::connect(). Whereas the "timeout" argument is the normal timeout used for reading the connection o...
The "terminal_type" and "window_size" arguments are Control::CLI arguments and are not overrides, they will change the object parameter as these settings are only applied during a connection. It is not necessary to set these for Extreme devices.
Which other arguments are used depends on the whether the object was created for Telnet, SSH or Serial port. 

=over 4

=item *

For Telnet, these arguments are used:

  $ok = $obj->connect("$host[ $port]");

  $ok = $obj->connect(
  	Host			=> $host,
  	[Port			=> $port,]
  	[Username		=> $username,]
  	[Password		=> $password,]
  	[Prompt_credentials	=> $flag,]
  	[Timeout		=> $secs,]
  	[Connection_timeout	=> $secs,]
  	[Read_attempts		=> $numberOfLoginReadAttemps,]
  	[Data_with_error	=> $flag,]
  	[Wake_console		=> $string,]
  	[Blocking               => $flag,]
  	[Errmode		=> $errmode,]
  	[Terminal_type		=> $string,]
  	[Window_size		=> [$width, $height],]
  	[Atomic_connect		=> $flag,]

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

  $ok = $obj->connect("$host[ $port]");

  $ok = $obj->connect(
  	Host			=> $host,
  	[Port			=> $port,]
  	[Username		=> $username,]
  	[Password		=> $password,]
  	[PublicKey		=> $publicKey,]
  	[PrivateKey		=> $privateKey,]
  	[Passphrase		=> $passphrase,]
  	[Prompt_credentials	=> $flag,]
  	[Timeout		=> $secs,]
  	[Connection_timeout	=> $secs,]
  	[Read_attempts		=> $numberOfLoginReadAttemps,]
  	[Data_with_error	=> $flag,]
  	[Wake_console		=> $string,]
  	[Blocking               => $flag,]
  	[Errmode		=> $errmode,]
  	[Terminal_type		=> $string,]
  	[Window_size		=> [$width, $height],]
  	[Callback		=> \&codeRef,]
  	[Atomic_connect		=> $flag,]
  	[Non_recognized_login	=> $flag,]
  	[Generic_login		=> $flag,]
  );

If not specified, the default port number for SSH is 22. The wake_console argument is only relevant when connecting to a SSH port other than 22 (i.e. to a Terminal Server device) or if console() has been manually set; see console(). In which case, th...

A username must always be provided for all SSH connections. If not provided and prompt_credentials is true then this method will prompt for it.
Once the SSH conection is established, this method will attempt one of two possible authentication types, based on the accepted authentications of the remote host:

=over 4

=item *

B<Publickey authentication> : If the remote host accepts it and the method was supplied with public/private keys. The public/private keys need to be in OpenSSH format. If the private key is protected by a passphrase then this must also be provided or...

=item *

B<Password authentication> : If the remote host accepts either 'password' or 'keyboard-interactive' authentication methods. A password must be provided or, if prompt_credentials is true, this method will prompt for the password. If password authentic...

=back


=item *

For Serial port, these arguments are used:

  $ok = $obj->connect(
  	[BaudRate		=> $baudRate,]
  	[ForceBaud		=> $flag,]
  	[Parity			=> $parity,]
  	[DataBits		=> $dataBits,]
  	[StopBits		=> $stopBits,]
  	[Handshake		=> $handshake,]
  	[Username		=> $username,]
  	[Password		=> $password,]
  	[Prompt_credentials	=> $flag,]
  	[Timeout		=> $secs,]
  	[Read_attempts		=> $numberOfLoginReadAttemps,]
  	[Data_with_error	=> $flag,]
  	[Wake_console		=> $string,]
  	[Blocking		=> $flag,]
  	[Errmode		=> $errmode,]
  	[Non_recognized_login	=> $flag,]
  	[Generic_login		=> $flag,]
  );

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

		$ok = $obj->connect_poll;
		die $obj->errmsg unless defined $ok;	# Error or timeout connecting
	}


=item B<login() & login_poll()> - handle login for Telnet / Serial port; also set the host CLI prompt

  $ok = $obj->login(
  	[Username		=> $username,]
  	[Password		=> $password,]
  	[Prompt_credentials	=> $flag,]
  	[Timeout		=> $secs,]
  	[Read_attempts		=> $numberOfLoginReadAttemps,]
  	[Data_with_error	=> $flag,]
  	[Wake_console		=> $string,]
  	[Blocking		=> $flag,]
  	[Errmode		=> $errmode,]
  	[Non_recognized_login	=> $flag,]
  	[Generic_login		=> $flag,]
  );

  ($ok, $output || $outputRef) = $obj->login(
  	[Username		=> $username,]
  	[Password		=> $password,]
  	[Prompt_credentials	=> $flag,]
  	[Timeout		=> $secs,]
  	[Return_reference	=> $flag,]
  	[Read_attempts		=> $numberOfLoginReadAttemps,]
  	[Data_with_error	=> $flag,]
  	[Wake_console		=> $string,]
  	[Blocking		=> $flag,]
  	[Errmode		=> $errmode,]
  	[Non_recognized_login	=> $flag,]
  	[Generic_login		=> $flag,]
  );

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

	}
	print "New baudrate = ", $baudrate, "\n";


=item B<enable() & enable_poll()> - Enter PrivExec mode

  $ok = $obj->enable($enablePassword);

  $ok = $obj->enable(
  	[Password		=> $enablePassword,]
  	[Prompt_credentials	=> $flag,]
  	[Blocking		=> $flag,]
  	[Timeout		=> $secs,]
  	[Errmode		=> $errmode,]
  );

  $ok = $obj->enable_poll();	# Only applicable in non-blocking mode

This method checks whether the 'is_acli' attribute is set and, if so, whether the last prompt ends with '>'; if both conditions are true, it will flush any unread pending input from the device and will just send an 'enable' command to enter Priviledg...
The method can take a password argument which only applies to the WLAN2300 series and in some older software versions of the ERS-8300 in NNCLI mode.
If a password is required, but not supplied, this method will try supplying first a blank password, then the same password which was used to connect/login and finally, if prompt_credentials is true for the object, prompt for it. On I/O failure, the e...
The optional "prompt_credentials" argument is provided to override the global setting of the parameter by the same name which is by default false. See prompt_credentials().

In non-blocking mode (blocking disabled), the enable() method will most likely immediately return with a false, but defined, value of 0. You will then need to call the enable_poll() method at regular intervals until it returns a true (1) value indica...

	$ok = $obj->enable(Blocking => 0);
	until ($ok) {
		
		<do other stuff here..>
	
		$ok = $obj->enable_poll;
	}

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

	
		$ok = $obj->device_more_paging_poll;
	}


=item B<device_peer_cpu() & device_peer_cpu_poll()> - Connect to peer CPU on ERS8x00 / VSP9000

  $ok = $obj->device_peer_cpu(
  	[Username		=> $username,]
  	[Password		=> $password,]
  	[Prompt_credentials	=> $flag,]
  	[Blocking		=> $flag,]
  	[Timeout		=> $secs,]
  	[Errmode		=> $errmode,]
  );

  $ok = $obj->device_peer_cpu_poll();	# Only applicable in non-blocking mode

This method, only applicable on ERS8x00 and VSP9000, will try to connect to the peer CPU. On success a true (1) value is returned otherwise the error mode action is performed. See errmode().
It should not normally be necessary to provide username/password since the credentials used to connect to the current CPU will automatically be used. If not so, or to override the cached ones, optional "username" & "password" arguments can be provide...
Attributes 'cpu_slot' and 'is_master_cpu' are automatically updated once the connection to the peer CPU succeeds. See attribute().

In non-blocking mode (blocking disabled), the device_peer_cpu() method will most likely immediately return with a false, but defined, value of 0. You will then need to call the device_peer_cpu_poll() method at regular intervals until it returns a tru...

	$ok = $obj->device_peer_cpu(Blocking => 0);
	until ($ok) {
		
		<do other stuff here..>
	
		$ok = $obj->device_peer_cpu_poll;

lib/Control/CLI/Extreme.pm  view on Meta::CPAN



=back



=head2 Methods to set/read Object variables

=over 4

=item B<flush_credentials> - flush the stored username, password, passphrase and enable password credentials

  $obj->flush_credentials;

The connect(), login() and enable() methods, if successful in authenticating, will automatically store the username/password/enable-password or SSH passphrase supplied to them.
These can be retrieved via the username, password, passphrase and enable_password methods. If you do not want these to persist in memory once the authentication has completed, use this method to flush them. This method always returns 1.


=item B<prompt()> - set the CLI prompt match pattern for this object

  $string = $obj->prompt;

  $prev = $obj->prompt($string);

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

=item B<readwait_timer()> - set the polling timer used in readwait() method

=item B<data_with_error()> - set the readwait() method behaviour in case a read error occurs after some data was read

=item B<return_reference()> - set whether read methods should return a hard reference or not 

=item B<binmode()> - enable/disable newline translation

=item B<output_record_separator()> - set the Output Record Separator automatically appended by print & cmd methods (Note that unlike Control::CLI this class will default to "\r")

=item B<prompt_credentials()> - set whether connect() and login() methods should be able to prompt for credentials 

=item B<username_prompt()> - set the login() username prompt match pattern for this object

=item B<password_prompt()> - set the login() password prompt match pattern for this object

=item B<terminal_type()> - set the terminal type for the connection

=item B<window_size()> - set the terminal window size for the connection

=item B<report_query_status()> - set if read methods should automatically respond to Query Device Status escape sequences 

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

=item B<poll_connect()> - performs a non-blocking poll for connect()

  $ok = $obj->poll_connect($pkgsub,
  	[Host                   => $host,]
  	[Port                   => $port,]
  	[Username               => $username,]
  	[Password               => $password,]
  	[PublicKey              => $publicKey,]
  	[PrivateKey             => $privateKey,]
  	[Passphrase             => $passphrase,]
  	[Prompt_credentials     => $flag,]
  	[BaudRate               => $baudRate,]
  	[Parity                 => $parity,]
  	[DataBits               => $dataBits,]
  	[StopBits               => $stopBits,]
  	[Handshake              => $handshake,]
  	[Login_Timeout          => $secs,]
  	[Connection_timeout     => $secs,]
  	[Read_attempts          => $numberOfLoginReadAttemps,]
  	[Data_with_error        => $flag,]
  	[Wake_console           => $string,]

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

  );

  ($ok, $outputref) = $obj->poll_connect($pkgsub,
  	[Host                   => $host,]
  	[Port                   => $port,]
  	[Username               => $username,]
  	[Password               => $password,]
  	[PublicKey              => $publicKey,]
  	[PrivateKey             => $privateKey,]
  	[Passphrase             => $passphrase,]
  	[Prompt_credentials     => $flag,]
  	[BaudRate               => $baudRate,]
  	[Parity                 => $parity,]
  	[DataBits               => $dataBits,]
  	[StopBits               => $stopBits,]
  	[Handshake              => $handshake,]
  	[Login_Timeout          => $secs,]
  	[Connection_timeout     => $secs,]
  	[Read_attempts          => $numberOfLoginReadAttemps,]
  	[Data_with_error        => $flag,]
  	[Wake_console           => $string,]

lib/Control/CLI/Extreme.pm  view on Meta::CPAN


Normally this is the internal method used by connect() and connect_poll() methods.
Arguments after $ok will only be defined if $ok is true(1).


=item B<poll_login()> - performs a non-blocking poll for login()

  $ok = $obj->poll_login($pkgsub,
  	[Username               => $username,]
  	[Password               => $password,]
  	[Prompt_credentials     => $flag,]
  	[Timeout                => $secs,]
  	[Read_attempts          => $numberOfLoginReadAttemps,]
  	[Data_with_error        => $flag,]
  	[Wake_console           => $string,]
  	[Errmode                => $errmode,]
  	[Non_recognized_login	=> $flag,]
  	[Generic_login		=> $flag,]
  );

  ($ok, $outputref) = $obj->poll_login($pkgsub,
  	[Username               => $username,]
  	[Password               => $password,]
  	[Prompt_credentials     => $flag,]
  	[Timeout                => $secs,]
  	[Read_attempts          => $numberOfLoginReadAttemps,]
  	[Data_with_error        => $flag,]
  	[Wake_console           => $string,]
  	[Errmode                => $errmode,]
  	[Non_recognized_login	=> $flag,]
  	[Generic_login		=> $flag,]
  );

Normally this is the internal method used by login() and login_poll() methods.

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

Normally this is the internal method used by change_baudrate() and change_baudrate_poll() methods.
Arguments after $ok will only be defined if $ok is true(1).


=item B<poll_enable()> - performs a non-blocking poll for enable()

  $ok = $obj->poll_enable($pkgsub, $password);

  $ok = $obj->poll_enable($pkgsub,
  	[Password               => $enablePassword,]
  	[Prompt_credentials     => $flag,]
  	[Timeout                => $secs,]
  	[Errmode                => $errmode,]
  );

Normally this is the internal method used by enable() and enable_poll() methods.

=item B<poll_device_more_paging()> - performs a non-blocking poll for device_more_paging()

  $ok = $obj->poll_device_more_paging($pkgsub, $flag);

lib/Control/CLI/Extreme.pm  view on Meta::CPAN

  );

Normally this is the internal method used by device_more_paging() and device_more_paging_poll() methods.


=item B<poll_device_peer_cpu()> - performs a non-blocking poll for device_peer_cpu()

  $ok = $obj->poll_device_peer_cpu($pkgsub,
  	[Username               => $username,]
  	[Password               => $password,]
  	[Prompt_credentials     => $flag,]
  	[Timeout                => $secs,]
  	[Errmode                => $errmode,]
  );

Normally this is the internal method used by device_peer_cpu() and device_peer_cpu_poll() methods.


=item B<cmdPrivExec()> - send a command requiring PrivExec mode

  ($ok, $outputref, $resultref) = $obj->cmdPrivExec($pkgsub, $cmdcli, $cmdnncli, $morePages);



( run in 0.236 second using v1.01-cache-2.11-cpan-4d50c553e7e )