11import inspect
2+
3+ from retrying import retry
4+
25from cloudshell .cp .vcenter .common .model_factory import ResourceModelParser
36from cloudshell .cp .vcenter .common .cloud_shell .driver_helper import CloudshellDriverHelper
4- from cloudshell .cp .vcenter .common .vcenter .vmomi_service import pyVmomiService
7+ from cloudshell .cp .vcenter .common .vcenter .vmomi_service import pyVmomiService , VCenterAuthError
58from cloudshell .cp .vcenter .models .VMwarevCenterResourceModel import VMwarevCenterResourceModel
69
710DISCONNCTING_VCENERT = 'disconnecting from vcenter: {0}'
2124LOG_FORMAT = 'action:{0} command_name:{1}'
2225
2326
27+ def retry_if_auth_error (ex ):
28+ return isinstance (ex , VCenterAuthError )
29+
30+
2431class CommandWrapper :
2532 def __init__ (self , pv_service , cloud_shell_helper , resource_model_parser , context_based_logger_factory ):
2633 """
@@ -37,6 +44,7 @@ def __init__(self, pv_service, cloud_shell_helper, resource_model_parser, contex
3744 self .resource_model_parser = resource_model_parser # type: ResourceModelParser
3845 self .context_based_logger_factory = context_based_logger_factory # type ContextBasedLoggerFactory
3946
47+ @retry (stop_max_attempt_number = 3 , wait_fixed = 2000 , retry_on_exception = retry_if_auth_error )
4048 def execute_command_with_connection (self , context , command , * args ):
4149 """
4250 Note: session & vcenter_data_model objects will be injected dynamically to the command
@@ -47,8 +55,8 @@ def execute_command_with_connection(self, context, command, *args):
4755 """
4856
4957 logger = self .context_based_logger_factory .create_logger_for_context (
50- logger_name = 'vCenterShell' ,
51- context = context )
58+ logger_name = 'vCenterShell' ,
59+ context = context )
5260
5361 if not command :
5462 logger .error (COMMAND_CANNOT_BE_NONE )
@@ -76,9 +84,9 @@ def execute_command_with_connection(self, context, command, *args):
7684 if connection_details :
7785 logger .info (INFO_CONNECTING_TO_VCENTER .format (connection_details .host ))
7886 logger .debug (
79- DEBUG_CONNECTION_INFO .format (connection_details .host ,
80- connection_details .username ,
81- connection_details .port ))
87+ DEBUG_CONNECTION_INFO .format (connection_details .host ,
88+ connection_details .username ,
89+ connection_details .port ))
8290
8391 si = self .pv_service .connect (connection_details .host ,
8492 connection_details .username ,
0 commit comments