
                            S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"  SSK#r#Sr$Sr%Sr&Sr'Sr(Sr)Sr* " S S\RV                  5      r, " S S\RZ                  5      r. " S S \/5      r0S\'SS!S!S4S" jr1S\)SS!S!S4S# jr2 " S$ S%\RZ                  5      r3 " S& S'\45      r5S9S( jr6 " S) S*\45      r7 " S+ S,\45      r8 " S- S.\45      r9 " S/ S0\45      r:S1 r;S2 r<S3 r=S9S4 jr>S5 r?S:S6 jr@S7 rAS8 rBg);z3Flags and helpers for the compute related commands.    )absolute_import)division)unicode_literalsN)filter_rewrite)service)actions)arg_parsers)
completers)scope)scope_prompter)
exceptions)log)
properties)	resources)
console_io)resource_projection_spec)textz projects/([^/]+)/global/([^/]+)/z!projects/([^/]+)/regions/([^/]+)/zprojects/([^/]+)/zones/([^/]+)/a  If not specified and the ``compute/zone'' property isn't set, you
might be prompted to select a zone (interactive mode only).

To avoid prompting when this flag is omitted, you can set the
``compute/zone'' property:

  $ gcloud config set compute/zone ZONE

A list of zones can be fetched by running:

  $ gcloud compute zones list

To unset the property, run:

  $ gcloud config unset compute/zone

Alternatively, the zone can be stored in the environment variable
``CLOUDSDK_COMPUTE_ZONE''.
zIf not specified, you might be prompted to select a zone (interactive mode
only).

A list of zones can be fetched by running:

  $ gcloud compute zones list
a  If not specified, you might be prompted to select a region (interactive mode
only).

To avoid prompting when this flag is omitted, you can set the
``compute/region'' property:

  $ gcloud config set compute/region REGION

A list of regions can be fetched by running:

  $ gcloud compute regions list

To unset the property, run:

  $ gcloud config unset compute/region

Alternatively, the region can be stored in the environment
variable ``CLOUDSDK_COMPUTE_REGION''.
zIf not specified, you might be prompted to select a region (interactive mode
only).

A list of regions can be fetched by running:

  $ gcloud compute regions list
c                   $    \ rS rSrSrSrSrSrSrg)ScopeFlagsUsagep   zFEnum representing gcloud flag generation options for ResourceArgument.          N)	__name__
__module____qualname____firstlineno____doc__GENERATE_DEDICATED_SCOPE_FLAGSUSE_EXISTING_SCOPE_FLAGSDONT_USE_SCOPE_FLAGS__static_attributes__r       /lib/googlecloudsdk/command_lib/compute/flags.pyr   r   p   s    N#$ r$   r   c                       \ rS rSrSrg)ScopesFetchingExceptionw   r   N)r   r   r   r   r#   r   r$   r%   r'   r'   w   s    r$   r'   c                       \ rS rSrSrSrg)BadArgumentException{   z2Unhandled error for validating function arguments.r   N)r   r   r   r   r   r#   r   r$   r%   r*   r*   {   s    :r$   r*   Fc	           
      |   SR                  [        R                  " [        U5      S-   U=(       d    SU5      U5      n	Sn
Ub  US-   U
-   n
U R	                  SU
-   U[
        R                  [        R                  " [        R                  R                  R                  5      U=(       d    SR                  X5      S	9  g)
a)  Adds a --zone flag to the given parser.

Args:
  parser: argparse parser.
  resource_type: str, human readable name for the resource type this flag is
    qualifying, for example "instance group".
  operation_type: str, human readable name for the operation, for example
    "update" or "delete".
  flag_prefix: str, flag will be named --{flag_prefix}-zone.
  explanation: str, detailed explanation of the flag.
  help_text: str, help text will be overridden with this value.
  hidden: bool, If True, --zone argument help will be hidden.
  plural: bool, resource_type will be pluralized or not depending on value.
  custom_plural: str, If plural is True then this string will be used as
                      resource types, otherwise resource_types will be
                      pluralized by appending 's'.
zZone of the {0} to {1}.r    zoneN---{0} {1})hidden	completeractionhelp)formatr   	Pluralizeintadd_argumentr
   ZonesCompleterr   StorePropertyr   VALUEScomputer.   parserresource_typeoperation_typeflag_prefixexplanation	help_textr2   pluralcustom_plural
short_help	flag_names              r%   AddZoneFlagrI      s    ( )//
nn
f+/=.B?@NP* )c!I-I
Y))"":#4#4#<#<#A#ABA	((A  Cr$   c	           
      |   SR                  [        R                  " [        U5      S-   U=(       d    SU5      U5      n	Sn
Ub  US-   U
-   n
U R	                  SU
-   [
        R                  [        R                  " [        R                  R                  R                  5      UU=(       d    SR                  X5      S	9  g)
a/  Adds a --region flag to the given parser.

Args:
  parser: argparse parser.
  resource_type: str, human readable name for the resource type this flag is
    qualifying, for example "instance group".
  operation_type: str, human readable name for the operation, for example
    "update" or "delete".
  flag_prefix: str, flag will be named --{flag_prefix}-region.
  explanation: str, detailed explanation of the flag.
  help_text: str, help text will be overridden with this value.
  hidden: bool, If True, --region argument help will be hidden.
  plural: bool, resource_type will be pluralized or not depending on value.
  custom_plural: str, If plural is True then this string will be used as
                      resource types, otherwise resource_types will be
                      pluralized by appending 's'.
zRegion of the {0} to {1}.r   r-   regionNr/   r0   r1   )r3   r4   r2   r5   )r6   r   r7   r8   r9   r
   RegionsCompleterr   r;   r   r<   r=   rK   r>   s              r%   AddRegionFlagrM      s    * +11
nn
f+/=.B?@NP* )c!I-I
Y++"":#4#4#<#<#C#CDA	((A  Cr$   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )UnderSpecifiedResourceError   zARaised when argument is required additional scope to be resolved.c           
         > [        U5      S:  a  SOSn[        [        U ]  SR	                  US   SR                  [        U5      5      US   SR                  U5      5      5        g )Nr   )zone of flags)r-   flagz8Underspecified resource [{3}]. Specify {0}the [{1}] {2}.r   z, )lensuperrO   __init__r6   joinsorted)selfunderspecified_names
flag_namesphrases	__class__s       r%   rV   $UnderSpecifiedResourceError.__init__   s^    &)*o&9"|G	
%t5B	
		&,-
		./
12r$   r   )r   r   r   r   r   rV   r#   __classcell__)r]   s   @r%   rO   rO      s    I2 2r$   rO   c                   "    \ rS rSrSrSS jrSrg)ResourceStub   z6Interface used by scope listing to report scope names.Nc                     Xl         X l        g N)name
deprecated)rY   re   rf   s      r%   rV   ResourceStub.__init__   s    I Or$   )rf   re   rd   r   r   r   r   r   rV   r#   r   r$   r%   ra   ra      s
    >!r$   ra   c                 F  ^^ [         R                  R                  [        R                  " [
        R                  U 5      [         R                  R                  [        R                  " [        R                  U 5      [         R                  R                  S 0mUU4S jnU$ )z&Constructs default zone/region lister.c                     [        SS9/$ )Nr-   )re   )ra   )_s    r%   <lambda>'GetDefaultScopeLister.<locals>.<lambda>   s    21F0Gr$   c                    > T=(       d1    [         R                  R                  R                  R	                  SS9n0 nU  H  nTU   " U5      X4'   M     U$ )NT)required)r   r<   coreprojectGet)scopesrk   prjresultsr   rq   
scope_funcs        r%   Lister%GetDefaultScopeLister.<locals>.Lister   sR    

FZ&&++33777FCG!%(-gn Nr$   )
compute_scope	ScopeEnumZONE	functoolspartialzones_serviceListREGIONregions_serviceGLOBAL)compute_clientrq   rw   rv   s    ` @r%   GetDefaultScopeListerr      st     ""


M..
?$$


O00.
A$$&G* 
-r$   c                       \ rS rSrSrS rSrg)ResourceArgScope   z2Facilitates mapping of scope, flag and collection.c                 R   Xl         U(       a_  UR                  SS5      nU[        R                  R                  L a  UR
                  S-   U-   U l        O)US-   UR
                  -   U l        OUR
                  U l        SU R
                  R                  SS5      -   U l        X0l        g )Nr/   rk   r0   )
scope_enumreplacery   rz   r   rH   rS   
collection)rY   r   rB   r   s       r%   rV   ResourceArgScope.__init__   s    O''S1k	-))00	03.<$s*U__<dnt~~--c377DI Or$   )r   rS   rH   r   Nrh   r   r$   r%   r   r      s
    :!r$   r   c                   R    \ rS rSrSrS rS rS rS rSS jr	S	 r
S
 rS rS rSrg)ResourceArgScopes   z Represents chosen set of scopes.c                     Xl         0 U l        g rd   rB   rs   )rY   rB   s     r%   rV   ResourceArgScopes.__init__   s    "DKr$   c                 J    [        XR                  U5      U R                  U'   g rd   )r   rB   rs   )rY   r   r   s      r%   AddScopeResourceArgScopes.AddScope  s    )%1A1A:NDKKr$   c                     [         R                  " U R                  5       H!  n[        XR                  S5      nUc  M  X#4s  $    g)z8Given argparse args return selected scope and its value.NNN)six
itervaluesrs   getattrrH   )rY   argsresource_scopescope_values       r%   SpecifiedByArgs!ResourceArgScopes.SpecifiedByArgs  s?    ..5D":":DAk		 ** 6 r$   c                    [         R                  " [        U5      (       a)  U R                  [        R
                  R                     S4$ [         R                  " [        U5      (       a)  U R                  [        R
                  R                     S4$ [         R                  " [        U5      (       a)  U R                  [        R
                  R                     S4$ g)z9Given resource value return selected scope and its value.globalrK   r.   r   )rematch_GLOBAL_RELATIVE_PATH_REGEXrs   ry   rz   r   _REGIONAL_RELATIVE_PATH_REGEXr   _ZONAL_RELATIVE_PATH_REGEXr{   )rY   values     r%   SpecifiedByValue"ResourceArgScopes.SpecifiedByValue  s    	xx+U33[[00778(BB	/	7	7[[00778(BB	,e	4	4[[00556>>r$   Nc                     [        U R                  5      S:X  a)  [        [        R                  " U R                  5      5      $ U$ )zBSee if there is no ambiguity even if scope is not known from args.r   )rT   rs   nextr   r   )rY   default_scopes     r%   GetImplicitScope"ResourceArgScopes.GetImplicitScope  s1    
4;;1#..-..r$   c                 T    [        [        R                  " U R                  5      5      $ rd   )iterr   r   rs   rY   s    r%   __iter__ResourceArgScopes.__iter__  s    t{{+,,r$   c                     XR                   ;   $ rd   rs   rY   r   s     r%   __contains__ResourceArgScopes.__contains__"  s    KKr$   c                      U R                   U   $ rd   r   r   s     r%   __getitem__ResourceArgScopes.__getitem__%  s    ;;ur$   c                 ,    [        U R                  5      $ rd   )rT   rs   r   s    r%   __len__ResourceArgScopes.__len__(  s    t{{r$   r   rd   )r   r   r   r   r   rV   r   r   r   r   r   r   r   r   r#   r   r$   r%   r   r      s3    (O- r$   r   c                   v    \ rS rSrSrS r\SS j5       rS rS r	 SS jr
S	 rS
 r SS jr     SS jrSrg)ResourceResolveri,  a  Object responsible for resolving resources.

There are two ways to build an instance of this object:
1. Preferred when you don't have instance of ResourceArgScopes already built,
   using .FromMap static function. For example:

   resolver = ResourceResolver.FromMap(
       'instance',
       {compute_scope.ScopeEnum.ZONE: 'compute.instances'})

   where:
   - 'instance' is human readable name of the resource,
   - dictionary maps allowed scope (in this case only zone) to resource types
     in those scopes.
   - optional prefix of scope flags was skipped.

2. Using constructor. Recommended only if you have instance of
   ResourceArgScopes available.

Once you've built the resover you can use it to build resource references (and
prompt for scope if it was not specified):

resolver.ResolveResources(
      instance_name, compute_scope.ScopeEnum.ZONE,
      instance_zone, self.resources,
      scope_lister=flags.GetDefaultScopeLister(
          self.compute_client, self.project))

will return a list of instances (of length 0 or 1 in this case, because we
pass a name of single instance or None). It will prompt if and only if
instance_name was not None but instance_zone was None.

scope_lister is necessary for prompting.
c                     Xl         X l        g)a:  Initilize ResourceResolver instance.

Prefer building with FromMap unless you have ResourceArgScopes object
already built.

Args:
  scopes: ResourceArgScopes, allowed scopes and resource types in those
          scopes.
  resource_name: str, human readable name for resources eg
                 "instance group".
N)rs   resource_name)rY   rs   r   s      r%   rV   ResourceResolver.__init__P  s     K&r$   Nc                     [        US9n[        R                  " U5       H  u  pEUR                  XE5        M     [	        X05      $ )am  Initilize ResourceResolver instance.

Args:
  resource_name: str, human readable name for resources eg
                 "instance group".
  scopes_map: dict, with keys should be instances of ScopeEnum, values
          should be instances of ResourceArgScope.
  scope_flag_prefix: str, prefix of flags specyfying scope.
Returns:
  New instance of ResourceResolver.
rB   )r   r   	iteritemsr   r   )r   
scopes_mapscope_flag_prefixrs   r   resources         r%   FromMapResourceResolver.FromMap_  s;     +<=F==4ooe& 5F22r$   c                 b    [        U[        5      (       d  [        SR                  U5      5      eg )Nz+Expected names to be a list but it is '{0}')
isinstancelistr*   r6   )rY   namess     r%   _ValidateNamesResourceResolver._ValidateNamesq  s1    eT"" 
7
>
>u
EG G #r$   c                     Ubh  XR                   ;  aX  [        SR                  USR                  U R                    Vs/ s H  o"R                  R
                  PM     sn5      5      5      eg g s  snf )Nz<Unexpected value for default_scope {0}, expected None or {1}z or )rs   r*   r6   rW   r   re   )rY   r   ss      r%   _ValidateDefaultScope&ResourceResolver._ValidateDefaultScopev  sf     ]++%E 
H6-++$++F+Q||00+FGIJ J &F  Gs   A-c                    Ub  UR                   [        R                  R                  :X  a  g[        R                  R	                  UR                   5      nU(       a!  UR                  USU0US9R                  5       $ UR                  U0 US9R                  5       $ U(       a?  UR                   [        R                  R                  :w  a  UR                   R                  $ gg)z#Gets the resource scope parameters.Nrq   )paramsr   )r   ry   rz   r   CollectionForScopeParseNameproperty_func)rY   r   r   rq   api_resource_registrywith_projectr   s          r%   _GetResourceScopeParam'ResourceResolver._GetResourceScopeParam}  s     		"	"m&=&=&D&D	D",,??%%'
&,,W#& - ( )-/
 ',," - ==ATVD 
^66*44;;<((666<r$   c                    / n/ nU H'  n UR                  XUSS9/n	UR                  U	5        M)     Xg4$ ! [        R                  [        R                  [        R
                  4 a    U(       a  e U/n	UR                  U	5         Nif = f)a/  Returns pair of lists: resolved references and unresolved names.

Args:
  names: list of names to attempt resolving
  params: params given when attempting to resolve references
  collection: collection for the names
  scope_defined: bool, whether scope is known
  api_resource_registry: Registry object
Fr   r   enforce_collection)r   r   UnknownCollectionExceptionRequiredFieldOmittedExceptionr   RequiredPropertyErrorappend)
rY   r   r   r   scope_definedr   refsrZ   re   refs
             r%   _GetRefsAndUnderspecifiedNames/ResourceResolver._GetRefsAndUnderspecifiedNames  s     D)$**46@>C + E F kk#  %% 2255..0 ) 
f##C()s   5ABBc           	         [         R                  " U5      nU R                   H  nU(       a  SU0nO0 nUR                  R                  XR                  R
                  '   U HW  n	 UR                  U	S   UUR                  SS9/n
UR                  U	5        UR                  U
5        UR                  U	5        MY     M     g! [        R                  [        R                  [        R                  [        4 a     M  f = f)z:Resolve argument against available scopes of the resource.rq   r   Fr   N)copydeepcopyrs   r   r   
param_namer   r   remover   r   r   r   r   r   
ValueError)rY   r   rq   rZ   r   r   r   r   r   re   r   s              r%   _ResolveMultiScope#ResourceResolver._ResolveMultiScope  s     MM./E	w
 ,1,<,<,J,Jf(()$	&,,T!WV8=8H8H@E - G H# ++d

++c


%
%d
+    447700 	 		s   &AC8C>=C>c                    U(       d  gU Vs/ s H  owS   PM	     nn[         R                  " 5       (       d/  [        XR                   V	s/ s H  oR                  PM     sn	5      e[
        R                  " U R                  XR                   V	s/ s H  oR                  PM     sn	Ub  UR                  OSU5      u  pU
c/  [        XR                   V	s/ s H  oR                  PM     sn	5      eU R                  U
   nU(       a  SU0nO0 nUR                  [        R                  R                  :w  a  XUR                  R                  '   U H%  nUR                  US   UUR                  SS9US'   M'     gs  snf s  sn	f s  sn	f s  sn	f )a  Attempt to resolve scope for unresolved names.

If unresolved_names was generated with _GetRefsAndUnderspecifiedNames
changing them will change corresponding elements of refs list.

Args:
  underspecified_names: list of one-items lists containing str
  default_scope: default scope for the resources
  scope_lister: callback used to list potential scopes for the resources
  project: str, id of the project
  api_resource_registry: resources Registry
  with_project: indicates whether or not project is associated. It should be
    False for flexible resource APIs

Raises:
  UnderSpecifiedResourceError: when resource scope can't be resolved.
Nr   rq   Tr   )r   	CanPromptrO   rs   rS   r   PromptForScoper   r   ry   rz   r   r   r   r   )rY   rZ   r   scope_listerrq   r   r   nr   r   resource_scope_enumr   r   r   re   s                  r%   _ResolveUnderspecifiedNames,ResourceResolver._ResolveUnderspecifiedNames  sc   0  /0/aqT/E0!!'/L1/LMM'5'D'DE++#F+QLL+#F$1$=  4($ "'/L1/LMM[[!45N
Wf f  M$;$;$B$BB5@^&&112$%++
q'#..!	 , #d1g %/ 1 0M $G 0Ms   E9
E>
FF
c
           	      N   U R                  U5        U R                  U5        Ub  U R                  U   nUb  U R                  U   nUb   UR                  USS9n
U
R	                  5       nSnU(       a@  U=(       d2    [
        R                  R                  R                  R                  5       nSU0nO0 nUc  U R                  R                  U5      nU	(       a  0 UEU	EnU R                  UUUUUS9nUb  XUR                  R                  '   U=(       a    UR                  nU R                  XXSLU5      u  nnU(       a,  [!        U R                  5      S:  a  U R#                  X{UXO5        U R%                  UUUUUUS9  U Vs/ s H  nUS   PM
     nnU R                   Vs/ s H  nUR                  PM     nnU HX  nUR'                  5       U;  d  M  [(        R*                  " SR-                  U5      UR'                  5       UR/                  5       S	9e   U$ s  snf s  snf )
a  Resolve this resource against the arguments.

Args:
  names: list of str, list of resource names
  resource_scope: ScopeEnum, kind of scope of resources; if this is not None
               scope_value should be name of scope of type specified by this
               argument. If this is None scope_value should be None, in that
               case if prompting is possible user will be prompted to
               select scope (if prompting is forbidden it will raise an
               exception).
  scope_value: ScopeEnum, scope of resources; if this is not None
               resource_scope should be type of scope specified by this
               argument. If this is None resource_scope should be None, in
               that case if prompting is possible user will be prompted to
               select scope (if prompting is forbidden it will raise an
               exception).
  api_resource_registry: instance of core.resources.Registry.
  default_scope: ScopeEnum, ZONE, REGION, GLOBAL, or None when resolving
      name and scope was not specified use this as default. If there is
      exactly one possible scope it will be used, there is no need to
      specify default_scope.
  scope_lister: func(scope, underspecified_names), a callback which returns
    list of items (with 'name' attribute) for given scope.
  with_project: indicates whether or not project is associated. It should be
    False for flexible resource APIs.
  source_project: indicates whether or not a project is specified. It could
      be other projects. If it is None, then it will use the current project
      if with_project is true
  additional_params: Dict, additional parameters to pass in.
Returns:
  Resource reference or list of references if plural.
Raises:
  BadArgumentException: when names is not a list or default_scope is not one
      of the configured scopes.
  UnderSpecifiedResourceError: if it was not possible to resolve given names
      as resources references.
Nzcompute.projectsr   rq   )r   r   r   ,)expectedgotpath)r   r   rs   r   r   r   r<   rp   rq   	GetOrFailr   r   r   r   r   r   rT   r   r   
Collectionr    WrongResourceCollectionExceptionrW   SelfLink)rY   r   r   r   r   r   r   r   source_projectadditional_paramssource_project_refrq   r   resource_scope_paramr   r   rZ   r   r   expected_collectionss                       r%   ResolveResources!ResourceResolver.ResolveResources  sH   ^ 	}-!{{>2n kk-0m!066
%7 7 9)..0nGL*"3"3"8"8"@"@"J"J"Lg
Wf f{{33MBn.&.-.f66! 7 # '5I^&&112=N$=$=J "&!D!Dzd#:"D

 DKK 01 4
l5I3;
 	$$! % # ##dsCFdD# ;?++F+E,,+F		!5	588XX23 ! 	!  K $ Gs   H%H")r   rs   rd   )TNNTNN)r   r   r   r   r   rV   staticmethodr   r   r   r   r   r   r   r  r#   r   r$   r%   r   r   ,  sd    !F' 3 3"G
J +/76&:@ 047#| &*$($(&*)-tr$   r   c                       \ rS rSrSrSSSSSSSSSSSSSSSSSS\R                  4S jr     SS jr     SS jr	S	 r
S
rg)ResourceArgumenti  ai  Encapsulates concept of compute resource as command line argument.

Basic Usage:
  class MyCommand(base.Command):
    _BACKEND_SERVICE_ARG = flags.ResourceArgument(
        resource_name='backend service',
        completer=compute_completers.BackendServiceCompleter,
        regional_collection='compute.regionBackendServices',
        global_collection='compute.backendServices')
    _INSTANCE_GROUP_ARG = flags.ResourceArgument(
        resource_name='instance group',
        completer=compute_completers.InstanceGroupsCompleter,
        zonal_collection='compute.instanceGroups',)

    @staticmethod
    def Args(parser):
      MyCommand._BACKEND_SERVICE_ARG.AddArgument(parser)
      MyCommand._INSTANCE_GROUP_ARG.AddArgument(parser)

    def Run(args):
      api_resource_registry = resources.REGISTRY.CloneAndSwitch(
          api_tools_client)
      backend_service_ref = _BACKEND_SERVICE_ARG.ResolveAsResource(
          args, api_resource_registry, default_scope=flags.ScopeEnum.GLOBAL)
      instance_group_ref = _INSTANCE_GROUP_ARG.ResolveAsResource(
          args, api_resource_registry, default_scope=flags.ScopeEnum.ZONE)
      ...

  In the above example the following five arguments/flags will be defined:
    NAME - positional for backend service
    --region REGION to qualify backend service
    --global  to qualify backend service
    --instance-group INSTANCE_GROUP name for the instance group
    --instance-group-zone INSTANCE_GROUP_ZONE further qualifies instance group

  More generally this construct can simultaneously support global, regional
  and zonal qualifiers (or any combination of) for each resource.
NFTc                 :   U=(       d    SU l         UU l        UU l        UU l        U R                   R	                  S5      (       ai  SU l        U R                   SS R                  SS5      U l        U R                  [        R                  :X  a  SOU R                   SS n[        US9U l        O[        SS9U l        U R                   U l        X l        X0l        X@l        UU l        XPl        U(       d$  U(       d  U(       d  ["        R$                  " S	5      eU(       a2  U R                  R'                  [(        R*                  R,                  US
9  U(       a2  U R                  R'                  [(        R*                  R.                  US
9  U(       a2  U R                  R'                  [(        R*                  R0                  US
9  Xl        U
=(       d    SU l        Xl        Xl        U=(       d    SU l        Xl        Xl        [A        U R                  U5      U l!        g)an	  Constructor.

Args:
  name: str, argument name.
  resource_name: str, human readable name for resources eg "instance group".
  completer: completion_cache.Completer, The completer class type.
  plural: bool, whether to accept multiple values.
  required: bool, whether this argument is required.
  zonal_collection: str, include zone flag and use this collection
                         to resolve it.
  regional_collection: str, include region flag and use this collection
                            to resolve it.
  global_collection: str, if also zonal and/or regional adds global flag
                          and uses this collection to resolve as
                          global resource.
  global_help_text: str, if provided, global flag help text will be
                         overridden with this value.
  region_explanation: str, long help that will be given for region flag,
                           empty by default.
  region_help_text: str, if provided, region flag help text will be
                         overridden with this value.
  region_hidden: bool, Hide region in help if True.
  zone_explanation: str, long help that will be given for zone flag, empty
                         by default.
  zone_help_text: str, if provided, zone flag help text will be overridden
                       with this value.
  zone_hidden: bool, Hide zone in help if True.
  short_help: str, help for the flag being added, if not provided help text
                   will be 'The name[s] of the ${resource_name}[s].'.
  detailed_help: str, detailed help for the flag being added, if not
                      provided there will be no detailed help for the flag.
  custom_plural: str, If plural is True then this string will be used as
                      plural resource name.
  scope_flags_usage: ScopeFlagsUsage, when set to
                              USE_EXISTING_SCOPE_FLAGS, already existing
                              zone and/or region flags will be used for
                              this argument,
                              GENERATE_DEDICATED_SCOPE_FLAGS, new scope
                              flags will be created,
                              DONT_USE_SCOPE_FLAGS to not generate
                              additional flags and use single argument for
                              all scopes.

Raises:
  exceptions.Error: if there some inconsistency in arguments.
re   r0   Tr   Nr/   rk   r   zAMust specify at least one resource type zonal, regional or globalr   r-   )"name_arg_short_help_detailed_helpscope_flags_usage
startswithis_flagr   re   r   r!   r   rs   r   r3   rE   rF   ro   r   Errorr   ry   rz   r{   r   r   _global_help_text_region_explanation_region_help_text_region_hidden_zone_explanation_zone_help_text_zone_hiddenr   _resource_resolver)rY   re   r   r3   rE   ro   zonal_collectionregional_collectionglobal_collectionglobal_help_textregion_explanationregion_help_textregion_hiddenzone_explanationzone_help_textzone_hiddenrG   detailed_helprF   r  rB   s                        r%   rV   ResourceArgument.__init__  s   H NFDM!D'D.D}}%%dl--#++C5di!33'@@AT]]12&  &+>dk%$7dk--di&NK&DM 37H 2 3 3
kk=2277&6  8
kk=2299&9  ;
kk=2299&7  9-17RD-'-3D)#.t{{MJDr$   c                 0	   [        U(       a  UOU R                  R                  5       U R                  S9nU R                  (       a  U R                  US'   OU R
                  (       a  U R
                  US'   OSR                  U R                  (       a  SOS[        R                  " [        U R                  5      S-   U R                  =(       d    SU R                  5      U5      US'   U R                  R                  S5      (       a  US==   S-  ss'   U R                  S	:X  a  US
:X  a  US==   S-  ss'   U R                  R                  S5      (       aM  U R                  US'   U R                  (       d  XWS'   U R                  (       a  [         R"                  " SS9US'   O@U R                  (       a  U R                  (       a  SUS'   OU R                  (       a  SOSUS'   U=(       d    UR$                  " U R                  40 UD6  U R&                  [(        R*                  :w  a  g[-        U R.                  5      S:  a  UR1                  SXVS9nOUn[2        R4                  R6                  U R.                  ;   aa  [9        UU R.                  R:                  U R                  UU R<                  U R>                  U R@                  U R                  U R                  S9	  [2        R4                  RB                  U R.                  ;   aa  [E        UU R.                  R:                  U R                  UU RF                  U RH                  U RJ                  U R                  U R                  S9	  [2        R4                  RL                  U R.                  ;   Ga  [-        U R.                  5      S:  a  U R                  (       d  SR                  U R                  5      n	OYU R                  (       a-  U R                  (       d  SR                  U R                  5      n	OSR                  U R                  5      n	UR%                  U R.                  [2        R4                  RL                     RN                  SSU RP                  =(       d    SR                  U	5      S9  ggg)z-Add this set of arguments to argparse parser.)metavarr3   r5   zName{} of the {} to {}.r   r-   r   instancez For details on valid instance names, refer to the criteria documented under the field 'name' at: https://cloud.google.com/compute/docs/reference/rest/v1/instances	DISK_NAMEcreatezy For details on the naming convention for this resource, refer to: https://cloud.google.com/compute/docs/naming-resourcesr0   ro   category)
min_lengthtype+nargs*?NT)mutexr2  ro   )rB   r@   rA   rC   rD   r2   rE   rF   z{} isz{}s arez{} are
store_truezIf set, the {0} global.r4   defaultr5   ))dictre   upperr3   r  r  r6   rE   r   r7   r8   r   rF   r  r  ro   r	   ArgListr9   r  r   r    rT   rs   	add_groupry   rz   r{   rI   rB   r  r  r  r   rM   r  r  r  r   rS   r  )
rY   r?   mutex_grouprA   cust_metavarr2  scope_requiredr   r   resource_mentions
             r%   AddArgumentResourceArgument.AddArgument  s     ,$))//2C..F
 **fVn			''fVn077#"
..$++"D$6$6$<"  " fVn 
		j	)	)v / 	0
 
k	!n&@v . 	/
 }}%%==fZ]]%z	$,,:v	;;&/!%##wF((A&A!O!OO
4;;!x  e e##t{{2
kk--**',,((""**	, %%4
kk--**'..**$$**	, %%4T[[9IA9M[[">>$*<*<=;;t11$++D,>,>?#??4+=+=>
++m--44
5
:
:%% $)B6"#  % :N4r$   c                    U R                  U5      nU R                  R                  U5      u  pU	c>  U R                  [        R
                  :X  a   U R                  R                  US   5      u  pU	b  U	R                  n	U R                  (       d  U(       d  U R                  R                  (       a1  SR                  U R                  R                  U	R                  5      nOSU	-   n[        R                  " SR                  XR                  5      5      eU R                  R!                  UU	U
UUUUUUS9	nU R"                  (       a  U$ U(       a  US   $ g)a  Resolve this resource against the arguments.

Args:
  args: Namespace, argparse.Namespace.
  api_resource_registry: instance of core.resources.Registry.
  default_scope: ScopeEnum, ZONE, REGION, GLOBAL, or None when resolving
      name and scope was not specified use this as default. If there is
      exactly one possible scope it will be used, there is no need to
      specify default_scope.
  scope_lister: func(scope, underspecified_names), a callback which returns
    list of items (with 'name' attribute) for given scope.
  with_project: indicates whether or not project is associated. It should be
    False for flexible resource APIs.
  source_project: indicates whether or not a project is specified. It could
    be other projects. If it is None, then it will use the current project
    if with_project is true
  additional_params: Dict, additional parameters to pass in.
Returns:
  Resource reference or list of references if plural.
Nr   z	--{0}-{1}r0   z5Can't specify {0} without specifying resource via {1})r   r  r  )_GetResourceNamesrs   r   r  r   r"   r   r   ro   rB   r6   rH   r   r  re   r   r  rE   )rY   r   r   r   r   r   r  r  r   r   r   rS   r   s                r%   ResolveAsResource"ResourceArgument.ResolveAsResource}  s6   8 ""4(E"&++"="=d"CN""o&J&JJ$(KK$@$@q$J!n!%00n]]5;;""##kk%%~'?'?A$ &$DKKii!" 	" ""33!%+ 4 	-D {{k!Wnr$   c                     U R                   (       a  [        XR                  5      $ [        XR                  5      nUb  U/$ / $ )z0Return list of resource names specified by args.)rE   r   re   )rY   r   
name_values      r%   rH  "ResourceArgument._GetResourceNames  s9    {{T99%%yy)J\Ir$   )r  r  r  r  r  r   r  r  r  r  r3   rF   r  re   r  rE   ro   r   r  rs   )Nz
operate onNNFr  )r   r   r   r   r   r   r    rV   rE  rI  rH  r#   r   r$   r%   r  r    s    %R 'FF)jKb !f%V '+%)%)'+*.=~r$   r  c                 &    U R                  SSSS9  g )Nz--regexpz-rz      A regular expression to filter the names of the results on. Any names
      that do not match the entire regular expression will be filtered out.
      r5   r9   r?   s    r%   AddRegexArgrR    s    $
  r$   c                 $    U R                  SSS9  g )Npolicy_filez2      JSON or YAML file containing the IAM policy.rO  rP  rQ  s    r%   AddPolicyFileFlagrU    s    m +6 7r$   c                 D    U R                  SSSR                  U5      S9  g )Nz--storage-locationLOCATIONz      Google Cloud Storage location, either regional or multi-regional, where
      {} content is to be stored. If absent, a nearby regional or
      multi-regional location is chosen automatically.
      )r.  r5   r9   r6   r?   r   s     r%   AddStorageLocationFlagrZ    s,    
 &
  r$   c                 \    SR                  U5      nU R                  SSSU(       a  UOUS9  g )Nzd
  Create an application-consistent {} by informing the OS
  to prepare for the snapshot process.
  z--guest-flushr:  Fr;  )r6   r9   )r?   r   custom_helprD   s       r%   AddGuestFlushFlagr]    s=     fX  	%;9	  6r$   c                    U R                  SSS9  U R                  S[        R                  " 5       SSS9  U R                  S[        R                  " 5       S	S
S9  U R                  S[        R                  " 5       SSS9  g)z1Adds the initial state for Shielded instance arg.z--platform-key-filez      File path that points to an X.509 certificate in DER format or raw binary
      file. When you create a Shielded VM instance from this image, this
      certificate or raw binary file is used as the platform key (PK).
        rO  z--key-exchange-key-file	KEK_VALUEa         Comma-separated list of file paths that point to X.509 certificates in DER
      format or raw binary files. When you create a Shielded VM instance from
      this image, these certificates or files are used as key exchange keys
      (KEK).
        )r4  r.  r5   z--signature-database-fileDB_VALUEa        Comma-separated list of file paths that point to valid X.509 certificates
      in DER format or raw binary files. When you create a Shielded VM instance
      from this image, these certificates or files are  added to the signature
      database (db).
        z--forbidden-database-file	DBX_VALUEa        Comma-separated list of file paths that point to revoked X.509
      certificates in DER format or raw binary files. When you create a Shielded
      VM instance from this image, these certificates or files are added to the
      forbidden signature database (dbx).
        N)r9   r	   r?  rQ  s    r%   %AddShieldedInstanceInitialStateKeyArgrb    s       	 	  	 	! 	  	 	! 	  	r$   c                 (   U R                   (       d  gU R                  5       n[        R                  " UR                  UR
                  S9n[        R                  " XS9R                  U R                   US9u  pV[        R                  " SXV5        XV4$ )a)  Rewrites args.filter into client and server filter expression strings.

Usage:

  args.filter, request_filter = flags.RewriteFilter(args)

Args:
  args: The parsed args namespace containing the filter expression args.filter
    and display_info.
  message: The response resource message proto for the request.
  frontend_fields: A set of dotted key names supported client side only.

Returns:
  A (client_filter, server_filter) tuple of filter expression strings.
  None means the filter does not need to applied on the respective
  client/server side.
r   )symbolsaliases)messagefrontend_fields)defaultsz!client_filter=%r server_filter=%r)filterGetDisplayInfor   ProjectionSpec
transformsre  r   RewriterRewriter   info)r   rf  rg  display_inforh  client_filterserver_filters          r%   RewriteFilterrs    s    $ 
$$&,%44%%""$( "0!8!8"88?
++ 9@ 9* - ((.M		%%r$   c                 h    [         [         S.nU R                  S[        R                  " US9SSSS9  g )N)diskzcsek-key-filez--source-disk-csek-key)specr   zPROPERTY=VALUEa  
              Customer-supplied encryption key of the disk attached to the
              source instance. Required if the source disk is protected by
              a customer-supplied encryption key. This flag can be repeated to
              specify multiple attached disks.

              *disk*::: URL of the disk attached to the source instance.
              This can be a full or   valid partial URL

              *csek-key-file*::: path to customer-supplied encryption key.
            )r4  r4   r.  r5   )strr9   r	   ArgDict)r?   rv  s     r%   AddSourceDiskCsekKeyArgry  4  s@    
$ 	D)
  r$   c           	      B    U R                  SSSSR                  US9S9  g )Nz--erase-windows-vss-signaturer:  Fz
              Specifies whether the disk restored from {resource} should
              erase Windows specific VSS signature.
              See https://cloud.google.com/sdk/gcloud/reference/compute/disks/snapshot#--guest-flush
           )r   r;  rX  rY  s     r%   AddEraseVssSignaturer{  L  s1    % vxv(  	r$   rd   r   )Cr   
__future__r   r   r   r   enumr|   r   googlecloudsdk.api_lib.computer   &googlecloudsdk.api_lib.compute.regionsr   r   $googlecloudsdk.api_lib.compute.zonesr~   googlecloudsdk.callioper   r	   "googlecloudsdk.command_lib.computer
   r   ry   r   googlecloudsdk.corer   r   r   r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr   r   r   r   r   ZONE_PROPERTY_EXPLANATION$ZONE_PROPERTY_EXPLANATION_NO_DEFAULTREGION_PROPERTY_EXPLANATION&REGION_PROPERTY_EXPLANATION_NO_DEFAULTEnumr   r  r'   r   r*   rI   rM   rO   objectra   r   r   r   r   r  rR  rU  rZ  r]  rb  rs  ry  r{  r   r$   r%   <module>r     sd    : &  '    	 9 M I + / 9 E = * # * ) 2 A ) 
@  C >  *( $ ** &dii j.. : 
 DH5U$CF #9TuD CF
2*"2"2 
2!6 !$!v !", ,^Pv Pf
Ev EP
7
	6&R&>0
r$   