plugins/compute/app/models/compute/server.rb
# This methods converts addresses to a map between fixed and floating ips.
# return:
# [
#   {
#     'fixed' => { 'addr' => ADDRESS, 'network_name' => NETWORK_NAME},
#     'floating' => { 'addr' => ADDRESS, 'network_name' => NETWORK_NAME}
#   },
#   ...
# ]
This methods converts addresses to a map between fixed and floating ips.
This methods converts addresses to a map between fixed and floating ips .
def ip_maps(project_floating_ips)
      return @ip_maps if @ip_maps
      return {} unless addresses
      ip_network_names = {}
      server_floating_ips = []
      addresses.each do |network_name, ips|
        ips.each do |ip|
          ip_network_names[ip['addr']] = network_name
          if ip['OS-EXT-IPS:type'] == 'floating'
            server_floating_ips << ip['addr']
          end
        end
      end
      fixed_floating_map = project_floating_ips.each_with_object({}) do |fip, map|
        next unless server_floating_ips.include?(fip.floating_ip_address)
        map[fip.fixed_ip_address] = fip
      end
      @ip_maps = addresses.values.flatten.each_with_object([]) do |ip, array|
        next if ip['OS-EXT-IPS:type'] == 'floating'
        fixed_address = ip['addr']
        floating_ip = fixed_floating_map[fixed_address]
        data = {
          'fixed' => {
            'addr' => fixed_address,
            'network_name' => ip_network_names[fixed_address]
          }
        }
        if floating_ip
          data['floating'] = {
            'addr' => floating_ip.floating_ip_address,
            'id' => floating_ip.id,
            'network_name' => ip_network_names[floating_ip.floating_ip_address]
          }
        end
        array << data
      end
    end
def ip_maps ( project_floating_ips ) return @ip_maps if @ip_maps return { } unless addresses ip_network_names = { } server_floating_ips = [ ] addresses . each do | network_name , ips | ips . each do | ip | ip_network_names [ ip [ 'addr' ] ] = network_name if ip [ 'OS-EXT-IPS:type' ] == 'floating' server_floating_ips << ip [ 'addr' ] end end end fixed_floating_map = project_floating_ips . each_with_object ( { } ) do | fip , map | next unless server_floating_ips . include? ( fip . floating_ip_address ) map [ fip . fixed_ip_address ] = fip end @ip_maps = addresses . values . flatten . each_with_object ( [ ] ) do | ip , array | next if ip [ 'OS-EXT-IPS:type' ] == 'floating' fixed_address = ip [ 'addr' ] floating_ip = fixed_floating_map [ fixed_address ] data = { 'fixed' => { 'addr' => fixed_address , 'network_name' => ip_network_names [ fixed_address ] } } if floating_ip data [ 'floating' ] = { 'addr' => floating_ip . floating_ip_address , 'id' => floating_ip . id , 'network_name' => ip_network_names [ floating_ip . floating_ip_address ] } end array << data end end
This methods converts addresses to a map between fixed and floating ips.
This methods converts addresses to a map between fixed and floating ips .
project_floating_ips
<not_specific>