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 );
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 (e.g., "Are you sure to continue") and returns the captured output.
$prompt
- Optional, specifies the prompt to wait for. If not provided, the default device prompt is used.
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.
\@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. The result is returned as 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.
$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 variablePDK_FTP_SERVER
.$username
- The FTP username. If not provided, it is loaded from the environment variablePDK_FTP_USERNAME
.$password
- The FTP password. If not provided, it is loaded from the environment variablePDK_FTP_PASSWORD
.
The method ensures that the FTP connection is established, uploads the configuration file, and verifies the successful completion of the transfer.
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.
RETURN VALUES
Methods typically return a hash reference with the following keys:
success
- A boolean indicating whether the method completed successfully.config
- A string containing the captured output or configuration.
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.