Example #1
0
    def _CreateSubnetwork(self, messages, subnet_ref, network_ref, args):
        subnetwork = super(CreateAlpha,
                           self)._CreateSubnetwork(messages, subnet_ref,
                                                   network_ref, args)

        if (args.enable_flow_logs is not None
                or args.aggregation_interval is not None
                or args.flow_sampling is not None
                or args.metadata is not None):
            log_config = messages.SubnetworkLogConfig(
                enable=args.enable_flow_logs)
            if args.aggregation_interval:
                log_config.aggregationInterval = (
                    flags.GetLoggingAggregationIntervalArgAlpha(
                        messages).GetEnumForChoice(args.aggregation_interval))
            if args.flow_sampling is not None:
                log_config.flowSampling = args.flow_sampling
            if args.metadata:
                log_config.metadata = flags.GetLoggingMetadataArgAlpha(
                    messages).GetEnumForChoice(args.metadata)
            subnetwork.logConfig = log_config

        if getattr(args, 'role', None):
            subnetwork.role = messages.Subnetwork.RoleValueValuesEnum(
                args.role)

        if args.enable_private_ipv6_access is not None:
            subnetwork.enablePrivateV6Access = args.enable_private_ipv6_access
        if args.private_ipv6_google_access_type is not None:
            subnetwork.privateIpv6GoogleAccess = (
                flags.GetPrivateIpv6GoogleAccessTypeFlagMapper(
                    messages).GetEnumForChoice(
                        args.private_ipv6_google_access_type))

        if args.purpose:
            subnetwork.purpose = messages.Subnetwork.PurposeValueValuesEnum(
                args.purpose)
        if (subnetwork.purpose == messages.Subnetwork.PurposeValueValuesEnum.
                INTERNAL_HTTPS_LOAD_BALANCER):
            # Clear unsupported fields in the subnet resource
            subnetwork.privateIpGoogleAccess = None
            subnetwork.enableFlowLogs = None
            subnetwork.logConfig = None

        return subnetwork
Example #2
0
def _CreateSubnetwork(messages, subnet_ref, network_ref, args,
                      include_alpha_logging, include_beta_logging,
                      include_l7_internal_load_balancing,
                      include_private_ipv6_access):
    """Create the subnet resource."""
    subnetwork = messages.Subnetwork(
        name=subnet_ref.Name(),
        description=args.description,
        network=network_ref.SelfLink(),
        ipCidrRange=args.range,
        privateIpGoogleAccess=args.enable_private_ip_google_access,
        enableFlowLogs=args.enable_flow_logs)

    if include_alpha_logging:
        if (args.enable_flow_logs is not None
                or args.aggregation_interval is not None
                or args.flow_sampling is not None
                or args.metadata is not None):
            log_config = messages.SubnetworkLogConfig(
                enable=args.enable_flow_logs)
            if args.aggregation_interval:
                log_config.aggregationInterval = (
                    flags.GetLoggingAggregationIntervalArgAlpha(
                        messages).GetEnumForChoice(args.aggregation_interval))
            if args.flow_sampling is not None:
                log_config.flowSampling = args.flow_sampling
            if args.metadata:
                log_config.metadata = flags.GetLoggingMetadataArgAlpha(
                    messages).GetEnumForChoice(args.metadata)
            subnetwork.logConfig = log_config
        if getattr(args, 'role', None):
            subnetwork.role = messages.Subnetwork.RoleValueValuesEnum(
                args.role)
    elif include_beta_logging:
        if (args.enable_flow_logs is not None
                or args.logging_aggregation_interval is not None
                or args.logging_flow_sampling is not None
                or args.logging_metadata is not None):
            log_config = messages.SubnetworkLogConfig(
                enable=args.enable_flow_logs)
            if args.logging_aggregation_interval:
                log_config.aggregationInterval = flags.GetLoggingAggregationIntervalArg(
                    messages).GetEnumForChoice(
                        args.logging_aggregation_interval)
            if args.logging_flow_sampling is not None:
                log_config.flowSampling = args.logging_flow_sampling
            if args.logging_metadata:
                log_config.metadata = flags.GetLoggingMetadataArg(
                    messages).GetEnumForChoice(args.logging_metadata)
            subnetwork.logConfig = log_config

    if include_l7_internal_load_balancing:
        if args.purpose:
            subnetwork.purpose = messages.Subnetwork.PurposeValueValuesEnum(
                args.purpose)
        if (subnetwork.purpose == messages.Subnetwork.PurposeValueValuesEnum.
                INTERNAL_HTTPS_LOAD_BALANCER):
            # Clear unsupported fields in the subnet resource
            subnetwork.privateIpGoogleAccess = None
            subnetwork.enableFlowLogs = None
            subnetwork.logConfig = None

    if include_private_ipv6_access:
        if args.enable_private_ipv6_access is not None:
            subnetwork.enablePrivateV6Access = args.enable_private_ipv6_access
        if args.private_ipv6_google_access_type is not None:
            subnetwork.privateIpv6GoogleAccess = (
                flags.GetPrivateIpv6GoogleAccessTypeFlagMapper(
                    messages).GetEnumForChoice(
                        args.private_ipv6_google_access_type))

    return subnetwork
Example #3
0
def _CreateSubnetwork(messages, subnet_ref, network_ref, args,
                      include_alpha_logging,
                      include_l7_internal_load_balancing,
                      include_aggregate_purpose,
                      include_private_service_connect, include_stack_type,
                      include_ipv6_access_type):
    """Create the subnet resource."""
    subnetwork = messages.Subnetwork(
        name=subnet_ref.Name(),
        description=args.description,
        network=network_ref.SelfLink(),
        ipCidrRange=args.range,
        privateIpGoogleAccess=args.enable_private_ip_google_access)

    if (args.enable_flow_logs is not None
            or args.logging_aggregation_interval is not None
            or args.logging_flow_sampling is not None
            or args.logging_metadata is not None
            or args.logging_filter_expr is not None
            or args.logging_metadata_fields is not None):
        log_config = messages.SubnetworkLogConfig(enable=args.enable_flow_logs)
        if args.logging_aggregation_interval:
            log_config.aggregationInterval = flags.GetLoggingAggregationIntervalArg(
                messages).GetEnumForChoice(args.logging_aggregation_interval)
        if args.logging_flow_sampling is not None:
            log_config.flowSampling = args.logging_flow_sampling
        if args.logging_metadata:
            log_config.metadata = flags.GetLoggingMetadataArg(
                messages).GetEnumForChoice(args.logging_metadata)
        if args.logging_filter_expr is not None:
            log_config.filterExpr = args.logging_filter_expr
        if args.logging_metadata_fields is not None:
            log_config.metadataFields = args.logging_metadata_fields
        subnetwork.logConfig = log_config

    if include_alpha_logging:
        if (args.enable_flow_logs is not None
                or args.aggregation_interval is not None
                or args.flow_sampling is not None
                or args.metadata is not None):
            log_config = (subnetwork.logConfig if subnetwork.logConfig
                          is not None else messages.SubnetworkLogConfig(
                              enable=args.enable_flow_logs))
            if args.aggregation_interval:
                log_config.aggregationInterval = (
                    flags.GetLoggingAggregationIntervalArgDeprecated(
                        messages).GetEnumForChoice(args.aggregation_interval))
            if args.flow_sampling is not None:
                log_config.flowSampling = args.flow_sampling
            if args.metadata:
                log_config.metadata = flags.GetLoggingMetadataArgDeprecated(
                    messages).GetEnumForChoice(args.metadata)
            if args.logging_filter_expr is not None:
                log_config.filterExpr = args.logging_filter_expr
            if args.logging_metadata_fields is not None:
                log_config.metadataFields = args.logging_metadata_fields
            subnetwork.logConfig = log_config

    if include_l7_internal_load_balancing:
        if args.purpose:
            subnetwork.purpose = messages.Subnetwork.PurposeValueValuesEnum(
                args.purpose)
        if (subnetwork.purpose == messages.Subnetwork.PurposeValueValuesEnum.
                INTERNAL_HTTPS_LOAD_BALANCER):
            # Clear unsupported fields in the subnet resource
            subnetwork.privateIpGoogleAccess = None
            subnetwork.enableFlowLogs = None
            subnetwork.logConfig = None
        if getattr(args, 'role', None):
            subnetwork.role = messages.Subnetwork.RoleValueValuesEnum(
                args.role)

    # At present aggregate purpose is available only in alpha whereas
    # https_load_balancer is available in Beta. Given Aggregate Purpose Enum
    # is not available in Beta, the code duplication below is necessary.
    if include_aggregate_purpose:
        if args.purpose:
            subnetwork.purpose = messages.Subnetwork.PurposeValueValuesEnum(
                args.purpose)
            if (subnetwork.purpose ==
                    messages.Subnetwork.PurposeValueValuesEnum.AGGREGATE):
                # Clear unsupported fields in the subnet resource
                subnetwork.privateIpGoogleAccess = None
                subnetwork.enableFlowLogs = None
                subnetwork.logConfig = None

    if include_private_service_connect:
        if args.purpose:
            subnetwork.purpose = messages.Subnetwork.PurposeValueValuesEnum(
                args.purpose)
            if (subnetwork.purpose == messages.Subnetwork.
                    PurposeValueValuesEnum.PRIVATE_SERVICE_CONNECT):
                # Clear unsupported fields in the subnet resource
                subnetwork.privateIpGoogleAccess = None
                subnetwork.enableFlowLogs = None
                subnetwork.logConfig = None

    if args.private_ipv6_google_access_type is not None:
        subnetwork.privateIpv6GoogleAccess = (
            flags.GetPrivateIpv6GoogleAccessTypeFlagMapper(
                messages).GetEnumForChoice(
                    args.private_ipv6_google_access_type))

    if include_stack_type and args.stack_type:
        subnetwork.stackType = messages.Subnetwork.StackTypeValueValuesEnum(
            args.stack_type)

    if include_ipv6_access_type and args.ipv6_access_type:
        subnetwork.ipv6AccessType = (
            messages.Subnetwork.Ipv6AccessTypeValueValuesEnum(
                args.ipv6_access_type))

    return subnetwork