
    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ZdZd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Z d Z!d Z"y)z8Shared resource flags for edge-cloud container commands.    )absolute_import)division)unicode_literals)util)messages)
exceptions)concepts)deps)concept_parsers)
propertiessystemAddonsConfig externalLoadBalancerAddressPoolsc                  0    t        j                  dd      S )NclusterzCluster of the {resource}.name	help_textr	    ResourceParameterAttributeConfig     Dlib/googlecloudsdk/command_lib/edge_cloud/container/resource_args.pyClusterAttributeConfigr   !   s    		2	2 <
> >r   c                  0    t        j                  dd      S )Nlocationz)Google Cloud location for the {resource}.r   r   r   r   r   LocationAttributeConfigr   &   s    		2	2!L
N Nr   c                  
   t        j                  d      t        j                  t        j                  j
                  j                        g} t               }| |_        t        j                  dd|t        j                        S )z6Gets the location resource spec for listing resources.
--locationz edgecontainer.projects.locationsr   )resource_namelocationsId
projectsId)r
   ArgFallthroughPropertyFallthroughr   VALUESedge_containerr   r   fallthroughsr	   ResourceSpec DEFAULT_PROJECT_ATTRIBUTE_CONFIG)r&   configs     r   GetLocationsListingResourceSpecr*   +   sp    
 ,'
z00??HHI	, #$&$&			(::	
< <r   c                  r    t        j                  ddt               t               t         j                        S )Nz)edgecontainer.projects.locations.clustersr   )r   
clustersIdr    r!   )r	   r'   r   r   r(   r   r   r   GetClusterResourceSpecr-   A   s0    			1'))+::
< <r   c                     t         j                  j                  dt               dj	                  d      d      j                  |        y)zAdds a resource argument for an Edge Container location.

  Args:
    parser: The argparse parser to add the resource arg to.
  r   zEdge Container location {}.zto listFrequiredN)r   ConceptParserForResourcer*   formatAddToParser)parsers    r   (AddLocationOptionalResourceArgForListingr6   J   sC     ++%'#**95	 ,  "k&)r   c                     |rdnd}t         j                  j                  |t               dj	                  |      d      j                  |        y)a  Adds a resource argument for an Edge Container cluster.

  Args:
    parser: The argparse parser to add the resource arg to.
    verb: str, the verb to describe the resource, such as 'to update'.
    positional: bool, whether the argument is positional or not.
  r   z	--clusterzEdge Container cluster {}.Tr/   N)r   r1   r2   r-   r3   r4   )r5   verb
positionalr   s       r   AddClusterResourceArgr:   W   sL     !k$++
"))$/	 ,  ![(r   c                  0    t        j                  dd      S )NnodePoolzNode pool of the {resource}.r   r   r   r   r   NodePoolAttributeConfigr=   g   s    		2	2!?
A Ar   c                      t        j                  ddt               t               t	               t         j
                        S )Nz3edgecontainer.projects.locations.clusters.nodePoolsz	node pool)r   r,   nodePoolsIdr    r!   )r	   r'   r   r=   r   r(   r   r   r   GetNodePoolResourceSpecr@   l   s6    			;'))+)+::
< <r   c                     d}t         j                  j                  |t               dj	                  |      d      j                  |        y)zAdds a resource argument for an Edge Container node pool.

  Args:
    parser: The argparse parser to add the resource arg to.
    verb: str, the verb to describe the resource, such as 'to update'.
  	node_poolzEdge Container node pool {}.Tr/   N)r   r1   r2   r@   r3   r4   )r5   r8   r   s      r   AddNodePoolResourceArgrC   v   sH     
$++
$++D1	 ,  ![(r   c                    | j                   j                         }t        j                  |      }| j                  }	 t        j                  |t           |j                        }||j                   _        y# t
        j                  t        t        f$ rM}t        j                  ddj                  |j                  r|j                  d               |            d}~ww xY w)z{Processes the cluster.system_addons_config.

  Args:
    args: command line arguments.
    req: API request to be issued
  z--system-addons-config'{}'r   N)calliope_commandReleaseTrackr   GetMessagesModulesystem_addons_configmessages_utilDictToMessageWithErrorCheckGDCE_SYS_ADDONS_CONFIGSystemAddonsConfigDecodeErrorAttributeErrorKeyErrorr   InvalidArgumentExceptionr3   argsr   r   )rR   reqrelease_trackmsgsdatarI   errs          r   ProcessSystemAddonsConfigrX      s     ''446-				.$		"	"$;(DD#$d&=&=? $8#++ 	 
#
#^X	> ;

-
- sxx9; ;589; ;;s   'A6 6C!ACC!c                 @    | j                  d      rt        | |       yy)zSets the cluster.system_addons_config if specified.

  Args:
    args: command line arguments.
    request: API request to be issued
  rI   N)IsKnownAndSpecifiedrX   rR   requests     r   SetSystemAddonsConfigr]      s"     
45dG, 6r   c                     t               }| D ]2  }d|v s|d   s|d   |v r
d|d    c S |j                  |d          4 y)a"  Checks for unique address pool names in the given list of dictionaries.

  Args:
    external_lb_address_pools: A list of dictionaries representing
    ExternalLoadBalancerPool messages.

  Returns:
    str: An error message if a duplicate address pool name is found,
    otherwise None.
  addressPoolzDuplicate address pool name: N)setadd)external_lb_address_poolsaddress_pool_setpools      r   CheckAddressPoolNameUniquenessre      s^     U'dm!4	m	 0	0.tM/B.CDD4./	 ( 
r   c                 x   | j                   j                         }t        j                  |      }| j                  }|sy|j                  t              }|syt        |      }|rt        j                  dd|       g }	 |D ]3  }t        j                  ||j                        }	|j                  |	       5 	 |r||j&                  _        yy# t        j                  t        t         f$ rM}t        j                  ddj#                  |j$                  r|j$                  d               |            d}~ww xY w)zProcesses the cluster.externalLoadBalancerAddressPools.

  Args:
    args: command line arguments.
    req: API request to be issued
  Nz--external-lb-address-poolszDuplicate address pool found: rE   r   )rF   rG   r   rH   rb   getGDCE_EXTERNAL_LB_CONFIGre   r   rQ   rJ   rK   ExternalLoadBalancerPoolappendrN   rO   rP   r3   rR   r   r   )
rR   rS   rT   rU   lbdatapoolsrW   mpoolsrd   mpools
             r   -ProcessExternalLoadBalancerAddressPoolsConfigro      s-    ''446-				.$))&	

**,
-%	
&u-#

-
-%
(. 
 &;77
--/emmE  39CKK0 	 
#
#^X	> ;

-
-%sxx9; ;589; ;;s    8C D9,AD44D9c                 @    | j                  d      rt        | |       yy)zSets the cluster.external_lb_address_pools if specified.

  Args:
    args: command line arguments.
    request: API request to be issued
  rb   N)rZ   ro   r[   s     r   )SetExternalLoadBalancerAddressPoolsConfigrq      s"     
9:1$@ ;r   N)T)#__doc__
__future__r   r   r   +googlecloudsdk.api_lib.edge_cloud.containerr   googlecloudsdk.api_lib.utilr   rJ   googlecloudsdk.callioper    googlecloudsdk.calliope.conceptsr	   r
   (googlecloudsdk.command_lib.util.conceptsr   googlecloudsdk.corer   rL   rh   r   r   r*   r-   r6   r:   r=   r@   rC   rX   r]   re   ro   rq   r   r   r   <module>rz      s~    ? &  ' < A . 5 1 D *- < >
N
<,<
*) A
<)8,	-.%:P	Ar   