@staticmethod
  def InitServerEnvironment():
    global _server_environment

    # Start with options settings.
    is_devbox = options.options.devbox
    is_staging = options.options.is_staging

    # Determine whether running as a staging server if not specified on the command-line.
    if is_staging is None:
      if is_devbox:
        # This is used to skip trying to retrieve AWS metadata and primarily for desktop development.
        is_staging = False
      else:
        # No override has been provided, so dynamically determine which type of instance we're on.

        # Get the AWS/EC2 instance id for the instance this is executing on.
        instance_id = GetAMIMetadata().get('meta-data/instance-id', None)
        if instance_id is None:
          raise ViewfinderConfigurationError(
                "We should have already retrieved the instance id by this point.  " +
                "If running on dev box, use the --devbox option.")

        reservations = None

        # Connect to EC2 and get instance tags.  This is done synchronously as there's nothing else the server
        #   should be doing until this has completed successfully.
        while not reservations:
          try:
            logging.info("Connecting to EC2 to retrieve instance tags")
            ec2conn = boto.connect_ec2(aws_access_key_id=GetSecret('aws_access_key_id'),
                                       aws_secret_access_key=GetSecret('aws_secret_access_key'))
            logging.info("Querying EC2 for instance data for instance: %s" % instance_id)
            reservations = ec2conn.get_all_instances([instance_id, ])
          except Exception  as e:
            logging.warning("Exception while trying to retrieve EC2 instance tags: %s: %s, %s",
                            type(e), e.message, e.args)
            time.sleep(_EC2_TAGS_RETRIEVAL_RETRY_SECS)
          else:
            if reservations is None:
              logging.warning("Empty result while trying to retrieve EC2 instance tags.")
              time.sleep(_EC2_TAGS_RETRIEVAL_RETRY_SECS)

        if len(reservations) != 1:
          raise ViewfinderConfigurationError("Should have gotten one and only one reservation.")
        reservation = reservations[0]
        if len(reservation.instances) != 1:
          raise ViewfinderConfigurationError("There should be one and only one instance in this reservation.")
        instance = reservation.instances[0]
        if instance is None:
          raise ViewfinderConfigurationError("Instance not found in reservation metadata.")
        if instance.__dict__.get('id', None) != instance_id:
          raise ViewfinderConfigurationError(
                "instance id in reservation metadata doesn't match expected value: %s vs. %s." %
                (instance.__dict__.get('id', None), instance_id))

        # Enumerate all the EC2 tags and their values to the log.
        for tagName in instance.__dict__['tags']:
          logging.info("This EC2 Instance Tag[%s]: '%s'" % (tagName, instance.__dict__['tags'][tagName]))

        nodetype = instance.__dict__['tags'].get('NodeType', None)

        logging.info("Retrieved instance tag for NodeType: %s" % nodetype)

        if nodetype == _EC2_TAG_NODETYPE_PRODUCTION:
          is_staging = False
        elif nodetype == _EC2_TAG_NODETYPE_STAGING:
          is_staging = True
        else:
          raise ViewfinderConfigurationError("Invalid EC2 tag for NodeType on this instance.  Tag: %s" % nodetype)

    if is_devbox:
      logging.info("server starting as DevBox instance.")

    if is_staging:
      _server_environment = ServerEnvironment(is_devbox, is_staging)
      logging.info('server starting as Staging instance: %s' % _server_environment.GetHost())
    else:
      _server_environment = ServerEnvironment(is_devbox, is_staging)
      logging.info('server starting as Production instance: %s' % _server_environment.GetHost())

    # Make a record in the log of what revision was last copied to this instance.
    hg_revision = ServerEnvironment.GetHGRevision()
    logging.info("Hg revision: %s" % hg_revision)
Intersect a list of polyline vertices with a rectilinear MODFLOW
dataset/ETHPy150Open viewfinderco/viewfinder/backend/base/environ.py/ServerEnvironment.InitServerEnvironment--crossover with--dataset/ETHPy150Open modflowpy/flopy/flopy/plot/plotutil.py/line_intersect_grid