-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3089 from robertcheramy/1802-fix-apc_aos
Fix FTP and prepare SCP for apc aos
- Loading branch information
Showing
8 changed files
with
199 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# APC AOS Configuration | ||
|
||
Currently, the configuration of APC Network Management Cards can be downloaded with FTP only. | ||
|
||
A download of the configuration with SCP is [work in progress](https://github.com/ytti/oxidized/issues/1802). | ||
As the APC has an unusual behavior (the connection is closed without an exit-status), this has to be | ||
[fixed](https://github.com/net-ssh/net-scp/pull/71) upstream in [Net::SCP](https://github.com/net-ssh/net-scp). | ||
As soon as there is a release of Net::SCP supporting the behavior of APC OS, we will activate SCP in oxidized. | ||
|
||
## Can I collect more information than just the configuration? | ||
APC OS does not have the ability to show the config.ini within an SSH-session. As oxidized can only get the | ||
configuration with one input type at a time, it is not possible to fetch config.ini via FTP/SCP and get the output of | ||
some commands via SSH at the same time. | ||
|
||
A ticket has been opened with APC support in order to support "cat config.ini" within an SSH-session, but | ||
the chances it will be supported at some time are not very good, and older versions will still not support it. | ||
|
||
## How do I activate FTP input? | ||
In order to download the configuration with FTP (and in the future with SCP), you have to activate it as an | ||
input in the oxidized configuration. If you do not activate the input, oxidized will fail for the node with | ||
a rather unspecific error (`WARN -- : /apc status fail, retry attempt 1`). | ||
|
||
The configuration can be done either globally or only for the model apc_aos. | ||
|
||
The global configuration would look like this. Note that Oxidized will try every input type in the given order | ||
until it succeeds, or it will report a failure. | ||
```yaml | ||
input: | ||
default: ssh, ftp, scp | ||
``` | ||
Configuration for activating the FTP input for apc_aos only: | ||
```yaml | ||
input: | ||
default: ssh | ||
models: | ||
apc_aos: | ||
input: ftp | ||
``` | ||
You can also set specific username and password for apc_aos only: | ||
```yaml | ||
username: default-user | ||
password: default-password | ||
input: | ||
default: ssh | ||
models: | ||
apc_aos: | ||
username: apc-user | ||
password: apc-password | ||
input: ftp | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module Oxidized | ||
require 'net/ssh' | ||
require 'net/scp' | ||
require 'timeout' | ||
require_relative 'cli' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
require_relative '../spec_helper' | ||
|
||
describe 'Model apc_aos' do | ||
before(:each) do | ||
Oxidized.asetus = Asetus.new | ||
Oxidized.asetus.cfg.debug = false | ||
Oxidized.setup_logger | ||
|
||
Oxidized::Node.any_instance.stubs(:resolve_repo) | ||
Oxidized::Node.any_instance.stubs(:resolve_output) | ||
end | ||
|
||
it "fetches the configuration with ftp" do | ||
@node = Oxidized::Node.new(name: 'example.com', | ||
input: 'ftp', | ||
output: 'file', | ||
model: 'apc_aos', | ||
username: 'alma', | ||
password: 'armud', | ||
prompt: 'test_prompt') | ||
Oxidized::FTP.any_instance.stubs(:connect).returns(true) | ||
Oxidized::FTP.any_instance.stubs(:node).returns(@node) | ||
Oxidized::FTP.any_instance.stubs(:connect_cli).returns(true) | ||
Oxidized::FTP.any_instance.stubs(:disconnect).returns(true) | ||
Oxidized::FTP.any_instance.stubs(:disconnect_cli).returns(true) | ||
# Make sure we only run "config.ini" an no other command | ||
Oxidized::FTP.any_instance.expects(:cmd).never | ||
Oxidized::FTP.any_instance.expects(:cmd).with("config.ini").returns(CONFIGURATION_FILE) | ||
|
||
status, result = @node.run | ||
|
||
_(status).must_equal :success | ||
_(result.to_cfg).must_equal EXPECTED_RESULT | ||
end | ||
|
||
it "fetches the configuration with scp" do | ||
skip "Work in Progress, see issue #1802" | ||
@node = Oxidized::Node.new(name: 'example.com', | ||
input: 'scp', | ||
output: 'file', | ||
model: 'apc_aos', | ||
username: 'alma', | ||
password: 'armud', | ||
prompt: 'test_prompt') | ||
Oxidized::SCP.any_instance.stubs(:connect).returns(true) | ||
Oxidized::SCP.any_instance.stubs(:node).returns(@node) | ||
Oxidized::SCP.any_instance.stubs(:connect_cli).returns(true) | ||
Oxidized::SCP.any_instance.stubs(:disconnect).returns(true) | ||
Oxidized::SCP.any_instance.stubs(:disconnect_cli).returns(true) | ||
# Make sure we only run "config.ini" an no other command | ||
Oxidized::SCP.any_instance.expects(:cmd).never | ||
Oxidized::SCP.any_instance.expects(:cmd).with("config.ini").returns(CONFIGURATION_FILE) | ||
|
||
status, result = @node.run | ||
|
||
_(status).must_equal :success | ||
_(result.to_cfg).must_equal EXPECTED_RESULT | ||
end | ||
|
||
it "does not fetch the configiguration with ssh" do | ||
@node = Oxidized::Node.new(name: 'example.com', | ||
input: 'ssh', | ||
output: 'file', | ||
model: 'apc_aos', | ||
username: 'alma', | ||
password: 'armud', | ||
prompt: 'test_prompt') | ||
|
||
status, = @node.run | ||
|
||
_(status).must_equal :fail | ||
end | ||
end | ||
|
||
# Not taking the whole configuration. | ||
# For now, the model does only mask the generation date | ||
# In the future, it may hide passwords, so I included a line with snmp comunity strings | ||
CONFIGURATION_FILE = <<~HEREDOC.freeze | ||
; Schneider Electric | ||
; Network Management Card AOS v2.5.0.8 | ||
; Smart-UPS APP v2.5.0.6 | ||
; (c) 2023 Schneider Electric. All rights reserved. | ||
; Configuration file, generated on 02/20/2024 at 09:27:23 by Administrator apc | ||
[NetworkTCP/IP] | ||
SystemIP=0.0.0.0 | ||
SubnetMask=0.0.0.0 | ||
DefaultGateway=0.0.0.0 | ||
IPv4=enabled | ||
BootMode=DHCP Only | ||
HostName=myhostname | ||
DomainName=mydomain.local | ||
; (...) | ||
[NetworkSNMP] | ||
; To change the User Profile Auth Phrase, or the | ||
; User Profile Encrypt Phrase, use the UserProfile#AuthPhrase, or | ||
; UserProfile#EncryptPhrase keywords respectively where # is | ||
; the number of the profile. i.e., UserProfile1EncryptPhrase=apc crypt passphrase | ||
Access=enabled | ||
AccessControl1Community=public | ||
AccessControl2Community=public | ||
; (...) | ||
HEREDOC | ||
|
||
EXPECTED_RESULT = <<~HEREDOC.freeze | ||
; Schneider Electric | ||
; Network Management Card AOS v2.5.0.8 | ||
; Smart-UPS APP v2.5.0.6 | ||
; (c) 2023 Schneider Electric. All rights reserved. | ||
[NetworkTCP/IP] | ||
SystemIP=0.0.0.0 | ||
SubnetMask=0.0.0.0 | ||
DefaultGateway=0.0.0.0 | ||
IPv4=enabled | ||
BootMode=DHCP Only | ||
HostName=myhostname | ||
DomainName=mydomain.local | ||
; (...) | ||
[NetworkSNMP] | ||
; To change the User Profile Auth Phrase, or the | ||
; User Profile Encrypt Phrase, use the UserProfile#AuthPhrase, or | ||
; UserProfile#EncryptPhrase keywords respectively where # is | ||
; the number of the profile. i.e., UserProfile1EncryptPhrase=apc crypt passphrase | ||
Access=enabled | ||
AccessControl1Community=public | ||
AccessControl2Community=public | ||
; (...) | ||
HEREDOC |