Class: Puppet::Transport::Panos
- Inherits:
-
Object
- Object
- Puppet::Transport::Panos
- Defined in:
- lib/puppet/transport/panos.rb
Overview
The main connection class to a PAN-OS API endpoint
Defined Under Namespace
Classes: API
Class Method Summary collapse
Instance Method Summary collapse
- #apikey ⇒ Object
- #commit ⇒ Object
- #delete_config(xpath) ⇒ Object
- #edit_config(xpath, document) ⇒ Object
- #facts(context) ⇒ Object
- #fetch_device_facts(context) ⇒ Object
- #get_config(xpath) ⇒ Object
- #import(file_path, category) ⇒ Object
-
#initialize(_context, connection_info) ⇒ Panos
constructor
attr_reader :config.
- #load_config(file_name) ⇒ Object
- #outstanding_changes? ⇒ Boolean
- #parse_device_facts(response) ⇒ Object
- #set_config(xpath, document) ⇒ Object
- #show_config ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(_context, connection_info) ⇒ Panos
attr_reader :config
17 18 19 |
# File 'lib/puppet/transport/panos.rb', line 17 def initialize(_context, connection_info) @connection_info = self.class.validate_connection_info(connection_info) end |
Class Method Details
.validate_connection_info(connection_info) ⇒ Object
10 11 12 13 |
# File 'lib/puppet/transport/panos.rb', line 10 def self.validate_connection_info(connection_info) raise Puppet::ResourceError, 'Could not find "user"/"password" or "apikey" in the configuration' unless (connection_info.key?(:user) && connection_info.key?(:password)) || connection_info.key?(:apikey) # rubocop:disable Metrics/LineLength connection_info end |
Instance Method Details
#apikey ⇒ Object
105 106 107 |
# File 'lib/puppet/transport/panos.rb', line 105 def apikey api.apikey end |
#commit ⇒ Object
99 100 101 102 103 |
# File 'lib/puppet/transport/panos.rb', line 99 def commit Puppet.debug('Committing outstanding changes') # https://<firewall>/api/?type=commit&cmd=<commit></commit> api.job_request('commit', cmd: '<commit></commit>') end |
#delete_config(xpath) ⇒ Object
62 63 64 65 66 |
# File 'lib/puppet/transport/panos.rb', line 62 def delete_config(xpath) Puppet.debug("Deleting #{xpath}") # https://<firewall>/api/?key=apikey&type=config&action=delete&xpath=xpath-value api.request('config', action: 'delete', xpath: xpath) end |
#edit_config(xpath, document) ⇒ Object
56 57 58 59 60 |
# File 'lib/puppet/transport/panos.rb', line 56 def edit_config(xpath, document) Puppet.debug("Updating #{xpath}") # https://<firewall>/api/?key=apikey&type=config&action=edit&xpath=xpath-value&element=element-value api.request('config', action: 'edit', xpath: xpath, element: document) end |
#facts(context) ⇒ Object
21 22 23 |
# File 'lib/puppet/transport/panos.rb', line 21 def facts(context) @facts ||= parse_device_facts(fetch_device_facts(context)) end |
#fetch_device_facts(context) ⇒ Object
25 26 27 28 29 |
# File 'lib/puppet/transport/panos.rb', line 25 def fetch_device_facts(context) context.debug('Retrieving PANOS Device Facts') # https://<firewall>/api/?key=apikey&type=version api.request('version') end |
#get_config(xpath) ⇒ Object
44 45 46 47 48 |
# File 'lib/puppet/transport/panos.rb', line 44 def get_config(xpath) Puppet.debug("Retrieving #{xpath}") # https://<firewall>/api/?key=apikey&type=config&action=get&xpath=<path-to-config-node> api.request('config', action: 'get', xpath: xpath) end |
#import(file_path, category) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/puppet/transport/panos.rb', line 68 def import(file_path, category) Puppet.debug("Importing #{category}") # https://<firewall>/api/?key=apikey&type=import&category=category # POST: File(file_path) api.upload('import', file_path, category: category) end |
#load_config(file_name) ⇒ Object
75 76 77 78 79 |
# File 'lib/puppet/transport/panos.rb', line 75 def load_config(file_name) Puppet.debug('Loading Config') # https://<firewall>/api/?type=op&cmd=<load><config><from>file_name</from></config></load> api.request('op', cmd: "<load><config><from>#{file_name}</from></config></load>") end |
#outstanding_changes? ⇒ Boolean
87 88 89 90 91 |
# File 'lib/puppet/transport/panos.rb', line 87 def outstanding_changes? # /api/?type=op&cmd=<check><pending-changes></pending-changes></check> result = api.request('op', cmd: '<check><pending-changes></pending-changes></check>') result.elements['/response/result'].text == 'yes' end |
#parse_device_facts(response) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet/transport/panos.rb', line 31 def parse_device_facts(response) facts = {} model = response.elements['/response/result/model'].text version = response.elements['/response/result/sw-version'].text vsys = response.elements['/response/result/multi-vsys'].text facts['operatingsystem'] = model if model facts['operatingsystemrelease'] = version if version facts['multi-vsys'] = vsys if vsys facts end |
#set_config(xpath, document) ⇒ Object
50 51 52 53 54 |
# File 'lib/puppet/transport/panos.rb', line 50 def set_config(xpath, document) Puppet.debug("Writing to #{xpath}") # https://<firewall>/api/?key=apikey&type=config&action=set&xpath=xpath-value&element=element-value api.request('config', action: 'set', xpath: xpath, element: document) end |
#show_config ⇒ Object
81 82 83 84 85 |
# File 'lib/puppet/transport/panos.rb', line 81 def show_config Puppet.debug('Retrieving Config') # https://<firewall>/api/?type=op&cmd=<show><config><running></running></config></show> api.request('op', cmd: '<show><config><running></running></config></show>') end |
#validate ⇒ Object
93 94 95 96 97 |
# File 'lib/puppet/transport/panos.rb', line 93 def validate Puppet.debug('Validating configuration') # https://<firewall>/api/?type=op&cmd=<validate><full></full></validate> api.job_request('op', cmd: '<validate><full></full></validate>') end |