44# --------------------------------------------------------------------------------------------
55
66# pylint: disable=unused-argument
7+ # pylint: disable=line-too-long
8+ # pylint: disable=too-many-locals
9+
710import copy
811from hashlib import md5
912from typing import Any , Dict , List , Tuple
1720import azure .mgmt .storage .models
1821import azure .mgmt .loganalytics
1922import azure .mgmt .loganalytics .models
20- from ..vendored_sdks .models import (
21- ExtensionInstance , ExtensionInstanceUpdate , Scope , ScopeCluster )
2223from azure .cli .core .azclierror import InvalidArgumentValueError
2324from azure .cli .core .commands .client_factory import get_mgmt_service_client , get_subscription_id
2425from azure .mgmt .resource .locks .models import ManagementLockObject
2728
2829from .._client_factory import cf_resources
2930from .PartnerExtensionModel import PartnerExtensionModel
31+ from ..vendored_sdks .models import (
32+ ExtensionInstance ,
33+ ExtensionInstanceUpdate ,
34+ Scope ,
35+ ScopeCluster
36+ )
3037
3138logger = get_logger (__name__ )
3239
3340resource_tag = {'created_by' : 'Azure Arc-enabled ML' }
3441
3542
43+ # pylint: disable=too-many-instance-attributes
3644class AzureMLKubernetes (PartnerExtensionModel ):
3745 def __init__ (self ):
3846 # constants for configuration settings.
@@ -157,7 +165,7 @@ def __validate_config(self, configuration_settings, configuration_protected_sett
157165 config_keys = configuration_settings .keys ()
158166 config_protected_keys = configuration_protected_settings .keys ()
159167 dup_keys = set (config_keys ) & set (config_protected_keys )
160- if len ( dup_keys ) > 0 :
168+ if dup_keys :
161169 for key in dup_keys :
162170 logger .warning (
163171 'Duplicate keys found in both configuration settings and configuration protected setttings: %s' , key )
@@ -250,9 +258,8 @@ def __create_required_resource(
250258 configuration_settings [self .AZURE_LOG_ANALYTICS_CUSTOMER_ID_KEY ] = ws_costumer_id
251259 configuration_protected_settings [self .AZURE_LOG_ANALYTICS_CONNECTION_STRING ] = shared_key
252260
253- if not configuration_settings .get (
254- self .RELAY_SERVER_CONNECTION_STRING ) and not configuration_protected_settings .get (
255- self .RELAY_SERVER_CONNECTION_STRING ):
261+ if not configuration_settings .get (self .RELAY_SERVER_CONNECTION_STRING ) and \
262+ not configuration_protected_settings .get (self .RELAY_SERVER_CONNECTION_STRING ):
256263 logger .info ('==== BEGIN RELAY CREATION ====' )
257264 relay_connection_string , hc_resource_id , hc_name = _get_relay_connection_str (
258265 cmd , subscription_id , resource_group_name , cluster_name , cluster_location , self .RELAY_HC_AUTH_NAME )
@@ -261,9 +268,8 @@ def __create_required_resource(
261268 configuration_settings [self .HC_RESOURCE_ID_KEY ] = hc_resource_id
262269 configuration_settings [self .RELAY_HC_NAME_KEY ] = hc_name
263270
264- if not configuration_settings .get (
265- self .SERVICE_BUS_CONNECTION_STRING ) and not configuration_protected_settings .get (
266- self .SERVICE_BUS_CONNECTION_STRING ):
271+ if not configuration_settings .get (self .SERVICE_BUS_CONNECTION_STRING ) and \
272+ not configuration_protected_settings .get (self .SERVICE_BUS_CONNECTION_STRING ):
267273 logger .info ('==== BEGIN SERVICE BUS CREATION ====' )
268274 topic_sub_mapping = {
269275 self .SERVICE_BUS_COMPUTE_STATE_TOPIC : self .SERVICE_BUS_COMPUTE_STATE_SUB ,
@@ -280,7 +286,7 @@ def __create_required_resource(
280286
281287def _get_valid_name (input_name : str , suffix_len : int , max_len : int ) -> str :
282288 normalized_str = '' .join (filter (str .isalnum , input_name ))
283- assert len ( normalized_str ) > 0 , "normalized name empty"
289+ assert normalized_str , "normalized name empty"
284290
285291 if len (normalized_str ) <= max_len :
286292 return normalized_str
@@ -295,6 +301,7 @@ def _get_valid_name(input_name: str, suffix_len: int, max_len: int) -> str:
295301 return new_name
296302
297303
304+ # pylint: disable=broad-except
298305def _lock_resource (cmd , lock_scope , lock_level = 'CanNotDelete' ):
299306 lock_client : azure .mgmt .resource .locks .ManagementLockClient = get_mgmt_service_client (
300307 cmd .cli_ctx , azure .mgmt .resource .locks .ManagementLockClient )
@@ -303,14 +310,13 @@ def _lock_resource(cmd, lock_scope, lock_level='CanNotDelete'):
303310 try :
304311 lock_client .management_locks .create_or_update_by_scope (
305312 scope = lock_scope , lock_name = 'amlarc-resource-lock' , parameters = lock_object )
306- except :
313+ except Exception :
307314 # try to lock the resource if user has the owner privilege
308315 pass
309316
310317
311318def _get_relay_connection_str (
312- cmd , subscription_id , resource_group_name , cluster_name , cluster_location , auth_rule_name ) -> Tuple [
313- str , str , str ]:
319+ cmd , subscription_id , resource_group_name , cluster_name , cluster_location , auth_rule_name ) -> Tuple [str , str , str ]:
314320 relay_client : azure .mgmt .relay .RelayManagementClient = get_mgmt_service_client (
315321 cmd .cli_ctx , azure .mgmt .relay .RelayManagementClient )
316322
@@ -398,8 +404,7 @@ def _get_service_bus_connection_string(cmd, subscription_id, resource_group_name
398404
399405
400406def _get_log_analytics_ws_connection_string (
401- cmd , subscription_id , resource_group_name , cluster_name , cluster_location ) -> Tuple [
402- str , str ]:
407+ cmd , subscription_id , resource_group_name , cluster_name , cluster_location ) -> Tuple [str , str ]:
403408 log_analytics_ws_client : azure .mgmt .loganalytics .LogAnalyticsManagementClient = get_mgmt_service_client (
404409 cmd .cli_ctx , azure .mgmt .loganalytics .LogAnalyticsManagementClient )
405410
0 commit comments