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:
            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

        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')

        return replacement, cleared_fields
  def _CreateBackendService(self, holder, args, backend_services_ref):
    health_checks = flags.GetHealthCheckUris(args, self, holder.resources)
    enable_cdn = True if args.enable_cdn else None

    return holder.client.messages.BackendService(
        description=args.description,
        name=backend_services_ref.Name(),
        healthChecks=health_checks,
        portName=_ResolvePortName(args),
        protocol=_ResolveProtocol(holder.client.messages, args),
        timeoutSec=args.timeout,
        enableCDN=enable_cdn)
Ejemplo n.º 3
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.description:
            replacement.description = args.description
        elif args.description is not None:
            replacement.description = None

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

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

        if args.port:
            replacement.port = args.port

        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

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

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

        return replacement
Ejemplo n.º 4
0
    def _CreateRegionBackendService(self, args, backend_services_ref):
        health_checks = flags.GetHealthCheckUris(args, self, self.resources)
        if not health_checks:
            raise exceptions.ToolException(
                'At least one health check required.')

        return self.messages.BackendService(
            description=args.description,
            name=backend_services_ref.Name(),
            healthChecks=health_checks,
            loadBalancingScheme=(self.messages.BackendService.
                                 LoadBalancingSchemeValueValuesEnum(
                                     args.load_balancing_scheme)),
            protocol=_ResolveProtocol(self.messages, args, default='TCP'),
            timeoutSec=args.timeout)
  def _CreateRegionBackendService(self, holder, args, backend_services_ref):
    """Creates a regional backend service."""

    health_checks = flags.GetHealthCheckUris(args, self, holder.resources)
    messages = holder.client.messages

    return messages.BackendService(
        description=args.description,
        name=backend_services_ref.Name(),
        healthChecks=health_checks,
        loadBalancingScheme=(
            messages.BackendService.LoadBalancingSchemeValueValuesEnum(
                args.load_balancing_scheme)),
        protocol=_ResolveProtocol(messages, args, default='TCP'),
        timeoutSec=args.timeout)
Ejemplo n.º 6
0
    def _CreateBackendService(self, args, backend_services_ref):
        health_checks = flags.GetHealthCheckUris(args, self, self.resources)
        if not health_checks:
            raise exceptions.ToolException(
                'At least one health check required.')

        enable_cdn = True if args.enable_cdn else None

        return self.messages.BackendService(description=args.description,
                                            name=backend_services_ref.Name(),
                                            healthChecks=health_checks,
                                            port=_ResolvePort(args),
                                            portName=_ResolvePortName(args),
                                            protocol=_ResolveProtocol(
                                                self.messages, args),
                                            timeoutSec=args.timeout,
                                            enableCDN=enable_cdn)
Ejemplo n.º 7
0
    def Modify(self, args, existing):
        replacement = copy.deepcopy(existing)

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

        if args.description:
            replacement.description = args.description
        elif args.description is not None:
            replacement.description = None

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

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

        if args.port:
            replacement.port = args.port

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

        if args.protocol:
            replacement.protocol = (
                self.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 = (
                self.messages.BackendService.SessionAffinityValueValuesEnum(
                    args.session_affinity))

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

        return replacement
Ejemplo n.º 8
0
    def Modify(self, client, resources, args, existing):
        """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 self._support_flexible_cache_step_one:
            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 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)

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

        backend_services_utils.ApplyCdnPolicyArgs(
            client,
            args,
            replacement,
            is_update=True,
            apply_signed_url_cache_max_age=True,
            cleared_fields=cleared_fields,
            support_flexible_cache_step_one=self.
            _support_flexible_cache_step_one,
            support_flexible_cache_step_two=self.
            _support_flexible_cache_step_two,
            support_negative_cache=self._support_negative_cache)

        if self._support_flexible_cache_step_one:
            if (replacement.cdnPolicy is not None
                    and replacement.cdnPolicy.cacheMode
                    and args.enable_cdn is not False):  # pylint: disable=g-bool-id-comparison
                replacement.enableCDN = True

        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)

        return replacement, cleared_fields
Ejemplo n.º 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