import logging


def get_instance_group_manager_to_delete(key):
  """Returns the URL of the instance group manager to delete.

  Args:
    key: ndb.Key for a models.InstanceGroupManager entity.

  Returns:
    The URL of the instance group manager to delete, or None if there isn't one.
  """
  instance_group_manager = key.get()
  if not instance_group_manager:
    logging.warning('InstanceGroupManager does not exist: %s', key)
    return

  if instance_group_manager.instances:
    logging.warning('InstanceGroupManager has active Instances: %s', key)
    return

  if not instance_group_manager.url:
    logging.warning('InstanceGroupManager URL unspecified: %s', key)
    return

  return instance_group_manager.url