class PaloAlto::XML

Attributes

auth_key[RW]
debug[RW]
host[RW]
password[RW]
port[RW]
username[RW]
verify_ssl[RW]

Public Class Methods

execute(payload) click to toggle source
# File lib/palo_alto.rb, line 195
def execute(payload)
  retried = false
  begin
    Helpers::Rest.execute(payload, headers: {'X-PAN-KEY': self.auth_key})
  rescue TemporaryException => e
    unless retried
      if XML.debug.include?(:warnings)
        warn "Got error #{e.inspect}; retrying"
      end
      retried = true
      if e.is_a?(SessionTimedOutException)
        get_auth_key
      end
      retry
    else
      raise e
    end
  end
end
get_auth_key() click to toggle source

Perform a query to the API endpoint for an auth_key based on the credentials provided

# File lib/palo_alto.rb, line 276
def self.get_auth_key

  # establish the required options for the key request
  payload = { type: 'keygen',
              user: self.username,
              password: self.password }

  # get and parse the response for the key
  xml_data = Helpers::Rest.execute(payload)
  self.auth_key = xml_data.xpath('//response/result/key')[0].content
end
new(host:, port:, username:, password:, debug: []) click to toggle source
# File lib/palo_alto.rb, line 254
def initialize(host:, port:, username:, password:, debug: [])
  self.class.host      = host
  self.class.port      = port
  self.class.username = username
  self.class.password = password
  self.class.verify_ssl = OpenSSL::SSL::VERIFY_NONE
  self.class.debug = debug

  @subclasses = {}

  # xpath
  @expression = :root
  @arguments = [Expression.new(:this_node), []]

  # attempt to obtain the auth_key
  #raise 'Exception attempting to obtain the auth_key' if (self.class.auth_key = get_auth_key).nil?
  self.class.get_auth_key

  self
end

Public Instance Methods

commit!(all: false) click to toggle source
# File lib/palo_alto.rb, line 216
def commit!(all: false)
  op = if all
         'commit'
       else
         { commit: { partial: [
           { 'admin': [XML.username] },
           'no-template',
           'no-template-stack',
           'no-log-collector',
           'no-log-collector-group',
           'no-wildfire-appliance',
           'no-wildfire-appliance-cluster',
           { 'device-and-network': 'excluded' },
           { 'shared-object': 'excluded' }
         ] } }
       end
  Op.new.execute(op)
end
config() click to toggle source
# File lib/palo_alto/config.rb, line 371271
def config
        @subclasses['config'] ||= Config.new(parent_instance: nil, create_children: @create_children)
end
log(*x) click to toggle source
# File lib/palo_alto/log.rb, line 4
def log(*x)
        Log.new(*x)
end
op() click to toggle source
# File lib/palo_alto/op.rb, line 6
def op
  Op.new
end
revert!(all: false) click to toggle source
# File lib/palo_alto.rb, line 235
def revert!(all: false)
  op = if all
         { revert: 'config' }
       else
         { revert: { config: { partial: [
           { 'admin': [XML.username] },
           'no-template',
           'no-template-stack',
           'no-log-collector',
           'no-log-collector-group',
           'no-wildfire-appliance',
           'no-wildfire-appliance-cluster',
           { 'device-and-network': 'excluded' },
           { 'shared-object': 'excluded' }
         ] } } }
       end
  Op.new.execute(op)
end