Chapter 09/circuit-oneops-1-master/components/cookbooks/panos/libraries/dataaccess/address_request.rb
# Update will update the address in the firewall device
# right now it just updates the IP address
Update will update the address in the firewall device
right now it just updates the IP address
Update will update the address in the firewall device right now it just updates the IP address
def update(address)
    fail ArgumentError, 'address must be of type Address' unless address.is_a? Address
    if 'IP_Netmask'.casecmp(address.type) == 0
      xpath = "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='#{address.device_group}']/address/entry[@name='#{address.name}']/ip-netmask"
      element = "<ip-netmask>#{address.address}</ip-netmask>"
    elsif 'IP_Range'.casecmp(address.type) == 0
      xpath = "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='#{address.device_group}']/address/entry[@name='#{address.name}']/ip-range"
      element = "<ip-range>#{address.address}</ip-range>"
    else   
      xpath = "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='#{address.device_group}']/address/entry[@name='#{address.name}']/fqdn"
      element = "<fqdn>#{address.address}</fqdn>"
    end
    begin
    	set_address_response = RestClient::Request.execute(
    		:method => :post,
    		:verify_ssl => false,
    		:url => @baseurl,
    		:headers => {
    			:params => {
    				:key => @key.value,
    				:type => 'config',
    				:action => 'edit',
    				:xpath => xpath,
    				:element => element
    			}
    		}
    	)
      update_hash = Crack::XML.parse(set_address_response)
      Chef::Log.info("update_address_hash is: #{update_hash}")
      raise Exception.new("PANOS error updating address: #{update_hash['response']['msg']}") if update_hash['response']['status'] == 'error'
    rescue => e
      raise Exception.new("Exception updating the address: #{e} ")
    end
  end
def update ( address ) fail ArgumentError , 'address must be of type Address' unless address . is_a? Address if 'IP_Netmask' . casecmp ( address . type ) == 0 xpath = "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='#{address.device_group}']/address/entry[@name='#{address.name}']/ip-netmask" element = "<ip-netmask>#{address.address}</ip-netmask>" elsif 'IP_Range' . casecmp ( address . type ) == 0 xpath = "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='#{address.device_group}']/address/entry[@name='#{address.name}']/ip-range" element = "<ip-range>#{address.address}</ip-range>" else xpath = "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='#{address.device_group}']/address/entry[@name='#{address.name}']/fqdn" element = "<fqdn>#{address.address}</fqdn>" end begin set_address_response = RestClient :: Request . execute ( :method => :post , :verify_ssl => false , :url => @baseurl , :headers => { :params => { :key => @key . value , :type => 'config' , :action => 'edit' , :xpath => xpath , :element => element } } ) update_hash = Crack :: XML . parse ( set_address_response ) Chef :: Log . info ( "update_address_hash is: #{update_hash}" ) raise Exception . new ( "PANOS error updating address: #{update_hash['response']['msg']}" ) if update_hash [ 'response' ] [ 'status' ] == 'error' rescue => e raise Exception . new ( "Exception updating the address: #{e} " ) end end
Update will update the address in the firewall device
right now it just updates the IP address
Update will update the address in the firewall device right now it just updates the IP address
# fqdn scenario # It might return from the firewall call successfully, but with an error, so we need to check that.
address
<not_specific>