code: def _allocate_address(self, instance):
          
          connection = self._connect()
          free_addresses = [ ip for ip in connection.get_all_addresses() if not ip.instance_id]
          if not free_addresses:
              try:
                  address = connection.allocate_address()
              except Exception as ex:
                  log.error("Unable to allocate a public IP address to instance `%s`",
                            instance.id)
                  return None
  
          try:
              address = free_addresses.pop()
              instance.use_ip(address)
              return address.public_ip
          except Exception as ex:
              log.error("Unable to associate IP address %s to instance `%s`",
                        address, instance.id)
              return None
docs: Allocates a free public ip address to the given instance
  
          :param instance: instance to assign address to
          :type instance: py:class:`boto.ec2.instance.Reservation`
  
          :return: public ip address