Skip to content

Commit cc88e66

Browse files
Alex AzarhAlex Azarh
authored andcommitted
fixing bug that prevents si singleton to recreate connection when credentials or host change
1 parent 385875b commit cc88e66

8 files changed

Lines changed: 36 additions & 20 deletions

File tree

deployment_drivers/deploy_clone_from_vm/drivermetadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Driver Description="Deploy App From VM" MainClass="driver.DeployCloneFromVMDriver" Name="Deploy Clone From VM Driver" Version="1.5.0">
1+
<Driver Description="Deploy App From VM" MainClass="driver.DeployCloneFromVMDriver" Name="Deploy Clone From VM Driver" Version="1.5.1">
22
<Layout>
33
<Category Name="App Management">
44
<Command Description="" DisplayName="Deploy" Name="Deploy" Tags="allow_shared" />

deployment_drivers/deploy_from_image/drivermetadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Driver Description="Deploy App From Image" MainClass="driver.DeployFromImage" Name="VM Deployment From Image" Version="1.5.0">
1+
<Driver Description="Deploy App From Image" MainClass="driver.DeployFromImage" Name="VM Deployment From Image" Version="1.5.1">
22
<Layout>
33
<Category Name="App Management">
44
<Command Description="" DisplayName="Deploy" Name="Deploy" Tags="allow_shared" />

deployment_drivers/deploy_from_linked_clone/drivermetadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Driver Description="Deploy App From VM" MainClass="driver.DeployCloneFromVMDriver" Name="Deploy Clone From VM Driver" Version="1.5.0">
1+
<Driver Description="Deploy App From VM" MainClass="driver.DeployCloneFromVMDriver" Name="Deploy Clone From VM Driver" Version="1.5.1">
22
<Layout>
33
<Category Name="App Management">
44
<Command Description="" DisplayName="Deploy" Name="Deploy" Tags="allow_shared" />

deployment_drivers/deploy_from_template/drivermetadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Driver Description="Deploy App From Template" MainClass="driver.DeployFromTemplateDriver" Name="VM Deployment From Template" Version="1.5.0">
1+
<Driver Description="Deploy App From Template" MainClass="driver.DeployFromTemplateDriver" Name="VM Deployment From Template" Version="1.5.1">
22
<Layout>
33
<Category Name="App Management">
44
<Command Description="" DisplayName="Deploy" Name="Deploy" Tags="allow_shared" />

package/cloudshell/cp/vcenter/common/wrappers/command_wrapper.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, pv_service, cloud_shell_helper, resource_model_parser, contex
4747
# add lock
4848
self.lock = Lock()
4949
self.si = None
50+
self.connection_details = None
5051

5152
@retry(stop_max_attempt_number=3, wait_fixed=2000, retry_on_exception=retry_if_auth_error)
5253
def execute_command_with_connection(self, context, command, *args):
@@ -59,8 +60,8 @@ def execute_command_with_connection(self, context, command, *args):
5960
"""
6061

6162
logger = self.context_based_logger_factory.create_logger_for_context(
62-
logger_name='vCenterShell',
63-
context=context)
63+
logger_name='vCenterShell',
64+
context=context)
6465

6566
if not command:
6667
logger.error(COMMAND_CANNOT_BE_NONE)
@@ -88,11 +89,11 @@ def execute_command_with_connection(self, context, command, *args):
8889
if connection_details:
8990
logger.info(INFO_CONNECTING_TO_VCENTER.format(connection_details.host))
9091
logger.debug(
91-
DEBUG_CONNECTION_INFO.format(connection_details.host,
92-
connection_details.username,
93-
connection_details.port))
92+
DEBUG_CONNECTION_INFO.format(connection_details.host,
93+
connection_details.username,
94+
connection_details.port))
9495

95-
si = self.get_py_service_connection(connection_details,logger)
96+
si = self.get_py_service_connection(connection_details, logger)
9697
if si:
9798
logger.info(CONNECTED_TO_CENTER.format(connection_details.host))
9899
command_args.append(si)
@@ -121,18 +122,33 @@ def execute_command_with_connection(self, context, command, *args):
121122
finally:
122123
logger.info(LOG_FORMAT.format(END, command_name))
123124

124-
def get_py_service_connection(self, connection_details, logger):
125+
def get_py_service_connection(self, req_connection_details, logger):
125126
logger.info("get_py_service_connection")
126-
if self.si is None:
127+
if self.si is None or self.has_connection_details_changed(req_connection_details):
127128
with self.lock:
128-
if self.si is None:
129+
if self.si is None or self.has_connection_details_changed(req_connection_details):
129130
logger.info("Creating a new connection.")
130-
self.si = self.pv_service.connect(connection_details.host,
131-
connection_details.username,
132-
connection_details.password,
133-
connection_details.port)
131+
self.si = self.pv_service.connect(req_connection_details.host,
132+
req_connection_details.username,
133+
req_connection_details.password,
134+
req_connection_details.port)
135+
self.connection_details = req_connection_details
134136
return self.si
135137

138+
def has_connection_details_changed(self, req_connection_details):
139+
"""
140+
:param cloudshell.cp.vcenter.models.VCenterConnectionDetails.VCenterConnectionDetails req_connection_details:
141+
:return:
142+
"""
143+
if self.connection_details is None and req_connection_details is None:
144+
return False
145+
if self.connection_details is None or req_connection_details is None:
146+
return True
147+
return not all([self.connection_details.host == req_connection_details.host,
148+
self.connection_details.username == req_connection_details.username,
149+
self.connection_details.password == req_connection_details.password,
150+
self.connection_details.port == req_connection_details.port])
151+
136152
@staticmethod
137153
def _get_domain(context):
138154
# noinspection PyBroadException

package/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.0
1+
1.5.1

vcentershell_driver/drivermetadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Driver Description="this driver manage all the commands that runs at the vcenter context" MainClass="driver.VCenterShellDriver" Name="VCenter Driver" Version="1.5.0">
1+
<Driver Description="this driver manage all the commands that runs at the vcenter context" MainClass="driver.VCenterShellDriver" Name="VCenter Driver" Version="1.5.1">
22
<Layout>
33
<Category Name="Deployment">
44
<Command Description="" DisplayName="Deploy From Template" EnableCancellation="true" Name="deploy_from_template" Tags="allow_unreserved" />

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.0
1+
1.5.1

0 commit comments

Comments
 (0)