Exemplo n.º 1
0
def PushMultipleServiceConfigFiles(service_name,
                                   config_files,
                                   is_async,
                                   validate_only=False):
    """Pushes a given set of service configuration files.

  Args:
    service_name: name of the service.
    config_files: a list of ConfigFile message objects.
    is_async: whether to wait for aync operations or not.
    validate_only: whether to perform a validate-only run of the operation
                     or not.

  Returns:
    Full response from the SubmitConfigSource request.

  Raises:
    ServiceDeployErrorException: the SubmitConfigSource API call returned a
      diagnostic with a level of ERROR.
  """
    messages = GetMessagesModule()
    client = GetClientInstance()

    config_source = messages.ConfigSource()
    config_source.files.extend(config_files)

    config_source_request = messages.SubmitConfigSourceRequest(
        configSource=config_source,
        validateOnly=validate_only,
    )
    submit_request = (messages.ServicemanagementServicesConfigsSubmitRequest(
        serviceName=service_name,
        submitConfigSourceRequest=config_source_request,
    ))
    api_response = client.services_configs.Submit(submit_request)
    operation = ProcessOperationResult(api_response, is_async)

    response = operation.get('response', {})
    diagnostics = response.get('diagnostics', [])

    num_errors = 0
    for diagnostic in diagnostics:
        kind = diagnostic.get('kind', '').upper()
        logger = log.error if kind == 'ERROR' else log.warning
        msg = '{l}: {m}'.format(l=diagnostic.get('location'),
                                m=diagnostic.get('message'))
        logger(msg)

        if kind == 'ERROR':
            num_errors += 1

    if num_errors > 0:
        exception_msg = (
            '{0} diagnostic error{1} found in service configuration '
            'deployment. See log for details.').format(
                num_errors, 's' if num_errors > 1 else '')
        raise exceptions.ServiceDeployErrorException(exception_msg)

    return response
Exemplo n.º 2
0
    for diagnostic in diagnostics:
        kind = diagnostic.get('kind', '').upper()
        logger = log.error if kind == 'ERROR' else log.warning
        msg = '{l}: {m}'.format(l=diagnostic.get('location'),
                                m=diagnostic.get('message'))
        logger(msg)

        if kind == 'ERROR':
            num_errors += 1

    if num_errors > 0:
        exception_msg = (
            '{0} diagnostic error{1} found in service configuration '
            'deployment. See log for details.').format(
                num_errors, 's' if num_errors > 1 else '')
        raise exceptions.ServiceDeployErrorException(exception_msg)

    return response


def PushOpenApiServiceConfig(service_name,
                             spec_file_contents,
                             spec_file_path,
                             async,
                             validate_only=False):
    """Pushes a given Open API service configuration.

  Args:
    service_name: name of the service
    spec_file_contents: the contents of the Open API spec file.
    spec_file_path: the path of the Open API spec file.