Esempio n. 1
0
def stop_version_async(module=None, version=None):
    """Returns a UserRPC  to stop all instances for the given module version.

  Args:
    module: The module to affect, if None the current module is used.
    version: The version of the given module to affect, if None the current
      version is used.

  Returns:
    A UserRPC  to stop all instances for the given module version.
  """
    def _ResultHook(rpc):
        mapped_errors = [
            modules_service_pb.ModulesServiceError.INVALID_VERSION,
            modules_service_pb.ModulesServiceError.TRANSIENT_ERROR
        ]
        expected_errors = {
            modules_service_pb.ModulesServiceError.UNEXPECTED_STATE:
            'The specified module: %s, version: %s is already stopped.' %
            (module, version)
        }
        _CheckAsyncResult(rpc, mapped_errors, expected_errors)

    request = modules_service_pb.StopModuleRequest()
    if module:
        request.set_module(module)
    if version:
        request.set_version(version)
    response = modules_service_pb.StopModuleResponse()
    return _MakeAsyncCall('StopModule', request, response, _ResultHook)
Esempio n. 2
0
def stop_module(module=None, version=None):
    """Stops all instances for the given version of the module.

  Args:
    module: The module to affect, if None the current module is used.
    version: The version of the given module to affect, if None the current
      version is used.

  Raises:
    InvalidVersionError if the given module version is invalid.
    UnexpectedStateError if the module is already stopped, or cannot be stopped.
    TransientError if there is a problem persisting the change.
  """
    req = modules_service_pb.StopModuleRequest()
    if module:
        req.set_module(module)
    if version:
        req.set_version(version)
    resp = modules_service_pb.StopModuleResponse()
    try:
        apiproxy_stub_map.MakeSyncCall('modules', 'StopModule', req, resp)
    except apiproxy_errors.ApplicationError, e:
        if (e.application_error ==
                modules_service_pb.ModulesServiceError.INVALID_VERSION):
            raise InvalidVersionError()
        elif (e.application_error ==
              modules_service_pb.ModulesServiceError.UNEXPECTED_STATE):
            raise UnexpectedStateError()
        elif (e.application_error ==
              modules_service_pb.ModulesServiceError.TRANSIENT_ERROR):
            raise TransientError()
        else:
            raise Error()