NAME
PDK::Device::Huawei - Module for managing Huawei devices and backing up configurations via FTP
SYNOPSIS
use PDK::Device::Huawei;
my $device = PDK::Device::Huawei->new( host => 'device_ip' );
my $config = $device->getConfig();
$device->ftpConfig( $hostname, $server, $username, $password );
DESCRIPTION
The PDK::Device::Huawei module provides functionality for interacting with Huawei devices. It includes methods for fetching configurations, running commands, and backing up the device configuration via FTP. The module extends PDK::Device::Base and uses the Expect
module for interacting with the device.
ATTRIBUTES
prompt
is => 'ro',
required => 1,
default => '^\s*[<\[].*?[>\]]\s*$',
This attribute defines the regular expression used to match the device's command prompt. It defaults to the common Huawei CLI prompt format.
METHODS
errCodes
$device->errCodes();
Returns an array reference of regular expressions representing possible error patterns that may occur during command execution.
waitfor
$device->waitfor( $prompt, $params );
Waits for a specific prompt (or uses the default prompt) and captures the output from the device. This method handles pagination (---- More ----
>) and confirmation prompts.
Parameters: - $prompt: Optional, specifies the prompt to wait for. If not provided, the default device prompt is used. - $params: Optional hash reference with the following keys: - send: Command to send - continue: Whether to continue execution (default: false) - cache: Whether to cache the output (default: true)
Returns: The captured output from the device.
runCommands
$device->runCommands( \@commands );
Executes a series of commands on the device. This method automatically ensures that configuration mode is entered, and the configuration is saved after the commands are executed.
Parameters: - \@commands: An array reference containing the list of commands to execute.
getConfig
$device->getConfig();
Fetches the current configuration of the device. This method runs commands to display the current configuration and returns the output.
Returns: A hash reference containing a success flag and the configuration content.
ftpConfig
$device->ftpConfig( $hostname, $server, $username, $password );
Backs up the current device configuration to an FTP server. This method connects to the specified FTP server, uploads the device's configuration, and returns the result.
Parameters: - $hostname: Optional, specifies a custom hostname to use in the backup filename. - $server: The FTP server address. If not provided, it is loaded from the environment variable PDK_FTP_SERVER
. - $username: The FTP username. If not provided, it is loaded from the environment variable PDK_FTP_USERNAME
. - $password: The FTP password. If not provided, it is loaded from the environment variable PDK_FTP_PASSWORD
.
Returns: A hash reference containing a success flag and the FTP operation result.
ERROR HANDLING
The module uses croak
to throw exceptions when errors occur, including:
Connection timeouts to the device or FTP server.
Failed logins or incorrect credentials.
Unexpected disconnections during command execution.
DEPENDENCIES
This module depends on the following Perl modules:
Moose
- For object-oriented programming.Expect
- For interacting with devices through terminal sessions.Carp
- For error handling withcroak
.
AUTHOR
WENWU YAN <968828@gmail.com>
LICENSE AND COPYRIGHT
Copyright (C) 2024 WENWU YAN
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.