Пример #1
0
def acquire_wan_vessels(lockserver_handle, geniuser, vesselcount):
  """
  <Purpose>
    Acquire 'wan' vessels for a geniuser.
  <Arguments>
    lockserver_handle
      The lockserver handle to be used for obtaining node locks.
    geniuser
      The GeniUser the vessels should be acquired for.
    vesselcount
      The number of vessels to acquire.
  <Exceptions>
    UnableToAcquireResourcesError
      If either the user does not not have enough vessel credits to acquire the
      number of vessels they requested or if there are not enough vessels
      available to fulfill the request.
  <Side Effects>
    The vessels are acquired for the user. The database has been updated to
    reflect the acquisition.
  <Returns>
    A list of the vessels that were acquired.
  """
  
  # Get a randomized list of vessels where no two vessels are on the same subnet.
  vessel_list = maindb.get_available_wan_vessels(geniuser, vesselcount)
  
  return _acquire_vessels_from_list(lockserver_handle, geniuser, vesselcount, vessel_list)
Пример #2
0
def acquire_wan_vessels(lockserver_handle, geniuser, vesselcount):
    """
  <Purpose>
    Acquire 'wan' vessels for a geniuser.
  <Arguments>
    lockserver_handle
      The lockserver handle to be used for obtaining node locks.
    geniuser
      The GeniUser the vessels should be acquired for.
    vesselcount
      The number of vessels to acquire.
  <Exceptions>
    UnableToAcquireResourcesError
      If either the user does not not have enough vessel credits to acquire the
      number of vessels they requested or if there are not enough vessels
      available to fulfill the request.
  <Side Effects>
    The vessels are acquired for the user. The database has been updated to
    reflect the acquisition.
  <Returns>
    A list of the vessels that were acquired.
  """

    # Get a randomized list of vessels where no two vessels are on the same subnet.
    vessel_list = maindb.get_available_wan_vessels(geniuser, vesselcount)

    return _acquire_vessels_from_list(lockserver_handle, geniuser, vesselcount,
                                      vessel_list)
Пример #3
0
    def test_get_available_wan_vessels(self):

        # Create a user who will be doing the acquiring.
        user = maindb.create_user("testuser", "password",
                                  "*****@*****.**", "affiliation", "1 2",
                                  "2 2 2", "3 4")

        userport = user.usable_vessel_port

        # We choose the numbers of each type of node in a way that helps ensure
        # that we don't accidentally pass the test if something is going wrong.

        # We will get one vessel on each created node for each port in portlist
        # and there will be only that one port on the vessel.
        portlist = [userport - 1, userport, userport + 1]

        create_nodes_on_same_subnet(3, portlist)
        create_nodes_on_different_subnets(7, portlist)
        create_nat_nodes(13, portlist)

        # Request 0 vessels, make sure it raises a AssertionError.
        self.assertRaises(AssertionError, maindb.get_available_wan_vessels,
                          user, 0)

        # Request a negative number of vessels, make sure it raises a AssertionError.
        self.assertRaises(AssertionError, maindb.get_available_wan_vessels,
                          user, -1)

        # We expect there to be 8 available rand vessels (one vessel on each node
        # non-nat node on each subnet, and there are 8 subnets).

        # Request 1 vessel, make sure we get back more than 1 potential vessels.
        vessel_list = maindb.get_available_wan_vessels(user, 1)
        self.assertTrue(len(vessel_list) > 1)

        # Request 5 vessels, make sure we get back more than 5 potential vessels.
        vessel_list = maindb.get_available_wan_vessels(user, 5)
        self.assertTrue(len(vessel_list) > 5)

        # Request 8 vessels, make sure we get back all 8 vessels we expect.
        vessel_list = maindb.get_available_wan_vessels(user, 8)
        self.assertEqual(8, len(vessel_list))

        # Request 9 vessels, make sure we get an exception.
        self.assertRaises(UnableToAcquireResourcesError,
                          maindb.get_available_wan_vessels, user, 9)
    def test_get_available_wan_vessels(self):

        # Create a user who will be doing the acquiring.
        user = maindb.create_user("testuser", "password", "*****@*****.**", "affiliation", "1 2", "2 2 2", "3 4")

        userport = user.usable_vessel_port

        # We choose the numbers of each type of node in a way that helps ensure
        # that we don't accidentally pass the test if something is going wrong.

        # We will get one vessel on each created node for each port in portlist
        # and there will be only that one port on the vessel.
        portlist = [userport - 1, userport, userport + 1]

        create_nodes_on_same_subnet(3, portlist)
        create_nodes_on_different_subnets(7, portlist)
        create_nat_nodes(13, portlist)

        # Request 0 vessels, make sure it raises a AssertionError.
        self.assertRaises(AssertionError, maindb.get_available_wan_vessels, user, 0)

        # Request a negative number of vessels, make sure it raises a AssertionError.
        self.assertRaises(AssertionError, maindb.get_available_wan_vessels, user, -1)

        # We expect there to be 8 available rand vessels (one vessel on each node
        # non-nat node on each subnet, and there are 8 subnets).

        # Request 1 vessel, make sure we get back more than 1 potential vessels.
        vessel_list = maindb.get_available_wan_vessels(user, 1)
        self.assertTrue(len(vessel_list) > 1)

        # Request 5 vessels, make sure we get back more than 5 potential vessels.
        vessel_list = maindb.get_available_wan_vessels(user, 5)
        self.assertTrue(len(vessel_list) > 5)

        # Request 8 vessels, make sure we get back all 8 vessels we expect.
        vessel_list = maindb.get_available_wan_vessels(user, 8)
        self.assertEqual(8, len(vessel_list))

        # Request 9 vessels, make sure we get an exception.
        self.assertRaises(UnableToAcquireResourcesError, maindb.get_available_wan_vessels, user, 9)
Пример #5
0
# Modules to make available for convenience so the names are available in the
# ipython shell. Just a lazy way to not have to execute these lines individually
# in a new shell.
from clearinghouse.website.control import interface
from clearinghouse.common.api import backend
from clearinghouse.common.api import keydb
from clearinghouse.common.api import keygen
from clearinghouse.common.api import lockserver
from clearinghouse.common.api import maindb
from clearinghouse.common.api import nodemanager

# grab a few objects to play with
g = maindb.get_user('user0')
(v, v2) = maindb.get_available_wan_vessels(g, 2)[:2]