
    L                     ,   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 ej                   ej"                   ej$                  ej&                  j(                         G d
 dej*                                             Zy)zACommand for adding an empty named set to a Compute Engine router.    )absolute_import)division)unicode_literals)base_classes)base)
exceptions)flags)	arg_utilsc                   6    e Zd ZdZdZed        Zd Zd Zd Z	y)AddNamedSetzxAdd an empty named set to a Compute Engine router.

  *{command}* adds an empty named set to a Compute Engine router.
  Nc                     t        j                         t        _        t        j                  j	                  |d       |j                  ddd       |j                  dt        j                  dd	d
dd       y )Ninsert)operation_typez
--set-namezName of the named set to add.T)helprequiredz
--set-typez$The Named Set is a Prefix Named Set.z'The Named Set is a Community Named Set.)PREFIX	COMMUNITYzType of the set's elements.)typechoicesr   r   )r	   RouterArgumentr   
ROUTER_ARGAddArgumentadd_argumentr
   ChoiceToEnumName)clsparsers     ,lib/surface/compute/routers/add_named_set.pyArgszAddNamedSet.Args)   s|    "113K&&vh&G
0  
 ''<B
 /  	    c                    t        j                  | j                               }|j                  }t        j
                  j                  ||j                  t        j                  |            }|j                  j                  |j                  |j                  j                  j                  | j                  |j                                    }| j!                  |||j                         |j"                  j$                  d |j                  j&                  di |j)                         d|if}|j+                  |g      d   S )zIssues the requests needed for adding an empty named set to a Router.

    Args:
      args: contains arguments passed to the command.

    Returns:
      The result of patching the router adding the empty named set.
    )scope_lister)namer   UpdateNamedSetnamedSetr    )r   ComputeApiHolderReleaseTrackclientr   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListermessagesNamedSetset_nameTypeValueValuesEnumConvertSetTypeset_typeRequireNamedSetDoesNotExistapitools_clientrouters#ComputeRoutersUpdateNamedSetRequestAsDictMakeRequests)selfargsholderr(   
router_ref	named_setrequests          r   RunzAddNamedSet.Run=   s    **4+<+<+>?F]]F''99"88@ : J
 ((]]__%%99.
 ) I 	$$VZG&&;;; 	
!	
,5	
G y)!,,r   c                    |j                   j                  d |j                  j                  di |j	                         d|if}	 |j                  |g       t        j                  ddj                  |            # t        $ r?}dj                  |      |j                         v sd|j                         v rY d }~y  d }~ww xY w)	NGetNamedSetr$   z)The named set '{set_name}' was not found.)r/   zACould not fetch resource:
 - Invalid value for field 'namedSet': zset-namez&A named set named '{0}' already existsr%   )r4   r5   r-    ComputeRoutersGetNamedSetRequestr7   r8   	Exceptionformat__str__r   BadArgumentException)r9   r(   r<   r/   r>   	exceptions         r   r3   z'AddNamedSet.RequireNamedSetDoesNotExist`   s    &&888 	
!	
,4	
G7)$ 
)
)<CCHM   

5
<
<h
<
O ! R ! 	
s   A> >	C4C CCc                     |dk(  ry|dk(  ry|S )Nr   NAMED_SET_TYPE_PREFIXr   NAMED_SET_TYPE_COMMUNITYr%   )r9   r2   s     r   r1   zAddNamedSet.ConvertSetTypey   s    8$	[	 'or   )
__name__
__module____qualname____doc__r   classmethodr   r?   r3   r1   r%   r   r   r   r      s0    
 * &!-F2r   r   N)rN   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer	   r+   *googlecloudsdk.command_lib.compute.routers$googlecloudsdk.command_lib.util.apisr
   HiddenUniverseCompatibleReleaseTracksr'   ALPHACreateCommandr   r%   r   r   <module>r[      s}     H &  ' 7 ( . E < : D%%++,^$$$ ^ -  ^r   