Compare commits

..

13 Commits

Author SHA1 Message Date
Piotr Pieprzycki a5d3b94663
Merge pull request #39 from marcushoff/get_config
Add get_config method
2020-12-17 22:31:52 +01:00
Piotr Pieprzycki 29ad1b85bd
Merge pull request #38 from marcushoff/get_facts
Update serial_number and model
2020-12-17 22:29:55 +01:00
Piotr Pieprzycki 27bc0c7623 Change version to 0.2.1 2020-12-17 22:16:09 +01:00
Piotr Pieprzycki 7fda2abd47
Merge pull request #40 from marcushoff/configure
Update file mode
2020-12-17 21:54:38 +01:00
Marcus Hoff d4e25b4e46 Update file mode
Default file mode i binary, updated to string
2020-11-16 09:27:15 +01:00
Marcus Hoff 619fc3d32c Fix expected results for sanitized
changed the return password to be hidden
2020-10-23 11:21:13 +02:00
Marcus Hoff 7e470df55e Fix expected results
Fixed wrong output and new lines in expected results and corrected the show output for test_get_config
2020-10-23 10:46:52 +02:00
Marcus Hoff 1200cf4328 Fix sanitized_test, Add str return to candidate
Change the expected results of sanitized test.
If candidate config is None return empty string
2020-10-22 18:28:34 +02:00
Marcus Hoff d970ad22c9 Fixed tests
Add missing case test_get_config_filtere
Correct names of mock files
2020-10-22 16:51:57 +02:00
Marcus Hoff 7107560f84 Add tests for get_config
Add test cases for normal and sanitized versions.
Add support for config mode in mock device.
2020-10-22 14:54:34 +02:00
Marcus Hoff 5ab6f4de21 Add get_config method
Supports all retrive options, where 'candidate' is the Napalm candidate.
Either gets the boot config as 'startup' or output from 'show' in edit mode for 'running'
Supports sanitized only for 'running'. Outputs the 'show' in op mode.
2020-10-21 16:34:52 +02:00
Marcus Hoff a205b99ca5 Update serial_number and model
Fixes my bugs
2020-10-18 15:06:58 +02:00
Marcus Hoff a4a0645f27 Update serial_number and model
Updated the match pattern of serial_number and model to the current 1.2/1.3 release of Vyos, maintained code for older versions
2020-10-18 14:22:50 +02:00
12 changed files with 805 additions and 6 deletions

View File

@ -126,7 +126,7 @@ class VyOSDriver(NetworkDriver):
raise ReplaceConfigException('filename or config param must be provided.')
if filename is None:
temp_file = tempfile.NamedTemporaryFile()
temp_file = tempfile.NamedTemporaryFile(mode='w+')
temp_file.write(config)
temp_file.flush()
cfg_filename = temp_file.name
@ -165,7 +165,7 @@ class VyOSDriver(NetworkDriver):
raise MergeConfigException('filename or config param must be provided.')
if filename is None:
temp_file = tempfile.NamedTemporaryFile()
temp_file = tempfile.NamedTemporaryFile(mode='w+')
temp_file.write(config)
temp_file.flush()
cfg_filename = temp_file.name
@ -698,10 +698,15 @@ class VyOSDriver(NetworkDriver):
ver_str = [line for line in output if "Version" in line][0]
version = self.parse_version(ver_str)
sn_str = [line for line in output if "S/N" in line][0]
snumber = self.parse_snumber(sn_str)
above_1_1 = False if version.startswith('1.0') or version.startswith('1.1') else True
if above_1_1:
sn_str = [line for line in output if "Hardware S/N" in line][0]
hwmodel_str = [line for line in output if "Hardware model" in line][0]
else:
sn_str = [line for line in output if "S/N" in line][0]
hwmodel_str = [line for line in output if "HW model" in line][0]
hwmodel_str = [line for line in output if "HW model" in line][0]
snumber = self.parse_snumber(sn_str)
hwmodel = self.parse_hwmodel(hwmodel_str)
output = self.device.send_command("show configuration")
@ -914,3 +919,42 @@ class VyOSDriver(NetworkDriver):
}
return ping_result
def get_config(self, retrieve="all", full=False, sanitized=False):
"""
Return the configuration of a device.
:param retrieve: String to determine which configuration type you want to retrieve, default is all of them.
The rest will be set to "".
:param full: Boolean to retrieve all the configuration. (Not supported)
:param sanitized: Boolean to remove secret data. (Only supported for 'running')
:return: The object returned is a dictionary with a key for each configuration store:
- running(string) - Representation of the native running configuration
- candidate(string) - Representation of the candidate configuration.
- startup(string) - Representation of the native startup configuration.
"""
if retrieve not in ["running", "candidate", "startup", "all"]:
raise Exception("ERROR: Not a valid option to retrieve.\nPlease select from 'running', 'candidate', "
"'startup', or 'all'")
else:
config_dict = {
"running": "",
"startup": "",
"candidate": ""
}
if retrieve in ["running", "all"]:
config_dict['running'] = self._get_running_config(sanitized)
if retrieve in ["startup", "all"]:
config_dict['startup'] = self.device.send_command(f"cat {self._BOOT_FILENAME}")
if retrieve in ["candidate", "all"]:
config_dict['candidate'] = self._new_config or ""
return config_dict
def _get_running_config(self, sanitized):
if sanitized:
return self.device.send_command("show configuration")
self.device.config_mode()
config = self.device.send_command("show")
config = config[:config.rfind('\n')]
self.device.exit_config_mode()
return config

View File

@ -11,7 +11,7 @@ __author__ = 'Piotr Pieprzycki <piotr.pieprzycki@dreamlab.pl>'
setup(
name="napalm-vyos",
version="0.2.0",
version="0.2.1",
packages=find_packages(),
author="Piotr Pieprzycki",
author_email="piotr.pieprzycki@dreamlab.pl",

View File

@ -51,7 +51,16 @@ class PatchedVyOSDriver(vyos.VyOSDriver):
class FakeVyOSDevice(BaseTestDouble):
"""VyOS device test double."""
def __init__(self):
self.mode_config = False
def send_command(self, command, **kwargs):
filename = '{}.text'.format(self.sanitize_text(command))
full_path = self.find_file(filename)
return self.read_txt_file(full_path)
def config_mode(self):
self.mode_config = True
def exit_config_mode(self):
self.mode_config = False

View File

@ -0,0 +1,123 @@
interfaces {
ethernet eth0 {
address dhcp
}
ethernet eth1 {
address 10.0.1.222/24
}
loopback lo {
address 10.2.2.2/32
address 8.8.8.8/32
}
}
policy {
prefix-list EXPORT {
rule 1 {
action permit
prefix 172.16.2.0/24
}
rule 65535 {
action permit
prefix 10.2.2.2/32
}
}
route-map EXPORT-POLICY {
rule 1 {
action permit
match {
ip {
address {
prefix-list EXPORT
}
}
}
}
}
}
protocols {
bgp 65002 {
neighbor 10.0.1.100 {
remote-as 65001
route-map {
export EXPORT-POLICY
}
}
redistribute {
connected {
route-map EXPORT-POLICY
}
}
}
}
service {
snmp {
community commro {
authorization ro
}
contact admin@foo.corp
location PL,Krakow
}
ssh {
disable-host-validation
port 22
}
}
system {
config-management {
commit-revisions 20
}
host-name vyos2
login {
banner {
pre-login "My banner for all devices"
}
user vagrant {
authentication {
encrypted-password $6$fcHhBu3T$WLmiu6/txlEfWK5uh4mKE8v7qocuftsoAN1oHqPIIoogXAX8zS.SKhB105EExYU6yBy4cKHUD/Q6Mm7CUbVTr.
plaintext-password ""
public-keys vagrant {
key AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==
type ssh-rsa
}
}
level admin
}
user vyos {
authentication {
encrypted-password $1$yHIMnG/J$aWDkd3oDYSYps8twB5vpw1
plaintext-password ""
}
level admin
}
}
ntp {
server 10.0.1.100 {
}
}
package {
auto-sync 1
repository community {
components main
distribution helium
password ""
url http://packages.vyos.net/vyos
username ""
}
}
syslog {
global {
facility all {
level notice
}
facility protocols {
level debug
}
}
}
time-zone UTC
}
/* Warning: Do not remove the following line. */
/* === vyatta-config-version: "cluster@1:config-management@1:conntrack-sync@1:conntrack@1:cron@1:dhcp-relay@1:dhcp-server@4:firewall@5:ipsec@4:nat@4:qos@1:quagga@2:system@6:vrrp@1:wanloadbalance@3:webgui@1:webproxy@1:zone-policy@1" === */
/* Release version: VyOS 1.1.7 */

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,125 @@
interfaces {
ethernet eth0 {
address dhcp
duplex auto
smp_affinity auto
speed auto
}
ethernet eth1 {
address 10.0.1.222/24
duplex auto
smp_affinity auto
speed auto
}
loopback lo {
address 10.2.2.2/32
address 8.8.8.8/32
}
}
policy {
prefix-list EXPORT {
rule 1 {
action permit
prefix 172.16.2.0/24
}
rule 65535 {
action permit
prefix 10.2.2.2/32
}
}
route-map EXPORT-POLICY {
rule 1 {
action permit
match {
ip {
address {
prefix-list EXPORT
}
}
}
}
}
}
protocols {
bgp 65002 {
neighbor 10.0.1.100 {
remote-as 65001
route-map {
export EXPORT-POLICY
}
}
redistribute {
connected {
route-map EXPORT-POLICY
}
}
}
}
service {
snmp {
community commro {
authorization ro
}
contact admin@foo.corp
location PL,Krakow
}
ssh {
disable-host-validation
port 22
}
}
system {
config-management {
commit-revisions 20
}
host-name vyos2
login {
banner {
pre-login "My banner for all devices"
}
user vagrant {
authentication {
encrypted-password $6$fcHhBu3T$WLmiu6/txlEfWK5uh4mKE8v7qocuftsoAN1oHqPIIoogXAX8zS.SKhB105EExYU6yBy4cKHUD/Q6Mm7CUbVTr.
plaintext-password ""
public-keys vagrant {
key AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==
type ssh-rsa
}
}
level admin
}
user vyos {
authentication {
encrypted-password $1$yHIMnG/J$aWDkd3oDYSYps8twB5vpw1
plaintext-password ""
}
level admin
}
}
ntp {
server 10.0.1.100 {
}
}
package {
auto-sync 1
repository community {
components main
distribution helium
password ""
url http://packages.vyos.net/vyos
username ""
}
}
syslog {
global {
facility all {
level notice
}
facility protocols {
level debug
}
}
}
time-zone UTC
}
[edit]

View File

@ -0,0 +1,123 @@
interfaces {
ethernet eth0 {
address dhcp
}
ethernet eth1 {
address 10.0.1.222/24
}
loopback lo {
address 10.2.2.2/32
address 8.8.8.8/32
}
}
policy {
prefix-list EXPORT {
rule 1 {
action permit
prefix 172.16.2.0/24
}
rule 65535 {
action permit
prefix 10.2.2.2/32
}
}
route-map EXPORT-POLICY {
rule 1 {
action permit
match {
ip {
address {
prefix-list EXPORT
}
}
}
}
}
}
protocols {
bgp 65002 {
neighbor 10.0.1.100 {
remote-as 65001
route-map {
export EXPORT-POLICY
}
}
redistribute {
connected {
route-map EXPORT-POLICY
}
}
}
}
service {
snmp {
community commro {
authorization ro
}
contact admin@foo.corp
location PL,Krakow
}
ssh {
disable-host-validation
port 22
}
}
system {
config-management {
commit-revisions 20
}
host-name vyos2
login {
banner {
pre-login "My banner for all devices"
}
user vagrant {
authentication {
encrypted-password $6$fcHhBu3T$WLmiu6/txlEfWK5uh4mKE8v7qocuftsoAN1oHqPIIoogXAX8zS.SKhB105EExYU6yBy4cKHUD/Q6Mm7CUbVTr.
plaintext-password ""
public-keys vagrant {
key AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==
type ssh-rsa
}
}
level admin
}
user vyos {
authentication {
encrypted-password $1$yHIMnG/J$aWDkd3oDYSYps8twB5vpw1
plaintext-password ""
}
level admin
}
}
ntp {
server 10.0.1.100 {
}
}
package {
auto-sync 1
repository community {
components main
distribution helium
password ""
url http://packages.vyos.net/vyos
username ""
}
}
syslog {
global {
facility all {
level notice
}
facility protocols {
level debug
}
}
}
time-zone UTC
}
/* Warning: Do not remove the following line. */
/* === vyatta-config-version: "cluster@1:config-management@1:conntrack-sync@1:conntrack@1:cron@1:dhcp-relay@1:dhcp-server@4:firewall@5:ipsec@4:nat@4:qos@1:quagga@2:system@6:vrrp@1:wanloadbalance@3:webgui@1:webproxy@1:zone-policy@1" === */
/* Release version: VyOS 1.1.7 */

View File

@ -0,0 +1 @@
{"running": "", "startup": "", "candidate": ""}

View File

@ -0,0 +1,125 @@
interfaces {
ethernet eth0 {
address dhcp
duplex auto
smp_affinity auto
speed auto
}
ethernet eth1 {
address 10.0.1.222/24
duplex auto
smp_affinity auto
speed auto
}
loopback lo {
address 10.2.2.2/32
address 8.8.8.8/32
}
}
policy {
prefix-list EXPORT {
rule 1 {
action permit
prefix 172.16.2.0/24
}
rule 65535 {
action permit
prefix 10.2.2.2/32
}
}
route-map EXPORT-POLICY {
rule 1 {
action permit
match {
ip {
address {
prefix-list EXPORT
}
}
}
}
}
}
protocols {
bgp 65002 {
neighbor 10.0.1.100 {
remote-as 65001
route-map {
export EXPORT-POLICY
}
}
redistribute {
connected {
route-map EXPORT-POLICY
}
}
}
}
service {
snmp {
community commro {
authorization ro
}
contact admin@foo.corp
location PL,Krakow
}
ssh {
disable-host-validation
port 22
}
}
system {
config-management {
commit-revisions 20
}
host-name vyos2
login {
banner {
pre-login "My banner for all devices"
}
user vagrant {
authentication {
encrypted-password $6$fcHhBu3T$WLmiu6/txlEfWK5uh4mKE8v7qocuftsoAN1oHqPIIoogXAX8zS.SKhB105EExYU6yBy4cKHUD/Q6Mm7CUbVTr.
plaintext-password ""
public-keys vagrant {
key AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==
type ssh-rsa
}
}
level admin
}
user vyos {
authentication {
encrypted-password $1$yHIMnG/J$aWDkd3oDYSYps8twB5vpw1
plaintext-password ""
}
level admin
}
}
ntp {
server 10.0.1.100 {
}
}
package {
auto-sync 1
repository community {
components main
distribution helium
password ""
url http://packages.vyos.net/vyos
username ""
}
}
syslog {
global {
facility all {
level notice
}
facility protocols {
level debug
}
}
}
time-zone UTC
}
[edit]

View File

@ -0,0 +1,123 @@
interfaces {
ethernet eth0 {
address dhcp
}
ethernet eth1 {
address 10.0.1.222/24
}
loopback lo {
address 10.2.2.2/32
address 8.8.8.8/32
}
}
policy {
prefix-list EXPORT {
rule 1 {
action permit
prefix 172.16.2.0/24
}
rule 65535 {
action permit
prefix 10.2.2.2/32
}
}
route-map EXPORT-POLICY {
rule 1 {
action permit
match {
ip {
address {
prefix-list EXPORT
}
}
}
}
}
}
protocols {
bgp 65002 {
neighbor 10.0.1.100 {
remote-as 65001
route-map {
export EXPORT-POLICY
}
}
redistribute {
connected {
route-map EXPORT-POLICY
}
}
}
}
service {
snmp {
community commro {
authorization ro
}
contact admin@foo.corp
location PL,Krakow
}
ssh {
disable-host-validation
port 22
}
}
system {
config-management {
commit-revisions 20
}
host-name vyos2
login {
banner {
pre-login "My banner for all devices"
}
user vagrant {
authentication {
encrypted-password $6$fcHhBu3T$WLmiu6/txlEfWK5uh4mKE8v7qocuftsoAN1oHqPIIoogXAX8zS.SKhB105EExYU6yBy4cKHUD/Q6Mm7CUbVTr.
plaintext-password ""
public-keys vagrant {
key AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==
type ssh-rsa
}
}
level admin
}
user vyos {
authentication {
encrypted-password $1$yHIMnG/J$aWDkd3oDYSYps8twB5vpw1
plaintext-password ""
}
level admin
}
}
ntp {
server 10.0.1.100 {
}
}
package {
auto-sync 1
repository community {
components main
distribution helium
password ""
url http://packages.vyos.net/vyos
username ""
}
}
syslog {
global {
facility all {
level notice
}
facility protocols {
level debug
}
}
}
time-zone UTC
}
/* Warning: Do not remove the following line. */
/* === vyatta-config-version: "cluster@1:config-management@1:conntrack-sync@1:conntrack@1:cron@1:dhcp-relay@1:dhcp-server@4:firewall@5:ipsec@4:nat@4:qos@1:quagga@2:system@6:vrrp@1:wanloadbalance@3:webgui@1:webproxy@1:zone-policy@1" === */
/* Release version: VyOS 1.1.7 */

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,124 @@
interfaces {
ethernet eth0 {
address dhcp
duplex auto
smp_affinity auto
speed auto
}
ethernet eth1 {
address 10.0.1.222/24
duplex auto
smp_affinity auto
speed auto
}
loopback lo {
address 10.2.2.2/32
address 8.8.8.8/32
}
}
policy {
prefix-list EXPORT {
rule 1 {
action permit
prefix 172.16.2.0/24
}
rule 65535 {
action permit
prefix 10.2.2.2/32
}
}
route-map EXPORT-POLICY {
rule 1 {
action permit
match {
ip {
address {
prefix-list EXPORT
}
}
}
}
}
}
protocols {
bgp 65002 {
neighbor 10.0.1.100 {
remote-as 65001
route-map {
export EXPORT-POLICY
}
}
redistribute {
connected {
route-map EXPORT-POLICY
}
}
}
}
service {
snmp {
community commro {
authorization ro
}
contact admin@foo.corp
location PL,Krakow
}
ssh {
disable-host-validation
port 22
}
}
system {
config-management {
commit-revisions 20
}
host-name vyos2
login {
banner {
pre-login "My banner for all devices"
}
user vagrant {
authentication {
encrypted-password **********
plaintext-password ""
public-keys vagrant {
key AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==
type ssh-rsa
}
}
level admin
}
user vyos {
authentication {
encrypted-password **********
plaintext-password ""
}
level admin
}
}
ntp {
server 10.0.1.100 {
}
}
package {
auto-sync 1
repository community {
components main
distribution helium
password ""
url http://packages.vyos.net/vyos
username ""
}
}
syslog {
global {
facility all {
level notice
}
facility protocols {
level debug
}
}
}
time-zone UTC
}