Esempio n. 1
0
def set_num_instances_async(instances, module=None, version=None):
    """Returns a UserRPC to set the number of instances on the module version.

  Args:
    instances: The number of instances to set.
    module: The module to set the number of instances for, if None the current
      module will be used.
    version: The version set the number of instances for, if None the current
      version will be used.

  Returns:
    A UserRPC to set the number of instances on the module version.
  """
    def _ResultHook(rpc):
        mapped_errors = [
            modules_service_pb.ModulesServiceError.INVALID_VERSION,
            modules_service_pb.ModulesServiceError.TRANSIENT_ERROR
        ]
        _CheckAsyncResult(rpc, mapped_errors, {})

    if not isinstance(instances, six.integer_types):
        raise TypeError("'instances' arg must be of type long or int.")
    request = modules_service_pb.SetNumInstancesRequest()
    request.set_instances(instances)
    if module:
        request.set_module(module)
    if version:
        request.set_version(version)
    response = modules_service_pb.SetNumInstancesResponse()
    return _MakeAsyncCall('SetNumInstances', request, response, _ResultHook)
Esempio n. 2
0
def set_num_instances(instances, module=None, version=None):
    """Sets the number of instances on the module and version.

  Args:
    instances: The number of instances to set.
    module: The module to set the number of instances for, if None the current
      module will be used.
    version: The version set the number of instances for, if None the current
      version will be used.

  Raises:
    InvalidVersionError if the given module version isn't valid, TransientError
    if there is an issue persisting the change.
    TypeError if the given instances type is invalid.
  """
    if not isinstance(instances, (long, int)):
        raise TypeError("'instances' arg must be of type long or int.")
    req = modules_service_pb.SetNumInstancesRequest()
    req.set_instances(instances)
    if module:
        req.set_module(module)
    if version:
        req.set_version(version)
    resp = modules_service_pb.SetNumInstancesResponse()
    try:
        apiproxy_stub_map.MakeSyncCall('modules', 'SetNumInstances', 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.TRANSIENT_ERROR):
            raise TransientError()
        else:
            raise Error()