Skip to content

Commit

Permalink
(FM-7602) Implement the panos Transport
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DavidS committed Feb 1, 2019
1 parent 837b319 commit 645f02c
Show file tree
Hide file tree
Showing 21 changed files with 807 additions and 760 deletions.
2 changes: 1 addition & 1 deletion .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Gemfile:
ref: 'master'
- gem: 'puppet-resource_api'
git: 'https://github.com/puppetlabs/puppet-resource_api.git'
ref: 'master'
ref: 'transport'
# required for internal pipelines
- gem: 'beaker-hostgenerator'
# the first version to contain Palo Alto support
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ group :development do
gem "webmock", require: false
gem "builder", '~> 3.2.2', require: false
gem "puppet-strings", require: false, git: 'https://github.com/puppetlabs/puppet-strings.git', ref: 'master'
gem "puppet-resource_api", require: false, git: 'https://github.com/puppetlabs/puppet-resource_api.git', ref: 'master'
gem "puppet-resource_api", require: false, git: 'https://github.com/DavidS/puppet-resource_api.git', ref: 'FM-7726-context-transport'
gem "beaker-hostgenerator", '~> 1.1.15', require: false
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')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def canonicalize(_context, resources)
def get(context, xpaths = nil)
return [] if xpaths.nil?
results = []
config = context.device.get_config('/config/' + xpaths.first) unless xpaths.first.nil?
config = context.transport.get_config('/config/' + xpaths.first) unless xpaths.first.nil?
if xpaths.first
config.elements.collect('/response/result') do |entry| # rubocop:disable Style/CollectionMethods
xml = str_from_xml(entry.to_s)
Expand All @@ -48,7 +48,7 @@ def create(context, xpath, should)
raise Puppet::ResourceError, parse_exception.message
end

context.device.set_config('/config/' + xpath, should)
context.transport.set_config('/config/' + xpath, should)
end

def update(context, xpath, should)
Expand All @@ -58,11 +58,11 @@ def update(context, xpath, should)
raise Puppet::ResourceError, parse_exception.message
end

context.device.edit_config('/config/' + xpath, should)
context.transport.edit_config('/config/' + xpath, should)
end

def delete(context, xpath)
context.device.delete_config('/config/' + xpath)
context.transport.delete_config('/config/' + xpath)
end

def str_from_xml(xml)
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/provider/panos_commit/panos_commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ def get(context)
{
name: 'commit',
# return a value that causes an update if the user requested one
commit: !context.device.outstanding_changes?,
commit: !context.transport.outstanding_changes?,
},
]
end

def set(context, changes)
if context.device.outstanding_changes?
if context.transport.outstanding_changes?
if changes['commit'][:should][:commit]
context.updating('commit') do
context.device.commit
context.transport.commit
end
else
context.info('changes detected, but skipping commit as requested')
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/provider/panos_path_monitor_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def xml_from_should(name, should)

def get(context)
results = []
config = context.device.get_config(context.type.definition[:base_xpath] + '/entry')
config = context.transport.get_config(context.type.definition[:base_xpath] + '/entry')
config.elements.collect('/response/result/entry') do |entry| # rubocop:disable Style/CollectionMethods
vr_name = REXML::XPath.match(entry, 'string(@name)').first
config.elements.collect("/response/result/entry[@name='#{vr_name}']/routing-table/#{@version_label}/static-route/entry") do |static_route_entry| # rubocop:disable Style/CollectionMethods
Expand All @@ -51,17 +51,17 @@ def get(context)
def create(context, name, should)
paths = name[:route].split('/')
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
context.device.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
context.transport.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
end

def update(context, name, should)
paths = name[:route].split('/')
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
context.device.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
context.transport.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
end

def delete(context, name)
names = name[:route].split('/')
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
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
end
end
8 changes: 4 additions & 4 deletions lib/puppet/provider/panos_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize
end

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

def create(context, name, should)
validate_should(should) if defined? validate_should
context.device.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
context.transport.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
end

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

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

def match(entry, attr, attr_name)
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/provider/panos_static_route_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def validate_should(should)
# 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.
def get(context)
results = []
config = context.device.get_config(context.type.definition[:base_xpath] + '/entry')
config = context.transport.get_config(context.type.definition[:base_xpath] + '/entry')
config.elements.collect('/response/result/entry') do |entry| # rubocop:disable Style/CollectionMethods
vr_name = REXML::XPath.match(entry, 'string(@name)').first
# rubocop:disable Style/CollectionMethods
Expand All @@ -84,16 +84,16 @@ def get(context)
def create(context, name, should)
context.type.definition[:base_xpath] = "/config/devices/entry/network/virtual-router/entry[@name='#{name[:vr_name]}']/routing-table/#{@version_label}/static-route"
validate_should(should)
context.device.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
context.transport.set_config(context.type.definition[:base_xpath], xml_from_should(name, should))
end

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

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

0 comments on commit 645f02c

Please sign in to comment.