Exemplo n.º 1
0
    def release_vessels(self, vessel_handlers):
        """
    <Purpose>
      Releases a set of vessels. A batch wrapper around the Experiment Library
      function run_parallelized, with logging support. Logs log_string as the
      reason for releasing vessels.

    <Arguments>
      vessel_handlers:
        List of vesselhandles of vessels to be released

    <Exceptions>
      None

    <Side Effects>
      None

    <Returns>
      None.
    """
        if len(vessel_handlers) == 0:
            return

        try:
            explib.seattlegeni_release_vessels(self.config["identity"], vessel_handlers)
        except explib.SeattleClearinghouseError, e:
            self.logger.error("Error while releasing vessels: " + str(e))
Exemplo n.º 2
0
    def release_vessels(self, vessel_handlers):
        """
    <Purpose>
      Releases a set of vessels. A batch wrapper around the Experiment Library
      function run_parallelized, with logging support. Logs log_string as the
      reason for releasing vessels.

    <Arguments>
      vessel_handlers:
        List of vesselhandles of vessels to be released

    <Exceptions>
      None

    <Side Effects>
      None

    <Returns>
      None.
    """
        if len(vessel_handlers) == 0:
            return

        try:
            explib.seattlegeni_release_vessels(self.config['identity'],
                                               vessel_handlers)
        except explib.SeattleClearinghouseError, e:
            self.logger.error('Error while releasing vessels: ' + str(e))
Exemplo n.º 3
0
def display_results(reqdict):
  """
  <Purpose>
    Callback function for httpserver_registercallback. Handles requests for
    root webpage, style.css, jquerygmaps.js, and the two map icon .png files
    used in the output webpage.

  <Arguments>
    reqdict:
      A dictionary describing the HTTP request, as per the documentation of
      httpserver.repy.

  <Exceptions>
    Any exceptions thrown by get_latencies() or generate_html().
    IOError if open() or read() fail.

  <Side Effects>
    If output file specified, writes return value of generate_html() to a local
    HTML file. If localhost output specified, hosts return value of
    generate_html() on localhost:1070.
    
  <Returns>
    A dictionary containing request response information, as per the
    documentation of httpserver.repy.
  """
  
  msg = ""
  content_type = ""

  # Handle a request to finish demo
  if reqdict['querydict'] and reqdict['querydict']['action'] \
        and reqdict['querydict']['action'] == 'finish':
    httpserver_stopcallback(CBFUNC_CONTEXT['listenerid'])
    
    # Now that we're done with node-interaction, release them
    experimentlib.seattlegeni_release_vessels(CBFUNC_CONTEXT['identity'], CBFUNC_CONTEXT['vesselhandle_list'])
    print "Vessels released."
    msg = "<html><head><title>Seattle Demo</title></head><body>Demo finished</body></html>"
    content_type = "text/html"

  # Handle a request to view demo
  elif reqdict['path'] == '/':
    # If NODEIPLIST is empty, then die gracefully
    if not NODEIPLIST:
      print "Error: All acquired nodes failed. Please retry."
      sys.exit()
      
    try:
      latency_dict = get_latencies()
      msg = generate_html(latency_dict)
      content_type = "text/html"
    except Exception, e:
      if repr(e).startswith("timeout("):
        raise HttpConnectionError("Socket timed out connecting to host/port.")
      raise
Exemplo n.º 4
0
def release_vessels(vesselhandle_list, log_string):
  """
  <Purpose>
    Releases a set of vessels. A batch wrapper around the Experiment Library
    function run_parallelized, with logging support. Logs log_string as the
    reason for releasing vessels.

    Note on format of log_string:
      Depending on the outcome of the attempted release operation, this
      function appends 'success' or 'failure' to its associated log entry.
      Thus, callers are advised to end the log_string argument in an ellipsis
      (...) to adhere to the logging conventions of this script.
      
      Example: logstring => 'Releasing a few vessels...'

  <Arguments>
    vesselhandle_list
      A list of vesselhandles of vessels to release.
    log_string
      A string describing the reason for vessel release.

  <Exceptions>
    None

  <Side Effects>
    None
    
  <Returns>
    None
  """

  # If vesselhandle_list is empty, do nothing
  if vesselhandle_list:
    # Log the fact that vessel release is occurring
    config['logfile'].write(str(time.time()) + ': ' + log_string)
    config['logfile'].flush()
    try:
      explib.seattlegeni_release_vessels(config['identity'], vesselhandle_list)
    except explib.SeattleGENIError, e:
      config['logfile'].write('failure\n')
      config['logfile'].write('Error was: ' + str(e) + '\n')
    else:
      config['logfile'].write('success\n')
    finally:
def main():

    identity = experimentlib.create_identity_from_key_files(PUBLICKEY_FILENAME, PRIVATEKEY_FILENAME)

    # Get a list of nodes advertising under the public key. Some of these
    # nodes may be unreachable or may have gone offline since they advertised.
    # This won't try to communicate with the actual nodes.
    nodelocation_list = experimentlib.lookup_node_locations_by_identity(identity)

    print("nodelocation_list:" + str(nodelocation_list))

    # Talk to each advertising node to find out which vessels we have on each.
    # We get back a list of dictionaries, where each dictionary describes a
    # vessel. There may be multiple vessels from any single node in this list.
    active_vesselhandle_list = experimentlib.find_vessels_on_nodes(identity, nodelocation_list)

    print("active_vesselhandle_list:" + str(active_vesselhandle_list))

    # Now we want to find out which vessels we've acquired through seattlegeni
    # that are not in our list. We may, for example, want to release those
    # vessels because we consider them unusable.

    try:
        expected_vesselhandle_list = experimentlib.seattlegeni_get_acquired_vessels(identity)

        print("expected_vesselhandle_list:" + str(expected_vesselhandle_list))

        # If we already have enough usable vessels, we're done.
        if len(active_vesselhandle_list) >= MIN_VESSELS_TO_KEEP:
            print(
                "There are already "
                + str(len(active_vesselhandle_list))
                + " active vessels "
                + "and our MIN_VESSELS_TO_KEEP is "
                + str(MIN_VESSELS_TO_KEEP)
            )
            return

        # We assume all of our vessels come from seattlegeni, so if any vessels we
        # should have access to according to seattlegeni aren't accessible or
        # otherwise usable, then release them.
        vesselhandles_to_release = []
        for vesselhandle in expected_vesselhandle_list:
            if vesselhandle not in active_vesselhandle_list:
                vesselhandles_to_release.append(vesselhandle)

        if vesselhandles_to_release:
            print(
                str(len(vesselhandles_to_release))
                + " vessels were inaccessible, so will try to release them:"
                + str(vesselhandles_to_release)
            )
            try:
                experimentlib.seattlegeni_release_vessels(identity, vesselhandles_to_release)
            except experimentlib.SeattleClearinghouseError, e:
                print("Failed to release vessels: " + str(e))
            else:
                print("Vessels successfully released.")

        # Determine the maximum number of vessels we can acquire through seattlegeni.
        max_vessels_allowed = experimentlib.seattlegeni_max_vessels_allowed(identity)
        print("max_vessels_allowed: " + str(max_vessels_allowed))

        # Determine the number of vessels we already have acquired through seattlegeni.
        num_currently_acquired = len(experimentlib.seattlegeni_get_acquired_vessels(identity))
        print("currently_acquired_count: " + str(num_currently_acquired))

        # Let's try to get as close to MIN_VESSELS_TO_KEEP without requesting more
        # than is allowed by this account.
        num_vessels_to_request = min(max_vessels_allowed, MIN_VESSELS_TO_KEEP) - num_currently_acquired

        if num_vessels_to_request <= 0:
            print("This account doesn't have enough vessel credits to request more vessels.")
            return
        else:
            print("Will try to acquire " + str(num_vessels_to_request) + " vessels.")

        vessel_type = experimentlib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_WAN
        acquired_vessels = experimentlib.seattlegeni_acquire_vessels(identity, vessel_type, num_vessels_to_request)

        print("Acquired " + str(num_vessels_to_request) + " vessels: " + str(acquired_vessels))
Exemplo n.º 6
0
    if repr(e).startswith("SeattleClearinghouseError"):
      print """Error: Cannot make secure SSL connection to SeattleGENI
Please make sure that:
  * M2Crypto is installed
  * the current directory contains a valid PEM file containing CA certificates

To run appmap.py without SSL authentication, use the `--insecure` switch. Check documentation for more details."""

      sys.exit()
    
  # Get list of vessels user has previously allocated
  CBFUNC_CONTEXT['vesselhandle_list'] = experimentlib.seattlegeni_get_acquired_vessels(CBFUNC_CONTEXT['identity'])

  if appmap_config['num_nodes'] > 0 and len(CBFUNC_CONTEXT['vesselhandle_list']) > 0:
    # Release any vessels previously acquired from GENI
    experimentlib.seattlegeni_release_vessels(CBFUNC_CONTEXT['identity'], CBFUNC_CONTEXT['vesselhandle_list'])

  if appmap_config['num_nodes'] > 0:
    # Acquire argument number of vessels using seattlegeni interface
    CBFUNC_CONTEXT['vesselhandle_list'] = experimentlib.seattlegeni_acquire_vessels(CBFUNC_CONTEXT['identity'], "wan", int(appmap_config['num_nodes']))

  # If no vessels were acquired, an error occurred and script exits
  if len(CBFUNC_CONTEXT['vesselhandle_list']) == 0:
    print "Error: No vessels acquired. Try rerunning " + sys.argv[0]
    sys.exit()
    
  nodelocation_list = []
  vessel_details = experimentlib.seattlegeni_get_acquired_vessels_details(CBFUNC_CONTEXT['identity'])
  for vessel in vessel_details:
    nodelocation_list.append(vessel["nodelocation"])
def main():

    identity = experimentlib.create_identity_from_key_files(
        PUBLICKEY_FILENAME, PRIVATEKEY_FILENAME)

    # Get a list of nodes advertising under the public key. Some of these
    # nodes may be unreachable or may have gone offline since they advertised.
    # This won't try to communicate with the actual nodes.
    nodelocation_list = experimentlib.lookup_node_locations_by_identity(
        identity)

    print("nodelocation_list:" + str(nodelocation_list))

    # Talk to each advertising node to find out which vessels we have on each.
    # We get back a list of dictionaries, where each dictionary describes a
    # vessel. There may be multiple vessels from any single node in this list.
    active_vesselhandle_list = experimentlib.find_vessels_on_nodes(
        identity, nodelocation_list)

    print("active_vesselhandle_list:" + str(active_vesselhandle_list))

    # Now we want to find out which vessels we've acquired through seattlegeni
    # that are not in our list. We may, for example, want to release those
    # vessels because we consider them unusable.

    try:
        expected_vesselhandle_list = experimentlib.seattlegeni_get_acquired_vessels(
            identity)

        print("expected_vesselhandle_list:" + str(expected_vesselhandle_list))

        # If we already have enough usable vessels, we're done.
        if len(active_vesselhandle_list) >= MIN_VESSELS_TO_KEEP:
            print("There are already " + str(len(active_vesselhandle_list)) +
                  " active vessels " + "and our MIN_VESSELS_TO_KEEP is " +
                  str(MIN_VESSELS_TO_KEEP))
            return

        # We assume all of our vessels come from seattlegeni, so if any vessels we
        # should have access to according to seattlegeni aren't accessible or
        # otherwise usable, then release them.
        vesselhandles_to_release = []
        for vesselhandle in expected_vesselhandle_list:
            if vesselhandle not in active_vesselhandle_list:
                vesselhandles_to_release.append(vesselhandle)

        if vesselhandles_to_release:
            print(
                str(len(vesselhandles_to_release)) +
                " vessels were inaccessible, so will try to release them:" +
                str(vesselhandles_to_release))
            try:
                experimentlib.seattlegeni_release_vessels(
                    identity, vesselhandles_to_release)
            except experimentlib.SeattleClearinghouseError, e:
                print("Failed to release vessels: " + str(e))
            else:
                print("Vessels successfully released.")

        # Determine the maximum number of vessels we can acquire through seattlegeni.
        max_vessels_allowed = experimentlib.seattlegeni_max_vessels_allowed(
            identity)
        print("max_vessels_allowed: " + str(max_vessels_allowed))

        # Determine the number of vessels we already have acquired through seattlegeni.
        num_currently_acquired = len(
            experimentlib.seattlegeni_get_acquired_vessels(identity))
        print("currently_acquired_count: " + str(num_currently_acquired))

        # Let's try to get as close to MIN_VESSELS_TO_KEEP without requesting more
        # than is allowed by this account.
        num_vessels_to_request = min(
            max_vessels_allowed, MIN_VESSELS_TO_KEEP) - num_currently_acquired

        if num_vessels_to_request <= 0:
            print(
                "This account doesn't have enough vessel credits to request more vessels."
            )
            return
        else:
            print("Will try to acquire " + str(num_vessels_to_request) +
                  " vessels.")

        vessel_type = experimentlib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_WAN
        acquired_vessels = experimentlib.seattlegeni_acquire_vessels(
            identity, vessel_type, num_vessels_to_request)

        print("Acquired " + str(num_vessels_to_request) + " vessels: " +
              str(acquired_vessels))