
    "                        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 ddlmZ dddZ G d dej0                        Ze
j4                   e
j6                  e
j8                  j:                  e
j8                  j<                         G d de
j>                                      Z d Z!d Z"d Z#d Z$ee _%        y)z1Command for adding interconnects to a wire group.    )absolute_import)division)unicode_literals)base_classes)client)base)scope)flags)
exceptions)
propertiesz        *{command}* is used to add interconnects to a wire group.

        For an example, refer to the *EXAMPLES* section below.
        a          To add an interconnect example-interconnect to wire group example-wire-group, run:

          $ {command} example-wire-group --project=example-project               --cross-site-network=example-cross-site-network               --endpoint-label=example-endpoint               --interconnect-label=example-interconnect               --interconnect=some-interconnect-uri               --vlan-tags=111,222
        )DESCRIPTIONEXAMPLESc                       e Zd ZdZy)InvalidEndpointErrorz.Raised when the endpoint label does not exist.N)__name__
__module____qualname____doc__     Alib/surface/compute/interconnects/wire_groups/add_interconnect.pyr   r   6   s    6r   r   c                   8    e Zd ZdZdZdZdZed        Zd Z	d Z
y)AddInterconnectztAdd interconnect to a Compute Engine wire group.

  *{command}* adds interconnect to a Compute Engine wire group.
  Nc                    t        j                         | _        | j                  j                  |       t	        j
                  d      | _        t        j                  d      | _	        | j                  j                  |d       | j                  j                  |       t        j                  |       t        j                  |       t        j                  |       y )Nz-The interconnect for the wire group endpoint.F)pluralupdate)operation_type)cross_site_network_flags(CrossSiteNetworkArgumentForOtherResourceCROSS_SITE_NETWORK_ARGAddArgumentinterconnect_flags$InterconnectArgumentForOtherResourceINTERCONNECT_ARGr
   WireGroupArgumentWIRE_GROUP_ARGAddEndpointLabelAddInterconnectLabelAddVlanTags)clsparsers     r   ArgszAddInterconnect.ArgsF   s     	!IIK  **62??;	
 
 00>C""6("C$$V,	6"	v&	fr   c                      y)Nzcompute.wireGroupsr   )selfs    r   
CollectionzAddInterconnect.CollectionX   s    r   c           	         t        j                  | j                               }| j                  j	                  ||j
                  t        j                  j                  d|j                  i      }t        j                  j                  j                  j                         }|j                  j                   | _        t        j$                  |||j                  |j                  |j
                        }|j&                  }|j(                  }|j*                  j-                  d      }|j/                         j0                  }	| j2                  j	                  ||j
                        }
t5        |	      }||vr+t7        ddj9                  |j;                               z         ||   j<                  }t?        |      }|j                  j                   jA                  |
jC                         |D cg c]  }tE        |       c}      ||<   tG        | j"                  |      }| j"                  jI                  |      ||<   tK        | j"                  |      }	|jM                  |		      S c c}w )
a  Runs the add-interconnect command.

    Modifies the existing endpoints and their interconnects. We need to break
    down the endpoints and interconnects to make it easier to add or update the
    interconnects. Since they are nested resources of a WireGroup, it can get
    tricky to do modifications.

    Args:
      args: Object containing CLI parameter values
    Returns:
      Result of running the request.

    Raises:
      InvalidEndpointError: If the endpoint does not exist.
    crossSiteNetwork)default_scopeadditional_params)refprojectcross_site_networkcompute_client	resources,z5Not a valid endpoint. Found the following endpoints: z, )interconnectvlanTags)interconnects)	endpoints)'r   ComputeApiHolderReleaseTrackr&   ResolveAsResourcer8   compute_scope	ScopeEnumGLOBALr6   r   VALUEScorer5   	GetOrFailr   messages	_messages	WireGroupendpoint_labelinterconnect_label	vlan_tagssplitDescriber=   r$   _convert_endpoints_to_dictr   joinkeysr<   _convert_interconnects_to_dictWireGroupEndpointInterconnectSelfLinkint_build_interconnect_messagesWireGroupEndpoint_build_endpoint_messagesPatch)r.   argsholderr4   r5   
wire_grouprJ   rK   rL   r=   interconnect_refendpoints_mapr<   interconnects_mapvlan_tags                  r   RunzAddInterconnect.Run[   s;     **4+<+<+>?F



/
/#--44-t/F/FG	 0 C $$,,668G]]++DN!!22}}""J ((N00$$S)I##%//I,,>>f  /y9M]* 
AIIm((*+, 
 ".1??M 7}E
 	<<)2244=>Ic(mI> 	= 	
 () 1)M %)NN$D$D# %E %M.! )GI    ?s   /I)
)r   r   r   r   r&   r    r$   classmethodr,   r/   ra   r   r   r   r   r   :   s7    
 . " Or   r   c                     i }| r| j                   s|S | j                   D ]  }|j                  |j                  }}|||<   ! |S )a  Extracts key value pairs from additionalProperties attribute.

  Creates a dict to be able to pass them into the client.

  Args:
    interconnects: the list of interconnect additionalProperties messages

  Returns:
    dictionary containing key value pairs
  additionalPropertieskeyvalue)r<   r_   interconnect_propertyrf   rg   s        r   rR   rR      sV     	m@@,AA&**,A,G,GC"c  B 
r   c                     i }| r| j                   s|S | j                   D ]  }|j                  |j                  }}|||<   ! |S )a  Extracts the key,value pairs from the additionalProperties attribute.

  Creates a python dict to be able to pass them into the client.

  Args:
    endpoints: the list of additionalProperties messages

  Returns:
    Python dictionary containing the key value pairs.
  rd   )r=   r^   endpoint_propertyrf   rg   s        r   rO   rO      sS     -	)88$99"&&(9(?(?CM# : 
r   c                     g }|j                         D ];  \  }}|j                  | j                  j                  j	                  ||             = | j                  j                  |      S )a  Builds a WireGroupEndpoint.InterconnectsValue message.

  Args:
    messages: the messages module
    interconnects_map: map of interconnects with label as the key and the
      interconnect message as the value

  Returns:
    WireGroupEndpoint.InterconnectsValue message
  rf   rg   re   )itemsappendrW   InterconnectsValueAdditionalProperty)rG   r_   interconnect_properties_listrK   interconnect_messages        r   rV   rV      s|     "$4E4K4K4M0/ ''""55HH"& 	I 	
 5N 
	#	#	6	67 
7 
 r   c                     g }|j                         D ];  \  }}|j                  | j                  j                  j	                  ||             = | j                  j                  |      S )ac  Builds a WireGroup.EndpointValue message.

  This is so we can re-assign them to the additionalProperties attribute on
  the WireGroup.EndpointsValue message.

  Args:
    messages: the messages module
    endpoints_map: map of endpoints with label as the key and the
      endpoint message as the value

  Returns:
    WireGroup.EndpointsValue message
  rl   rm   )rn   ro   rI   EndpointsValuerq   )rG   r^   endpoint_properties_listrJ   endpoints_messages        r   rX   rX      sz      -:-@-@-B)~(##))<<# 	= 	
 .C 
			*	*3 
+ 
 r   N)&r   
__future__r   r   r   googlecloudsdk.api_lib.computer   8googlecloudsdk.api_lib.compute.interconnects.wire_groupsr   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   rA   0googlecloudsdk.command_lib.compute.interconnectsr
   r"   Dgooglecloudsdk.command_lib.compute.interconnects.cross_site_networksr   <googlecloudsdk.command_lib.compute.interconnects.wire_groupsgooglecloudsdk.corer   r   DETAILED_HELPErrorr   UniverseCompatibleReleaseTracksr?   ALPHABETAUpdateCommandr   rR   rO   rV   rX   detailed_helpr   r   r   <module>r      s     8 &  ' 7 K ( E X r N * *	*7:++ 7 D%%++T->->-C-CDnd(( n E nb..48 !. r   