
    0                        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 Zd Zd Zd Zd Zd Zd Zd Z ej4                  ej6                  j8                  ej6                  j:                  ej6                  j<                         G d dej>                               Z y)z,Command for adding a host rule to a URL map.    )absolute_import)division)unicode_literals)encoding)base_classes)arg_parsers)base)scope)flags)url_maps_utilsc                      ddddS )N7Add a rule to a URL map to map hosts to a path matcher.a  
*{command}* is used to add a mapping of hosts to a path
matcher in a URL map. The mapping will match the host
component of HTTP requests to path matchers which in turn map
the request to a backend service. Before adding a host rule,
at least one path matcher must exist in the URL map to take
care of the path component of the requests.
`gcloud compute url-maps add-path-matcher` or
`gcloud compute url-maps edit` can be used to add path matchers.
z
To create a host rule mapping the ```*-foo.example.com``` and
```example.com``` hosts to the ```www``` path matcher, run:

  $ {command} MY-URL-MAP --hosts='*-foo.example.com,example.com' --path-matcher-name=www
)briefDESCRIPTIONEXAMPLES r       -lib/surface/compute/url_maps/add_host_rule.py_DetailedHelpr       s     D	
 r   c                     | j                  dd       | j                  dt        j                  d      ddd	
       | j                  ddd       y)z%Add command line flags to the parser.z--descriptionz3An optional, textual description for the host rule.)helpz--hosts   )
min_lengthHOSTTaL        The set of hosts to match requests against. Each host must be
      a fully qualified domain name (FQDN) with the exception that
      the host can begin with a ``*'' or ``*-''. ``*'' acts as a
      glob and will match any string of atoms to the left where an
      atom is separated by dots (``.'') or dashes (``-'').
      )typemetavarrequiredr   z--path-matcher-namez      The name of the path matcher to use if a request matches this
      host rule. The path matcher must already exist in the URL map
      (see `gcloud compute url-maps add-path-matcher`).
      )r   r   N)add_argumentr   ArgList)parsers    r   _Argsr!   9   so     	@  B 	!,
   	
  r   c                     | j                   j                  d| j                  j                  |j	                         |j
                        fS )z6Returns the request for the existing URL map resource.Get)urlMapproject)apitools_clienturlMapsmessagesComputeUrlMapsGetRequestNamer%   clienturl_map_refs     r   _GetGetRequestr.   W   sK    

 
 
(
(%
//
2
2 %%'1D1D 3 F
G Gr   c                     | j                   j                  d| j                  j                  |j	                         ||j
                        fS )NUpdate)r$   urlMapResourcer%   )r&   r'   r(   ComputeUrlMapsUpdateRequestr*   r%   r,   r-   replacements      r   _GetSetRequestr5   ^   sL    

 
 
(
((
//
5
5 %%'(!)) 6 +
, ,r   c                     t        j                  |      }| j                  j                  |j                  t        |j                        |j                        }|j                  j                  |       |S )z#Returns a modified URL map message.)descriptionhostspathMatcher)
r   CopyProtoMessager(   HostRuler7   sortedr8   path_matcher_name	hostRulesappend)r,   argsexistingr4   new_host_rules        r   _ModifyrC   f   se    ))(3+//**""4::(( + *-
 }-	r   c                     | j                   j                  d| j                  j                  |j	                         |j
                  |j                        fS )zAReturns the request to get an existing regional URL map resource.r#   )r$   r%   region)r&   regionUrlMapsr(   ComputeRegionUrlMapsGetRequestr*   r%   rE   r+   s     r   _GetRegionalGetRequestrH   t   sR    

 
 
.
.
//
8
8 %%'!)) '' 9 )
* *r   c                     | j                   j                  d| j                  j                  |j	                         ||j
                  |j                        fS )zDReturns the request to update an existing regional URL map resource.r0   )r$   r1   r%   rE   )r&   rF   r(   !ComputeRegionUrlMapsUpdateRequestr*   r%   rE   r3   s      r   _GetRegionalSetRequestrK   }   sU    

 
 
.
.
//
;
; %%'(!)) ''	 < )
* *r   c                    |j                   }|j                  | |j                  t        j                  j
                        }t        j                  |      rt        ||      }nt        ||      }|j                  |g      d   }t        || |      }t        j                  |      rt        |||      }nt        |||      }|j                  |g      S ):Issues requests necessary to add host rule to the Url Map.)default_scoper   )r,   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALr   IsRegionalUrlMapRefrH   r.   MakeRequestsrC   rK   r5   )	r@   holderurl_map_argr,   r-   get_requestold_url_mapmodified_url_mapset_requests	            r   _Runr\      s     ==&--
FM,C,C,J,J . L+''4(=K 5K##[M215+VT;7''4(>NOK 6FGK			k]	++r   c                   8    e Zd ZdZ e       ZdZed        Zd Z	y)AddHostRuler   Nc                     t        j                         | _        | j                  j                  |       t	        |       y )N)r   UrlMapArgumentURL_MAP_ARGAddArgumentr!   )clsr    s     r   ArgszAddHostRule.Args   s+    **,COOO'	&Mr   c                 v    t        j                  | j                               }t        ||| j                        S )rM   )r   ComputeApiHolderReleaseTrackr\   ra   )selfr@   rV   s      r   RunzAddHostRule.Run   s0    **4+<+<+>?Ffd..//r   )
__name__
__module____qualname____doc__r   detailed_helpra   classmethodrd   ri   r   r   r   r^   r^      s+     @/-+ 
0r   r^   N)!rm   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r	   "googlecloudsdk.command_lib.computer
   rQ   +googlecloudsdk.command_lib.compute.url_mapsr   r   r   r!   r.   r5   rC   rH   rK   r\   ReleaseTracksrg   ALPHABETAGAUpdateCommandr^   r   r   r   <module>r{      s     3 &  ' % 7 / ( E = F2<G,**,6 D%%++T->->-C-C%%((*0$$$ 0*0r   