@@ -529,6 +529,56 @@ def __validate_counts_in_autoscaler(
529529 )
530530 )
531531
532+ def __validate_cluster_autoscaler_profile (
533+ self , cluster_autoscaler_profile : Union [List , Dict , None ]
534+ ) -> Union [Dict , None ]:
535+ """Helper function to parse and verify cluster_autoscaler_profile.
536+
537+ If the user input is a list, parse it with function "extract_comma_separated_string". If the type of user input
538+ or parsed value is not a dictionary, raise an InvalidArgumentValueError. Otherwise, take the keys from the
539+ attribute map of ManagedClusterPropertiesAutoScalerProfile to verify whether the keys in the key-value pairs
540+ provided by the user are valid. If not, raise an InvalidArgumentValueError.
541+
542+ :return: dictionary or None
543+ """
544+ if cluster_autoscaler_profile is not None :
545+ # convert list to dict
546+ if isinstance (cluster_autoscaler_profile , list ):
547+ params_dict = {}
548+ for item in cluster_autoscaler_profile :
549+ params_dict .update (
550+ extract_comma_separated_string (
551+ item ,
552+ extract_kv = True ,
553+ allow_empty_value = True ,
554+ default_value = {},
555+ )
556+ )
557+ cluster_autoscaler_profile = params_dict
558+ # check if the type is dict
559+ if not isinstance (cluster_autoscaler_profile , dict ):
560+ raise InvalidArgumentValueError (
561+ "Unexpected input cluster-autoscaler-profile, value: '{}', type '{}'." .format (
562+ cluster_autoscaler_profile ,
563+ type (cluster_autoscaler_profile ),
564+ )
565+ )
566+ # verify keys
567+ # pylint: disable=protected-access
568+ valid_keys = list (
569+ k .replace ("_" , "-" ) for k in self .models .ManagedClusterPropertiesAutoScalerProfile ._attribute_map .keys ()
570+ )
571+ for key in cluster_autoscaler_profile .keys ():
572+ if not key :
573+ raise InvalidArgumentValueError ("Empty key specified for cluster-autoscaler-profile" )
574+ if key not in valid_keys :
575+ raise InvalidArgumentValueError (
576+ "'{}' is an invalid key for cluster-autoscaler-profile. Valid keys are {}." .format (
577+ key , ", " .join (valid_keys )
578+ )
579+ )
580+ return cluster_autoscaler_profile
581+
532582 def get_subscription_id (self ):
533583 """Helper function to obtain the value of subscription_id.
534584
@@ -4077,42 +4127,20 @@ def get_node_osdisk_diskencryptionset_id(self) -> Union[str, None]:
40774127 def _get_cluster_autoscaler_profile (self , read_only : bool = False ) -> Union [Dict [str , str ], None ]:
40784128 """Internal function to dynamically obtain the value of cluster_autoscaler_profile according to the context.
40794129
4130+ This function will call function "__validate_cluster_autoscaler_profile" to parse and verify the parameter
4131+ by default.
4132+
40804133 In update mode, when cluster_autoscaler_profile is assigned and auto_scaler_profile in the `mc` object has also
40814134 been set, dynamic completion will be triggerd. We will first make a copy of the original configuration
40824135 (extract the dictionary from the ManagedClusterPropertiesAutoScalerProfile object), and then update the copied
40834136 dictionary with the dictionary of new options.
40844137
4085- This function will verify the parameter by default. If the user input is not empty, take the keys from the
4086- attribute map of ManagedClusterPropertiesAutoScalerProfile to verify whether the keys in the key-value pairs
4087- provided by the user are valid. If not, raise an InvalidArgumentValueError. The value of the raw parameter
4088- should be a dictionary after being processed by the validator. If not, raise a CLIInternalError.
4089-
40904138 :return: dictionary or None
40914139 """
40924140 # read the original value passed by the command
40934141 cluster_autoscaler_profile = self .raw_param .get ("cluster_autoscaler_profile" )
4094- # validate user input (replace function "_validate_cluster_autoscaler_key" in file "_validators.py")
4095- if cluster_autoscaler_profile is not None :
4096- if not isinstance (cluster_autoscaler_profile , dict ):
4097- raise CLIInternalError (
4098- "Unexpected input cluster-autoscaler-profile, value: '{}', type '{}'." .format (
4099- cluster_autoscaler_profile ,
4100- type (cluster_autoscaler_profile ),
4101- )
4102- )
4103- # pylint: disable=protected-access
4104- valid_keys = list (
4105- k .replace ("_" , "-" ) for k in self .models .ManagedClusterPropertiesAutoScalerProfile ._attribute_map .keys ()
4106- )
4107- for key in cluster_autoscaler_profile .keys ():
4108- if not key :
4109- raise InvalidArgumentValueError ("Empty key specified for cluster-autoscaler-profile" )
4110- if key not in valid_keys :
4111- raise InvalidArgumentValueError (
4112- "'{}' is an invalid key for cluster-autoscaler-profile. Valid keys are {}." .format (
4113- key , ", " .join (valid_keys )
4114- )
4115- )
4142+ # parse and validate user input
4143+ cluster_autoscaler_profile = self .__validate_cluster_autoscaler_profile (cluster_autoscaler_profile )
41164144
41174145 # In create mode, try to read the property value corresponding to the parameter from the `mc` object.
41184146 if self .decorator_mode == DecoratorMode .CREATE :
@@ -4141,16 +4169,14 @@ def _get_cluster_autoscaler_profile(self, read_only: bool = False) -> Union[Dict
41414169 def get_cluster_autoscaler_profile (self ) -> Union [Dict [str , str ], None ]:
41424170 """Dynamically obtain the value of cluster_autoscaler_profile according to the context.
41434171
4172+ This function will call function "__validate_cluster_autoscaler_profile" to parse and verify the parameter
4173+ by default.
4174+
41444175 In update mode, when cluster_autoscaler_profile is assigned and auto_scaler_profile in the `mc` object has also
41454176 been set, dynamic completion will be triggerd. We will first make a copy of the original configuration
41464177 (extract the dictionary from the ManagedClusterPropertiesAutoScalerProfile object), and then update the copied
41474178 dictionary with the dictionary of new options.
41484179
4149- This function will verify the parameter by default. If the user input is not empty, take the keys from the
4150- attribute map of ManagedClusterPropertiesAutoScalerProfile to verify whether the keys in the key-value pairs
4151- provided by the user are valid. If not, raise an InvalidArgumentValueError. The value of the raw parameter
4152- should be a dictionary after being processed by the validator. If not, raise a CLIInternalError.
4153-
41544180 :return: dictionary or None
41554181 """
41564182 return self ._get_cluster_autoscaler_profile ()
0 commit comments