示例#1
0
def get_num_instances(module=None, version=None):
    """Return the number of instances that are set for the given module version.

  This is only valid for fixed modules, an error will be raised for
  automatically-scaled modules.  Support for automatically-scaled modules may be
  supported in the future.

  Args:
    module: String containing the name of the module to fetch this info for, if
      None the module of the current instance will be used.
    version: String containing the name of the version to fetch this info for,
      if None the version of the current instance will be used.  If that version
      does not exist in the other module, then an InvalidVersionError is raised.

  Returns:
    The number of instances that are set for the given module version.

  Raises:
    InvalidVersionError on invalid input.
  """
    def _ResultHook(rpc):
        mapped_errors = [
            modules_service_pb.ModulesServiceError.INVALID_VERSION
        ]
        _CheckAsyncResult(rpc, mapped_errors, {})
        return rpc.response.instances()

    request = modules_service_pb.GetNumInstancesRequest()
    if module:
        request.set_module(module)
    if version:
        request.set_version(version)
    response = modules_service_pb.GetNumInstancesResponse()
    return _MakeAsyncCall('GetNumInstances', request, response,
                          _ResultHook).get_result()
示例#2
0
def get_num_instances(module=None, version=None):
    """Return the number of instances that are set for the given module version.

  This is only valid for fixed modules, an error will be raised for
  automatically-scaled modules.  Support for automatically-scaled modules may be
  supported in the future.

  Args:
    module: String containing the name of the module to fetch this info for, if
      None the module of the current instance will be used.
    version: String containing the name of the version to fetch this info for,
      if None the version of the current instance will be used.  If that version
      does not exist in the other module, then an InvalidVersionError is raised.

  Raises:
    InvalidVersionError on invalid input.
  """
    req = modules_service_pb.GetNumInstancesRequest()
    if module:
        req.set_module(module)
    if version:
        req.set_version(version)
    resp = modules_service_pb.GetNumInstancesResponse()
    try:
        apiproxy_stub_map.MakeSyncCall('modules', 'GetNumInstances', req, resp)
    except apiproxy_errors.ApplicationError, e:
        if (e.application_error ==
                modules_service_pb.ModulesServiceError.INVALID_VERSION):
            raise InvalidVersionError()
        else:
            raise Error()
示例#3
0
def get_num_instances_async(module=None, version=None):
    """Returns a UserRPC whose result holds the number of instances for a version.

  DEPRECATED. Please use get_num_instances instead.

  This is only valid for fixed modules, an error will be raised for
  automatically-scaled modules.  Support for automatically-scaled modules may be
  supported in the future.

  Args:
    module: String containing the name of the module to fetch this info for, if
      None the module of the current instance will be used.
    version: String containing the name of the version to fetch this info for,
      if None the version of the current instance will be used.  If that version
      does not exist in the other module, then an InvalidVersionError is raised.

  Returns:
    A UserRPC whose result holds the number of instances for a version.
  """
    logging.warning('The get_num_instances_async function is deprecated. '
                    'Please use get_num_instances instead.')

    def _ResultHook(rpc):
        mapped_errors = [
            modules_service_pb.ModulesServiceError.INVALID_VERSION
        ]
        _CheckAsyncResult(rpc, mapped_errors, {})
        return rpc.response.instances()

    request = modules_service_pb.GetNumInstancesRequest()
    if module:
        request.set_module(module)
    if version:
        request.set_version(version)
    response = modules_service_pb.GetNumInstancesResponse()
    return _MakeAsyncCall('GetNumInstances', request, response, _ResultHook)