예제 #1
0
    def Modify(self, client, resources, args, existing):
        """Modify Backend Service."""
        replacement, cleared_fields = super(UpdateBeta, self).Modify(
            client, resources, args, existing)

        if args.connection_draining_timeout is not None:
            replacement.connectionDraining = client.messages.ConnectionDraining(
                drainingTimeoutSec=args.connection_draining_timeout)
        if args.no_custom_request_headers is not None:
            replacement.customRequestHeaders = []
        if args.custom_request_header is not None:
            replacement.customRequestHeaders = args.custom_request_header

        backend_services_utils.ApplyCdnPolicyArgs(
            client,
            args,
            replacement,
            is_update=True,
            apply_signed_url_cache_max_age=True)

        backend_services_utils.ApplyFailoverPolicyArgs(client.messages, args,
                                                       replacement)

        backend_services_utils.ApplyLogConfigArgs(client.messages, args,
                                                  replacement)

        if not replacement.customRequestHeaders:
            cleared_fields.append('customRequestHeaders')
        return replacement, cleared_fields
    def CreateRegionalRequests(self, holder, args, backend_services_ref):
        if (args.enable_logging is not None
                or args.logging_sample_rate is not None):
            raise exceptions.InvalidArgumentException(
                '--region',
                'cannot specify logging options for regional backend services.'
            )

        backend_service = self._CreateRegionBackendService(
            holder, args, backend_services_ref)
        client = holder.client

        if args.connection_draining_timeout is not None:
            backend_service.connectionDraining = client.messages.ConnectionDraining(
                drainingTimeoutSec=args.connection_draining_timeout)
        if args.IsSpecified('custom_request_header'):
            backend_service.customRequestHeaders = args.custom_request_header
        backend_services_utils.ApplyFailoverPolicyArgs(client.messages, args,
                                                       backend_service)

        if args.session_affinity is not None:
            backend_service.sessionAffinity = (
                client.messages.BackendService.SessionAffinityValueValuesEnum(
                    args.session_affinity))

        if args.port_name is not None:
            backend_service.portName = args.port_name

        request = client.messages.ComputeRegionBackendServicesInsertRequest(
            backendService=backend_service,
            region=backend_services_ref.region,
            project=backend_services_ref.project)

        return [(client.apitools_client.regionBackendServices, 'Insert',
                 request)]
예제 #3
0
    def CreateRegionalRequests(self, holder, args, backend_services_ref):
        if (not args.cache_key_include_host
                or not args.cache_key_include_protocol
                or not args.cache_key_include_query_string
                or args.cache_key_query_string_blacklist is not None
                or args.cache_key_query_string_whitelist is not None):
            raise exceptions.ToolException(
                'Custom cache key flags cannot be used for regional requests.')
        backend_service = self._CreateRegionBackendService(
            holder, args, backend_services_ref)
        client = holder.client

        if args.connection_draining_timeout is not None:
            backend_service.connectionDraining = client.messages.ConnectionDraining(
                drainingTimeoutSec=args.connection_draining_timeout)
        if args.custom_request_header is not None:
            backend_service.customRequestHeaders = args.custom_request_header
        backend_services_utils.ApplyFailoverPolicyArgs(client.messages, args,
                                                       backend_service)

        request = client.messages.ComputeRegionBackendServicesInsertRequest(
            backendService=backend_service,
            region=backend_services_ref.region,
            project=backend_services_ref.project)

        return [(client.apitools_client.regionBackendServices, 'Insert',
                 request)]
예제 #4
0
    def _CreateRegionalRequests(self, holder, args, backend_services_ref):
        """Returns a regional backend service create request."""

        if (not args.cache_key_include_host
                or not args.cache_key_include_protocol
                or not args.cache_key_include_query_string
                or args.cache_key_query_string_blacklist is not None
                or args.cache_key_query_string_whitelist is not None):
            raise exceptions.ToolException(
                'Custom cache key flags cannot be used for regional requests.')

        if (self._support_multinic and args.IsSpecified('network')
                and args.load_balancing_scheme != 'INTERNAL'):
            raise exceptions.InvalidArgumentException(
                '--network',
                'can only specify network for INTERNAL backend service.')

        backend_service = self._CreateRegionBackendService(
            holder, args, backend_services_ref)
        client = holder.client

        if args.connection_draining_timeout is not None:
            backend_service.connectionDraining = client.messages.ConnectionDraining(
                drainingTimeoutSec=args.connection_draining_timeout)
        if args.custom_request_header is not None:
            backend_service.customRequestHeaders = args.custom_request_header
        backend_services_utils.ApplyFailoverPolicyArgs(client.messages, args,
                                                       backend_service,
                                                       self._support_failover)
        if self._support_subsetting:
            backend_services_utils.ApplySubsettingArgs(client, args,
                                                       backend_service)

        if args.session_affinity is not None:
            backend_service.sessionAffinity = (
                client.messages.BackendService.SessionAffinityValueValuesEnum(
                    args.session_affinity))

        if args.port_name is not None:
            backend_service.portName = args.port_name

        if self._support_multinic and args.IsSpecified('network'):
            backend_service.network = flags.NETWORK_ARG.ResolveAsResource(
                args, holder.resources).SelfLink()

        request = client.messages.ComputeRegionBackendServicesInsertRequest(
            backendService=backend_service,
            region=backend_services_ref.region,
            project=backend_services_ref.project)

        return [(client.apitools_client.regionBackendServices, 'Insert',
                 request)]
예제 #5
0
    def _CreateRegionalRequests(self, holder, args, backend_services_ref):
        """Returns a regional backend service create request."""

        if (not args.cache_key_include_host
                or not args.cache_key_include_protocol
                or not args.cache_key_include_query_string
                or args.cache_key_query_string_blacklist is not None
                or args.cache_key_query_string_whitelist is not None):
            raise exceptions.ToolException(
                'Custom cache key flags cannot be used for regional requests.')
        if (self._support_logging
                and (args.IsSpecified('enable_logging')
                     or args.IsSpecified('logging_sample_rate'))):
            raise exceptions.InvalidArgumentException(
                '--region',
                'cannot specify logging options for regional backend services.'
            )

        backend_service = self._CreateRegionBackendService(
            holder, args, backend_services_ref)
        client = holder.client

        if args.connection_draining_timeout is not None:
            backend_service.connectionDraining = client.messages.ConnectionDraining(
                drainingTimeoutSec=args.connection_draining_timeout)
        if args.custom_request_header is not None:
            backend_service.customRequestHeaders = args.custom_request_header
        backend_services_utils.ApplyFailoverPolicyArgs(client.messages, args,
                                                       backend_service,
                                                       self._support_failover)

        if args.session_affinity is not None:
            backend_service.sessionAffinity = (
                client.messages.BackendService.SessionAffinityValueValuesEnum(
                    args.session_affinity))

        if args.port_name is not None:
            backend_service.portName = args.port_name

        request = client.messages.ComputeRegionBackendServicesInsertRequest(
            backendService=backend_service,
            region=backend_services_ref.region,
            project=backend_services_ref.project)

        return [(client.apitools_client.regionBackendServices, 'Insert',
                 request)]
    def Modify(self, client, resources, args, existing):
        """Modify Backend Service."""
        replacement, cleared_fields = super(UpdateAlpha, self).Modify(
            client, resources, args, existing)

        if args.connection_draining_timeout is not None:
            replacement.connectionDraining = client.messages.ConnectionDraining(
                drainingTimeoutSec=args.connection_draining_timeout)

        backend_services_utils.ApplyCdnPolicyArgs(
            client,
            args,
            replacement,
            is_update=True,
            apply_signed_url_cache_max_age=True)

        backend_services_utils.ApplyFailoverPolicyArgs(client.messages, args,
                                                       replacement)

        backend_services_utils.ApplyLogConfigArgs(client.messages, args,
                                                  replacement)

        return replacement, cleared_fields
예제 #7
0
  def Modify(self, client, resources, args, existing):
    """Modify Backend Service."""
    replacement = encoding.CopyProtoMessage(existing)

    if args.connection_draining_timeout is not None:
      replacement.connectionDraining = client.messages.ConnectionDraining(
          drainingTimeoutSec=args.connection_draining_timeout)
    if args.no_custom_request_headers is not None:
      replacement.customRequestHeaders = []
    if args.custom_request_header is not None:
      replacement.customRequestHeaders = args.custom_request_header

    if args.IsSpecified('description'):
      replacement.description = args.description

    health_checks = flags.GetHealthCheckUris(args, self, resources)
    if health_checks or args.IsSpecified('no_health_checks'):
      replacement.healthChecks = health_checks

    if args.timeout:
      replacement.timeoutSec = args.timeout

    if args.port_name:
      replacement.portName = args.port_name

    if args.protocol:
      replacement.protocol = (
          client.messages.BackendService.ProtocolValueValuesEnum(args.protocol))

    if args.enable_cdn is not None:
      replacement.enableCDN = args.enable_cdn

    if args.session_affinity is not None:
      replacement.sessionAffinity = (
          client.messages.BackendService.SessionAffinityValueValuesEnum(
              args.session_affinity))

    if args.affinity_cookie_ttl is not None:
      replacement.affinityCookieTtlSec = args.affinity_cookie_ttl

    if args.connection_draining_timeout is not None:
      replacement.connectionDraining = client.messages.ConnectionDraining(
          drainingTimeoutSec=args.connection_draining_timeout)

    backend_services_utils.ApplyCdnPolicyArgs(
        client,
        args,
        replacement,
        is_update=True,
        apply_signed_url_cache_max_age=True)

    self._ApplyIapArgs(client, args.iap, existing, replacement)

    cleared_fields = []
    if not replacement.customRequestHeaders:
      cleared_fields.append('customRequestHeaders')

    backend_services_utils.ApplyFailoverPolicyArgs(
        client.messages,
        args,
        replacement,
        support_failover=self._support_failover)

    backend_services_utils.ApplyLogConfigArgs(
        client.messages,
        args,
        replacement,
        support_logging=self._support_logging)

    return replacement, cleared_fields
  def _CreateRegionalRequests(self, holder, args, backend_services_ref):
    """Returns a regional backend service create request."""

    if (not args.cache_key_include_host or
        not args.cache_key_include_protocol or
        not args.cache_key_include_query_string or
        args.cache_key_query_string_blacklist is not None or
        args.cache_key_query_string_whitelist is not None):
      raise compute_exceptions.ArgumentError(
          'Custom cache key flags cannot be used for regional requests.')

    if (self._support_multinic and args.IsSpecified('network') and
        args.load_balancing_scheme != 'INTERNAL'):
      raise exceptions.InvalidArgumentException(
          '--network', 'can only specify network for INTERNAL backend service.')

    backend_service = self._CreateRegionBackendService(holder, args,
                                                       backend_services_ref)
    client = holder.client

    if args.connection_draining_timeout is not None:
      backend_service.connectionDraining = client.messages.ConnectionDraining(
          drainingTimeoutSec=args.connection_draining_timeout)
    if args.custom_request_header is not None:
      backend_service.customRequestHeaders = args.custom_request_header
    if args.custom_response_header is not None:
      backend_service.customResponseHeaders = args.custom_response_header
    backend_services_utils.ApplyFailoverPolicyArgs(client.messages, args,
                                                   backend_service,
                                                   self._support_failover)
    if (self._support_advanced_load_balancing and
        args.service_lb_policy is not None):
      backend_service.serviceLbPolicy = reference_utils.BuildServiceLbPolicyUrl(
          project_name=backend_services_ref.project,
          location=backend_services_ref.region,
          policy_name=args.service_lb_policy)

    if args.service_bindings is not None:
      raise exceptions.InvalidArgumentException(
          '--service-bindings',
          'Service bindings are allowed only for global backend services.')

    if self._support_subsetting:
      backend_services_utils.ApplySubsettingArgs(
          client, args, backend_service, self._support_subsetting_subset_size)

    backend_services_utils.ApplyConnectionTrackingPolicyArgs(
        client,
        args,
        backend_service,
        support_strong_session_affinity=self._support_strong_session_affinity)

    self._ApplyIapArgs(client.messages, args.iap, backend_service)

    if args.session_affinity is not None:
      backend_service.sessionAffinity = (
          client.messages.BackendService.SessionAffinityValueValuesEnum(
              args.session_affinity))

    if args.port_name is not None:
      backend_service.portName = args.port_name

    if self._support_multinic and args.IsSpecified('network'):
      backend_service.network = flags.NETWORK_ARG.ResolveAsResource(
          args, holder.resources).SelfLink()

    if self._support_weighted_lb and args.locality_lb_policy is not None:
      backend_service.localityLbPolicy = (
          client.messages.BackendService.LocalityLbPolicyValueValuesEnum(
              args.locality_lb_policy))

    request = client.messages.ComputeRegionBackendServicesInsertRequest(
        backendService=backend_service,
        region=backend_services_ref.region,
        project=backend_services_ref.project)

    return [(client.apitools_client.regionBackendServices, 'Insert', request)]
예제 #9
0
    def Modify(self, client, resources, args, existing, backend_service_ref):
        """Modify Backend Service."""
        replacement = encoding.CopyProtoMessage(existing)
        cleared_fields = []

        if args.connection_draining_timeout is not None:
            replacement.connectionDraining = client.messages.ConnectionDraining(
                drainingTimeoutSec=args.connection_draining_timeout)
        if args.no_custom_request_headers is not None:
            replacement.customRequestHeaders = []
        if args.custom_request_header is not None:
            replacement.customRequestHeaders = args.custom_request_header
        if not replacement.customRequestHeaders:
            cleared_fields.append('customRequestHeaders')

        if args.custom_response_header is not None:
            replacement.customResponseHeaders = args.custom_response_header
        if args.no_custom_response_headers:
            replacement.customResponseHeaders = []
        if not replacement.customResponseHeaders:
            cleared_fields.append('customResponseHeaders')

        if args.IsSpecified('description'):
            replacement.description = args.description

        health_checks = flags.GetHealthCheckUris(args, self, resources)
        if health_checks:
            replacement.healthChecks = health_checks

        if args.IsSpecified('no_health_checks'):
            replacement.healthChecks = []
            cleared_fields.append('healthChecks')

        if args.timeout:
            replacement.timeoutSec = args.timeout

        if args.port_name:
            replacement.portName = args.port_name

        if args.protocol:
            replacement.protocol = (
                client.messages.BackendService.ProtocolValueValuesEnum(
                    args.protocol))

        if args.enable_cdn is not None:
            replacement.enableCDN = args.enable_cdn
        elif not replacement.enableCDN and args.cache_mode:
            # TODO (b/209812994): Replace implicit config change with
            # warning that CDN is disabled and a prompt to enable it with
            # --enable-cdn
            log.warning(
                'Setting a cache mode also enabled Cloud CDN, which was previously '
                + 'disabled. If this was not intended, disable Cloud ' +
                'CDN with `--no-enable-cdn`.')
            replacement.enableCDN = True

        if args.session_affinity is not None:
            replacement.sessionAffinity = (
                client.messages.BackendService.SessionAffinityValueValuesEnum(
                    args.session_affinity))

        if args.affinity_cookie_ttl is not None:
            replacement.affinityCookieTtlSec = args.affinity_cookie_ttl

        if args.connection_draining_timeout is not None:
            replacement.connectionDraining = client.messages.ConnectionDraining(
                drainingTimeoutSec=args.connection_draining_timeout)

        if self._support_subsetting:
            backend_services_utils.ApplySubsettingArgs(
                client, args, replacement,
                self._support_subsetting_subset_size)

        if self._support_weighted_lb and args.locality_lb_policy is not None:
            replacement.localityLbPolicy = (
                client.messages.BackendService.LocalityLbPolicyValueValuesEnum(
                    args.locality_lb_policy))

        backend_services_utils.ApplyCdnPolicyArgs(
            client,
            args,
            replacement,
            is_update=True,
            apply_signed_url_cache_max_age=True,
            cleared_fields=cleared_fields)

        backend_services_utils.ApplyConnectionTrackingPolicyArgs(
            client,
            args,
            replacement,
            support_strong_session_affinity=self.
            _support_strong_session_affinity)

        if self._support_dynamic_compression and args.compression_mode is not None:
            replacement.compressionMode = (
                client.messages.BackendService.CompressionModeValueValuesEnum(
                    args.compression_mode))

        self._ApplyIapArgs(client, args.iap, existing, replacement)

        backend_services_utils.ApplyFailoverPolicyArgs(
            client.messages,
            args,
            replacement,
            support_failover=self._support_failover)

        backend_services_utils.ApplyLogConfigArgs(
            client.messages,
            args,
            replacement,
            support_logging=self._support_logging,
            support_tcp_ssl_logging=self._support_tcp_ssl_logging)

        if self._support_advanced_load_balancing:
            if args.service_lb_policy is not None:
                location = (backend_service_ref.region
                            if backend_service_ref.Collection()
                            == 'compute.regionBackendServices' else 'global')
                replacement.serviceLbPolicy = reference_utils.BuildServiceLbPolicyUrl(
                    project_name=backend_service_ref.project,
                    location=location,
                    policy_name=args.service_lb_policy)
            if args.no_service_lb_policy is not None:
                replacement.serviceLbPolicy = None
                cleared_fields.append('serviceLbPolicy')

        if args.service_bindings is not None:
            replacement.serviceBindings = [
                reference_utils.BuildServiceBindingUrl(
                    backend_service_ref.project, 'global', binding_name)
                for binding_name in args.service_bindings
            ]
        if args.no_service_bindings is not None:
            replacement.serviceBindings = []
            cleared_fields.append('serviceBindings')

        return replacement, cleared_fields