AppController/djinn.rb
# Updates all instance variables stored within the AppController with the new
# public and private IP addreses of this machine.
#
# The issue here is that an AppController may back up state when running, but
# when it is restored, its IP address changes (e.g., when taking AppScale down
# then starting it up on new machines in a cloud deploy). This method searches
# through internal AppController state to update any place where the old
# public and private IP addresses were used, replacing them with the new one.
Updates all instance variables stored within the AppController with the new
public and private IP addreses of this machine.

The issue here is that an AppController may back up state when running, but
when it is restored, its IP address changes . This method searches
through internal AppController state to update any place where the old
public and private IP addresses were used, replacing them with the new one.
Updates all instance variables stored within the AppController with the new public and private IP addreses of this machine . The issue here is that an AppController may back up state when running but when it is restored its IP address changes . This method searches through internal AppController state to update any place where the old public and private IP addresses were used replacing them with the new one .
def update_state_with_new_local_ip()
    all_local_ips = HelperFunctions.get_all_local_ips()
    new_private_ip = all_local_ips[@eth_interface]
    if ["ec2", "euca", "gce"].include?(@options['infrastructure'])
      new_public_ip = HelperFunctions.get_public_ip_from_metadata_service()
    else
      new_public_ip = new_private_ip
    end
    old_public_ip = @my_public_ip
    old_private_ip = @my_private_ip
    @nodes.each { |node|
      if node.public_ip == old_public_ip
        node.public_ip = new_public_ip
      end
      if node.private_ip == old_private_ip
        node.private_ip = new_private_ip
      end
    }
    if @options['hostname'] == old_public_ip
      @options['hostname'] = new_public_ip
    end
    unless is_cloud?
      nodes = JSON.load(@options['ips'])
      nodes.each { |node|
        if node['ip'] == old_private_ip
          node['ip'] == new_private_ip
        end
      }
      @options['ips'] = JSON.dump(nodes)
    end
    @app_info_map.each { |_app_id, app_info|
      if app_info['appengine'].nil?
        next
      end
      changed = false
      new_app_info = []
      app_info['appengine'].each { |location|
        host, port = location.split(":")
        if host == old_private_ip
          host = new_private_ip
          changed = true
        end
        new_app_info << "#{host}:#{port}"
        if changed
          app_info['appengine'] = new_app_info
        end
      }
    }
    @all_stats = []
    @my_public_ip = new_public_ip
    @my_private_ip = new_private_ip
  end
def update_state_with_new_local_ip ( ) all_local_ips = HelperFunctions . get_all_local_ips ( ) new_private_ip = all_local_ips [ @eth_interface ] if [ "ec2" , "euca" , "gce" ] . include? ( @options [ 'infrastructure' ] ) new_public_ip = HelperFunctions . get_public_ip_from_metadata_service ( ) else new_public_ip = new_private_ip end old_public_ip = @my_public_ip old_private_ip = @my_private_ip @nodes . each { | node | if node . public_ip == old_public_ip node . public_ip = new_public_ip end if node . private_ip == old_private_ip node . private_ip = new_private_ip end } if @options [ 'hostname' ] == old_public_ip @options [ 'hostname' ] = new_public_ip end unless is_cloud? nodes = JSON . load ( @options [ 'ips' ] ) nodes . each { | node | if node [ 'ip' ] == old_private_ip node [ 'ip' ] == new_private_ip end } @options [ 'ips' ] = JSON . dump ( nodes ) end @app_info_map . each { | _app_id , app_info | if app_info [ 'appengine' ] . nil? next end changed = false new_app_info = [ ] app_info [ 'appengine' ] . each { | location | host , port = location . split ( ":" ) if host == old_private_ip host = new_private_ip changed = true end new_app_info << "#{host}:#{port}" if changed app_info [ 'appengine' ] = new_app_info end } } @all_stats = [ ] @my_public_ip = new_public_ip @my_private_ip = new_private_ip end
Updates all instance variables stored within the AppController with the new
public and private IP addreses of this machine.
Updates all instance variables stored within the AppController with the new public and private IP addreses of this machine .
# First, find out this machine's private IP address. If multiple eth devices # are present, use the same one we used last time. # Next, find out this machine's public IP address. In a cloud deployment, we # have to rely on the metadata server, while in a cluster deployment, it's # the same as the private IP. # Finally, replace anywhere that the old public or private IP addresses were # used with the new one.