-
Notifications
You must be signed in to change notification settings - Fork 18
(WIP) (MODULES-10385) - Allow vsys to be set #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+153
−24
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/puppet/provider/panos_address_group/panos_address_group.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/puppet/provider/panos_security_policy_rule/panos_security_policy_rule.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/puppet/provider/panos_service_group/panos_service_group.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| require_relative 'panos_provider' | ||
|
|
||
| # A base provider for all PANOS providers inside a VSYS | ||
| class Puppet::Provider::PanosVsysBase < Puppet::Provider::PanosProvider | ||
| def set(context, changes) | ||
| changes.each do |name, change| | ||
| is = if context.type.feature?('simple_get_filter') | ||
| change.key?(:is) ? change[:is] : (get(context, [name]) || []).find { |r| r[:name] == name } | ||
| else | ||
| change.key?(:is) ? change[:is] : (get(context) || []).find { |r| r[:name] == name } | ||
| end | ||
| context.type.check_schema(is) unless change.key?(:is) | ||
|
|
||
| should = change[:should] | ||
|
|
||
| raise 'SimpleProvider cannot be used with a Type that is not ensurable' unless context.type.ensurable? | ||
|
|
||
| is = SimpleProvider.create_absent(:name, name) if is.nil? | ||
| should = SimpleProvider.create_absent(:name, name) if should.nil? | ||
|
|
||
| name_hash = if context.type.namevars.length > 1 | ||
| # pass a name_hash containing the values of all namevars | ||
| name_hash = {} | ||
| context.type.namevars.each do |namevar| | ||
| name_hash[namevar] = change[:should][namevar] | ||
| end | ||
| name_hash | ||
| else | ||
| name | ||
| end | ||
|
|
||
| if is[:ensure].to_s == 'absent' && should[:ensure].to_s == 'present' | ||
| context.creating(name) do | ||
| create(context, name_hash, should) | ||
| end | ||
| elsif is[:ensure].to_s == 'present' && should[:ensure].to_s == 'present' | ||
| context.updating(name) do | ||
| update(context, name_hash, should, is) | ||
| end | ||
| elsif is[:ensure].to_s == 'present' && should[:ensure].to_s == 'absent' | ||
| context.deleting(name) do | ||
| delete(context, name_hash) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def get(context) | ||
| results = [] | ||
| config = context.transport.get_config('/config/devices/entry/vsys/entry') | ||
| config.elements.collect('/response/result/entry') do |vsys_entry| # rubocop:disable Style/CollectionMethods | ||
| result = {} | ||
| vsys = match(vsys_entry, { xpath: 'string(@name)' }, 'name') | ||
| vsys_entry.elements.collect("/response/result/entry/#{context.type.definition[:base_xpath]}/entry") do |entry| # rubocop:disable Style/CollectionMethods | ||
| result = {} | ||
| context.type.attributes.each do |attr_name, attr| | ||
| result[attr_name] = match(entry, attr, attr_name) | ||
| end | ||
| result[:vsys] = vsys | ||
| results << result | ||
| end | ||
| end | ||
| results | ||
| end | ||
|
|
||
| def create(context, name, should) | ||
| validate_should(should) if defined? validate_should | ||
| xpath = if should[:vsys] | ||
| "/config/devices/entry/vsys/entry[@name='#{should[:vsys]}']/#{context.type.definition[:base_xpath]}" | ||
| else | ||
| "/config/devices/entry/vsys/entry/#{context.type.definition[:base_xpath]}" | ||
| end | ||
| context.transport.set_config(xpath, xml_from_should(name, should)) | ||
| context.transport.move(context.type.definition[:base_xpath], name, should[:insert_after]) unless should[:insert_after].nil? | ||
| end | ||
|
|
||
| def update(context, name, should, is) | ||
| validate_should(should) if defined? validate_should | ||
| if should[:vsys] == is[:vsys] | ||
| xpath = if should[:vsys] | ||
| "/config/devices/entry/vsys/entry[@name='#{should[:vsys]}']/#{context.type.definition[:base_xpath]}/entry[@name='#{name}']" | ||
| else | ||
| "/config/devices/entry/vsys/entry/#{context.type.definition[:base_xpath]}/entry[@name='#{name}']" | ||
| end | ||
|
|
||
| context.transport.edit_config("#{xpath}/entry[@name='#{name}']", xml_from_should(name, should)) | ||
| context.transport.move(context.type.definition[:base_xpath], name, should[:insert_after]) unless should[:insert_after].nil? | ||
| else | ||
| delete(context, name) | ||
| create(context, name, should) | ||
| end | ||
| end | ||
|
|
||
| def delete(context, name) | ||
| context.transport.delete_config("/config/devices/entry/vsys/entry/#{context.type.definition[:base_xpath]}/entry[@name='#{name}']") | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.