Пример #1
0
  def test_convert_fqdn_to_ip(self):
    google_ip = """74.125.224.167
74.125.224.165
74.125.224.161
74.125.224.163
74.125.224.160
74.125.224.166
74.125.224.174
74.125.224.162
74.125.224.169
74.125.224.164
74.125.224.168"""
    (flexmock(utils)
     .should_receive('shell')
     .with_args('dig {0} +short'.format('google.com'))
     .and_return(google_ip))

    (flexmock(utils)
     .should_receive('shell')
     .with_args('dig {0} +short'.format('appscale.com'))
     .and_return('107.21.138.175'))

    ip = utils.convert_fqdn_to_ip('google.com')
    self.assertEquals(ip, '74.125.224.167')

    ip = utils.convert_fqdn_to_ip('appscale.com')
    self.assertEquals(ip, '107.21.138.175')

    ip = utils.convert_fqdn_to_ip('1.2.3.4')
    self.assertEquals(ip, '1.2.3.4')

    (flexmock(utils)
     .should_receive('shell')
     .with_args('dig {0} +short'.format('google.com'))
     .reset())
    (flexmock(utils)
     .should_receive('shell')
     .with_args('dig {0} +short'.format('appscale.com'))
     .reset())
Пример #2
0
  def get_ip_addresses(self, all_addresses):
    """
    Extract public IPs and private IPs from a list of IP addresses.
    This method is used to extract the IP addresses from the EC2
    command outputs.

    Args:
      all_addresses A list of IP addresses

    Returns:
      A tuple of the form (public_ips, private_ips)
    """
    if len(all_addresses) % 2 != 0:
      sys.exit('IP address list is not of even length')
    reported_public = []
    reported_private = []
    for index in range(0, len(all_addresses)):
      if index % 2 == 0:
        reported_public.append(all_addresses[index])
      else:
        reported_private.append(all_addresses[index])
    utils.log('Reported public IPs: {0}'.format(reported_public))
    utils.log('Reported private IPs: {0}'.format(reported_private))

    actual_public = []
    actual_private = []
    for index in range(0, len(reported_public)):
      public = reported_public[index]
      private = reported_private[index]
      if public != '0.0.0.0' and private != '0.0.0.0':
        actual_public.append(public)
        actual_private.append(private)

    for index in range(0, len(actual_private)):
      ip = utils.convert_fqdn_to_ip(actual_private[index])
      if ip is not None:
        actual_private[index] = ip
      else:
        utils.log('Failed to convert {0} into an IP'.format(actual_private[index]))

    return actual_public, actual_private