
                            d Z ddlmZ ddlmZ ddlmZ ddl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ZdddZej,                   ej.                  ej0                  j2                  ej0                  j4                  ej0                  j6                         G d dej8                                      Zy)z%Export firewall policy rules command.    )absolute_import)division)unicode_literalsN)base_classes)client)base)firewall_policies_utils)flags)util)fileszG        Exports Firewall Policy rules configuration to a file.
        z        Firewall Policy rules can be exported by running:

          $ {command} FIREWALL_POLICY --destination=<path-to-file>
            --organization=<organization>
        )DESCRIPTIONEXAMPLESc                   P    e Zd ZdZdZeZed        Zedd       Z	ed        Z
d Zy)ExportzExport Compute Engine organization firewall policy rules.

  Exports organization firewall policy rules configuration to a file.
  This configuration can be imported at a later time.
  Nc                     | j                         t        j                   j                  k(  ry| j                         t        j                   j                  k(  ryy)z3Returns the API version based on the release track.alphabetav1)ReleaseTrackr   ALPHABETA)clss    5lib/surface/compute/firewall_policies/export_rules.pyGetApiVersionzExport.GetApiVersion:   sG     T..444				t0055	5    c                 P    t        j                  d| j                         d|      S )z!Returns the resource schema path.computeFirewallPolicyfor_help)export_utilGetSchemaPathr   )r   r    s     r   r"   zExport.GetSchemaPathC   s,     $$	 r   c                     t        j                  dd      | _        | j                  j                  |d       |j	                  dd       t        j                  || j                  d	             y )
NTzexport rules from)required	operationzexport-rules)operation_typez--organizationzwOrganization in which the organization firewall policy rules export from. Must be set if FIREWALL_POLICY is short name.)helpr   )r
   FirewallPolicyArgumentFIREWALL_POLICY_ARGAddArgumentadd_argumentr!   AddExportFlagsr"   )r   parsers     r   ArgszExport.ArgsM   sr    #::!4C ''~'N
J   vs'8'8$'8'GHr   c           	      t   t        j                  | j                               }| j                  j	                  ||j
                  d      }t        j                  ||j                  |j
                  t        j                  | j                               j                               }t        j                  ||j                         |j                        }|j                  |d      d   }|j                  j                   j#                  |j$                        }|j&                  rOt)        j*                  |j&                        5 }t-        j.                  ||| j1                                d d d        y t-        j.                  |t2        j4                  | j1                                y # 1 sw Y   y xY w)	NF)with_project)refcompute_client	resourcesversion)organization)fp_idonly_generate_requestr   )rules)messagestreamschema_path)r   ComputeApiHolderr   r)   ResolveAsResourcer3   r   OrgFirewallPolicysix	text_typelowerr	   GetFirewallPolicyIdNamer5   Describemessagesr   r8   destinationr   
FileWriterr!   r   r"   sysstdout)	selfargsholderfirewall_policy_reforg_firewall_policyr6   firewall_policyfirewall_policy_rulesr:   s	            r   Runz
Export.Run\   s{   **4+<+<+>?F22DDfU E  !22}}""d//1288:	 $77  "&&E *225 3 	O
 #MM22AA## B  D,,-)**,	
 .- '((* .-s   	'F..F7)F)__name__
__module____qualname____doc__r)   DETAILED_HELPdetailed_helpclassmethodr   r"   r.   rQ    r   r   r   r   ,   sU    
 -    I I'r   r   )rU   
__future__r   r   r   rH   googlecloudsdk.api_lib.computer   0googlecloudsdk.api_lib.compute.firewall_policiesr   googlecloudsdk.callioper   4googlecloudsdk.command_lib.compute.firewall_policiesr	   r
   !googlecloudsdk.command_lib.exportr   r!   googlecloudsdk.core.utilr   r?   rV   DefaultUniverseOnlyReleaseTracksr   r   r   GACommandr   rY   r   r   <module>re      s    , &  ' 
 7 C ( X F A * 
	
 T..33T5F5F5I5IST\\ S Sr   