
                         2   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 Zd Ze
j&                   e
j(                  e
j*                  j,                         G d de
j.                                      Ze
j&                   e
j(                  e
j*                  j2                         G d de                    Ze
j&                   e
j(                  e
j*                  j6                         G d de                    Zy)z!gcloud dns policy update command.    )absolute_import)division)unicode_literals)util)apis)base)flags)resource_args)logc                    t        j                         j                  |        t        j                         j                  |        t        j                         j                  |        t        j
                         j                  |        t        j                         j                  |        t        j                         j                  |        t        j                  d      j                  |        y )NT)update)	r	   GetPolicyDescriptionArgAddToParserGetPolicyNetworksArgGetPolicyInboundForwardingArgGetPolicyAltNameServersArgGetPolicyLoggingArg!GetPolicyPrivateAltNameServersArgGetEnableDns64AllQueriesArgparsers    "lib/surface/dns/policies/update.py_AddArgsCommonr      s    !--f5**62%%'33F;""$008))&1))+77?##40<<VD    c                       y)N)networksdescriptionenable_inbound_forwardingenable_loggingalternative_name_serversenable_dns64_all_queries r"   r   r   _ArgsNeededForUpdateCommonr#   (   s    
r   c                   ,    e Zd ZdZd Zed        Zd Zy)UpdateGAUpdate an existing Cloud DNS policy.

  Update an existing Cloud DNS policy.

  ## EXAMPLES

  To change the description of a policy, run:

    $ {command} mypolicy --description="Hello, world!"

  c                     t        j                  |      }t        j                  d|      }|j	                  |j                         |j                        }|j                  j                  |      S )zGet policy to be Updated.dns)policyproject)	r   GetApiClientr   GetMessagesModuleDnsPoliciesGetRequestNamer*   policiesGet)self
policy_refapi_versionclientmget_requests         r   _FetchPolicyzUpdateGA._FetchPolicyB   s`    {+Fuk2A)) **<*< * >K??{++r   c                     t        j                  | dd       t        |        | j                  j	                  d       y )N	to updatev1verbr3   jsonr
   AddPolicyResourceArgr   display_info	AddFormatr   s    r   ArgszUpdateGA.ArgsJ   s3    &&[d46
!!&)r   c                 l   t        j                  | j                               }t        j                  |      }t	        j
                  d|      }j                  j                  j                         }| j                  ||      }t               }t        fd|D              s!t        j                  j                  d       |S j                  d      rGj                   dgk(  rg _        t#        j$                  j                   |j&                  |      |_        j                  d      sj                  d      r_j(                  dgk(  rg _        j*                  dgk(  rg _        t#        j,                  |j(                  j*                        |_        j                  d	      rj0                  |_        j                  d
      rj4                  |_        j                  d      r1|j9                  |j;                  j<                              |_        j                  d      rj@                  |_         |jC                  |jD                  ||j&                        }|jF                  jI                  |      j                  }	t        jJ                  |	jD                  d       |	S )Nr(   c              3   @   K   | ]  }j                  |        y wNIsSpecified.0argargss     r   	<genexpr>zUpdateGA.Run.<locals>.<genexpr>Z        G0Ft$0F   Nothing to update.r    r     private_alternative_name_serversversionserver_listprivate_server_listr   r   r!   
allQueriesscoper   r)   policyResourcer*   Policykind&r   GetApiFromTrackReleaseTrackr+   r   r,   CONCEPTSr)   Parser7   r#   anyr   statusPrintrG   r   command_utilParsePolicyNetworksr*   r    rQ   ParseAltNameServersalternativeNameServerConfigr   enableInboundForwardingr   enableLoggingPolicyDns64ConfigPolicyDns64ConfigScoper!   dns64Configr   DnsPoliciesUpdateRequestnamer/   UpdateUpdatedResource
r1   rK   r3   r4   messagesr2   	to_updateargs_needed_for_update
update_requpdated_policys
    `        r   RunzUpdateGA.RunQ   sY   &&t'8'8':;K{+F%%e[9H %%++-J!!*k:I79G0FGG	jj+,
#	2$	';;
--++[:i 23t7G7G*8,		&	&2$	.(*%		.	.2$	602-.:.N.N33"CC/Ei+
 34*.*H*Hi'() $ 3 3i23&88//66 0  9 i &"..i22~~ "" 3 $J
 __++J7>>N++(;r   N)__name__
__module____qualname____doc__r7   staticmethodrB   rz   r"   r   r   r%   r%   3   s%    
, * *7r   r%   c                   &    e Zd ZdZed        Zd Zy)
UpdateBetar&   c                     t        j                  | dd       t        |        | j                  j	                  d       y )Nr9   v1beta2r;   r=   r>   r   s    r   rB   zUpdateBeta.Args   s3    &&[i96
!!&)r   c                 l   t        j                  | j                               }t        j                  |      }t	        j
                  d|      }j                  j                  j                         }| j                  ||      }t               }t        fd|D              s!t        j                  j                  d       |S j                  d      rGj                   dgk(  rg _        t#        j$                  j                   |j&                  |      |_        j                  d      sj                  d      r_j(                  dgk(  rg _        j*                  dgk(  rg _        t#        j,                  |j(                  j*                        |_        j                  d	      rj0                  |_        j                  d
      rj4                  |_        j                  d      r1|j9                  |j;                  j<                              |_        j                  d      rj@                  |_         |jC                  |jD                  ||j&                        }|jF                  jI                  |      j                  }	t        jJ                  |	jD                  d       |	S )Nr(   c              3   @   K   | ]  }j                  |        y wrE   rF   rH   s     r   rL   z!UpdateBeta.Run.<locals>.<genexpr>   rM   rN   rO   r   rP   r    rQ   rR   r   r   r!   rV   rX   r   rZ   r\   r]   r_   rt   s
    `        r   rz   zUpdateBeta.Run   sY   &&t'8'8':;K{+F%%e[9H %%++-J!!*k:I79G0FGG	jj+,
#	2$	';;
--++[:i 23t7G7G*8,		&	&2$	.(*%		.	.2$	602-.:.N.N33"CC/Ei+
 34*.*H*Hi'() $ 3 3i23&88//66 0  9 i &"..i22~~ "" 3 $J
 __++J7>>N++(;r   N)r{   r|   r}   r~   r   rB   rz   r"   r   r   r   r      s     
 * *5r   r   c                        e Zd ZdZed        Zy)UpdateAlphar&   c                     t        j                  | dd       t        |        | j                  j	                  d       y )Nr9   v1alpha2r;   r=   r>   r   s    r   rB   zUpdateAlpha.Args   s3    &&[j:6
!!&)r   N)r{   r|   r}   r~   r   rB   r"   r   r   r   r      s    
 * *r   r   N)r~   
__future__r   r   r   googlecloudsdk.api_lib.dnsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.command_lib.dnsr	   r
   rg   googlecloudsdk.corer   r   r#   UniverseCompatibleReleaseTracksra   GAUpdateCommandr%   BETAr   ALPHAr   r"   r   r   <module>r      s   ( &  ' + , ( 0 8 ? #E D%%(()St!! S * Sl D%%**+I I , IX D%%++,** * - *r   