
    b                         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  G d dej                         Z G d dej$                        Zy)z?Command for removing an interface from a Compute Engine router.    )absolute_import)division)unicode_literals)encoding)base_classes)arg_parsers)base)flags)
exceptionsc                   "     e Zd ZdZ fdZ xZS )InterfaceNotFoundErrorz&Raised when an interface is not found.c                     ddj                  dgt        |      z        z   t        |      z  dz   }t        t        |   |       y )Nz
interface z, z%sz
 not found)joinlentuplesuperr   __init__)self	name_list	error_msg	__class__s      /lib/surface/compute/routers/remove_interface.pyr   zInterfaceNotFoundError.__init__!   sO    			Y!! !$))$457CDI	
 $     )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      s    . r   r   c                   R    e Zd ZdZdZed        Zed        Zd Zd Z	d Z
d Zd	 Zy)
RemoveInterfacezvRemove an interface from a Compute Engine router.

  *{command}* removes an interface from a Compute Engine router.
  Nc                    t        j                         | _        | j                  j                  |d       |j	                  d      }|j                  dd       |j                  dt        j                         d	d
       y )Nupdate)operation_typeT)requiredz--interface-namez(The name of the interface being removed.)helpz--interface-namesINTERFACE_NAMEz/The list of names for interfaces being removed.)typemetavarr%   )r
   RouterArgument
ROUTER_ARGAddArgumentadd_mutually_exclusive_groupadd_argumentr   ArgList)clsparserinterface_parsers      r   _ArgszRemoveInterface._Args0   s    ))+CNNNvh?::D:I!!!K " M!!  " >	 " @r   c                 &    | j                  |       y N)r2   )r/   r0   s     r   ArgszRemoveInterface.Args?   s    IIfr   c                     |j                   j                  d|j                  j                  |j	                         |j
                  |j                        fS )NGet)routerregionproject)apitools_clientroutersmessagesComputeRoutersGetRequestNamer9   r:   )r   client
router_refs      r   GetGetRequestzRemoveInterface.GetGetRequestC   sQ    ""**OO44!(!(("** 5 ,- -r   c                     |j                   j                  d|j                  j                  |j	                         ||j
                  |j                        fS )NPatch)r8   routerResourcer9   r:   )r;   r<   r=   ComputeRoutersPatchRequestr?   r9   r:   )r   r@   rA   replacements       r   GetSetRequestzRemoveInterface.GetSetRequestK   sT    ""**OO66!(*!(("**	 7 ,- -r   c                    |j                   r|j                   ng }||j                  r|j                  gng z   }d}g }t        j                  |      }t        j                  |      }|j                  D ]f  }	|	j
                  |v s|	}|j                  j                  |       |j                  s|j                  d       |j                  |j
                         h t        t        |      t        |      z
        }
|
rt        |
      |S )zBMutate the router and record any cleared_fields for Patch request.N
interfaces)interface_namesinterface_namer   CopyProtoMessagerJ   nameremoveappendlistsetr   )r   argsexistingcleared_fieldsinput_remove_list	interfaceacutal_remove_listrG   existing_routerinot_found_interfaces              r   ModifyzRemoveInterface.ModifyT   s     150D0D,,")040C0C /3.A.A-BIKM I++H5K//9O''	
$	$	%%i0%%



-!!)..1 ( s#45<N8OOP"#677r   c                    t        j                  | j                               }|j                  }| j                  j                  ||j                        }| j                  ||      }|j                  |g      }g }| j                  ||d   |      }|j                  j                  |      5  |j                  | j                  |||      g      }	|	cd d d        S # 1 sw Y   y xY w)Nr   )r   ComputeApiHolderReleaseTrackr@   r*   ResolveAsResource	resourcesrB   MakeRequestsr\   r;   IncludeFieldsrH   )
r   rS   holderr@   rA   get_requestobjectsrU   
new_objectresults
             r   _RunzRemoveInterface._Runp   s    **4+<+<+>?F]]F2249I9IJJ$$VZ8K!!;-0G NT71:~>J				-	-n	=""fj*=
>@f	 
>	=	=s   -%CC%c                 $    | j                  |      S r4   )ri   )r   rS   s     r   RunzRemoveInterface.Run   s    99T?r   )r   r   r   r   r*   classmethodr2   r5   rB   rH   r\   ri   rk    r   r   r    r    (   sO    
 *@ @  --8&r   r    N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r	   *googlecloudsdk.command_lib.compute.routersr
   googlecloudsdk.corer   Errorr   UpdateCommandr    rm   r   r   <module>rv      sL     F &  ' % 7 / ( < *Z-- \d(( \r   