this methods parses host in touple hostname,port. Created to avoid
code duplication when support for hostlist in interactive mode
will be released.
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
---
lnst/Controller/Wizard.py | 46 ++++++++++++++++++++++++++++------------------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/lnst/Controller/Wizard.py b/lnst/Controller/Wizard.py
index 562efe1..a917949 100644
--- a/lnst/Controller/Wizard.py
+++ b/lnst/Controller/Wizard.py
@@ -96,24 +96,9 @@ class Wizard:
for host in hostlist:
print("Processing host '%s'" % host)
- # Check if port was entered along with hostname
- if host.find(":") != -1:
- hostname = host.split(":")[0]
- if hostname == "":
- msg = "'%s' does not contain valid hostname\n" %
host
- sys.stderr.write(msg)
- sys.stderr.write("Skipping host '%s'\n" % host)
- continue
- try:
- port = int(host.split(":")[1])
- except:
- port = DefaultRPCPort
- msg = "Invalid port entered, "\
- "using '%s' instead\n" % port
- sys.stderr.write(msg)
- else:
- hostname = host
- port = DefaultRPCPort
+ hostname, port = self._parse_host(host)
+ if hostname == -1:
+ continue
if not self._check_hostname(hostname):
sys.stderr.write("Hostname '%s' is not translatable into a
"
@@ -353,6 +338,31 @@ class Wizard:
if data["type"] == "result":
return data["result"]
+ def _parse_host(self, host):
+ """ Parses hostname:port string
+ @param host String where hostname and optionally port is stored
+ @return touple with string hostname and int port
+ """
+ if host.find(":") != -1:
+ hostname = host.split(":")[0]
+ if hostname == "":
+ msg = "'%s' does not contain valid hostname\n" % host
+ sys.stderr.write(msg)
+ sys.stderr.write("Skipping host '%s'\n" % host)
+ return -1, -1
+ try:
+ port = int(host.split(":")[1])
+ except:
+ port = DefaultRPCPort
+ msg = "Invalid port entered, "\
+ "using '%s' instead\n" % port
+ sys.stderr.write(msg)
+ else:
+ hostname = host
+ port = DefaultRPCPort
+
+ return hostname, port
+
def _query_continuation(self):
""" Queries user for adding next machine
@return True if user wants to add another machine, False otherwise
--
2.4.3