summaryrefslogtreecommitdiff
path: root/lib/oxidized/model
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2017-07-01 11:25:17 +0300
committerGitHub <noreply@github.com>2017-07-01 11:25:17 +0300
commitccd00e4e8c9d7f559982447ad1505cf65d91bcd9 (patch)
tree8706bca3daa6a37a7cdf47f7f28535d8224d3b9c /lib/oxidized/model
parentc7682cf1743b6ff3627e6350f4413bd66faa9fd1 (diff)
parent89e2eb7a3fbb2aefaafbac1193831d535214472c (diff)
Merge pull request #859 from marnovdm/feature-cisco-multicontext
u/panzerfly's patch for 'Cisco ASA - Added support for multiple contexts' with fixes
Diffstat (limited to 'lib/oxidized/model')
-rw-r--r--lib/oxidized/model/asa.rb71
1 files changed, 53 insertions, 18 deletions
diff --git a/lib/oxidized/model/asa.rb b/lib/oxidized/model/asa.rb
index 038dd6b..9df4206 100644
--- a/lib/oxidized/model/asa.rb
+++ b/lib/oxidized/model/asa.rb
@@ -20,6 +20,11 @@ class ASA < Oxidized::Model
cfg
end
+ # check for multiple contexts
+ cmd 'show mode' do |cfg|
+ @is_multiple_context = cfg.include? 'multiple'
+ end
+
cmd 'show version' do |cfg|
# avoid commits due to uptime / ixo-router01 up 2 mins 28 secs / ixo-router01 up 1 days 2 hours
cfg = cfg.each_line.select { |line| not line.match /(\s+up\s+\d+\s+)|(.*days.*)/ }
@@ -31,25 +36,12 @@ class ASA < Oxidized::Model
comment cfg
end
- cmd 'more system:running-config' do |cfg|
- cfg = cfg.each_line.to_a[3..-1].join
- cfg.gsub! /^: [^\n]*\n/, ''
- # backup any xml referenced in the configuration.
- anyconnect_profiles = cfg.scan(Regexp.new('(\sdisk0:/.+\.xml)')).flatten
- anyconnect_profiles.each do |profile|
- cfg << (comment profile + "\n" )
- cmd ("more" + profile) do |xml|
- cfg << (comment xml)
- end
+ post do
+ if @is_multiple_context
+ multiple_context
+ else
+ single_context
end
- # if DAP is enabled, also backup dap.xml
- if cfg.rindex(/dynamic-access-policy-record\s(?!DfltAccessPolicy)/)
- cfg << (comment "disk0:/dap.xml\n")
- cmd "more disk0:/dap.xml" do |xml|
- cfg << (comment xml)
- end
- end
- cfg
end
cfg :ssh do
@@ -62,5 +54,48 @@ class ASA < Oxidized::Model
post_login 'terminal pager 0'
pre_logout 'exit'
end
+
+ def single_context
+ # Single context mode
+ cmd 'more system:running-config' do |cfg|
+ cfg = cfg.each_line.to_a[3..-1].join
+ cfg.gsub! /^: [^\n]*\n/, ''
+ # backup any xml referenced in the configuration.
+ anyconnect_profiles = cfg.scan(Regexp.new('(\sdisk0:/.+\.xml)')).flatten
+ anyconnect_profiles.each do |profile|
+ cfg << (comment profile + "\n" )
+ cmd ("more" + profile) do |xml|
+ cfg << (comment xml)
+ end
+ end
+ # if DAP is enabled, also backup dap.xml
+ if cfg.rindex(/dynamic-access-policy-record\s(?!DfltAccessPolicy)/)
+ cfg << (comment "disk0:/dap.xml\n")
+ cmd "more disk0:/dap.xml" do |xml|
+ cfg << (comment xml)
+ end
+ end
+ cfg
+ end
+ end
+
+ def multiple_context
+ # Multiple context mode
+ cmd 'changeto system' do |cfg|
+ cmd 'show running-config' do |systemcfg|
+ allcfg = "\n\n" + systemcfg + "\n\n"
+ contexts = systemcfg.scan(/^context (\S+)$/)
+ files = systemcfg.scan(/config-url (\S+)$/)
+ contexts.each_with_index do |cont, i|
+ allcfg = allcfg + "\n\n----------========== [ CONTEXT " + cont.join(" ") + " FILE " + files[i].join(" ") + " ] ==========----------\n\n"
+ cmd "more " + files[i].join(" ") do |cfgcontext|
+ allcfg = allcfg + "\n\n" + cfgcontext
+ end
+ end
+ cfg = allcfg
+ end
+ cfg
+ end
+ end
end