Exemple #1
0
def DisplayProposedDeployment(app, project, app_config, version, promote):
    """Prints the details of the proposed deployment.

  Args:
    app: Application resource for the current application (required if any
      services are deployed, otherwise ignored).
    project: The name of the current project.
    app_config: yaml_parsing.AppConfigSet, The configurations being deployed.
    version: The version identifier of the application to be deployed.
    promote: Whether the newly deployed version will receive all traffic
      (this affects deployed URLs).

  Returns:
    dict (str->str), a mapping of service names to deployed service URLs

  This includes information on to-be-deployed services (including service name,
  version number, and deployed URLs) as well as configurations.
  """
    deployed_urls = {}

    if app_config.Services():
        if app is None:
            raise TypeError(
                'If services are deployed, must provide `app` parameter.')
        deploy_messages = []
        for service, info in app_config.Services().iteritems():
            use_ssl = deploy_command_util.UseSsl(info.parsed.handlers)
            deploy_message = DEPLOY_MESSAGE_TEMPLATE.format(
                project=project,
                service=service,
                version=version,
                file=console_attr.DecodeFromInput(info.file))

            url = deploy_command_util.GetAppHostname(
                app=app,
                service=info.module,
                version=None if promote else version,
                use_ssl=use_ssl)
            deployed_urls[service] = url
            deploy_message += DEPLOYED_URL_TEMPLATE.format(url=url)
            if not promote:
                default_url = deploy_command_util.GetAppHostname(
                    app=app, service=info.module, use_ssl=use_ssl)
                deploy_message += PROMOTE_MESSAGE_TEMPLATE.format(
                    default_url=default_url)
            deploy_messages.append(deploy_message)
        fmt = 'list[title="You are about to deploy the following services:"]'
        resource_printer.Print(deploy_messages, fmt, out=log.status)

    if app_config.Configs():
        fmt = 'list[title="You are about to deploy the following configurations:"]'
        resource_printer.Print([
            u'{0}/{1}  (from [{2}])'.format(project, c.config, c.file)
            for c in app_config.Configs().values()
        ],
                               fmt,
                               out=log.status)

    return deployed_urls
def _DisplayProposedDeployment(project, app_config, version, promote):
    """Prints the details of the proposed deployment.

  Args:
    project: the name of the current project
    app_config: the application configuration to be deployed
    version: the version identifier of the application to be deployed
    promote: whether the newly deployed version will receive all traffic
      (this affects deployed URLs)

  Returns:
    dict (str->str), a mapping of module names to deployed module URLs

  This includes information on to-be-deployed modules (including module name,
  version number, and deployed URLs) as well as configurations.
  """
    # TODO(user): Have modules and configs be able to print themselves.  We
    # do this right now because we actually need to pass a yaml file to appcfg.
    # Until we can make a call with the correct values for project and version
    # it is weird to override those values in the yaml parsing code (because
    # it does not carry through to the actual file contents).
    deployed_urls = {}
    if app_config.Modules():
        printer = console_io.ListPrinter(
            'You are about to deploy the following modules:')
        deploy_messages = []
        for module, info in app_config.Modules().iteritems():
            use_ssl = deploy_command_util.UseSsl(info.parsed.handlers)
            version = None if promote else version
            if ':' in project:
                deploy_message = DEPLOY_MESSAGE_DOMAIN_SCOPED_TEMPLATE.format(
                    project=project, module=module, file=info.file)
            else:
                url = deploy_command_util.GetAppHostname(project,
                                                         module=info.module,
                                                         version=version,
                                                         use_ssl=use_ssl)
                deployed_urls[module] = url
                deploy_message = DEPLOY_MESSAGE_TEMPLATE.format(
                    project=project, module=module, file=info.file, url=url)
            if not promote:
                default_url = deploy_command_util.GetAppHostname(
                    project, module=info.module, use_ssl=use_ssl)
                deploy_message += PROMOTE_MESSAGE.format(
                    default_url=default_url)
            deploy_messages.append(deploy_message)
        printer.Print(deploy_messages, output_stream=log.status)

    if app_config.Configs():
        printer = console_io.ListPrinter(
            'You are about to deploy the following configurations:')
        printer.Print([
            '{0}/{1}  (from [{2}])'.format(project, c.config, c.file)
            for c in app_config.Configs().values()
        ],
                      output_stream=log.status)

    return deployed_urls
Exemple #3
0
def DisplayProposedDeployment(app, project, services, configs, version,
                              promote, service_account):
    """Prints the details of the proposed deployment.

  Args:
    app: Application resource for the current application (required if any
      services are deployed, otherwise ignored).
    project: The name of the current project.
    services: [deployables.Service], The services being deployed.
    configs: [yaml_parsing.ConfigYamlInfo], The configurations being updated.
    version: The version identifier of the application to be deployed.
    promote: Whether the newly deployed version will receive all traffic
      (this affects deployed URLs).
    service_account: The service account that the deployed version will run as.

  Returns:
    dict (str->str), a mapping of service names to deployed service URLs

  This includes information on to-be-deployed services (including service name,
  version number, and deployed URLs) as well as configurations.
  """
    deployed_urls = {}
    if services:
        if app is None:
            raise TypeError(
                'If services are deployed, must provide `app` parameter.')
        log.status.Print('Services to deploy:\n')
        for service in services:
            use_ssl = deploy_command_util.UseSsl(service.service_info)
            url = deploy_command_util.GetAppHostname(
                app=app,
                service=service.service_id,
                version=None if promote else version,
                use_ssl=use_ssl)
            deployed_urls[service.service_id] = url
            log.status.Print(
                DEPLOY_SERVICE_MESSAGE_TEMPLATE.format(
                    project=project,
                    service=service.service_id,
                    version=version,
                    descriptor=service.descriptor,
                    source=service.source,
                    url=url,
                    service_account=service_account if service_account else
                    'App Engine default service account'))
            if not promote:
                default_url = deploy_command_util.GetAppHostname(
                    app=app, service=service.service_id, use_ssl=use_ssl)
                log.status.Print(
                    PROMOTE_MESSAGE_TEMPLATE.format(default_url=default_url))

    if configs:
        DisplayProposedConfigDeployments(project, configs)

    return deployed_urls
Exemple #4
0
def DisplayProposedDeployment(app,
                              project,
                              services,
                              configs,
                              version,
                              promote,
                              service_account,
                              api_version='v1'):
  """Prints the details of the proposed deployment.

  Args:
    app: Application resource for the current application (required if any
      services are deployed, otherwise ignored).
    project: The name of the current project.
    services: [deployables.Service], The services being deployed.
    configs: [yaml_parsing.ConfigYamlInfo], The configurations being updated.
    version: The version identifier of the application to be deployed.
    promote: Whether the newly deployed version will receive all traffic
      (this affects deployed URLs).
    service_account: The service account that the deployed version will run as.
    api_version: Version of the yaml file parser to use. Use 'v1' by default.

  Returns:
    dict (str->str), a mapping of service names to deployed service URLs

  This includes information on to-be-deployed services (including service name,
  version number, and deployed URLs) as well as configurations.
  """
  deployed_urls = {}
  if services:
    if app is None:
      raise TypeError('If services are deployed, must provide `app` parameter.')
    log.status.Print('Services to deploy:\n')
    for service in services:
      use_ssl = deploy_command_util.UseSsl(service.service_info)
      url = deploy_command_util.GetAppHostname(
          app=app, service=service.service_id,
          version=None if promote else version, use_ssl=use_ssl)
      deployed_urls[service.service_id] = url
      schema_parser = convert_yaml.GetSchemaParser(api_version)
      service_account_from_yaml = ''
      try:
        service_account_from_yaml = schema_parser.ConvertValue(
            service.service_info.parsed.ToDict()).get('serviceAccount', None)
      except ValueError as e:
        raise exceptions.ConfigError(
            '[{f}] could not be converted to the App Engine configuration '
            'format for the following reason: {msg}'.format(
                f=service.service_info, msg=six.text_type(e)))
      display_service_account = 'App Engine default service account'
      if service_account:
        display_service_account = service_account
      elif service_account_from_yaml:
        display_service_account = service_account_from_yaml
      log.status.Print(
          DEPLOY_SERVICE_MESSAGE_TEMPLATE.format(
              project=project,
              service=service.service_id,
              version=version,
              descriptor=service.descriptor,
              source=service.source,
              url=url,
              service_account=display_service_account))
      if not promote:
        default_url = deploy_command_util.GetAppHostname(
            app=app, service=service.service_id, use_ssl=use_ssl)
        log.status.Print(PROMOTE_MESSAGE_TEMPLATE.format(
            default_url=default_url))

  if configs:
    DisplayProposedConfigDeployments(project, configs)

  return deployed_urls