Esempio n. 1
0
def renew_all_vessels(geniuser):
    """
  <Purpose>
    Extend the expiration dates of vessels acquired by a user.
  <Arguments>
    geniuser
      The GeniUser whose vessels are to be renewed.
  <Exceptions>
    InvalidRequestError
      If the user has no acquired vessels.
    InsufficientUserResourcesError
      If the user is currently over their limit of acquired resources.
  <Side Effects>
    All vessels acquired by the user at the time of this function all are
    renewed to the maximum time vessels can be acquired for, regardless of
    their previous individual expiration times.
  <Returns>
    None
  """
    # We get the list of vessels without holding a lock. An acquisition
    # request or other request could sneak in after we get the vessel list but
    # before we hold the lock. I'm not going to worry about this because it won't
    # lead to data integrity. At worst the user could get an error about not
    # being able to renew all vessels.

    # Get a list of all vessels acquired by the user.
    vessel_list = maindb.get_acquired_vessels(geniuser)

    if not vessel_list:
        raise InvalidRequestError("You have no vessels and so nothing to renew.")

    renew_vessels(geniuser, vessel_list)
Esempio n. 2
0
def release_all_vessels(geniuser):
    """
  <Purpose>
    Release all vessels that have been acquired by the user.
  <Arguments>
    geniuser
      The GeniUser who is to have their vessels released.
  <Exceptions>
    None
  <Side Effects>
    All of the user's acquired vessels at the time of this function call
    have been released. This function does not guarantee that the user has
    no acquired vessels at the time that it returns, though.
  <Returns>
    None
  """
    # We get the list of vessels without holding a lock. An acquisition
    # request or other request could sneak in after we get the vessel list but
    # before we hold the lock. I'm not going to worry about this because it won't
    # lead to data integrity. At worst the user could get an error about not
    # being able to release all vessels.

    # Get a list of all vessels acquired by the user.
    vessel_list = maindb.get_acquired_vessels(geniuser)

    if not vessel_list:
        raise InvalidRequestError("You have no vessels and so nothing to release.")

    release_vessels(geniuser, vessel_list)
Esempio n. 3
0
def get_available_vessel_credits(geniuser):
    """
  <Purpose>
    Determine the number vessels the user is allowed to acquire at the moment
    (that is, the total vessel credits they have minus the number of vessels
    they have acquired).
  <Arguments>
    geniuser
      The GeniUser whose available vessel credit count is wanted.
  <Exceptions>
    None
  <Side Effects>
    None
  <Returns>
    The maximum number of vessels the user is allowed to acquire at this
    moment without exceeding the total number they are allowed to acquire.
  """
    assert_geniuser(geniuser)

    max_allowed_vessels = maindb.get_user_total_vessel_credits(geniuser)
    acquired_vessel_count = len(maindb.get_acquired_vessels(geniuser))

    if acquired_vessel_count >= max_allowed_vessels:
        return 0
    else:
        return max_allowed_vessels - acquired_vessel_count
Esempio n. 4
0
def release_all_vessels(geniuser):
  """
  <Purpose>
    Release all vessels that have been acquired by the user.
  <Arguments>
    geniuser
      The GeniUser who is to have their vessels released.
  <Exceptions>
    None
  <Side Effects>
    All of the user's acquired vessels at the time of this function call
    have been released. This function does not guarantee that the user has
    no acquired vessels at the time that it returns, though.
  <Returns>
    None
  """
  # We get the list of vessels without holding a lock. An acquisition
  # request or other request could sneak in after we get the vessel list but
  # before we hold the lock. I'm not going to worry about this because it won't
  # lead to data integrity. At worst the user could get an error about not
  # being able to release all vessels.

  # Get a list of all vessels acquired by the user.
  vessel_list = maindb.get_acquired_vessels(geniuser)
  
  if not vessel_list:
    raise InvalidRequestError("You have no vessels and so nothing to release.")
  
  release_vessels(geniuser, vessel_list)
Esempio n. 5
0
def get_available_vessel_credits(geniuser):
  """
  <Purpose>
    Determine the number vessels the user is allowed to acquire at the moment
    (that is, the total vessel credits they have minus the number of vessels
    they have acquired).
  <Arguments>
    geniuser
      The GeniUser whose available vessel credit count is wanted.
  <Exceptions>
    None
  <Side Effects>
    None
  <Returns>
    The maximum number of vessels the user is allowed to acquire at this
    moment without exceeding the total number they are allowed to acquire.
  """
  assert_geniuser(geniuser)
  
  max_allowed_vessels = maindb.get_user_total_vessel_credits(geniuser)
  acquired_vessel_count = len(maindb.get_acquired_vessels(geniuser))
  
  if acquired_vessel_count >= max_allowed_vessels:
    return 0
  else:
    return max_allowed_vessels - acquired_vessel_count
Esempio n. 6
0
def renew_all_vessels(geniuser):
  """
  <Purpose>
    Extend the expiration dates of vessels acquired by a user.
  <Arguments>
    geniuser
      The GeniUser whose vessels are to be renewed.
  <Exceptions>
    InvalidRequestError
      If the user has no acquired vessels.
    InsufficientUserResourcesError
      If the user is currently over their limit of acquired resources.
  <Side Effects>
    All vessels acquired by the user at the time of this function all are
    renewed to the maximum time vessels can be acquired for, regardless of
    their previous individual expiration times.
  <Returns>
    None
  """
  # We get the list of vessels without holding a lock. An acquisition
  # request or other request could sneak in after we get the vessel list but
  # before we hold the lock. I'm not going to worry about this because it won't
  # lead to data integrity. At worst the user could get an error about not
  # being able to renew all vessels.
    
  # Get a list of all vessels acquired by the user.
  vessel_list = maindb.get_acquired_vessels(geniuser)
  
  if not vessel_list:
    raise InvalidRequestError("You have no vessels and so nothing to renew.")
  
  renew_vessels(geniuser, vessel_list)
def ban_user_and_remove_vessels(username):

    try:
        geniuser = maindb.get_user(username, allow_inactive=True)
    except DoesNotExistError:
        print "No such user: %s." % username
        sys.exit(1)

    # Lock the user.
    lockserver_handle = lockserver.create_lockserver_handle()
    lockserver.lock_user(lockserver_handle, geniuser.username)

    try:
        if geniuser.is_active:
            geniuser.is_active = False
            geniuser.save()
            print "This account has been set to inactive (banned)."
        else:
            print "This account is already inactive (banned)."

        acquired_vessels = maindb.get_acquired_vessels(geniuser)
        if not acquired_vessels:
            print "No acquired vessels to stop/remove access to."
        else:
            print "Vessels acquired by this user: %s" % acquired_vessels
            print "Indicating to the backend to release %s vessels." % len(
                acquired_vessels)
            vessels.release_vessels(lockserver_handle, geniuser,
                                    acquired_vessels)
            print "Release indicated. Monitoring db to see if the backend cleaned them up."
            while True:
                for vessel in acquired_vessels[:]:
                    updated_vessel = maindb.get_vessel(
                        vessel.node.node_identifier, vessel.name)
                    if vessel.node.is_broken or not vessel.node.is_active:
                        print "Node %s is broken or inactive, so backend won't contact it." % vessel.node
                        acquired_vessels.remove(vessel)
                        continue

                    if updated_vessel.is_dirty:
                        print "Vessel %s has not been cleaned up yet." % updated_vessel
                    else:
                        print "Vessel %s has been cleaned up." % updated_vessel
                        acquired_vessels.remove(vessel)

                if not acquired_vessels:
                    print "All vessels have been cleaned up."
                    break
                else:
                    print "%s vessels remain to be cleaned up." % len(
                        acquired_vessels)

                print "Sleeping 10 seconds."
                time.sleep(10)

    finally:
        # Unlock the user.
        lockserver.unlock_user(lockserver_handle, geniuser.username)
        lockserver.destroy_lockserver_handle(lockserver_handle)
def ban_user_and_remove_vessels(username):

  try:
    geniuser = maindb.get_user(username, allow_inactive=True)
  except DoesNotExistError:
    print "No such user: %s." % username
    sys.exit(1)

  # Lock the user.
  lockserver_handle = lockserver.create_lockserver_handle()
  lockserver.lock_user(lockserver_handle, geniuser.username)

  try:
    if geniuser.is_active:
      geniuser.is_active = False
      geniuser.save()
      print "This account has been set to inactive (banned)."
    else:
      print "This account is already inactive (banned)."

    acquired_vessels = maindb.get_acquired_vessels(geniuser)
    if not acquired_vessels:
      print "No acquired vessels to stop/remove access to."
    else:
      print "Vessels acquired by this user: %s" % acquired_vessels
      print "Indicating to the backend to release %s vessels." % len(acquired_vessels)
      vessels.release_vessels(lockserver_handle, geniuser, acquired_vessels)
      print "Release indicated. Monitoring db to see if the backend cleaned them up."
      while True:
        for vessel in acquired_vessels[:]:
          updated_vessel = maindb.get_vessel(vessel.node.node_identifier, vessel.name)
          if vessel.node.is_broken or not vessel.node.is_active:
            print "Node %s is broken or inactive, so backend won't contact it." % vessel.node
            acquired_vessels.remove(vessel)
            continue

          if updated_vessel.is_dirty:
            print "Vessel %s has not been cleaned up yet." % updated_vessel
          else:
            print "Vessel %s has been cleaned up." % updated_vessel
            acquired_vessels.remove(vessel)

        if not acquired_vessels:
          print "All vessels have been cleaned up."
          break
        else:
          print "%s vessels remain to be cleaned up." % len(acquired_vessels)

        print "Sleeping 10 seconds."
        time.sleep(10)

  finally:
    # Unlock the user.
    lockserver.unlock_user(lockserver_handle, geniuser.username)
    lockserver.destroy_lockserver_handle(lockserver_handle)
Esempio n. 9
0
def get_vessel_acquisition_counts_by_user():

  # Set the log level high enough so that we don't produce a bunch of logging
  # output due to the logging decorators.
  initial_log_level = log.loglevel
  log.set_log_level(log.LOG_LEVEL_INFO)
  
  vessel_acquisition_dict = {}
  
  for user in GeniUser.objects.all():
    acquired_vessels = maindb.get_acquired_vessels(user)
    if len(acquired_vessels) > 0:
      vessel_acquisition_dict[user.username] = len(acquired_vessels)
      
  # Restore the original log level.
  log.set_log_level(initial_log_level)
      
  return vessel_acquisition_dict
Esempio n. 10
0
def get_acquired_vessels(geniuser):
    """
  <Purpose>
    Gets a list of vessels that have been acquired by the user.
  <Arguments>
    user
      A GeniUser object of the user who is assigned to the vessels.
  <Exceptions>
    None
  <Side Effects>
    None
  <Returns>
    A list of Vessel objects for the vessels that have been acquired by the
    user.
  """
    assert_geniuser(geniuser)

    # This is read-only, so not locking the user.
    return maindb.get_acquired_vessels(geniuser)
Esempio n. 11
0
def get_acquired_vessels(geniuser):
  """
  <Purpose>
    Gets a list of vessels that have been acquired by the user.
  <Arguments>
    user
      A GeniUser object of the user who is assigned to the vessels.
  <Exceptions>
    None
  <Side Effects>
    None
  <Returns>
    A list of Vessel objects for the vessels that have been acquired by the
    user.
  """
  assert_geniuser(geniuser)
  
  # This is read-only, so not locking the user.
  return maindb.get_acquired_vessels(geniuser)