Skip to content

Commit 3309421

Browse files
committed
(FM-7602) Implement the panos Transport
Experimental implementation of a `panos` transport based on the new in development transport support. This still needs some cleanups before it can be merged. Follow the TODO breadcrumbs.
1 parent 837b319 commit 3309421

File tree

21 files changed

+807
-760
lines changed

21 files changed

+807
-760
lines changed

.sync.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Gemfile:
1010
ref: 'master'
1111
- gem: 'puppet-resource_api'
1212
git: 'https://github.com/puppetlabs/puppet-resource_api.git'
13-
ref: 'master'
13+
ref: 'transport'
1414
# required for internal pipelines
1515
- gem: 'beaker-hostgenerator'
1616
# the first version to contain Palo Alto support

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ group :development do
2929
gem "webmock", require: false
3030
gem "builder", '~> 3.2.2', require: false
3131
gem "puppet-strings", require: false, git: 'https://github.com/puppetlabs/puppet-strings.git', ref: 'master'
32-
gem "puppet-resource_api", require: false, git: 'https://github.com/puppetlabs/puppet-resource_api.git', ref: 'master'
32+
gem "puppet-resource_api", require: false, git: 'https://github.com/DavidS/puppet-resource_api.git', ref: 'FM-7726-context-transport'
3333
gem "beaker-hostgenerator", '~> 1.1.15', require: false
3434
gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')
3535
end

lib/puppet/provider/panos_arbitrary_commands/panos_arbitrary_commands.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def canonicalize(_context, resources)
2626
def get(context, xpaths = nil)
2727
return [] if xpaths.nil?
2828
results = []
29-
config = context.device.get_config('/config/' + xpaths.first) unless xpaths.first.nil?
29+
config = context.transport.get_config('/config/' + xpaths.first) unless xpaths.first.nil?
3030
if xpaths.first
3131
config.elements.collect('/response/result') do |entry| # rubocop:disable Style/CollectionMethods
3232
xml = str_from_xml(entry.to_s)
@@ -48,7 +48,7 @@ def create(context, xpath, should)
4848
raise Puppet::ResourceError, parse_exception.message
4949
end
5050

51-
context.device.set_config('/config/' + xpath, should)
51+
context.transport.set_config('/config/' + xpath, should)
5252
end
5353

5454
def update(context, xpath, should)
@@ -58,11 +58,11 @@ def update(context, xpath, should)
5858
raise Puppet::ResourceError, parse_exception.message
5959
end
6060

61-
context.device.edit_config('/config/' + xpath, should)
61+
context.transport.edit_config('/config/' + xpath, should)
6262
end
6363

6464
def delete(context, xpath)
65-
context.device.delete_config('/config/' + xpath)
65+
context.transport.delete_config('/config/' + xpath)
6666
end
6767

6868
def str_from_xml(xml)

lib/puppet/provider/panos_commit/panos_commit.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ def get(context)
55
{
66
name: 'commit',
77
# return a value that causes an update if the user requested one
8-
commit: !context.device.outstanding_changes?,
8+
commit: !context.transport.outstanding_changes?,
99
},
1010
]
1111
end
1212

1313
def set(context, changes)
14-
if context.device.outstanding_changes?
14+
if context.transport.outstanding_changes?
1515
if changes['commit'][:should][:commit]
1616
context.updating('commit') do
17-
context.device.commit
17+
context.transport.commit
1818
end
1919
else
2020
context.info('changes detected, but skipping commit as requested')

lib/puppet/provider/panos_path_monitor_base.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def xml_from_should(name, should)
2626

2727
def get(context)
2828
results = []
29-
config = context.device.get_config(context.type.definition[:base_xpath] + '/entry')
29+
config = context.transport.get_config(context.type.definition[:base_xpath] + '/entry')
3030
config.elements.collect('/response/result/entry') do |entry| # rubocop:disable Style/CollectionMethods
3131
vr_name = REXML::XPath.match(entry, 'string(@name)').first
3232
config.elements.collect("/response/result/entry[@name='#{vr_name}']/routing-table/#{@version_label}/static-route/entry") do |static_route_entry| # rubocop:disable Style/CollectionMethods
@@ -51,17 +51,17 @@ def get(context)
5151
def create(context, name, should)
5252
paths = name[:route].split('/')
5353
context.type.definition[:base_xpath] = "/config/devices/entry/network/virtual-router/entry[@name='#{paths[0]}']/routing-table/#{@version_label}/static-route/entry[@name='#{paths[1]}']/path-monitor/monitor-destinations" # rubocop:disable Metrics/LineLength
54-
context.device.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
54+
context.transport.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
5555
end
5656

5757
def update(context, name, should)
5858
paths = name[:route].split('/')
5959
context.type.definition[:base_xpath] = "/config/devices/entry/network/virtual-router/entry[@name='#{paths[0]}']/routing-table/#{@version_label}/static-route/entry[@name='#{paths[1]}']/path-monitor/monitor-destinations" # rubocop:disable Metrics/LineLength
60-
context.device.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
60+
context.transport.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
6161
end
6262

6363
def delete(context, name)
6464
names = name[:route].split('/')
65-
context.device.delete_config(context.type.definition[:base_xpath] + "/entry[@name='#{names[0]}']/routing-table/#{@version_label}/static-route/entry[@name='#{names[1]}']/path-monitor/monitor-destinations/entry[@name='#{name[:path]}']") # rubocop:disable Metrics/LineLength
65+
context.transport.delete_config(context.type.definition[:base_xpath] + "/entry[@name='#{names[0]}']/routing-table/#{@version_label}/static-route/entry[@name='#{names[1]}']/path-monitor/monitor-destinations/entry[@name='#{name[:path]}']") # rubocop:disable Metrics/LineLength
6666
end
6767
end

lib/puppet/provider/panos_provider.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def initialize
99
end
1010

1111
def get(context)
12-
config = context.device.get_config(context.type.definition[:base_xpath] + '/entry')
12+
config = context.transport.get_config(context.type.definition[:base_xpath] + '/entry')
1313
config.elements.collect('/response/result/entry') do |entry| # rubocop:disable Style/CollectionMethods
1414
result = {}
1515
context.type.attributes.each do |attr_name, attr|
@@ -21,16 +21,16 @@ def get(context)
2121

2222
def create(context, name, should)
2323
validate_should(should) if defined? validate_should
24-
context.device.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
24+
context.transport.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
2525
end
2626

2727
def update(context, name, should)
2828
validate_should(should) if defined? validate_should
29-
context.device.edit_config(context.type.definition[:base_xpath] + "/entry[@name='#{name}']", xml_from_should(name, should))
29+
context.transport.edit_config(context.type.definition[:base_xpath] + "/entry[@name='#{name}']", xml_from_should(name, should))
3030
end
3131

3232
def delete(context, name)
33-
context.device.delete_config(context.type.definition[:base_xpath] + "/entry[@name='#{name}']")
33+
context.transport.delete_config(context.type.definition[:base_xpath] + "/entry[@name='#{name}']")
3434
end
3535

3636
def match(entry, attr, attr_name)

lib/puppet/provider/panos_static_route_base.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def validate_should(should)
6161
# Overiding the get method, as the base xpath points towards virtual routers, and therefore the base provider's get will only return once for each VR.
6262
def get(context)
6363
results = []
64-
config = context.device.get_config(context.type.definition[:base_xpath] + '/entry')
64+
config = context.transport.get_config(context.type.definition[:base_xpath] + '/entry')
6565
config.elements.collect('/response/result/entry') do |entry| # rubocop:disable Style/CollectionMethods
6666
vr_name = REXML::XPath.match(entry, 'string(@name)').first
6767
# rubocop:disable Style/CollectionMethods
@@ -84,16 +84,16 @@ def get(context)
8484
def create(context, name, should)
8585
context.type.definition[:base_xpath] = "/config/devices/entry/network/virtual-router/entry[@name='#{name[:vr_name]}']/routing-table/#{@version_label}/static-route"
8686
validate_should(should)
87-
context.device.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
87+
context.transport.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
8888
end
8989

9090
def update(context, name, should)
9191
context.type.definition[:base_xpath] = "/config/devices/entry/network/virtual-router/entry[@name='#{name[:vr_name]}']/routing-table/#{@version_label}/static-route"
9292
validate_should(should)
93-
context.device.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
93+
context.transport.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
9494
end
9595

9696
def delete(context, name)
97-
context.device.delete_config(context.type.definition[:base_xpath] + "/entry[@name='#{name[:vr_name]}']/routing-table/#{@version_label}/static-route/entry[@name='#{name[:route]}']")
97+
context.transport.delete_config(context.type.definition[:base_xpath] + "/entry[@name='#{name[:vr_name]}']/routing-table/#{@version_label}/static-route/entry[@name='#{name[:route]}']")
9898
end
9999
end

0 commit comments

Comments
 (0)