
    m                        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mZ e
j$                   e
j&                  e
j(                  j*                  e
j(                  j,                  e
j(                  j.                         G d de
j0                  e
j2                                      Zddde_        y)zSCommand for getting the effective firewalls applied on instance network interfaces.    )absolute_import)division)unicode_literals)base_classes)firewalls_utils)lister)base)
exceptions)flags)logc                   ,    e Zd ZdZed        Zd Zd Zy)GetEffectiveFirewallsan  Get the effective firewalls for a Compute Engine virtual machine network interface.

  ## EXAMPLES

  To get the effective firewalls for an instance, run:

    $ {command} example-instance --zone us-central1-a

  gets the effective firewalls applied on the default network interface of a
  Compute Engine virtual machine "example-instance" in zone
  us-central1-a
  c                     t         j                  j                  |        | j                  ddd       | j                  j                  t        j                         t        j                  |        y )Nz--network-interfacenic0zEThe name of the network interface to get the effective firewalls for.)defaulthelp)
instances_flagsINSTANCE_ARGAddArgumentadd_argumentdisplay_info	AddFormatr   EFFECTIVE_FIREWALL_LIST_FORMATr   AddBaseListerArgs)parsers    Klib/surface/compute/instances/network_interfaces/get_effective_firewalls.pyArgszGetEffectiveFirewalls.Args1   sc      ,,V4
	   !!66 V$    c                 0   t        j                  | j                               }|j                  }|j                  j                  }t
        j                  j                  ||j                  t        j                  |j                              }|j                  j                  j                   |j                  di |j                               }|j                   D ]  }|j"                  |j$                  k(  s nb t'        j(                  ddj+                  |j$                  dj-                  |j                   D cg c]  }|j"                   c}                  |j/                  |j0                  |j2                  |j4                  |j$                        }|j                  j                  j7                  |      }	g }
g }g }t9        |	d      r t;        j<                  ||	j>                        }t9        |	d      r|	j@                  rg }|	j@                  D ]  }t;        jB                  ||jD                        }t;        jB                  ||jF                        }|j                  jI                  |j"                  |||jJ                  |jL                        }|jO                  |        t;        jP                  ||      }nst9        |	d	      rg|	jR                  D ]X  }t;        jT                  ||jD                        }|
jO                  |j                  jW                  |jX                  |
             Z |j[                  d      rL|j*                  dk(  r=|
r|j                  j]                  |
||      S |j                  j]                  ||      S g }|D ]'  }|j_                  t;        j`                  ||             ) |
D ]&  }|j_                  t;        jb                  |             ( |j_                  t;        jd                  |             |S c c}w )N)scope_listerznetwork-interfacezMInstance does not have a network interface [{}], present interfaces are [{}].z, )projectinstancezonenetworkInterface	firewallsfirewallPolicys)namerulespacketMirroringRulestypepriorityorganizationFirewalls)idr(   formatjson)r,   r%   r&   )r%   r&    )3r   ComputeApiHolderReleaseTrackclientmessagesr   r   ResolveAsResource	resourcesr   GetDefaultScopeListerapitools_client	instancesGetComputeInstancesGetRequestAsDictnetworkInterfacesr'   network_interfacer
   UnknownArgumentExceptionr.   join,ComputeInstancesGetEffectiveFirewallsRequestr!   r"   r#   r   hasattrr   SortNetworkFirewallRulesr%   r&   SortFirewallPolicyRulesr(   r)   =InstancesGetEffectiveFirewallsResponseEffectiveFirewallPolicyr*   r+   appendSortFirewallPoliciesr,   SortOrgFirewallRules@InstancesGetEffectiveFirewallsResponseOrganizationFirewallPolicyr-   IsSpecified&InstancesGetEffectiveFirewallsResponseextend,ConvertFirewallPolicyRulesToEffectiveFwRules/ConvertOrgSecurityPolicyRulesToEffectiveFwRules-ConvertNetworkFirewallRulesToEffectiveFwRules)selfargsholderr3   r4   instance_refr"   irequestresorg_firewallnetwork_firewallall_firewall_policyall_unsorted_firewall_policyfpfirewall_policy_rulepacket_mirroring_rulesfp_responsesporg_firewall_ruleresults                        r   RunzGetEffectiveFirewalls.RunA   s   **4+<+<+>?F]]F}}%%H"//AA00? B L %%//33+++Dl.A.A.CDH ''	
4))	) ( //
))/$$ii)C)CD)CA)CDE*  CC$$&&//	 D G 
 
 
*
*
@
@
ICLsK (AA
#-- s%&3+>+>%'"##".FFBHH 
 "1!H!HB++"
 oocc&!7[[ d 
 	%++K8! $" ,@@
. 
-	.))"+@@BHH
 	OO\\55 1 ] 	
	 * !dkkV&;	EE".&/ F 
 	
 EE&8K F 
 	
 F!mm

F
Fb " mm

I
I"
M  MMEE	

 Mc Es   =Pc                 f    ~t         j                  j                  dt        j                  z          y )N
)r   statusPrintr   LIST_NOTICE)rP   resources_were_displayeds     r   EpilogzGetEffectiveFirewalls.Epilog   s"     JJTO7778r   N)__name__
__module____qualname____doc__staticmethodr   rb   ri   r0   r   r   r   r      s'    
 % %hT9r   r   z
        *{command}* is used to get the effective firewalls applied to the
         network interfaces of a Compute Engine virtual machine.
    a      To get the effective firewalls of instance with name example-instance, run:

      $ {command} example-instance

    To show all fields of the firewall rules, please show in JSON format with
    option --format=json

    To see more firewall rule fields in table format, run the following for
    "example-instance":

      $ {command} example-instance --format="table(
        type,
        firewall_policy_name,
        rule_type,
        priority,
        action,
        direction,
        ip_ranges.list():label=IP_RANGES,
        target_svc_acct,
        enableLogging,
        description,
        name,
        disabled,
        target_tags,
        src_svc_acct,
        src_tags,
        ruleTupleCount,
        targetResources:label=TARGET_RESOURCES)"
        )DESCRIPTIONEXAMPLESN)rm   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   r
   "googlecloudsdk.command_lib.computer   ,googlecloudsdk.command_lib.compute.instancesr   googlecloudsdk.corer   DefaultUniverseOnlyReleaseTracksr2   GABETAALPHADescribeCommandListCommandr   detailed_helpr0   r   r   <module>r      s    Z &  ' 7 : 1 ( . 4 Q # $++00$2C2C2I2IJ9D00$2B2B J9 J9\#'  #r   