Example #1
0
def get_hostname_async(module=None, version=None, instance=None):
    """Returns a UserRPC whose result contains the hostname to contact a module.

  DEPRECATED. Please use get_hostname instead.

  Args:
    module: Name of module, if None, take module of the current instance.
    version: Name of version, if version is None then either use the version of
      the current instance if that version exists for the target module,
      otherwise use the default version of the target module.
    instance: Instance to construct a hostname for, if instance is None, a
      loadbalanced hostname for the module will be returned.  If the target
      module is not a fixed module, then instance is not considered valid.

  Returns:
    Returns a UserRPC whose result contains a valid canonical hostname that
    can be used to communicate with the given module/version/instance.
    E.g. 0.v1.module5.myapp.appspot.com

  Raises:
    TypeError: If the given instance type is invalid.
  """
    logging.warning('The get_hostname_async function is deprecated. Please '
                    'use get_hostname instead.')

    def _ResultHook(rpc):
        mapped_errors = [
            modules_service_pb.ModulesServiceError.INVALID_MODULE,
            modules_service_pb.ModulesServiceError.INVALID_INSTANCES
        ]
        _CheckAsyncResult(rpc, mapped_errors, [])
        return rpc.response.hostname()

    request = modules_service_pb.GetHostnameRequest()
    if module:
        request.set_module(module)
    if version:
        request.set_version(version)
    if instance:
        if not isinstance(instance, (basestring, long, int)):
            raise TypeError(
                "'instance' arg must be of type basestring, long or int.")
        request.set_instance(str(instance))
    response = modules_service_pb.GetHostnameResponse()
    return _MakeAsyncCall('GetHostname', request, response, _ResultHook)
Example #2
0
def get_hostname(module=None, version=None, instance=None):
    """Returns a hostname to use to contact the module.

  Args:
    module: Name of module, if None, take module of the current instance.
    version: Name of version, if version is None then either use the version of
      the current instance if that version exists for the target module,
      otherwise use the default version of the target module.
    instance: Instance to construct a hostname for, if instance is None, a
      loadbalanced hostname for the module will be returned.  If the target
      module is not a fixed module, then instance is not considered valid.

  Returns:
    A valid canonical hostname that can be used to communicate with the given
    module/version/instance.  E.g. 0.v1.module5.myapp.appspot.com

  Raises:
    InvalidModuleError if the given moduleversion is invalid.
    InvalidInstancesError if the given instance value is invalid.
    TypeError if the given instance type is invalid.
  """
    req = modules_service_pb.GetHostnameRequest()
    if module:
        req.set_module(module)
    if version:
        req.set_version(version)
    if instance:
        if not isinstance(instance, (basestring, long, int)):
            raise TypeError(
                "'instance' arg must be of type basestring, long or int.")
        req.set_instance('%s' % instance)
    resp = modules_service_pb.GetHostnameResponse()
    try:
        apiproxy_stub_map.MakeSyncCall('modules', 'GetHostname', req, resp)
    except apiproxy_errors.ApplicationError, e:
        if (e.application_error ==
                modules_service_pb.ModulesServiceError.INVALID_MODULE):
            raise InvalidModuleError()
        elif (e.application_error ==
              modules_service_pb.ModulesServiceError.INVALID_INSTANCES):
            raise InvalidInstancesError()
        else:
            raise Error()
Example #3
0
def get_hostname(module=None, version=None, instance=None):
    """Returns a hostname to use to contact the module.

  Args:
    module: Name of module, if None, take module of the current instance.
    version: Name of version, if version is None then either use the version of
      the current instance if that version exists for the target module,
      otherwise use the default version of the target module.
    instance: Instance to construct a hostname for, if instance is None, a
      loadbalanced hostname for the module will be returned.  If the target
      module is not a fixed module, then instance is not considered valid.

  Returns:
    A valid canonical hostname that can be used to communicate with the given
    module/version/instance.  E.g. 0.v1.module5.myapp.appspot.com

  Raises:
    InvalidModuleError if the given moduleversion is invalid.
    InvalidInstancesError if the given instance value is invalid.
    TypeError if the given instance type is invalid.
  """
    def _ResultHook(rpc):
        mapped_errors = [
            modules_service_pb.ModulesServiceError.INVALID_MODULE,
            modules_service_pb.ModulesServiceError.INVALID_INSTANCES
        ]
        _CheckAsyncResult(rpc, mapped_errors, [])
        return rpc.response.hostname()

    request = modules_service_pb.GetHostnameRequest()
    if module:
        request.set_module(module)
    if version:
        request.set_version(version)
    if instance:
        if not isinstance(instance, (six.string_types, int)):
            raise TypeError(
                "'instance' arg must be of type basestring, long or int.")
        request.set_instance(str(instance))
    response = modules_service_pb.GetHostnameResponse()
    return _MakeAsyncCall('GetHostname', request, response,
                          _ResultHook).get_result()