
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddl
mZ ddlmZ dd	lmZ dd
lmZ d Z G d dej"                        Zy)zList usable subnets command.    )absolute_import)division)unicode_literals)
exceptions)util)base)log)
properties)	resourcesc                 r    t         j                  j                  | j                  d      j	                         S )Nzcompute.subnetworks)r   REGISTRYParseRelativeName
subnetworkSelfLink)resources    ,lib/surface/container/subnets/list_usable.py_GetUriFunctionr      s/    				-	-h.A.A.C
EEMXZP    c                   &    e Zd ZdZed        Zd Zy)
ListUsablea  List subnets usable for cluster creation in a specific project.

      Usability of subnetworks for cluster creation is dependent on the IAM
      policy of the project's Google Kubernetes Engine Service Account. Use the
      `--project` flag to evaluate subnet usability in different projects. This
      list may differ from the list returned by Google Compute Engine's
      `list-usable` command, which returns subnets only usable by the caller.

      To show subnetworks shared from a Shared-VPC host project, use
      `--network-project` to specify the project that owns the subnetworks.

      ## EXAMPLES

      List all subnetworks usable for cluster creation in project `my-project`.

          $ {command} \
            --project=my-project

      List all subnetworks existing in project `my-shared-host-project` usable
      for cluster creation in project `my-service-project`.

          $ {command} \
             --project=my-service-project \
             --network-project=my-shared-host-project

  c                 .   | j                  dd       dj                  dj                  g d            }| j                  j	                  |       | j                  j                  t               dd	d
ddddi}| j                  j                  |       y)zRegister flags for this command.

    Args:
      parser: An argparse.ArgumentParser-like object. It is mocked out in order
        to capture some information, but behaves like an ArgumentParser.
    z--network-projectz        The project owning the subnetworks returned. This field is translated
        into the expression `networkProjectId=[PROJECT_ID]` and ANDed to
        the `--filter` flag value.

        Defaults to the *--project* value.
)helpztable({fields}),)z$subnetwork.segment(-5):label=PROJECTz#subnetwork.segment(-3):label=REGIONz!network.segment(-1):label=NETWORKz#subnetwork.segment(-1):label=SUBNETzipCidrRange:label=RANGEz
        secondaryIpRanges:format="table[box](
          rangeName:label=SECONDARY_RANGE_NAME,
          ipCidrRange,
          status.enum(UsableSubnetworkSecondaryRange.Status)
        )":label=SECONDARY_RANGES
        )fieldsz+UsableSubnetworkSecondaryRange.Status::enumUnknownzusable for pods or serviceszusable for serviceszusable for podsunusable)UNKNOWNUNUSEDIN_USE_SERVICEIN_USE_SHAREABLE_PODIN_USE_MANAGED_PODN)add_argumentformatjoindisplay_info	AddFormat
AddUriFuncr   AddTransforms)parserdisplay_formatstatus_enums      r   ArgszListUsable.Args@   s        '--SXX ? 6- N !!.1
""?3 	6 33$5",8
K %%k2r   c                 6   | j                   d   }|j                  j                  dt        j                  j
                  j                  j                               }	 |j                  ||j                  |j                        j                  }t               }|D ]<  }|j                  }|s||vs|j                  |       t        j                   |       > |S # t"        j$                  $ r)}t'        j(                  |t*        j,                        d}~ww xY w)zThis is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    api_adapterzcontainer.projects)
projectsIdN)contextregistryCreater
   VALUEScoreproject	GetOrFailListUsableSubnetsnetwork_projectfiltersubnetworkssetstatusMessageaddr	   warningapitools_exceptions	HttpErrorr   HttpExceptionr   HTTP_ERROR_FORMAT)	selfargsadapterproject_refrespmsg_setsubnetmsgerrors	            r   RunzListUsable.Runm   s     ll=)G""))$$))11;;= * ?KD&&{D4H4H'+{{44?K  g&""3g%
++c

++c
	 
 k(( D$$UD,B,BCCDs%   AC -C 2)C D/$DDN)__name__
__module____qualname____doc__staticmethodr,   rL    r   r   r   r   $   s"    6 *3 *3XDr   r   N)rP   
__future__r   r   r   apitools.base.pyr   r?    googlecloudsdk.api_lib.containerr   googlecloudsdk.callioper   googlecloudsdk.corer	   r
   r   r   ListCommandr   rR   r   r   <module>rY      sD    # &  ' > 1 ( . # * )P
eD!! eDr   