
    2                         S r SSKJr  SSKJr  SSKJr  SSKrSSKJs  Jr	  SSK
Jr  SSKJr  S rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rg)z3Utilities for "gcloud metastore services" commands.    )absolute_import)division)unicode_literalsN)parsers)
propertiesc                  d    [         R                  R                  R                  R	                  SS9$ )zReturns the value of the metastore/tier config property.

Config properties can be overridden with command line flags. If the --tier
flag was provided, this will return the value provided with the flag.
T)required)r   VALUES	metastoretierGet     9lib/googlecloudsdk/command_lib/metastore/services/util.pyGetTierr      s*     
			$	$	)	)	-	-t	-	<<r   c                     0 n[         R                  " U 5      nUR                  S5       H9  nUR                  S5      R                  XR                  S5      R                  '   M;     U$ )z:Convert Input XML file into Hive metastore configurations.propertyvaluename)element_tree
fromstringiterfindtext)file_arghive_metastore_configsrootprops       r   #LoadHiveMetatsoreConfigsFromXmlFiler   %   sX    		 	 	*$ii
#d59YYw5G5L5L99V,112 $	r   c                     UR                   (       d  UR                  (       a'  SUR                  R                  R                  l        U$ UR                  (       a  SUR                  l        U$ )a  Updates the Service scaling config.

Sets autoscalingEnabled to true if the service specified a min scaling factor,
max scaling factor, or both. Sets the scaling config to None if tier is
specified. If no scaling configs are specified, the scaling config is set to
None.

Args:
  args: The request arguments.
  req: A request with `service` field.

Returns:
  The same request object with a modified scaling config.
  1. Scaling config with autoscaling enabled if min or max scaling factors are
  specified.
  2. Scaling config is set to None if tier is specified. Do note if tier and
  scaling configs are specified, the SDK will throw a 400. The scaling config
  is set to an empty dictionary by default that fails on the server side.
TN)min_scaling_factormax_scaling_factorservicescalingConfigautoscalingConfigautoscalingEnabledr   
unused_refargsreqs      r   UpdateScalingConfigr+   /   sN    ( 
 7 7EICKK//B 
* yy $CKK	*r   c                     [        XU5      nUR                  (       dD  UR                  (       d3  UR                  (       d"  UR                  (       d  SUR
                  l        U$ )a  Updates the Service scaling config.

Sets autoscalingEnabled to true if the service specified a min scaling factor,
max scaling factor, or both. Sets the scaling config to None if tier is
specified. If no scaling configs are specified, the scaling config is set to
None.

Args:
  args: The request arguments.
  req: A request with `service` field.

Returns:
  A request with a modified scaling config.
N)r+   r!   r"   instance_sizescaling_factorr#   r$   r'   s      r   UpdateScalingConfigForCreater/   J   sE     	Jc2#
		 	 						 $CKK	*r   c           	          UR                   (       aN  SUR                    Vs/ s H%  nS[        R                  " X1R                  5      0PM'     sn0UR                  l        U$ s  snf )zGenerates the NetworkConfig message from the list of subnetworks.

Args:
  args: The request arguments.
  req: A request with `service` field.

Returns:
  A request with network configuration field if `consumer-subnetworks` is
  present in the arguments.
	consumers
subnetwork)consumer_subnetworksr   ParseSubnetworklocationr#   networkConfig)r(   r)   r*   ss       r   #GenerateNetworkConfigFromSubnetListr8   d   s_     
..
. 7221mmDE.
!CKK 
*
s   ,A"c                     UR                   (       aV  UR                  R                  c  0 UR                  l        [        UR                   5      UR                  R                  l        U$ )aY  Generates the auxiliary versions map from the list of auxiliary versions.

Args:
  args: The request arguments.
  req: A request with `service` field.

Returns:
  If `auxiliary-versions` is present in the arguments, a request with hive
  metastore config's auxiliary versions map field is returned.
  Otherwise the original request is returned.
)auxiliary_versionsr#   hiveMetastoreConfig%_GenerateAuxiliaryVersionsVersionListauxiliaryVersionsr'   s      r   'GenerateAuxiliaryVersionsConfigFromListr>   y   sP     

{{&&.(*ckk%-d.E.EF KK##5 
*r   c                 ^    0 nU  H$  nSUS   0XS   '   SU;   d  M  US   XS      S'   M&     U$ )a&  Convert Input YAML file into auxiliary versions configurations map.

Args:
  file_contents: The YAML file contents of the file containing the auxiliary
    versions configurations.

Returns:
  The auxiliary versions configuration mapping with service name as the key
  and config as the value.
versionr   config_overridesconfigOverridesr   )file_contentsaux_versions
aux_configs      r   (LoadAuxiliaryVersionsConfigsFromYamlFilerF      sU     ,!j(1:i3H'ILF#$Z'<F
=lf%&'89 " 
r   c                     [         R                  " U 5      n0 nSU;   a  UR                  S5      US'   UR                  SS5      (       a"  SU;  a  [	        S5      eSU;  a  [	        S5      eUR                  S5      US'   UR                  S5      US'   UR                  SS5      US'   U$ ! [         R
                  [        4 a  n[	        S	U 35      eS
nAff = f)zConvert Input JSON file into scheduled backup configurations map.

Args:
  file_contents: The JSON file contents of the file containing the scheduled
    backup configurations.

Returns:
  The scheduled backup configuration mapping with key and value.
enabledFcron_schedulez%Missing required field: cron_schedulebackup_locationz'Missing required field: backup_location	time_zoneUTCz2Invalid scheduled backup configuration JSON data: N)jsonloadspopget
ValueErrorJSONDecodeErrorKeyError)rC   scheduled_backup_configsconfiges       r   &LoadScheduledBackupConfigsFromJsonFilerW      s    O#zz-8F,,266yAfYzz)U##	 8	8@AA	":	:BCC6::?KF? 8 < <=N OF266{EJF;M


	) O
I!M
NNOs   B)B, ,CCCc                 t    [        U R                  5       5       VVs/ s H	  u  pXS.PM     nnnSU0$ s  snnf )z8Format values_dict into additionalProperties-style dict.)keyr   additionalProperties)sorteditems)values_dictkvpropss       r   _GenerateAdditionalPropertiesra      s<    .4[5F5F5H.I
J.Ida1!.I%
J
 %	(( Ks   4c                 D   SnSn0 SS_SS_SS_S	S
_SS_SS_SS_SS_SU_SU_SS_SS_SS_SS_SS_SS_SS_S S S!S"S"S"S#S#S$S#S#S%S&S'S(S).En[        5       n[        U R                  5       5      R                  U5       H  nUR                  X5   5        M     US*-   nX;  an  U R                  (       a&  U R                   H  nUR                  Xg-   5        M     U R
                  (       a&  U R
                   H  nUR                  Xg-   5        M     US*-   nX$;  an  U R                  (       a&  U R                   H  nUR                  X-   5        M     U R                  (       a&  U R                   H  nUR                  X-   5        M     S+R                  [        U5      5      $ ),zConstructs updateMask for patch requests.

Args:
  args: The parsed args namespace from CLI.

Returns:
  String containing update mask for patch request.
z&hive_metastore_config.config_overrideslabelsz--portportz--tierr   z--instance-sizezscaling_config.instance_sizez--scaling-factorzscaling_config.scaling_factorz--autoscaling-enabledz5scaling_config.autoscaling_config.autoscaling_enabledz--min-scaling-factorzAscaling_config.autoscaling_config.limit_config.min_scaling_factorz--max-scaling-factorzAscaling_config.autoscaling_config.limit_config.max_scaling_factorz)--update-hive-metastore-configs-from-filez--clear-hive-metastore-configsz--clear-labelsz--kerberos-principalz/hive_metastore_config.kerberos_config.principalz--keytabz,hive_metastore_config.kerberos_config.keytabz--krb5-configz9hive_metastore_config.kerberos_config.krb5_config_gcs_uriz--maintenance-window-daymaintenance_windowz--maintenance-window-hourz--data-catalog-syncz-metadataIntegration.dataCatalogConfig.enabledz--no-data-catalog-syncdeletion_protectionz'hive_metastore_config.endpoint_protocolz(hive_metastore_config.auxiliary_versionsscheduled_backupzscheduled_backup.enabled#bigquery_metastore_migration_configz7bigquery_metastore_migration_config.bigquery_project_idz=bigquery_metastore_migration_config.bigquery_dataset_locationz;bigquery_metastore_migration_config.desired_migration_state)z--deletion-protectionz--no-deletion-protectionz--endpoint-protocolz--add-auxiliary-versionsz%--update-auxiliary-versions-from-filez--clear-auxiliary-versionsz$--scheduled-backup-configs-from-filez--enable-scheduled-backupz--no-enable-scheduled-backupz--scheduled-backup-cronz--scheduled-backup-locationz+--clear-bigquery-metastore-migration-configz--bigquery-project-idz--bigquery-dataset-locationz--desired-migration-state.,)
setGetSpecifiedArgNamesintersectionaddupdate_hive_metastore_configsremove_hive_metastore_configsupdate_labelsremove_labelsjoinr[   )	r)   r   rc   arg_name_to_fieldupdate_maskarg_name)hive_metastore_configs_update_mask_prefixrY   labels_update_mask_prefixs	            r   _GenerateUpdateMaskry      sJ    D&555 75 9	5
 
A5 
M5 
M5 2
25" '(>#5$ %5& O'5( @)5* 
E-50 !"6152 "#7354 L556  O758  5"7F"L
4$N.@#5&@!3%7
/ D J Hg5n +d//12??h OO%/0 /Es.J+.))33#AGH 4))33#AGH 4$sl###178 $###178 $	&%	&&r   c                     0 nUR                   (       a  UR                   nUR                  (       a  [        UR                  5      n[        U5      UR                  R
                  l        U$ )a;  Modify the Service update request to update, remove, or clear Hive metastore configurations.

Args:
  unused_ref: A resource ref to the parsed Service resource.
  args: The parsed args namespace from CLI.
  update_service_req: Created Update request for the API call.

Returns:
  Modified request for the API call.
)ro   'update_hive_metastore_configs_from_filer   ra   r#   r;   rB   )unused_job_refr)   update_service_reqr   s       r   +SetServiceRequestUpdateHiveMetastoreConfigsr~   %  sc     	''!??	11@44 $$:; 00@ 
r   c                 ,   UR                   R                  c  0 UR                   l        UR                  (       a  0 UR                   R                  l        UR                  (       a.  [        UR                  5      UR                   R                  l        U$ )a  Modify the Service update request to add or clear list of auxiliary versions configurations.

Args:
  unused_ref: A resource ref to the parsed Service resource.
  args: The parsed args namespace from CLI.
  update_service_req: Created Update request for the API call.

Returns:
  Modified request for the API call containing auxiliary version updates if
  specified else the original request.
)r#   r;   clear_auxiliary_versionsr=   add_auxiliary_versionsr<   )r|   r)   r}   s      r   &GenerateUpdateAuxiliaryVersionsConfigsr   ?  sv     33;572	""GI22D	  -d.I.IJ 22D 
r   c           
      p    [        U  Vs0 s H  nSUR                  SS5      -   SU0_M     sn5      $ s  snf )Nzaux-ri   -r@   )ra   replace)rD   r@   s     r   r<   r<   X  sI    	&!(!' wsC((9g*>>!( 
  (s   "3c                 &    [        U5      Ul        U$ )a(  Constructs updateMask for update requests of Dataproc Metastore services.

Args:
  unused_ref: A resource ref to the parsed Service resource.
  args: The parsed args namespace from CLI.
  update_service_req: Created Update request for the API call.

Returns:
  Modified request for the API call.
)ry   
updateMask)r(   r)   r}   s      r   UpdateServiceMaskHookr   _  s     #6d";	r   )__doc__
__future__r   r   r   rM   xml.etree.cElementTreeetreecElementTreer   $googlecloudsdk.command_lib.metastorer   googlecloudsdk.corer   r   r   r+   r/   r8   r>   rF   rW   ra   ry   r~   r   r<   r   r   r   r   <module>r      sl    : &  '  - - 8 *= 64***OD)W't42r   