
                         >   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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  \R0                  \R2                  " \R4                  R6                  5       " S S\R8                  5      5       5       rg)z?Command for uploading a named set into a Compute Engine router.    )absolute_import)division)unicode_literalsN)base_classes)messages)base)
exceptions)flags)yaml)filesc                   D    \ rS rSrSrSr\S 5       rS rS r	S r
S rS	rg)
UploadNamedSet$   zpUpload a named set into a Compute Engine router.

*{command}* uploads a named set into a Compute Engine router.
Nc                     [         R                  " 5       [        l        [        R                  R	                  USS9  UR                  SSS9  UR                  SSSS	9  UR                  S
SS/SS9  g )Nupload)operation_typez
--set-namez%Name of the named set to add/replace.)helpz--file-nameTz-Local path to the file defining the named set)requiredr   z--file-formatjsonr   z(Format of the file passed to --file-name)choicesr   )r
   RouterArgumentr   
ROUTER_ARGAddArgumentadd_argument)clsparsers     /lib/surface/compute/routers/upload_named_set.pyArgsUploadNamedSet.Args.   s     % 4 4 6N))&)J
B   <  
  7      c                 *   [         R                  " U R                  5       5      nUR                  n[        R
                  R                  UUR                  [        R                  " U5      S9nU R                  UR                  UR                  UR                  5      nU R                  UR                  U5        UR                   R"                  SUR                  R$                  " S0 UR'                  5       DSU0D64nUR)                  U/5      S   $ )zIssues the request necessary for uploading a named set into a Router.

Args:
  args: contains arguments passed to the command.

Returns:
  The result of patching the router uploading the named set.
)scope_listerUpdateNamedSetnamedSetr    )r   ComputeApiHolderReleaseTrackclientr   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerParseNamedSetFromFile	file_namefile_formatr   EnsureSameSetNameset_nameapitools_clientrouters#ComputeRoutersUpdateNamedSetRequestAsDictMakeRequests)selfargsholderr(   
router_ref	named_setrequests          r   RunUploadNamedSet.Run@   s     **4+<+<+>?F]]F**<<"88@ = J **((&//I 	4==)4 	&&;; 	
!	
,5	
G y)!,,r    c                     UbP  [        US5      (       a?  XR                  :w  a0  [        R                  " SSR	                  XR                  5      5      e[        US5      (       d  Ub  Xl        g g g )Nnamezset-namezFThe set name provided [{0}] does not match the one from the file [{1}])hasattrr@   r	   BadArgumentExceptionformat)r7   r1   r;   s      r   r0    UploadNamedSet.EnsureSameSetNamea   sh    	6 : :	^^	#-- &>>:
 	

 9f%%(*>n +?%r    c                     U R                  X5      nSU;   a  US   n[        R                  " XCR                  5      nSU;   a  [        R
                  " US   5      Ul        U$ )Nresourcefingerprint)	ParseFilemessages_utilDictToMessageWithErrorCheckNamedSetbase64	b64decoderG   )r7   
input_filer/   r   rF   r;   s         r   r-   $UploadNamedSet.ParseNamedSetFromFilel   sc    ~~j6HX*%h99##I  $..x/FGir    c                 r   [         R                  R                  U5      (       a%  [        R                  " SR                  U5      5      e[         R                  R                  U5      (       d%  [        R                  " SR                  U5      5      e [        R                  " U5       nUS:X  a  [        R                  " U5      sS S S 5        $ [        R                  " U5      sS S S 5        $ ! , (       d  f       g = f! [         a,  nSR                  X5      n[        R                  " U5      eS nAff = f)Nz[{0}] is a directoryzNo such file [{0}]r   zEUnable to read named set config from specified file [{0}] because {1})ospathisdirr	   BadFileExceptionrC   isfiler   
FileReaderr   loadr   	Exception)r7   rN   r/   import_fileexpmsgs         r   rH   UploadNamedSet.ParseFilex   s    	ww}}Z  ''
 
'
'

3  77>>*%%''(<(C(CJ(OPP
-J';& ;' (' yy% (''  -
0 
 '',,-sB   D  *C/	D  C/%	D  /
C=9D  =D   
D6
'D11D6r%   )__name__
__module____qualname____firstlineno____doc__r   classmethodr   r=   r0   r-   rH   __static_attributes__r%   r    r   r   r   $   s5    
 * "-B	 
-r    r   )ra   
__future__r   r   r   rL   r   rQ   googlecloudsdk.api_lib.computer   googlecloudsdk.api_lib.utilr   rI   googlecloudsdk.callioper   r	   "googlecloudsdk.command_lib.computer
   r+   *googlecloudsdk.command_lib.compute.routersgooglecloudsdk.corer   googlecloudsdk.core.utilr   HiddenReleaseTracksr'   ALPHASilentCommandr   r%   r    r   <module>rp      s|     F &  '   	 7 A ( . E < $ * D%%++,c-T'' c- - c-r    