
                            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d Zd Zd Z	 ddZ ej2                  ej4                  j6                  ej4                  j8                        ej:                   G d dej<                                      Z ej2                  ej4                  j@                        ej:                   G d de                    Z!y)zCommand for creating URL maps.    )absolute_import)division)unicode_literals)base_classes)base)flags)scope)url_maps_utilsc                      dddd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                     | j                  dd       | j                  d      }|j                  dd       |j                  dd	       | j                  j                  t        j
                         y
)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           	      
   |j                   j                  |j                  |j                   j                  || j                  |j                                     }|j                  |j                  j                  d|fg      S )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           	          |j                   j                  |j                  |j                   j                  || j                  |j                               |j                        }|j                  |j                  j                  d|fg      S )Nr!   )r%   r&   regionr'   )
r(   !ComputeRegionUrlMapsInsertRequestr%   r*   r#   r+   r7   r,   r-   regionUrlMapsr/   s        r   _MakeRegionalRequestr:   n   s    OO==!!__##,&&! $ 
  > ' 
		,,h@A
 r   c                 p   |j                   }|j                  | |j                  t        j                  j
                  t        j                  |            }| j                  r1t        j                  | |||j                        j                         }n]|r1t        j                  | |||j                        j                         }n*|j                  | |j                        j                         }t        j                  |      rt        | |||      S t        j                  |      rt!        | |||      S y)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
"K1A1A
  /@@
  
  %%k2dK1DfMM))+6k3FOO 7r   c                   D    e Zd ZdZdZ e       ZdZdZdZ	e
d        Zd Zy)Creater   FNc                    |j                   j                  t        j                         | j                  rt        j                  d      | _        nt        j                  d      | _        t        j                  d      | _        t        j                         | _        | j                  j                  |d       t        |       y )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   ArgszCreate.Args   s    
!!%";";<
,,

M
M 
 
=
=u
M 
 	==uM  **,COOOx@	&Mr   c                     t        j                  | j                               }t        ||| j                  | j
                  | j                  | j                        S )N)r   ComputeApiHolderReleaseTrackrP   r[   r_   ra   rX   )selfr0   rK   s      r   Runz
Create.Run   sR    **4+<+<+>?F  .. r   )__name__
__module____qualname____doc__rX   r   detailed_helpr[   r_   ra   classmethodrd   ri   r   r   r   rR   rR      s<     &+#/-+ &	r   rR   c                       e Zd ZdZdZy)CreateAlphar   TN)rj   rk   rl   rm   rX   r   r   r   rq   rq      s     &*#r   rq   N)F)"rm   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   rC   r	   r@   2googlecloudsdk.command_lib.compute.backend_bucketsrY   3googlecloudsdk.command_lib.compute.backend_servicesr]   +googlecloudsdk.command_lib.compute.url_mapsr
   r   r   r5   r:   rP   ReleaseTracksrg   BETAGAUniverseCompatibleCreateCommandrR   ALPHArq   r   r   r   <module>r      s    % &  ' 7 ( E E \ ^ = F$N>4* &+#PL D%%**D,=,=,@,@A&T &  B&R D%%++,+& +  -+r   