Exemple #1
0
def _Run(args, holder, include_alpha_logging, include_beta_logging,
         include_l7_internal_load_balancing, include_private_ipv6_access):
    """Issues a list of requests necessary for adding a subnetwork."""
    client = holder.client

    network_ref = network_flags.NetworkArgumentForOtherResource(
        'The network to which the subnetwork belongs.').ResolveAsResource(
            args, holder.resources)
    subnet_ref = flags.SubnetworkArgument().ResolveAsResource(
        args,
        holder.resources,
        scope_lister=compute_flags.GetDefaultScopeLister(client))

    subnetwork = _CreateSubnetwork(client.messages, subnet_ref, network_ref,
                                   args, include_alpha_logging,
                                   include_beta_logging,
                                   include_l7_internal_load_balancing,
                                   include_private_ipv6_access)
    request = client.messages.ComputeSubnetworksInsertRequest(
        subnetwork=subnetwork,
        region=subnet_ref.region,
        project=subnet_ref.project)

    secondary_ranges = []
    if args.secondary_range:
        for secondary_range in args.secondary_range:
            for range_name, ip_cidr_range in sorted(
                    six.iteritems(secondary_range)):
                secondary_ranges.append(
                    client.messages.SubnetworkSecondaryRange(
                        rangeName=range_name, ipCidrRange=ip_cidr_range))

    request.subnetwork.secondaryIpRanges = secondary_ranges
    return client.MakeRequests([(client.apitools_client.subnetworks, 'Insert',
                                 request)])
Exemple #2
0
  def Args(cls, parser):
    """The command arguments handler.

    Args:
      parser: An argparse.ArgumentParser instance.
    """
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='update')

    flags.AddUpdateArgs(parser)
    def Args(parser):
        SetIamPolicy.SUBNETWORK_ARG = flags.SubnetworkArgument()
        SetIamPolicy.SUBNETWORK_ARG.AddArgument(
            parser, operation_type='set the IAM Policy of')

        parser.add_argument('policy_file',
                            metavar='POLICY_FILE',
                            help="""\
        Path to a local JSON or YAML formatted file containing a valid policy.
        """)
Exemple #4
0
    def Args(cls, parser):
        """The command arguments handler.

    Args:
      parser: An argparse.ArgumentParser instance.
    """
        cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
        cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='update')

        flags.AddUpdateArgs(parser, cls._include_alpha_logging,
                            cls._include_l7_internal_load_balancing,
                            cls._include_private_ipv6_access)
Exemple #5
0
    def Args(cls, parser):
        """The command arguments handler.

    Args:
      parser: An argparse.ArgumentParser instance.
    """
        cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
        cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='update')

        flags.AddUpdateArgs(parser,
                            include_secondary_ranges=True,
                            include_enable_flow_logs=True)
Exemple #6
0
    def Args(cls, parser):
        cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
        cls.SUBNETWORK_ARG.AddArgument(parser)

        parser.add_argument(
            '--prefix-length',
            type=int,
            help=
            ('The new prefix length of the subnet. It must be smaller than the '
             'original and in the private address space 10.0.0.0/8, '
             '172.16.0.0/12 or 192.168.0.0/16 defined in RFC 1918.'),
            required=True)
    def Args(cls, parser):
        cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
        cls.NETWORK_ARG = network_flags.NetworkArgumentForOtherResource(
            'The network to which the subnetwork belongs.')
        cls.SUBNETWORK_ARG.AddArgument(parser)
        cls.NETWORK_ARG.AddArgument(parser)

        parser.add_argument('--description',
                            help='An optional description of this subnetwork.')

        parser.add_argument(
            '--range',
            required=True,
            help='The IP space allocated to this subnetwork in CIDR format.')
Exemple #8
0
  def Args(cls, parser):
    """The command arguments handler.

    Args:
      parser: An argparse.ArgumentParser instance.
    """
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.SUBNETWORK_ARG.AddArgument(parser)

    parser.add_argument(
        '--enable-private-ip-google-access',
        action='store_true',
        default=None,  # Tri-valued, None => do not change.
        help=('Enable/disable access to Google Cloud APIs from this subnet for '
              'instances without a public ip address.'))
Exemple #9
0
def _AddArgs(cls, parser):
    """Add subnetwork create arguments to parser."""
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.NETWORK_ARG = network_flags.NetworkArgumentForOtherResource(
        'The network to which the subnetwork belongs.')
    cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='create')
    cls.NETWORK_ARG.AddArgument(parser)

    parser.add_argument('--description',
                        help='An optional description of this subnetwork.')

    parser.add_argument(
        '--range',
        required=True,
        help='The IP space allocated to this subnetwork in CIDR format.')

    parser.add_argument(
        '--enable-private-ip-google-access',
        action='store_true',
        default=False,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

    parser.add_argument('--secondary-range',
                        type=arg_parsers.ArgDict(min_length=1),
                        action='append',
                        metavar='PROPERTY=VALUE',
                        help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

    parser.add_argument(
        '--enable-flow-logs',
        action='store_true',
        default=None,
        help=(
            'Enable/disable VPC flow logging for this subnet. More information '
            'for VPC flow logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))
Exemple #10
0
def _AddArgs(cls, parser):
    """Add subnetwork create arguments to parser."""
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.NETWORK_ARG = network_flags.NetworkArgumentForOtherResource(
        'The network to which the subnetwork belongs.')
    cls.SUBNETWORK_ARG.AddArgument(parser)
    cls.NETWORK_ARG.AddArgument(parser)

    parser.add_argument('--description',
                        help='An optional description of this subnetwork.')

    parser.add_argument(
        '--range',
        required=True,
        help='The IP space allocated to this subnetwork in CIDR format.')

    parser.add_argument(
        '--enable-private-ip-google-access',
        action='store_true',
        default=False,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))
Exemple #11
0
def _Run(args, holder, include_alpha_logging,
         include_l7_internal_load_balancing, include_global_managed_proxy,
         include_aggregate_purpose, include_private_service_connect, include_l2,
         include_reserved_internal_range):
  """Issues a list of requests necessary for adding a subnetwork."""
  client = holder.client

  network_ref = network_flags.NetworkArgumentForOtherResource(
      'The network to which the subnetwork belongs.').ResolveAsResource(
          args, holder.resources)
  subnet_ref = flags.SubnetworkArgument().ResolveAsResource(
      args,
      holder.resources,
      scope_lister=compute_flags.GetDefaultScopeLister(client))

  subnetwork = _CreateSubnetwork(
      client.messages, subnet_ref, network_ref, args, include_alpha_logging,
      include_l7_internal_load_balancing, include_global_managed_proxy,
      include_aggregate_purpose, include_private_service_connect, include_l2,
      include_reserved_internal_range)
  request = client.messages.ComputeSubnetworksInsertRequest(
      subnetwork=subnetwork,
      region=subnet_ref.region,
      project=subnet_ref.project)

  if include_reserved_internal_range:
    secondary_ranges = subnets_utils.CreateSecondaryRanges(
        client, args.secondary_range,
        args.secondary_range_with_reserved_internal_range)
  else:
    secondary_ranges = subnets_utils.CreateSecondaryRanges(
        client, args.secondary_range, None)

  request.subnetwork.secondaryIpRanges = secondary_ranges
  return client.MakeRequests([(client.apitools_client.subnetworks, 'Insert',
                               request)])
Exemple #12
0
def _AddArgs(cls, parser, include_beta=False, include_alpha=False):
    """Add subnetwork create arguments to parser."""
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.NETWORK_ARG = network_flags.NetworkArgumentForOtherResource(
        'The network to which the subnetwork belongs.')
    cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='create')
    cls.NETWORK_ARG.AddArgument(parser)

    parser.add_argument('--description',
                        help='An optional description of this subnetwork.')

    parser.add_argument(
        '--range',
        required=True,
        help='The IP space allocated to this subnetwork in CIDR format.')

    parser.add_argument(
        '--enable-private-ip-google-access',
        action='store_true',
        default=False,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

    parser.add_argument('--secondary-range',
                        type=arg_parsers.ArgDict(min_length=1),
                        action='append',
                        metavar='PROPERTY=VALUE',
                        help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

    parser.add_argument(
        '--enable-flow-logs',
        action='store_true',
        default=None,
        help=(
            'Enable/disable VPC flow logging for this subnet. More information '
            'for VPC flow logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

    if include_beta:
        messages = apis.GetMessagesModule('compute',
                                          compute_api.COMPUTE_BETA_API_VERSION)

        flags.AddLoggingAggregationInterval(parser, messages)

        parser.add_argument('--logging-flow-sampling',
                            type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                          upper_bound=1.0),
                            help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)

        flags.AddLoggingMetadata(parser, messages)

    if include_alpha:
        messages = apis.GetMessagesModule(
            'compute', compute_api.COMPUTE_ALPHA_API_VERSION)

        parser.add_argument(
            '--purpose',
            choices={
                'PRIVATE':
                'Regular user created or automatically created subnet.',
                'INTERNAL_HTTPS_LOAD_BALANCER':
                'Reserved for Internal HTTP(S) Load Balancing.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help='The purpose of this subnetwork.')

        parser.add_argument(
            '--role',
            choices={
                'ACTIVE': 'The ACTIVE subnet that is currently used.',
                'BACKUP': 'The BACKUP subnet that could be promoted to ACTIVE.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help=
            ('The role of subnetwork. This field is only used when'
             'purpose=INTERNAL_HTTPS_LOAD_BALANCER. The value can be set to '
             'ACTIVE or BACKUP. An ACTIVE subnetwork is one that is currently '
             'being used for Internal HTTP(S) Load Balancing. A BACKUP '
             'subnetwork is one that is ready to be promoted to ACTIVE or is '
             'currently draining.'))

        flags.AddLoggingAggregationIntervalAlpha(parser, messages)

        parser.add_argument('--flow-sampling',
                            type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                          upper_bound=1.0),
                            help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)

        flags.AddLoggingMetadataAlpha(parser, messages)

        parser.add_argument(
            '--enable-private-ipv6-access',
            action='store_true',
            default=None,
            help=('Enable/disable private IPv6 access for the subnet.'))

        GetPrivateIpv6GoogleAccessTypeFlagMapper(
            messages).choice_arg.AddToParser(parser)
def _AddArgs(cls, parser, include_alpha=False):
    """Add subnetwork create arguments to parser."""
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.NETWORK_ARG = network_flags.NetworkArgumentForOtherResource(
        'The network to which the subnetwork belongs.')
    cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='create')
    cls.NETWORK_ARG.AddArgument(parser)

    parser.add_argument('--description',
                        help='An optional description of this subnetwork.')

    parser.add_argument(
        '--range',
        required=True,
        help='The IP space allocated to this subnetwork in CIDR format.')

    parser.add_argument(
        '--enable-private-ip-google-access',
        action='store_true',
        default=False,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

    parser.add_argument('--secondary-range',
                        type=arg_parsers.ArgDict(min_length=1),
                        action='append',
                        metavar='PROPERTY=VALUE',
                        help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

    parser.add_argument(
        '--enable-flow-logs',
        action='store_true',
        default=None,
        help=(
            'Enable/disable VPC flow logging for this subnet. More information '
            'for VPC flow logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

    if include_alpha:
        parser.add_argument(
            '--purpose',
            choices={
                'PRIVATE_RFC_1918':
                'Regular user created or automatically created subnet.',
                'INTERNAL_HTTPS_LOAD_BALANCER':
                'Reserved for Internal HTTP(S) Load Balancing.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help='The purpose of this subnetwork.')

        parser.add_argument(
            '--role',
            choices={
                'ACTIVE': 'The ACTIVE subnet that is currently used.',
                'BACKUP': 'The BACKUP subnet that could be promoted to ACTIVE.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help=
            ('The role of subnetwork. This field is only used when'
             'purpose=INTERNAL_HTTPS_LOAD_BALANCER. The value can be set to '
             'ACTIVE or BACKUP. An ACTIVE subnetwork is one that is currently '
             'being used for Internal HTTP(S) Load Balancing. A BACKUP '
             'subnetwork is one that is ready to be promoted to ACTIVE or is '
             'currently draining.'))
 def Args(parser):
   Describe.SUBNETWORK_ARG = flags.SubnetworkArgument()
   Describe.SUBNETWORK_ARG.AddArgument(parser, operation_type='describe')
Exemple #15
0
def _AddArgs(parser, include_alpha_logging, include_global_managed_proxy,
             include_l7_internal_load_balancing, include_aggregate_purpose,
             include_private_service_connect,
             include_l2, include_private_nat, include_reserved_internal_range,
             api_version):
  """Add subnetwork create arguments to parser."""
  parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT_WITH_IPV6_FIELD)

  flags.SubnetworkArgument().AddArgument(parser, operation_type='create')
  network_flags.NetworkArgumentForOtherResource(
      'The network to which the subnetwork belongs.').AddArgument(parser)

  messages = apis.GetMessagesModule('compute',
                                    compute_api.COMPUTE_GA_API_VERSION)

  parser.add_argument(
      '--description', help='An optional description of this subnetwork.')

  parser.add_argument(
      '--range',
      required=not include_reserved_internal_range,
      help='The IP space allocated to this subnetwork in CIDR format.')

  parser.add_argument(
      '--enable-private-ip-google-access',
      action='store_true',
      default=False,
      help=('Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

  parser.add_argument(
      '--secondary-range',
      type=arg_parsers.ArgDict(min_length=1),
      action='append',
      metavar='PROPERTY=VALUE',
      help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

  parser.add_argument(
      '--enable-flow-logs',
      action='store_true',
      default=None,
      help=('Enable/disable VPC Flow Logs for this subnet. More information '
            'for VPC Flow Logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

  flags.AddLoggingAggregationInterval(parser, messages)
  parser.add_argument(
      '--logging-flow-sampling',
      type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
      help="""\
      Can only be specified if VPC Flow Logs for this subnetwork is
      enabled. The value of the field must be in [0, 1]. Set the sampling rate
      of VPC flow logs within the subnetwork where 1.0 means all collected
      logs are reported and 0.0 means no logs are reported. Default is 0.5
      which means half of all collected logs are reported.
      """)

  parser.add_argument(
      '--logging-filter-expr',
      help="""\
        Can only be specified if VPC Flow Logs for this subnetwork is enabled.
        Export filter used to define which logs should be generated.
        """)
  flags.AddLoggingMetadata(parser, messages)
  parser.add_argument(
      '--logging-metadata-fields',
      type=arg_parsers.ArgList(),
      metavar='METADATA_FIELD',
      default=None,
      help="""\
      Can only be specified if VPC Flow Logs for this subnetwork is enabled
      and "metadata" is set to CUSTOM_METADATA. The comma-separated list of
      metadata fields that should be added to reported logs.
      """)

  if include_alpha_logging:
    messages = apis.GetMessagesModule('compute',
                                      compute_api.COMPUTE_ALPHA_API_VERSION)
    flags.AddLoggingAggregationIntervalDeprecated(parser, messages)
    parser.add_argument(
        '--flow-sampling',
        type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
        help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)
    flags.AddLoggingMetadataDeprecated(parser, messages)

  purpose_choices = {
      'PRIVATE':
          'Regular user created or automatically created subnet.',
      'INTERNAL_HTTPS_LOAD_BALANCER':
          'Reserved for Internal HTTP(S) Load Balancing.',
      'REGIONAL_MANAGED_PROXY':
          'Reserved for Regional HTTP(S) Load Balancing.',
  }

  if include_global_managed_proxy:
    purpose_choices['GLOBAL_MANAGED_PROXY'] = (
        'Reserved for Global HTTP(S) Load Balancing.')

  if include_aggregate_purpose:
    purpose_choices['AGGREGATE'] = (
        'Reserved for Aggregate Ranges used for aggregating '
        'private subnetworks.')

  if include_private_service_connect:
    purpose_choices['PRIVATE_SERVICE_CONNECT'] = (
        'Reserved for Private Service Connect Internal Load Balancing.')

  if include_private_nat:
    purpose_choices['PRIVATE_NAT'] = (
        'Reserved for use as source range for Private NAT.')

  # Subnetwork purpose is introduced with L7ILB feature. Aggregate purpose
  # will have to be enabled for a given release track only after L7ILB feature
  # is enabled for that release track. Hence if include_aggregate_purpose
  # true, this code assumes that L7ILB purpose is enabled.
  if include_l7_internal_load_balancing:
    parser.add_argument(
        '--purpose',
        choices=purpose_choices,
        type=arg_utils.ChoiceToEnumName,
        help='The purpose of this subnetwork.')

  if include_l7_internal_load_balancing:
    if include_global_managed_proxy:
      help_text = (
          'The role of subnetwork. This field is required when the '
          'purpose is set to GLOBAL_MANAGED_PROXY, REGIONAL_MANAGED_PROXY or '
          'INTERNAL_HTTPS_LOAD_BALANCER.')
    else:
      help_text = ('The role of subnetwork. This field is required when the '
                   'purpose is set to REGIONAL_MANAGED_PROXY or '
                   'INTERNAL_HTTPS_LOAD_BALANCER.')

    parser.add_argument(
        '--role',
        choices={
            'ACTIVE': 'The ACTIVE subnet that is currently used.',
            'BACKUP': 'The BACKUP subnet that could be promoted to ACTIVE.'
        },
        type=lambda x: x.replace('-', '_').upper(),
        help=help_text)

  # Add private ipv6 google access enum based on api version.
  messages = apis.GetMessagesModule('compute', api_version)
  GetPrivateIpv6GoogleAccessTypeFlagMapper(messages).choice_arg.AddToParser(
      parser)

  parser.add_argument(
      '--stack-type',
      choices={
          'IPV4_ONLY':
              'New VMs in this subnet will only be assigned IPv4 addresses',
          'IPV4_IPV6':
              'New VMs in this subnet can have both IPv4 and IPv6 addresses'
      },
      type=arg_utils.ChoiceToEnumName,
      help=('The stack type for this subnet. Determines if IPv6 is enabled '
            'on the subnet. If not specified IPV4_ONLY will be used.'))

  ipv6_access_type_choices = {
      'EXTERNAL': 'VMs in this subnet can have external IPv6.',
      'INTERNAL': 'VMs in this subnet can have internal IPv6.'
  }
  parser.add_argument(
      '--ipv6-access-type',
      choices=ipv6_access_type_choices,
      type=arg_utils.ChoiceToEnumName,
      help=('IPv6 access type can be specified only when the subnet is '
            'created, or when the subnet is first updated to have a stack '
            'type of IPV4_IPV6. Once set, the access type is immutable.'))

  parser.display_info.AddCacheUpdater(network_flags.NetworksCompleter)

  if include_l2:
    l2_args = parser.add_group(help='L2 networking specifications.')
    l2_args.add_argument(
        '--enable-l2',
        action='store_true',
        required=True,
        help="""\
        If set to true, enables l2 networking capability on subnetwork.
        """)
    l2_args.add_argument(
        '--vlan',
        type=int,
        metavar='VLAN',
        help="""\
        Specifies ID of the vlan to tag the subnetwork.
        """)

  if include_reserved_internal_range:
    parser.add_argument(
        '--reserved-internal-range',
        help=("""
        If set, the primary IP range of the subnetwork will be
        associated with the given InternalRange resource.

        If --range is set, the subnetwork will only use the given IP range.
        It has to be contained by the IP range defined by the InternalRange resource.

        For example,
        --range=10.0.0.0/24
        --reserved-internal-range //networkconnectivity.googleapis.com/projects/PROJECT/locations/global/internalRanges/RANGE

        If --range is not set, the subnetwork will use the entire IP range
        defined by the InternalRange resource.

        For example, `--reserved-internal-range //networkconnectivity.googleapis.com/projects/PROJECT/locations/global/internalRanges/RANGE`

        """))
    parser.add_argument(
        '--secondary-range-with-reserved-internal-range',
        type=arg_parsers.ArgDict(min_length=1),
        action='append',
        metavar='RANGE_NAME=INTERNAL_RANGE_URL',
        help="""\
         Adds secondary IP ranges that are associated with InternalRange
         resources.

         For example, `--secondary-range-with-reserved-internal-range
         range1=//networkconnectivity.googleapis.com/projects/PROJECT/locations/global/internalRanges/RANGE`
         adds a secondary range with the reserved internal range resource.

         * `RANGE_NAME` - Name of the secondary range.
         * `INTERNAL_RANGE_URL` - `URL of an InternalRange resource.`
        """)
 def Args(parser):
   GetIamPolicy.SUBNETWORK_ARG = flags.SubnetworkArgument()
   GetIamPolicy.SUBNETWORK_ARG.AddArgument(
       parser, operation_type='describe the IAM Policy of')
Exemple #17
0
 def Args(parser):
     Delete.SUBNET_ARG = flags.SubnetworkArgument(plural=True)
     Delete.SUBNET_ARG.AddArgument(parser, operation_type='delete')
Exemple #18
0
 def Args(parser):
   GetIamPolicy.SUBNETWORK_ARG = flags.SubnetworkArgument()
   GetIamPolicy.SUBNETWORK_ARG.AddArgument(
       parser, operation_type='describe the IAM Policy of')
   base.URI_FLAG.RemoveFromParser(parser)
Exemple #19
0
def _AddArgs(cls, parser, include_alpha=False):
    """Add subnetwork create arguments to parser."""
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.NETWORK_ARG = network_flags.NetworkArgumentForOtherResource(
        'The network to which the subnetwork belongs.')
    cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='create')
    cls.NETWORK_ARG.AddArgument(parser)

    parser.add_argument('--description',
                        help='An optional description of this subnetwork.')

    parser.add_argument(
        '--range',
        required=True,
        help='The IP space allocated to this subnetwork in CIDR format.')

    parser.add_argument(
        '--enable-private-ip-google-access',
        action='store_true',
        default=False,
        help=(
            'Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

    parser.add_argument('--secondary-range',
                        type=arg_parsers.ArgDict(min_length=1),
                        action='append',
                        metavar='PROPERTY=VALUE',
                        help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

    parser.add_argument(
        '--enable-flow-logs',
        action='store_true',
        default=None,
        help=(
            'Enable/disable VPC flow logging for this subnet. More information '
            'for VPC flow logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

    if include_alpha:
        parser.add_argument(
            '--purpose',
            choices={
                'PRIVATE_RFC_1918':
                'Regular user created or automatically created subnet.',
                'INTERNAL_HTTPS_LOAD_BALANCER':
                'Reserved for Internal HTTP(S) Load Balancing.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help='The purpose of this subnetwork.')

        parser.add_argument(
            '--role',
            choices={
                'ACTIVE': 'The ACTIVE subnet that is currently used.',
                'BACKUP': 'The BACKUP subnet that could be promoted to ACTIVE.'
            },
            type=lambda x: x.replace('-', '_').upper(),
            help=
            ('The role of subnetwork. This field is only used when'
             'purpose=INTERNAL_HTTPS_LOAD_BALANCER. The value can be set to '
             'ACTIVE or BACKUP. An ACTIVE subnetwork is one that is currently '
             'being used for Internal HTTP(S) Load Balancing. A BACKUP '
             'subnetwork is one that is ready to be promoted to ACTIVE or is '
             'currently draining.'))

        aggregation_interval_argument = base.ChoiceArgument(
            '--aggregation-interval',
            choices=[
                'interval-5-sec', 'interval-30-sec', 'interval-1-min',
                'interval-5-min', 'interval-10-min', 'interval-15-min'
            ],
            help_str="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. Toggles the aggregation interval for collecting flow logs.
        Increasing the interval time will reduce the amount of generated flow
        logs for long lasting connections. Default is an interval of 5 seconds
        per connection.
        """)
        aggregation_interval_argument.AddToParser(parser)

        parser.add_argument('--flow-sampling',
                            type=arg_parsers.BoundedFloat(lower_bound=0.0,
                                                          upper_bound=1.0),
                            help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)

        metadata_argument = base.ChoiceArgument(
            '--metadata',
            choices=['include-all-metadata', 'exclude-all-metadata'],
            help_str="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. Configures whether metadata fields should be added to the
        reported VPC flow logs. Default is to include all metadata.
        """)
        metadata_argument.AddToParser(parser)
Exemple #20
0
 def Args(parser):
     Delete.SUBNET_ARG = flags.SubnetworkArgument(plural=True)
     Delete.SUBNET_ARG.AddArgument(parser, operation_type='delete')
     parser.display_info.AddCacheUpdater(flags.SubnetworksCompleter)
Exemple #21
0
  def Args(cls, parser):
    """The command argument handler."""
    cls.SUBNETWORK_ARG = flags.SubnetworkArgument()
    cls.SUBNETWORK_ARG.AddArgument(parser, operation_type='update')

    flags.AddUpdateArgs(parser, include_alpha=True)
Exemple #22
0
def _AddArgs(parser, include_alpha_logging, include_l7_internal_load_balancing,
             include_private_ipv6_access, include_aggregate_purpose):
  """Add subnetwork create arguments to parser."""
  parser.display_info.AddFormat(flags.DEFAULT_LIST_FORMAT)

  flags.SubnetworkArgument().AddArgument(parser, operation_type='create')
  network_flags.NetworkArgumentForOtherResource(
      'The network to which the subnetwork belongs.').AddArgument(parser)

  messages = apis.GetMessagesModule('compute',
                                    compute_api.COMPUTE_GA_API_VERSION)

  parser.add_argument(
      '--description', help='An optional description of this subnetwork.')

  parser.add_argument(
      '--range',
      required=True,
      help='The IP space allocated to this subnetwork in CIDR format.')

  parser.add_argument(
      '--enable-private-ip-google-access',
      action='store_true',
      default=False,
      help=('Enable/disable access to Google Cloud APIs from this subnet for '
            'instances without a public ip address.'))

  parser.add_argument(
      '--secondary-range',
      type=arg_parsers.ArgDict(min_length=1),
      action='append',
      metavar='PROPERTY=VALUE',
      help="""\
      Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      """)

  parser.add_argument(
      '--enable-flow-logs',
      action='store_true',
      default=None,
      help=('Enable/disable VPC flow logging for this subnet. More information '
            'for VPC flow logs can be found at '
            'https://cloud.google.com/vpc/docs/using-flow-logs.'))

  flags.AddLoggingAggregationInterval(parser, messages)
  parser.add_argument(
      '--logging-flow-sampling',
      type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
      help="""\
      Can only be specified if VPC flow logging for this subnetwork is
      enabled. The value of the field must be in [0, 1]. Set the sampling rate
      of VPC flow logs within the subnetwork where 1.0 means all collected
      logs are reported and 0.0 means no logs are reported. Default is 0.5
      which means half of all collected logs are reported.
      """)

  if include_alpha_logging:
    messages = apis.GetMessagesModule('compute',
                                      compute_api.COMPUTE_ALPHA_API_VERSION)
    flags.AddLoggingAggregationIntervalDeprecated(parser, messages)
    parser.add_argument(
        '--flow-sampling',
        type=arg_parsers.BoundedFloat(lower_bound=0.0, upper_bound=1.0),
        help="""\
        Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        """)
    flags.AddLoggingMetadataDeprecated(parser, messages)

    parser.add_argument(
        '--logging-filter-expr',
        help="""\
        Can only be specified if VPC flow logs for this subnetwork is enabled.
        Export filter used to define which VPC flow logs should be logged.
        """)
    flags.AddLoggingMetadataAlpha(parser, messages)
    parser.add_argument(
        '--logging-metadata-fields',
        type=arg_parsers.ArgList(),
        metavar='METADATA_FIELD',
        default=None,
        help="""\
        Can only be specified if VPC flow logs for this subnetwork is enabled
        and "metadata" is set to CUSTOM_METADATA. The custom list of metadata
        fields that should be added to reported VPC flow logs.
        """)
  else:
    flags.AddLoggingMetadata(parser, messages)

  purpose_choices = {
      'PRIVATE':
          'Regular user created or automatically created subnet.',
      'INTERNAL_HTTPS_LOAD_BALANCER':
          'Reserved for Internal HTTP(S) Load Balancing.',
  }

  if include_aggregate_purpose:
    purpose_choices['AGGREGATE'] = (
        'Reserved for Aggregate Ranges used for aggregating '
        'private subnetworks.')

  # Subnetwork purpose is introduced with L7ILB feature. Aggregate purpose
  # will have to be enabled for a given release track only after L7ILB feature
  # is enabled for that release track. Hence if include_aggregate_purpose
  # true, this code assumes that L7ILB purpose is enabled.
  if include_l7_internal_load_balancing:
    parser.add_argument(
        '--purpose',
        choices=purpose_choices,
        type=arg_utils.ChoiceToEnumName,
        help='The purpose of this subnetwork.')

  if include_l7_internal_load_balancing:
    parser.add_argument(
        '--role',
        choices={
            'ACTIVE': 'The ACTIVE subnet that is currently used.',
            'BACKUP': 'The BACKUP subnet that could be promoted to ACTIVE.'
        },
        type=lambda x: x.replace('-', '_').upper(),
        help=('The role of subnetwork. This field is only used when'
              'purpose=INTERNAL_HTTPS_LOAD_BALANCER. The value can be set to '
              'ACTIVE or BACKUP. An ACTIVE subnetwork is one that is currently '
              'being used for Internal HTTP(S) Load Balancing. A BACKUP '
              'subnetwork is one that is ready to be promoted to ACTIVE or is '
              'currently draining.'))

  if include_private_ipv6_access:
    parser.add_argument(
        '--enable-private-ipv6-access',
        action='store_true',
        default=None,
        help=('Enable/disable private IPv6 access for the subnet.'))

    GetPrivateIpv6GoogleAccessTypeFlagMapper(messages).choice_arg.AddToParser(
        parser)

    parser.add_argument(
        '--private-ipv6-google-access-service-accounts',
        default=None,
        metavar='EMAIL',
        type=arg_parsers.ArgList(min_length=1),
        help="""\
        The service accounts can be used to selectively turn on Private IPv6
        Google Access only on the VMs primary service account matching the
        value.
        """)

  parser.display_info.AddCacheUpdater(network_flags.NetworksCompleter)