
                         h    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 Z	d Z
d	 Zd
 Zd Zd Zy)z9Code that's shared between multiple url-maps subcommands.    )absolute_import)division)unicode_literals)operation_utils)scopec                     t        j                  | d      s.t        |      r|j                  | _        n| j
                  | _        |j                  | |      S )aE  Parses the backend service that is pointed to by a URL map from args.

  This function handles parsing a regional/global backend service that is
  pointed to by a regional/global URL map.

  Args:
    args: The arguments provided to the url-maps command
    backend_service_arg: The ResourceArgument specification for the backend
      service argument.
    url_map_ref: The resource reference to the URL MAP. This is returned by
      parsing the URL map arguments provided.
    resources: ComputeApiHolder resources.

  Returns:
    Backend service reference parsed from args.
  default_service)compute_scopeIsSpecifiedForFlagIsRegionalUrlMapRefregiondefault_service_regionr	   global_default_serviceResolveAsResource)argsbackend_service_argurl_map_ref	resourcess       Alib/googlecloudsdk/command_lib/compute/url_maps/url_maps_utils.pyResolveUrlMapDefaultServicer      sL    ( 
	)	)$0A	B;'$/$6$6d!$($8$8d!		.	.tY	??    c                     t        j                  | d      s.t        |      r|j                  | _        n| j
                  | _        |j                  | |      S )a  Parses the backend bucket that is pointed to by a URL map from args.

  This function handles parsing a backend bucket that is pointed to by a URL
  map. If neither the --default-backend-bucket-region,
  --global-default-backend-bucket is specified, the scope is set to the scope
  of url map.

  Args:
    args: The arguments provided to the url-maps command
    backend_bucket_arg: The ResourceArgument specification for the backend
      bucket argument.
    url_map_ref: The resource reference to the URL MAP. This is returned by
      parsing the URL map arguments provided.
    resources: ComputeApiHolder resources.

  Returns:
    Backend bucket reference parsed from args.
  default_backend_bucket)r
   r   r   r   default_backend_bucket_regionr   global_default_backend_bucketr   )r   backend_bucket_argr   r   s       r   !ResolveUrlMapDefaultBackendBucketr   6   sL    , 
	)	)$0H	I;'+6+=+=d(+/+F+Fd(		-	-dI	>>r   c                 (    | j                         dk(  S )z2Returns True if the URL Map reference is regional.compute.regionUrlMaps
Collectionr   s    r   r   r   U   s     
			!%<	<<r   c                 (    | j                         dk(  S )z0Returns True if the URL Map reference is global.zcompute.urlMapsr    r"   s    r   IsGlobalUrlMapRefr$   [   s     
			!%6	66r   c                 \   |j                         dk(  rM| j                  j                  j                   | j                  j
                  di |j                               S | j                  j                  j                   | j                  j                  di |j                               S )zSend Url Maps get request.r    )	r!   apitools_clientregionUrlMapsGetmessagesComputeRegionUrlMapsGetRequestAsDicturlMapsComputeUrlMapsGetRequest)clientr   s     r   SendGetRequestr0   a   s    !88!!//33666N9K9K9MN  
			'	'	+	+.foo..F1C1C1EF
 r   c                     |j                         dk(  rt        j                         }nt        j                         }t        j                  | |||||      S )ag  Waits for the URL map operation to finish.

  Args:
    resources: The resource parser.
    service: apitools.base.py.base_api.BaseApiService, the service representing
      the target of the operation.
    operation: The operation to wait for.
    url_map_ref: The URL map reference.
    message: The message to show.

  Returns:
    The operation result.
  r   )r!   r   GetRegionalOperationsCollectionGetGlobalOperationsCollectionWaitForOperation)r   service	operationr   message
collections         r   r4   r4   l   sR     !88 @@BJ >>@J		)	))Zg
 r   N)__doc__
__future__r   r   r   "googlecloudsdk.command_lib.computer   r   r
   r   r   r   r$   r0   r4   r&   r   r   <module>r<      s9    @ &  ' > E@:?>=7r   