Chapter 09/circuit-oneops-1-master/components/cookbooks/panos/libraries/address_manager.rb
# This function handles updating the firewall device
This function handles updating the firewall device
This function handles updating the firewall device
def update(addresses, tag_name, device_groups)
    device_groups.each do |device_group|
      deploy_addresses = []
      addresses['entries'].each do |deploy_addr|
        deploy_addresses.push(Address.new(deploy_addr['name'], 'IP_NETMASK', deploy_addr['ip_address'], device_group, tag_name))
      end
      address = AddressRequest.new(@url, @key)
      existing_addresses = address.get_all_for_tag(tag_name, device_group)
      delete_address = []
      create_address = []
      update_address = []
      Chef::Log.info("Existing addresses: #{existing_addresses}")
      Chef::Log.info("Deployment addresses: #{deploy_addresses}")
      existing_addresses.each do |addr|
        if !deploy_addresses.include?(addr)
          delete_address.push(addr)
        end
      end
      deploy_addresses.each do |dep_addr|
        if existing_addresses.include?(dep_addr)
          update_address.push(dep_addr)
        else
          create_address.push(dep_addr)
        end
      end
      Chef::Log.info("Delete address are: #{delete_address}")
      if delete_address.size > 0
        delete_address.each do |del_addr|
          address.delete(del_addr.name, device_group)
        end
      end
      Chef::Log.info("Create address are: #{create_address}")
      if create_address.size > 0
        create_address.each do |create_addr|
          address.create(create_addr)
        end
      end
      Chef::Log.info("Update address are: #{update_address}")
      if update_address.size > 0
        update_address.each do |update_addr|
          address.update(update_addr)
        end
      end
    end
    commit_and_check_status(device_groups)
  end
def update ( addresses , tag_name , device_groups ) device_groups . each do | device_group | deploy_addresses = [ ] addresses [ 'entries' ] . each do | deploy_addr | deploy_addresses . push ( Address . new ( deploy_addr [ 'name' ] , 'IP_NETMASK' , deploy_addr [ 'ip_address' ] , device_group , tag_name ) ) end address = AddressRequest . new ( @url , @key ) existing_addresses = address . get_all_for_tag ( tag_name , device_group ) delete_address = [ ] create_address = [ ] update_address = [ ] Chef :: Log . info ( "Existing addresses: #{existing_addresses}" ) Chef :: Log . info ( "Deployment addresses: #{deploy_addresses}" ) existing_addresses . each do | addr | if ! deploy_addresses . include? ( addr ) delete_address . push ( addr ) end end deploy_addresses . each do | dep_addr | if existing_addresses . include? ( dep_addr ) update_address . push ( dep_addr ) else create_address . push ( dep_addr ) end end Chef :: Log . info ( "Delete address are: #{delete_address}" ) if delete_address . size > 0 delete_address . each do | del_addr | address . delete ( del_addr . name , device_group ) end end Chef :: Log . info ( "Create address are: #{create_address}" ) if create_address . size > 0 create_address . each do | create_addr | address . create ( create_addr ) end end Chef :: Log . info ( "Update address are: #{update_address}" ) if update_address . size > 0 update_address . each do | update_addr | address . update ( update_addr ) end end end commit_and_check_status ( device_groups ) end
This function handles updating the firewall device
This function handles updating the firewall device
#  convert address hash to an array of Address objects. # do this for easier comparison of the existing addresses in the firewall # get the existing addresses from the firewall # this is an array of Address objects # array holders for actions to be taken later # compare with my hash of addresses from the deployment # address from firewall is not in deployment, delete it # these are the addresses passed into the method, the new or updated addresses. # both arrays have the address, add it to the update array # if the deployment address is not found on the firewall # we need to create it # delete the addresses the firewall has that the deployment doesn't # add the addresses the deployment has the firewall doesn't # update the addresses that both have
addresses
<not_specific>
tag_name
<not_specific>
device_groups
<not_specific>