
                            S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r  SSK	Jr  SSKJ
r  SSKJ
r  SSKJ
r
  SS	KJr  S
 rS rS rS r SS jr\R2                  " \R4                  R6                  \R4                  R8                  5      \R:                   " S S\R<                  5      5       5       r\R2                  " \R4                  R@                  5      \R:                   " S S\5      5       5       r!g)zCommand for creating URL maps.    )absolute_import)division)unicode_literals)base_classes)base)flags)scope)url_maps_utilsc                      SSSS.$ )NCreate a URL map.a  
      *{command}* is used to create URL maps which map HTTP and
      HTTPS request URLs to backend services and backend buckets.
      Mappings are done using a longest-match strategy.

      There are two components to a mapping: a host rule and a path
      matcher. A host rule maps one or more hosts to a path
      matcher. A path matcher maps request paths to backend
      services or backend buckets. For example, a host rule can map
      the hosts ``*.google.com'' and ``google.com'' to a path
      matcher called ``www''. The ``www'' path matcher in turn can
      map the path ``/search/*'' to the search backend service, the
      path ``/static/*'' to the static backend bucket  and everything
      else to a default backend service or default backend bucket.

      Host rules and patch matchers can be added to the URL map
      after the map is created by using `gcloud compute url-maps edit`
      or by using `gcloud compute url-maps add-path-matcher`
      and `gcloud compute url-maps add-host-rule`.
      a  
        To create a global URL map with a default service, run:

        $ {command} URL_MAP_NAME --default-service=BACKEND_SERVICE_NAME

        To create a regional URL map with a default service, run:

        $ {command} URL_MAP_NAME --default-service=BACKEND_SERVICE_NAME --region=REGION_NAME

        To create a global URL map with a default backend bucket, run:

        $ {command} URL_MAP_NAME --default-backend-bucket=BACKEND_BUCKET_NAME
      )briefDESCRIPTIONEXAMPLES r       &lib/surface/compute/url_maps/create.py_DetailedHelpr      s    "
(
-#
 #r   c                     U R                  SSS9  U R                  SS9nUR                  SSS9  UR                  SS	S9  U R                  R                  [        R
                  5        g
)z;Common arguments to create commands for each release track.z--descriptionz1An optional, textual description for the URL map.)helpTrequiredz--default-servicezA backend service that will be used for requests for which this URL map has no mappings. Exactly one of --default-service or --default-backend-bucket is required.z--default-backend-bucketzA backend bucket that will be used for requests for which this URL map has no mappings. Exactly one of --default-service or --default-backend-bucket is required.N)add_argumentadd_mutually_exclusive_groupdisplay_infoAddCacheUpdaterr   UrlMapsCompleter)parsergroups     r   _Argsr   F   s    O   
-
-t
-
<%2    2   	%%e&<&<=r   c           	          UR                   R                  UR                  UR                   R                  UU R                  UR                  5       S9S9nUR                  UR                  R                  SU4/5      $ )NdefaultServicedescriptionname)projecturlMapInsert)	messagesComputeUrlMapsInsertRequestr%   UrlMapr#   NameMakeRequestsapitools_clienturlMapsargsurl_map_refdefault_backend_uriclientrequests        r   _MakeGlobalRequestr5   `   s    OO77!!__##,&&! $  8 ' 
		&&':;
 r   c           	         UR                   R                  UR                  UR                   R                  UU R                  UR                  5       S9UR                  S9nUR                  UR                  R                  SU4/5      $ )Nr!   )r%   r&   regionr'   )
r(   !ComputeRegionUrlMapsInsertRequestr%   r*   r#   r+   r7   r,   r-   regionUrlMapsr/   s        r   _MakeRegionalRequestr:   n   s    OO==!!__##,&&! $ 
  > ' 
		,,h@A
 r   c                    UR                   nUR                  U UR                  [        R                  R
                  [        R                  " U5      S9nU R                  (       a0  [        R                  " XXqR                  5      R                  5       nO`U(       a0  [        R                  " XXqR                  5      R                  5       nO)UR                  XR                  5      R                  5       n[        R                  " U5      (       a  [        XX5      $ [        R                  " U5      (       a  [!        XX5      $ g)z.Issues requests necessary to create a Url Map.)default_scopescope_listerN)r3   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALcompute_flagsGetDefaultScopeListerdefault_servicer
   ResolveUrlMapDefaultServiceSelfLink!ResolveUrlMapDefaultBackendBucketIsGlobalUrlMapRefr5   IsRegionalUrlMapRefr:   )	r0   holderbackend_bucket_argbackend_service_argurl_map_arg supports_regional_backend_bucketr3   r1   r2   s	            r   _RunrP   }   s    ==&--
!++22 66v>	 . + 
(DD;0@0@hj  (*LL
K1A1A
  /@@
  
  %%k22d1DMM))+663FOO 7r   c                   L    \ rS rSrSrSr\" 5       rSrSr	Sr
\S 5       rS rSrg)Create   r   FNc                    UR                   R                  [        R                  5        U R                  (       a  [
        R                  " SS9U l        O[
        R                  " SS9U l        [        R                  " SS9U l        [        R                  " 5       U l        U R                  R                  USS9  [        U5        g )NFr   create)operation_type)r   	AddFormatr   DEFAULT_LIST_FORMAT!_supports_regional_backend_bucketbackend_bucket_flags.RegionSupportingBackendBucketArgumentForUrlMapBACKEND_BUCKET_ARGBackendBucketArgumentForUrlMapbackend_service_flagsBackendServiceArgumentForUrlMapBACKEND_SERVICE_ARGUrlMapArgumentURL_MAP_ARGAddArgumentr   )clsr   s     r   ArgsCreate.Args   s    
!!%";";<
,,

M
M 
 
=
=u
M 
 	==uM  **,COOOx@	&Mr   c                     [         R                  " U R                  5       5      n[        UUU R                  U R
                  U R                  U R                  5      $ )N)r   ComputeApiHolderReleaseTrackrP   r\   r`   rb   rY   )selfr0   rK   s      r   Run
Create.Run   sR    **4+<+<+>?F  .. r   r   )__name__
__module____qualname____firstlineno____doc__rY   r   detailed_helpr\   r`   rb   classmethodre   rk   __static_attributes__r   r   r   rR   rR      s<     &+#/-+ &	r   rR   c                       \ rS rSrSrSrSrg)CreateAlpha   r   Tr   N)rm   rn   ro   rp   rq   rY   rt   r   r   r   rv   rv      s     &*#r   rv   N)F)"rq   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   rC   r	   r@   2googlecloudsdk.command_lib.compute.backend_bucketsrZ   3googlecloudsdk.command_lib.compute.backend_servicesr^   +googlecloudsdk.command_lib.compute.url_mapsr
   r   r   r5   r:   rP   ReleaseTracksri   BETAGAUniverseCompatibleCreateCommandrR   ALPHArv   r   r   r   <module>r      s    % &  ' 7 ( E E \ ^ = F$N>4* &+#PL D%%**D,=,=,@,@A&T &  B&R D%%++,+& +  -+r   