
    n                        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dlZdddZe
j*                   e
j,                  e
j.                  j0                  e
j.                  j2                  e
j.                  j4                         G d de
j6                                      Zy)z%Import firewall policy rules command.    )absolute_import)division)unicode_literals)base_classes)client)base)firewall_policies_utils)flags)util)
console_ioNzI        Imports Firewall Policy rules configuration from a file.
        z        Firewall Policy rules can be imported by running:

          $ {command} FIREWALL_POLICY --source=<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)ImportzImport Compute Engine organization firewall policy rules.

  Imports organization firewall policy rules configuration from a file.
  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/import_rules.pyGetApiVersionzImport.GetApiVersion7   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Import.GetSchemaPath@   s,     $$	 r   c                     t        j                  dd      | _        | j                  j                  |d       |j	                  dd       t        j                  || j                  d	             y )
NTzimports rules to)required	operationzexport-rules)operation_typez--organizationzuOrganization in which the organization firewall policy rules import to. Must be set if FIREWALL_POLICY is short name.)helpr   )r
   FirewallPolicyArgumentFIREWALL_POLICY_ARGAddArgumentadd_argumentr!   AddImportFlagsr"   )r   parsers     r   ArgszImport.ArgsJ   sr    #::!3C ''~'N
H   vs'8'8$'8'GHr   c           	         t        j                  | j                               }| j                  j	                  ||j
                  d      }t        j                  ||j                  |j
                  t        j                  | j                               j                               }t        j                  |j                  xs dd      }t        j                  |j                  j                   j"                  || j%                               }t'        j(                  ||j+                         |j,                        }|j/                  |d      d	   }t        j0                  d
d       |j                  j                   j#                  |j2                  |j4                  |j6                        }	|j9                  |d|	      S )NF)with_project)refcompute_client	resourcesversion-)binary)message_typestreamschema_path)organization)fp_idonly_generate_requestr   z*Firewall Policy rules will be overwritten.T)messagecancel_on_no)fingerprintrulespacketMirroringRules)r;   r<   firewall_policy)r   ComputeApiHolderr   r)   ResolveAsResourcer3   r   OrgFirewallPolicysix	text_typelowerr   ReadFromFileOrStdinsourcer!   r   messagesr   r"   r	   GetFirewallPolicyIdNamer:   DescribePromptContinuer?   r@   rA   Update)
selfargsholderfirewall_policy_reforg_firewall_policydatafirewall_policy_rulesr;   existing_firewall_policyrB   s
             r   Runz
Import.RunY   s   **4+<+<+>?F22DDfU E  !22}}""d//1288:	 ))$++*<UKD'..]]++::&&( $77  "&&E  3;;5  <   	 <4 mm,,;;,88#))2GG < O %%#' &  r   )F)__name__
__module____qualname____doc__NETWORK_FIREWALL_POLICY_ARGDETAILED_HELPdetailed_helpclassmethodr   r"   r.   rY    r   r   r   r   *   sU    

 !%-    I I,r   r   )r]   
__future__r   r   r   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.consoler   rF   r_   DefaultUniverseOnlyReleaseTracksr   r   r   GACommandr   rb   r   r   <module>rn      s    , &  ' 7 C ( X F A 2 
	
 T..33T5F5F5I5IWT\\ W Wr   