[elbe-devel] [PATCH 02/21] elbepack: soapclient: move connection establishment out of constructor
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Tue Aug 6 11:18:00 CEST 2024
It is useful to be able to have an ElbeSoapClient object without it
already being connected. Move the connection logic into its own method
and call that where appropriate.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/commands/control.py | 4 +++-
elbepack/commands/prjrepo.py | 4 +++-
elbepack/soapclient.py | 14 ++++++++++----
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/elbepack/commands/control.py b/elbepack/commands/control.py
index 58beff1481de..6d042c1fe270 100644
--- a/elbepack/commands/control.py
+++ b/elbepack/commands/control.py
@@ -379,8 +379,10 @@ def run_command(argv):
args = aparser.parse_args(argv)
args.parser = aparser
+ control = ElbeSoapClient.from_args(args)
+
try:
- control = ElbeSoapClient.from_args(args)
+ control.connect()
except (URLError, socket.error, BadStatusLine):
print(
f'Failed to connect to Soap server {args.soaphost}:{args.soapport}\n',
diff --git a/elbepack/commands/prjrepo.py b/elbepack/commands/prjrepo.py
index f8ba94b9c160..f226ab00a9b7 100644
--- a/elbepack/commands/prjrepo.py
+++ b/elbepack/commands/prjrepo.py
@@ -140,9 +140,11 @@ def run_command(argv):
args = aparser.parse_args(argv)
+ control = ElbeSoapClient.from_args(args)
+
# Try to connect to initvm via SOAP
try:
- control = ElbeSoapClient.from_args(args)
+ control.connect()
except (URLError, socket.error, BadStatusLine):
print(
f'Failed to connect to Soap server {args.soaphost}:{args.soapport}\n',
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index dec3fa4a824e..c5a69032eedb 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -50,7 +50,13 @@ class ElbeSoapClient:
set_suds_debug(debug)
# Attributes
- self.wsdl = 'http://' + host + ':' + str(port) + '/soap/?wsdl'
+ self._wsdl = 'http://' + host + ':' + str(port) + '/soap/?wsdl'
+ self._timeout = timeout
+ self._retries = retries
+ self._user = user
+ self._passwd = passwd
+
+ def connect(self):
control = None
current_retries = 0
@@ -58,9 +64,9 @@ class ElbeSoapClient:
while control is None:
current_retries += 1
try:
- control = Client(self.wsdl, timeout=timeout)
+ control = Client(self._wsdl, timeout=self._timeout)
except (URLError, socket.error, BadStatusLine):
- if current_retries > retries:
+ if current_retries > self._retries:
raise
time.sleep(1)
@@ -71,7 +77,7 @@ class ElbeSoapClient:
ElbeVersionMismatch.check(elbe_version, self.service.get_version())
# We have a Connection, now login
- self.service.login(user, passwd)
+ self.service.login(self._user, self._passwd)
@classmethod
def from_args(cls, args):
--
2.46.0
More information about the elbe-devel
mailing list