Change in vdsm[master]: vdscli: update cannonize helper function for IPv6 environmen...
mhuntxu at gmail.com
mhuntxu at gmail.com
Fri Jun 28 11:06:01 UTC 2013
Hunt Xu has uploaded a new change for review.
Change subject: vdscli: update cannonize helper function for IPv6 environment
......................................................................
vdscli: update cannonize helper function for IPv6 environment
The original approach considers any string contains a colon to have
a port information which is not true in IPv6 environment.
The new approach assumes the input string follows the format
'host [ ":" port ]' in rfc3986 as it would be then used in a URI, gives
a default port if the input doesn't supply one. This means IPv6
addresses should be enclosed within square brackets ("[" and "]").
How to test:
* The following commands should all work correctly in a default setup
1) for IPv4 environment:
* vdsClient -s 127.0.0.1 getVdsCaps
* vdsClient -s 127.0.0.1:54321 getVdsCaps
* vdsClient -s localhost getVdsCaps
* vdsClient -s localhost:54321 getVdsCaps
2) for IPv6 environment:
* vdsClient -s [::1] getVdsCaps
* vdsClient -s [::1]:54321 getVdsCaps
* vdsClient -s localhost6 getVdsCaps
* vdsClient -s localhost6:54321 getVdsCaps
* vdsClient -s ['IPv6 link-local addr'%ovirtmgmt] getVdsCaps
* vdsClient -s ['IPv6 link-local addr'%ovirtmgmt]:54321 getVdsCaps
Change-Id: I7c450aaa141ed2877a2d380f17959d2dd8fa77c9
Signed-off-by: huntxu <mhuntxu at gmail.com>
---
M client/vdsClient.py
M lib/vdsm/vdscli.py.in
M vdsm/vm.py
3 files changed, 30 insertions(+), 26 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/25/16225/1
diff --git a/client/vdsClient.py b/client/vdsClient.py
index 2d7a8de..d8fca3d 100644
--- a/client/vdsClient.py
+++ b/client/vdsClient.py
@@ -131,9 +131,8 @@
self.truststore = None
self.pretty = True
- def do_connect(self, server, port):
- self.s = vdscli.connect(server + ':' + port,
- self.useSSL, self.truststore)
+ def do_connect(self, hostPort):
+ self.s = vdscli.connect(hostPort, self.useSSL, self.truststore)
def ExecAndExit(self, response, parameterName='none'):
if response['status']['code'] != 0:
@@ -2463,7 +2462,7 @@
server, command = args[0:2]
if command not in commands:
raise Exception("Unknown command")
- server, serverPort = vdscli.cannonizeAddrPort(server).split(':', 1)
+ hostPort = vdscli.cannonizeHostPort(server)
except SystemExit as status:
sys.exit(status)
@@ -2473,7 +2472,7 @@
sys.exit(-1)
try:
- serv.do_connect(server, serverPort)
+ serv.do_connect(hostPort)
try:
commandArgs = args[2:]
except:
@@ -2493,7 +2492,7 @@
sys.exit(status)
except socket.error as e:
if e[0] == 111:
- print "Connection to %s:%s refused" % (server, serverPort)
+ print "Connection to %s refused" % hostPort
else:
traceback.print_exc()
sys.exit(-1)
diff --git a/lib/vdsm/vdscli.py.in b/lib/vdsm/vdscli.py.in
index f888e83..ff16177 100644
--- a/lib/vdsm/vdscli.py.in
+++ b/lib/vdsm/vdscli.py.in
@@ -22,6 +22,7 @@
import xmlrpclib
import subprocess
import os
+import re
from vdsm import SecureXMLRPCServer
d_useSSL = False
@@ -90,18 +91,24 @@
__guessDefaults()
-def cannonizeAddrPort(addrport=None):
- if addrport is None or addrport == '0':
- return d_addr + ':' + d_port
- elif ':' in addrport:
- return addrport
+def cannonizeHostPort(hostPort=None, port=d_port):
+ if hostPort is None or hostPort == '0':
+ addr = d_addr
+ if ':' in addr:
+ # __guessDefaults() might set an IPv6 address, cannonize it
+ addr = '[%s]' % addr
else:
- return addrport + ':' + d_port
+ # hostPort is in rfc3986 'host [ ":" port ]' format
+ hostPort = re.match(r'(?P<Host>.+?)(:(?P<Port>\d+))?$', hostPort)
+ addr = hostPort.group('Host')
+ port = hostPort.group('Port') or port
+
+ return addr + ':' + port
-def connect(addrport=None, useSSL=None, tsPath=None,
+def connect(hostPort=None, useSSL=None, tsPath=None,
TransportClass=SecureXMLRPCServer.VerifyingSafeTransport):
- addrport = cannonizeAddrPort(addrport)
+ hostPort = cannonizeHostPort(hostPort)
if useSSL is None:
useSSL = d_useSSL
if tsPath is None:
@@ -122,10 +129,10 @@
transport = TransportClass(key_file=KEYFILE,
cert_file=CERTFILE, ca_certs=CACERT)
- server = xmlrpclib.ServerProxy('https://%s' % addrport,
+ server = xmlrpclib.ServerProxy('https://%s' % hostPort,
transport=transport)
else:
- server = xmlrpclib.Server('http://%s' % addrport,
+ server = xmlrpclib.Server('http://%s' % hostPort,
transport=SingleRequestTransport())
return server
diff --git a/vdsm/vm.py b/vdsm/vm.py
index e8118a3..2b51158 100644
--- a/vdsm/vm.py
+++ b/vdsm/vm.py
@@ -154,23 +154,21 @@
def _setupVdsConnection(self):
if self._mode == 'file':
return
- self.remoteHost = self._dst.split(':')[0]
+
# FIXME: The port will depend on the binding being used.
# This assumes xmlrpc
- self.remotePort = self._vm.cif.bindings['xmlrpc'].serverPort
- try:
- self.remotePort = self._dst.split(':')[1]
- except:
- pass
- serverAddress = self.remoteHost + ':' + self.remotePort
+ hostPort = vdscli.cannonizeHostPort(
+ self._dst, self._vm.cif.bindings['xmlrpc'].serverPort)
+ self.remoteHost, self.remotePort = hostPort.rsplit(':', 1)
+
if config.getboolean('vars', 'ssl'):
self.destServer = vdscli.connect(
- serverAddress,
+ hostPort,
useSSL=True,
TransportClass=kaxmlrpclib.TcpkeepSafeTransport)
else:
- self.destServer = kaxmlrpclib.Server('http://' + serverAddress)
- self.log.debug('Destination server is: ' + serverAddress)
+ self.destServer = kaxmlrpclib.Server('http://' + hostPort)
+ self.log.debug('Destination server is: ' + hostPort)
try:
self.log.debug('Initiating connection with destination')
status = self.destServer.getVmStats(self._vm.id)
--
To view, visit http://gerrit.ovirt.org/16225
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c450aaa141ed2877a2d380f17959d2dd8fa77c9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Hunt Xu <mhuntxu at gmail.com>
More information about the vdsm-patches
mailing list