
                         V   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 e
j(                  e
j*                  j,                  e
j*                  j.                  e
j*                  j0                         G d de
j2                               Zy)z)Command for updating network attachments.    )absolute_import)division)unicode_literals)encoding)base_classes)base)flags)scopec                      ddddS )N2Update a Google Compute Engine network attachment.a"        *{command}* is used to update network attachments. You can update the
      following fields: description, subnets, producer-accept-list and
      producer-reject-list. If you update the producer-accept-list or
      producer-reject-list, the full new list should be specified.
      a        To update all the parameters with the new list, run:

        $ {command} NETWORK_ATTACHMENT_NAME --region=us-central1 --subnets=MY_SUBNET2 --description='default network attachment' --producer-accept-list=PROJECT5,PROJECT6 --producer-reject-list=PROJECT7,PROJECT8

      To update a network attachment to change only the subnet to MY_SUBNET3, run:

        $ {command} NETWORK_ATTACHMENT_NAME --region=us-central1 --subnets=MY_SUBNET3

      )briefDESCRIPTIONEXAMPLES r       1lib/surface/compute/network_attachments/update.py_DetailedHelpr      s    C
	

 r   c                   P    e Zd ZdZdZ e       Zed        Zd Z	d Z
d Zd Zd Zy)	Updater   Nc                 Z   t        j                         | _        | j                  j                  |d       t	        j
                  d      | _        | j                  j                  |       t        j                  |       t        j                  |       t        j                  |       y )Nupdate)operation_typeF)required)
r	   NetworkAttachmentArgumentNETWORK_ATTACHMENT_ARGAddArgumentsubnetwork_flags&SubnetworkArgumentForNetworkAttachmentSUBNETWORK_ARGAddDescriptionAddProducerRejectListAddProducerAcceptList)clsparsers     r   ArgszUpdate.Args=   s    !&!@!@!BC**6(*K??O  ""6*	 	'	'r   c                      |j                   j                  di |j                         }|j                  j                  }|j                  |d|fg      d   S )z0Returns the existing NetworkAttachment resource.Getr   r   )messages#ComputeNetworkAttachmentsGetRequestAsDictapitools_clientnetworkAttachmentsMakeRequests)selfclientnetwork_attachment_refrequest
collections        r   _GetOldResourcezUpdate._GetOldResourceJ   s\    AfooAA 
 
'
'
)G ''::JUG <=>qAAr   c                    | j                   j                  ||j                  t        j                  j
                  t        j                  |j                              }|D cg c]  }|j                          }}|S c c}w )z*Returns subnetwork urls from the argument.)default_scopescope_lister)
r   ResolveAsResource	resourcescompute_scope	ScopeEnumREGIONcompute_flagsGetDefaultScopeListerr/   SelfLink)r.   holderargssubnetwork_refssubnetwork_refsubnetworkss         r   _GetSubnetworkszUpdate._GetSubnetworksR   s    ));;#--44"88G	 < O 9H8Gn!   s   #A>c                     |j                   j                  d|j                  j                  |j                  |j
                  |j                         |      fS )z3Returns a request to update the network attachment.Patch)projectregionnetworkAttachmentnetworkAttachmentResource)r+   r,   r(   %ComputeNetworkAttachmentsPatchRequestrG   rH   Name)r.   r/   r0   replacements       r   _GetPatchRequestzUpdate._GetPatchRequest_   sX     	11==*22)00499;&1	 	> 	
	 	r   c                    t        j                  |      }d}|j                  d      rHt        | j	                  ||            }|j
                  |t        |j
                        k7  r	||_        d}|j                  d      r,|j                  |j                  k7  r|j                  |_        d}|j                  d      rUt        |j                        }|j                  |t        |j                        k7  r||_        d}|s|j                  d       |j                  d      rUt        |j                        }	|j                  |	t        |j                        k7  r|	|_        d}|	s|j                  d	       |r|S y)
z'Returns the updated network attachment.FsubnetsNTdescriptionproducer_reject_listproducerRejectListsproducer_accept_listproducerAcceptLists)r   CopyProtoMessageIsSpecifiedsortedrD   rC   rQ   rR   rS   appendrT   rU   )
r.   r?   r@   old_resourcecleared_fieldsrM   
is_updatednew_subnetworksnew_reject_listnew_accept_lists
             r   _ModifyzUpdate._Modifyl   sx   ++L9KJ	"t33FDABo		!	!	)_

"
"A . #2
&			\55	5"&"2"2
./t889o		)	)	1_

*
*I 6 +:'



 5
6./t889o		)	)	1_

*
*I 6 +:'



 5
6r   c                    t        j                  | j                               }|j                  }| j                  j                  ||j                  t        j                  j                        }| j                  ||      }g }| j                  ||||      }||S |j                  j                  |      5  |j                  | j                  |||      g      cddd       S # 1 sw Y   yxY w)z)Issue a network attachment PATCH request.)r5   N)r   ComputeApiHolderReleaseTrackr/   r   r7   r8   r9   r:   r;   r3   r`   r+   IncludeFieldsr-   rN   )r.   r@   r?   r/   r0   rZ   r[   rM   s           r   Runz
Update.Run   s    **4+<+<+>?F]]F!88JJfm.E.E.L.L K  ''0FGLN,,vt\>JK				-	-n	=    )?M
N 
>	=	=s   7#C$$C-)__name__
__module____qualname____doc__r   r   detailed_helpclassmethodr%   r3   rD   rN   r`   re   r   r   r   r   r   4   sA     ;/-
( 
(B*Xr   r   N)ri   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   r<   r
   r9   6googlecloudsdk.command_lib.compute.network_attachments3googlecloudsdk.command_lib.compute.networks.subnetsr   r   ReleaseTracksrc   ALPHABETAGAUpdateCommandr   r   r   r   <module>rx      s    0 &  ' % 7 ( E E H Y, T..33T5F5F5I5IqT qqr   