예제 #1
0
def _GetMetricResourceName(consumer, service, metric, unit):
    """Get the metric resource name from metric name and unit.

  Args:
    consumer: The consumer to manage an override for, e.g. "projects/123".
    service: The service to manage an override for.
    metric: The quota metric name.
    unit: The unit of quota metric.

  Raises:
    exceptions.Error: when the limit with given metric and unit is not found.

  Returns:
    The quota override operation.
  """
    metrics = ListQuotaMetrics(consumer, service)
    for m in metrics:
        if m.metric == metric:
            for q in m.consumerQuotaLimits:
                if q.unit == unit:
                    return q.name
    raise exceptions.Error('limit not found with name "%s" and unit "%s".' %
                           (metric, unit))
예제 #2
0
def _ValidateConsumer(consumer):
    for prefix in _VALID_CONSUMER_PREFIX:
        if consumer.startswith(prefix):
            return
    raise exceptions.Error('invalid consumer format "%s".' % consumer)