Beispiel #1
0
def main(appmap_config):
  # Set SSL security level and warn user if running without SSL
  experimentlib.SEATTLECLEARINGHOUSE_ALLOW_SSL_INSECURE = appmap_config['allow_ssl_insecure']
  if appmap_config['allow_ssl_insecure']:
    print "Running without secure SSL connection to SeattleGENI"
  
  # Get GENI user identity object and port
  CBFUNC_CONTEXT['identity'] = experimentlib.create_identity_from_key_files(appmap_config['geni_username'] + ".publickey", appmap_config['geni_username'] + ".privatekey")

  # If --insecure switch not used, attempt a secure SSL connection to
  # SeattleGENI. If SeattleClearinghouseError exception thrown, print warning.
  try:
    CBFUNC_CONTEXT['geniport'] = experimentlib.seattlegeni_user_port(CBFUNC_CONTEXT['identity'])
  except Exception, e:
    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()
Beispiel #2
0
    def __init__(self,
                 geni_username,
                 vessel_count,
                 vessel_type,
                 program_filename,
                 log_filename=None):
        """
    <Purpose>
      Initializes an instance of Overlord for the deployment of an arbitrary service.
      Populates the instance's configuration dictionary, which can be accessed from
      the object if data is needed for the run() function

    <Arguments>
      geni_username
        SeattleGENI username. Used to locate and handle public and private key
        files.
      vesselcount
        The number of vessels on which to deploy.
      vesseltype
        The type of vessel to acquire, based on the SEATTLECLEARINGHOUSE_VESSEL_TYPE_*
        constants within experimentlib.py
      program_filename
        The filename of the program to deploy and monitor on vessels.
      log_filename
        The file the user wants overlord to log to. If None, logs directly to
        console

    <Exceptions>
      ValueError
        Raised if argument vesseltype doesn't match one of the experimentlib
        SEATTLECLEARINGHOUSE_VESSEL_TYPE_* constants, if argument program file does not
        exist, or if argument number of vessels on which to deploy exceeds the
        user's number of vessel credits.

    <Side Effects>
      Initializes certain global variables.
      Removes 'stop' file from directory if it exists
      Sets the functions that makes up run() to the default methods listed at the
      end of the code.
    
    <Returns>
      None
    """
        # If a stop file still exists, delete it for the user
        if os.path.isfile("./stop"):
            os.remove(os.path.expanduser("./stop"))

        # List of valid vessel types.
        vessel_types = [
            explib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_WAN,
            explib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_LAN,
            explib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_NAT,
            explib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_RAND
        ]

        if vessel_type not in vessel_types:
            raise ValueError(
                "Invalid vessel type specified. Argument 'vessel_type' must be one of "
                +
                "the SEATTLECLEARINGHOUSE_VESSEL_TYPE_* constants defined in 'experimentlib.py'"
            )

        self.config['vessel_type'] = vessel_type

        # If a program file isn't passed, assume user will handle the issue
        if program_filename:
            # Verify that program file exists
            if not os.path.isfile(program_filename):
                raise ValueError("Specified program file '" +
                                 program_filename + "' does not exist")

            self.config['program_filename'] = program_filename

        # Setup explib identity object and GENI details
        self.config['identity'] = explib.create_identity_from_key_files(
            geni_username + '.publickey', geni_username + '.privatekey')
        self.config['geni_port'] = explib.seattlegeni_user_port(
            self.config['identity'])

        # Ensure that the user has enough credits to acquire the specified number of vessels.
        num_vessel_credits = explib.seattlegeni_max_vessels_allowed(
            self.config['identity'])

        if vessel_count > num_vessel_credits:
            raise ValueError(
                "Invalid number of vessels specified. The number of deployed vessels must "
                +
                "be less than or equal to the user's number of vessel credits."
            )

        self.config['vessel_count'] = vessel_count

        # Set up the logger according to passed arguments
        if log_filename:
            # Add the file logger.
            fileLog = logging.FileHandler(log_filename, 'w')
            fileLog.setFormatter(
                logging.Formatter('%(asctime)s %(levelname)-8s %(message)s',
                                  '%Y-%m-%d %H:%M:%S'))
            self.logger.addHandler(fileLog)
        else:
            # Add the console logger.
            consoleLog = logging.StreamHandler()
            consoleLog.setFormatter(
                logging.Formatter('%(asctime)s %(levelname)-8s %(message)s',
                                  '%H:%M:%S'))
            self.logger.addHandler(consoleLog)

        # Setting the functions of 'run' to default
        self.init_overlord_func = default_init_overlord
        self.acquire_vessels_func = default_acquire_vessels
        self.init_vessels_func = default_initiate_vessels
        self.remove_vessels_func = default_remove_vessels
        self.maintenance_func = default_maintenance
Beispiel #3
0
def init(geni_username, vesselcount, vesseltype, program_filename):
  """
  <Purpose>
    Initializes the deployment of an arbitrary service. Populates a global
    configuration dictionary and returns a dict of data that could be required
    by the run() function. init() must be called before the run() function.

    Note on the return dict:
      The return value of init() is meant to contain data that is needed by
      calls to explib.start_vessel() within the run() function. At the time of
      creation of this library, the only such data that is required by
      deployable services is the user's GENI port.

      To add support for services requiring more arguments, simply add the
      necessary data to the dictionary returned by this function.

  <Arguments>
    geni_username
      SeattleGENI username. Used to locate and handle public and private key
      files.
    vesselcount
      The number of vessels on which to deploy.
    vesseltype
      The type of vessel to acquire, based on the SEATTLEGENI_VESSEL_TYPE_*
      constants within experimentlib.py
    program_filename
      The filename of the program to deploy and monitor on vessels.

  <Exceptions>
    ValueError
      Raised if argument vesseltype doesn't match one of the experimentlib
      SEATTLEGENI_VESSEL_TYPE_* constants, if argument program file does not
      exist, or if argument number of vessels on which to deploy exceeds the
      user's number of vessel credits.

  <Side Effects>
    Initializes certain global variables.
    
  <Returns>
    A dictionary containing data that clients might need for running program on
    vessels.
  """
  
  # Fill config dict with argument data
  # Validate vesseltype, based on constants in explib
  if vesseltype not in [explib.SEATTLEGENI_VESSEL_TYPE_WAN,
                        explib.SEATTLEGENI_VESSEL_TYPE_LAN,
                        explib.SEATTLEGENI_VESSEL_TYPE_NAT,
                        explib.SEATTLEGENI_VESSEL_TYPE_RAND]:
    raise ValueError('Invalid vessel type specified. Argument vessel type must be one of the SEATTLEGENI_VESSEL_TYPE_* constants defined in experimentlib.py')
  config['vesseltype'] = vesseltype
    
  # Verify that program file exists
  if not os.path.isfile(program_filename):
    raise ValueError('Specified program file ' + program_filename + ' does not exist')
  config['program_filename'] = program_filename
    
  # Setup explib identity object and GENI details
  config['identity'] = explib.create_identity_from_key_files(
    geni_username + '.publickey',
    geni_username + '.privatekey')
  print config['identity']
  config['geni_port'] = explib.seattlegeni_user_port(config['identity'])
  
  # Validate number of vessels on which to deploy
  num_vslcredits = explib.seattlegeni_max_vessels_allowed(config['identity'])
  if vesselcount > num_vslcredits:
    raise ValueError('Invalid number of vessels specified. The number of deployed vessels must be less than or equal to the user\'s number of vessel credits.')
  config['vesselcount'] = vesselcount


  # Create and populate the return dict
  ret_dict = {
    'geni_port': config['geni_port']
    }

  return ret_dict
Beispiel #4
0
    def __init__(self, geni_username, vessel_count, vessel_type, program_filename, log_filename=None):
        """
    <Purpose>
      Initializes an instance of Overlord for the deployment of an arbitrary service.
      Populates the instance's configuration dictionary, which can be accessed from
      the object if data is needed for the run() function

    <Arguments>
      geni_username
        SeattleGENI username. Used to locate and handle public and private key
        files.
      vesselcount
        The number of vessels on which to deploy.
      vesseltype
        The type of vessel to acquire, based on the SEATTLECLEARINGHOUSE_VESSEL_TYPE_*
        constants within experimentlib.py
      program_filename
        The filename of the program to deploy and monitor on vessels.
      log_filename
        The file the user wants overlord to log to. If None, logs directly to
        console

    <Exceptions>
      ValueError
        Raised if argument vesseltype doesn't match one of the experimentlib
        SEATTLECLEARINGHOUSE_VESSEL_TYPE_* constants, if argument program file does not
        exist, or if argument number of vessels on which to deploy exceeds the
        user's number of vessel credits.

    <Side Effects>
      Initializes certain global variables.
      Removes 'stop' file from directory if it exists
      Sets the functions that makes up run() to the default methods listed at the
      end of the code.
    
    <Returns>
      None
    """
        # If a stop file still exists, delete it for the user
        if os.path.isfile("./stop"):
            os.remove(os.path.expanduser("./stop"))

        # List of valid vessel types.
        vessel_types = [
            explib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_WAN,
            explib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_LAN,
            explib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_NAT,
            explib.SEATTLECLEARINGHOUSE_VESSEL_TYPE_RAND,
        ]

        if vessel_type not in vessel_types:
            raise ValueError(
                "Invalid vessel type specified. Argument 'vessel_type' must be one of "
                + "the SEATTLECLEARINGHOUSE_VESSEL_TYPE_* constants defined in 'experimentlib.py'"
            )

        self.config["vessel_type"] = vessel_type

        # If a program file isn't passed, assume user will handle the issue
        if program_filename:
            # Verify that program file exists
            if not os.path.isfile(program_filename):
                raise ValueError("Specified program file '" + program_filename + "' does not exist")

            self.config["program_filename"] = program_filename

        # Setup explib identity object and GENI details
        self.config["identity"] = explib.create_identity_from_key_files(
            geni_username + ".publickey", geni_username + ".privatekey"
        )
        self.config["geni_port"] = explib.seattlegeni_user_port(self.config["identity"])

        # Ensure that the user has enough credits to acquire the specified number of vessels.
        num_vessel_credits = explib.seattlegeni_max_vessels_allowed(self.config["identity"])

        if vessel_count > num_vessel_credits:
            raise ValueError(
                "Invalid number of vessels specified. The number of deployed vessels must "
                + "be less than or equal to the user's number of vessel credits."
            )

        self.config["vessel_count"] = vessel_count

        # Set up the logger according to passed arguments
        if log_filename:
            # Add the file logger.
            fileLog = logging.FileHandler(log_filename, "w")
            fileLog.setFormatter(logging.Formatter("%(asctime)s %(levelname)-8s %(message)s", "%Y-%m-%d %H:%M:%S"))
            self.logger.addHandler(fileLog)
        else:
            # Add the console logger.
            consoleLog = logging.StreamHandler()
            consoleLog.setFormatter(logging.Formatter("%(asctime)s %(levelname)-8s %(message)s", "%H:%M:%S"))
            self.logger.addHandler(consoleLog)

        # Setting the functions of 'run' to default
        self.init_overlord_func = default_init_overlord
        self.acquire_vessels_func = default_acquire_vessels
        self.init_vessels_func = default_initiate_vessels
        self.remove_vessels_func = default_remove_vessels
        self.maintenance_func = default_maintenance