[virt-tools-list] [PATCH virt-manager] sshtunnels: use ipaddr to check if address is loopback or unspecified

Giuseppe Scrivano gscrivan at redhat.com
Fri Apr 24 09:11:36 UTC 2015


It supports IPv6 addresses written as "0::0", "0:0::0".

Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
---
 virtManager/sshtunnels.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/virtManager/sshtunnels.py b/virtManager/sshtunnels.py
index 53274ea..53f43be 100644
--- a/virtManager/sshtunnels.py
+++ b/virtManager/sshtunnels.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2014 Red Hat, Inc.
+# Copyright (C) 2014, 2015 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@ import Queue
 import socket
 import signal
 import threading
+import ipaddr
 
 from .baseclass import vmmGObject
 
@@ -47,10 +48,10 @@ class ConnectionInfo(object):
             self._connhost = "127.0.0.1"
 
     def _is_listen_localhost(self, host=None):
-        return (host or self.gaddr) in ["127.0.0.1", "::1"]
+        return ipaddr.IPNetwork(host or self.gaddr).is_loopback
 
     def _is_listen_any(self):
-        return self.gaddr in ["0.0.0.0", "::"]
+        return ipaddr.IPNetwork(self.gaddr).is_unspecified
 
     def need_tunnel(self):
         if not self._is_listen_localhost():
-- 
2.1.0




More information about the virt-tools-list mailing list