This repository has been archived by the owner. It is now read-only.

Implemented get_config #38

Merged
merged 4 commits into from Sep 17, 2016
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+119 −1
Diff settings

Always

Just for now

Copy path View file
@@ -34,4 +34,5 @@ script:
- nosetests -v TestEOSDriver:TestGetterEOSDriver.test_traceroute
- nosetests -v TestEOSDriver:TestGetterEOSDriver.test_get_bgp_neighbors_detail
- nosetests -v TestEOSDriver:TestGetterEOSDriver.test_get_optics
- nosetests -v TestEOSDriver:TestGetterEOSDriver.test_get_config
- cd ../..
Copy path View file
@@ -72,7 +72,9 @@ def open(self):
port=self.port,
timeout=self.timeout
)
self.device = pyeapi.client.Node(connection)

if self.device is None:
self.device = pyeapi.client.Node(connection)
# does not raise an Exception if unusable

# let's try to run a very simple command
@@ -1426,3 +1428,48 @@ def get_optics(self):
optics_detail[port] = port_detail

return optics_detail

def get_config(self, retrieve="all"):
"""get_config implementation for EOS."""
get_startup = retrieve == "all" or retrieve == "startup"
get_running = retrieve == "all" or retrieve == "running"
get_candidate = (retrieve == "all" or retrieve == "candidate") and self.config_session

if retrieve == "all":
commands = ['show startup-config',
'show running-config']

if self.config_session:
commands.append('show session-config named {}'.format(self.config_session))

output = self.device.run_commands(commands, encoding="text")
return {
'startup': output[0]['output'] if get_startup else "",
'running': output[1]['output'] if get_running else "",
'candidate': output[2]['output'] if get_candidate else "",
}
elif get_startup or get_running:
commands = ['show {}-config'.format(retrieve)]
output = self.device.run_commands(commands, encoding="text")
return {
'startup': output[0]['output'] if get_startup else "",
'running': output[0]['output'] if get_running else "",
'candidate': "",
}
elif get_candidate:
commands = ['show session-config named {}'.format(self.config_session)]
output = self.device.run_commands(commands, encoding="text")
return {
'startup': "",
'running': "",
'candidate': output[0]['output'],
}
elif retrieve == "candidate":
# If we get here it means that we want the candidate but there is none.
return {
'startup': "",
'running': "",
'candidate': "",
}
else:
raise Exception("Wrong retrieve filter: {}".format(retrieve))
@@ -0,0 +1,35 @@
! Command: show startup-config
! Startup-config last modified at Sun Sep 11 18:35:01 2016 by root
! device: localhost (vEOS, EOS-4.15.2.1F)
!
! boot system flash:/vEOS-lab.swi
!
event-handler dhclient
trigger on-boot
action bash sudo /mnt/flash/initialize_ma1.sh
!
transceiver qsfp default-mode 4x10G
!
spanning-tree mode mstp
!
aaa authorization exec default local
!
aaa root secret 5 $1$zr7sHZaW$WagNykw1d5wjy4ZhtMgUS/
!
username admin privilege 15 role network-admin secret 5 $1$VoQBHXed$4z2.EoAeoIY2SFme/Pz3Q/
username vagrant privilege 15 role network-admin secret 5 $1$l/6gq.Qs$ifURvKWUYzLm0RqmRgr.W1
!
interface Ethernet1
!
interface Ethernet2
!
interface Management1
ip address 10.0.2.15/24
!
no ip routing
!
management api http-commands
no shutdown
!
!
end
@@ -0,0 +1,35 @@
! Command: show startup-config
! Startup-config last modified at Sun Sep 11 18:35:01 2016 by root
! device: localhost (vEOS, EOS-4.15.2.1F)
!
! boot system flash:/vEOS-lab.swi
!
event-handler dhclient
trigger on-boot
action bash sudo /mnt/flash/initialize_ma1.sh
!
transceiver qsfp default-mode 4x10G
!
spanning-tree mode mstp
!
aaa authorization exec default local
!
aaa root secret 5 $1$zr7sHZaW$WagNykw1d5wjy4ZhtMgUS/
!
username admin privilege 15 role network-admin secret 5 $1$VoQBHXed$4z2.EoAeoIY2SFme/Pz3Q/
username vagrant privilege 15 role network-admin secret 5 $1$l/6gq.Qs$ifURvKWUYzLm0RqmRgr.W1
!
interface Ethernet1
!
interface Ethernet2
!
interface Management1
ip address 10.0.2.15/24
!
no ip routing
!
management api http-commands
no shutdown
!
!
end
ProTip! Use n and p to navigate between commits in a pull request.