
    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 d
 Z G d de      Zej.                   ej0                  ej2                  j4                         G d dej6                                      Z ej0                  ej2                  j:                         G d de             Z ej0                  ej2                  j>                         G d de             Z y)z)Command for creating service attachments.    )absolute_import)division)unicode_literals)base_classes)base)flags)scope)service_attachments_utilsc                      ddddS )N2Create a Google Compute Engine service attachment.a        *{command}* is used to create service attachments. A service producer
      creates service attachments to make a service available to consumers.
      Service consumers use Private Service Connect endpoints to privately
      forward traffic to the service attachment.
      a        If there is an already-created internal load balancer (ILB) with the name
      MY_ILB in region us-central1 and there is an already-created Private
      Service Connect subnets MY_SUBNET1 and MY_SUBNET2, create a service
      attachment pointing to the ILB by running:

        $ {command} SERVICE_ATTACHMENT_NAME --region=us-central1 --producer-forwarding-rule=MY_ILB --connection-preference=ACCEPT_AUTOMATIC --nat-subnets=MY_SUBNET1,MY_SUBNET2

      To create a service attachment with a textual description, run:

        $ {command} SERVICE_ATTACHMENT_NAME --region=us-central1 --producer-forwarding-rule=MY_ILB --connection-preference=ACCEPT_AUTOMATIC --nat-subnets=MY_SUBNET1,MY_SUBNET2 --description='default service attachment'

      )briefDESCRIPTIONEXAMPLES r       1lib/surface/compute/service_attachments/create.py_DetailedHelpr      s     ?


 r   c                   8    e Zd ZdZdZdZdZd Zed        Z	d Z
y)CreateHelperz,Helper class to create a service attachment.Nc                     || _         y N)_holder)selfholders     r   __init__zCreateHelper.__init__B   s	    DLr   c                 ,   t        j                         | _        | j                  j                  |d       t	        j
                         | _        t        j                         | _	        | j                  j                  |       |j                  j                  t         j                         |j                  j                  t         j                         t        j                  |       t        j                   |       t        j"                  |d       t        j$                  |       t        j&                  |       t        j(                  |       t        j*                  |       t        j,                  |       t        j.                  |       y)zCreate a Google Compute Engine service attachment.

    Args:
      parser: the parser that parses the input from the user.
    create)operation_typeF)	is_updateN)r   ServiceAttachmentArgumentSERVICE_ATTACHMENT_ARGAddArgumentforwarding_rule_flags*ForwardingRuleArgumentForServiceAttachmentPRODUCER_FORWARDING_RULE_ARGsubnetwork_flags&SubnetworkArgumentForServiceAttachmentNAT_SUBNETWORK_ARGdisplay_info	AddFormatDEFAULT_LIST_FORMATAddCacheUpdaterServiceAttachmentsCompleterAddDescription-AddTargetServiceAndProducerForwardingRuleArgsAddConnectionPreferenceAddEnableProxyProtocolForCreate AddReconcileConnectionsForCreateAddConsumerRejectListAddConsumerAcceptListAddDomainNamesAddPropagatedConnectionLimitclsparsers     r   ArgszCreateHelper.ArgsE   s"    "'!@!@!BC**6(*KHHJ $ 	??A  &&v.
!!%";";<
''(I(IJ	 	77?	!!&E:	))&1	**62	'	'	 	&&v.r   c           	         | j                   j                  }| j                  j                  || j                   j                  t
        j                  j                        }| j                  j                  || j                   j                  t
        j                  j                        }|j                  x}r|}d}n"|r |j                         }|j                         }| j                  j                  || j                   j                  t
        j                  j                  t        j                  |            }|D 	cg c]  }	|	j                          }
}	t        j                  ||j                         }|j"                  }|j                   j%                  |j&                  |j)                         |
||      }|j+                  d      r|j,                  |_        |j+                  d      r't        j0                  ||j                         }||_        |j+                  d      r|j4                  |_        |j+                  d      r|j8                  |_        |j+                  d	      r|j<                  |_        |j                   jA                  |jB                  |jD                  |
      }|jF                  jH                  }|jK                  |d|fg      S c c}	w )z*Issue a service attachment INSERT request.)default_scopeN)r<   scope_lister)descriptionname
natSubnetsconnectionPreferenceenableProxyProtocolproducerForwardingRuletargetServiceconsumer_reject_listconsumer_accept_listdomain_namesreconcile_connectionspropagated_connection_limit)projectregionserviceAttachmentInsert)&r   clientr!   ResolveAsResource	resourcescompute_scope	ScopeEnumREGIONr%   target_serviceSelfLinkr(   compute_flagsGetDefaultScopeListerr
   GetConnectionPreferencemessagesenable_proxy_protocolServiceAttachmentr>   NameIsSpecifiedrE   consumerRejectListsGetConsumerAcceptListconsumerAcceptListsrG   domainNamesrH   reconcileConnectionsrI   propagatedConnectionLimit&ComputeServiceAttachmentsInsertRequestrJ   rK   apitools_clientserviceAttachmentsMakeRequests)r   argsrN   service_attachment_refproducer_forwarding_rule_reftarget_service_argsrT   producer_forwarding_rulenat_subnetwork_refsnat_subnetwork_refnat_subnetworksconnection_preferencerZ   service_attachmentaccept_listrequest
collections                    r   RunzCreateHelper.Runc   s   \\  F!88JJ#--44 K  	));;LL""'1188 	< 	
 ! #1111*n!%	%!=!F!F!H3<<>n11CC#--44"88@	 D  #6"5 	##%"5   6MMfoo 66::$$#((*"217$ ;  .//3/H/H,./-CC
!k/:,''+'8'8$/0040J0J-56

*
* 2 ooDD&..%,,, E .G ''::JXw ?@AAMs   K)__name__
__module____qualname____doc__r!   r%   r(   r   classmethodr:   ru   r   r   r   r   r   ;   s7    4!% / /:ABr   r   c                   4    e Zd ZdZ e       Zed        Zd Zy)Creater   c                 .    t         j                  |       y r   )r   r:   r7   s     r   r:   zCreate.Args   s    fr   c                 |    t        j                  | j                               }t        |      j	                  |      S r   )r   ComputeApiHolderReleaseTrackr   ru   )r   rh   r   s      r   ru   z
Create.Run   s1    **4+<+<+>?F##D))r   N)	rv   rw   rx   ry   r   detailed_helprz   r:   ru   r   r   r   r|   r|      s%    
 ;/- *r   r|   c                       e Zd ZdZ e       Zy)
CreateBetar   Nrv   rw   rx   ry   r   r   r   r   r   r   r           ;/-r   r   c                       e Zd ZdZ e       Zy)CreateAlphar   Nr   r   r   r   r   r      r   r   r   N)!ry   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   rV   r	   rQ   3googlecloudsdk.command_lib.compute.forwarding_rulesr#   3googlecloudsdk.command_lib.compute.networks.subnetsr&   6googlecloudsdk.command_lib.compute.service_attachmentsr
   r   objectr   UniverseCompatibleReleaseTracksr   GACreateCommandr|   BETAr   ALPHAr   r   r   r   <module>r      s    0 &  ' 7 ( E E ^ Y H \8iB6 iBX *T * * " "" "& ""r   