Пример #1
0
  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client

    backend_service_ref = (
        flags.GLOBAL_REGIONAL_BACKEND_SERVICE_ARG.ResolveAsResource(
            args,
            holder.resources,
            scope_lister=compute_flags.GetDefaultScopeLister(client)))

    data = console_io.ReadFromFileOrStdin(args.source or '-', binary=False)

    try:
      backend_service = export_util.Import(
          message_type=client.messages.BackendService,
          stream=data,
          schema_path=self.GetSchemaPath())
    except yaml_validator.ValidationError as e:
      raise exceptions.ToolException(e.message)

    # Get existing backend service.
    try:
      backend_service_old = backend_services_utils.SendGetRequest(
          client, backend_service_ref)
    except apitools_exceptions.HttpError as error:
      if error.status_code != 404:
        raise error
      # Backend service does not exist, create a new one.
      return self.SendInsertRequest(client, backend_service_ref,
                                    backend_service)

    # No change, do not send requests to server.
    if backend_service_old == backend_service:
      return

    console_io.PromptContinue(
        message=('Backend Service [{0}] will be overwritten.').format(
            backend_service_ref.Name()),
        cancel_on_no=True)

    # populate id and fingerprint fields. These two fields are manually
    # removed from the schema files.
    backend_service.id = backend_service_old.id
    backend_service.fingerprint = backend_service_old.fingerprint

    # Unspecified fields are assumed to be cleared.
    cleared_fields = []
    if hasattr(backend_service, 'securitySettings') is None:
      cleared_fields.append('securitySettings')
    if hasattr(backend_service, 'localityLbPolicy') is None:
      cleared_fields.append('localityLbPolicy')
    if hasattr(backend_service, 'circuitBreakers') is None:
      cleared_fields.append('circuitBreakers')
    if hasattr(backend_service, 'consistentHash') is None:
      cleared_fields.append('consistentHash')
    if hasattr(backend_service, 'outlierDetection') is None:
      cleared_fields.append('outlierDetection')

    with client.apitools_client.IncludeFields(cleared_fields):
      return self.SendPatchRequest(client, backend_service_ref, backend_service)
Пример #2
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        (backend_services_utils.
         IsDefaultRegionalBackendServicePropertyNoneWarnOtherwise())
        backend_service_ref = (
            flags.GLOBAL_REGIONAL_BACKEND_SERVICE_ARG.ResolveAsResource(
                args,
                holder.resources,
                scope_lister=compute_flags.GetDefaultScopeLister(client)))

        backend_service = backend_services_utils.SendGetRequest(
            client, backend_service_ref)

        codecs.RegisterL7TrafficControlCodecs(self.GetApiVersion())
        if args.destination:
            with files.FileWriter(args.destination) as stream:
                export_util.Export(message=backend_service,
                                   stream=stream,
                                   schema_path=self.GetSchemaPath())
        else:
            export_util.Export(message=backend_service,
                               stream=sys.stdout,
                               schema_path=self.GetSchemaPath())