Chapter 09/circuit-oneops-1-master/components/cookbooks/panos/libraries/dataaccess/address_group_request.rb
# initialize the class making sure we have a URL endpoint and a KEY to use when communicating
# to the firewall device
initialize the class making sure we have a URL endpoint and a KEY to use when communicating
to the firewall device
initialize the class making sure we have a URL endpoint and a KEY to use when communicating to the firewall device
def create(address_group, address = nil)
		fail ArgumentError, 'address_group must be of type AddressGroup' unless address_group.is_a? AddressGroup
		if address_group.type =~ /Dynamic/
			element = "<entry name='#{address_group.name}'><dynamic><filter>'#{address_group.criteria}'</filter></dynamic></entry>"
		else
			raise Exception.new('Address is required to configure a STATIC type address group') if address.nil?
			raise Exception.new('Address must be of type Address') unless address.is_a? Address
			element = "<entry name='#{address_group.name}'<static><member>#{address.name}</member></static>"
		end
		begin
    	set_ag_response = RestClient::Request.execute(
    		:method => :post,
    		:verify_ssl => false,
    		:url => @baseurl,
    		:headers => {
    			:params => {
    				:key => @key.value,
    				:type => 'config',
    				:action => 'set',
    				:xpath => "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='#{address_group.device_group}']/address-group",
    				:element => element
    			}
    		}
    	)
      dag_hash = Crack::XML.parse(set_ag_response)
      Chef::Log.info("dag_hash is: #{dag_hash}")
      raise Exception.new("PANOS Error creating a DAG: #{dag_hash['response']['msg']}") if dag_hash['response']['status'] == 'error'
    rescue => e
      raise Exception.new("Exception creating DAG: #{e} ")
    end
  end
def create ( address_group , address = nil ) fail ArgumentError , 'address_group must be of type AddressGroup' unless address_group . is_a? AddressGroup if address_group . type =~ / Dynamic / element = "<entry name='#{address_group.name}'><dynamic><filter>'#{address_group.criteria}'</filter></dynamic></entry>" else raise Exception . new ( 'Address is required to configure a STATIC type address group' ) if address . nil? raise Exception . new ( 'Address must be of type Address' ) unless address . is_a? Address element = "<entry name='#{address_group.name}'<static><member>#{address.name}</member></static>" end begin set_ag_response = RestClient :: Request . execute ( :method => :post , :verify_ssl => false , :url => @baseurl , :headers => { :params => { :key => @key . value , :type => 'config' , :action => 'set' , :xpath => "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='#{address_group.device_group}']/address-group" , :element => element } } ) dag_hash = Crack :: XML . parse ( set_ag_response ) Chef :: Log . info ( "dag_hash is: #{dag_hash}" ) raise Exception . new ( "PANOS Error creating a DAG: #{dag_hash['response']['msg']}" ) if dag_hash [ 'response' ] [ 'status' ] == 'error' rescue => e raise Exception . new ( "Exception creating DAG: #{e} " ) end end
initialize the class making sure we have a URL endpoint and a KEY to use when communicating
to the firewall device
initialize the class making sure we have a URL endpoint and a KEY to use when communicating to the firewall device
# this is a static type address group, it requires an address to add to the group
address_group
<not_specific>
address
<not_specific>