import os
import time
import threading
-import xmlrpclib
+
+from six import integer_types, string_types
+from six.moves import xmlrpc_client
def _retry(fn):
def rv(*p, **kw):
self._url = urlpattern % {'hostname':hostname}
if (proxy is not None):
- import urllib2
- class HTTPSProxyTransport(xmlrpclib.Transport):
+ from six.moves.urllib import request as urllib_request
+ class HTTPSProxyTransport(xmlrpc_client.Transport):
def __init__(self, proxy, use_datetime=0):
- opener = urllib2.build_opener(urllib2.ProxyHandler({"https" : proxy}))
- xmlrpclib.Transport.__init__(self, use_datetime)
+ opener = urllib_request.build_opener(urllib2.ProxyHandler({"https" : proxy}))
+ xmlrpc_client.Transport.__init__(self, use_datetime)
self.opener = opener
def request(self, host, handler, request_body, verbose=0):
- req = urllib2.Request('https://%s%s' % (host, handler), request_body)
+ req = urllib_request.Request('https://%s%s' % (host, handler), request_body)
req.add_header('User-agent', self.user_agent)
self.verbose = verbose
return self.parse_response(self.opener.open(req))
@property
def api(self):
# Cannot reuse same proxy in all threads, py2.7 is not threadsafe
- return xmlrpclib.ServerProxy(
+ return xmlrcp_client.ServerProxy(
self._url ,
transport = self._proxy_transport(),
allow_none = True)
try:
# test authorization
network_types = _retry(self.mcapi.GetNetworkTypes)(self.auth)
- except (xmlrpclib.ProtocolError, xmlrpclib.Fault) as e:
+ except (xmlrpc_client.ProtocolError, xmlrpc_client.Fault) as e:
warnings.warn(str(e))
return True
* nodefamily : string, the nodefamily this node should be based upon
* plain : boolean, use plain bootstrapfs image if set (for tests)
"""
- if not isinstance(node, (str, int, long)):
+ if not isinstance(node, integer_types + string_types):
raise ValueError("Node must be either a non-unicode string or an int")
return _retry(self.mcapi.GetNodeFlavour)(self.auth, node)
return _retry(self.mcapi.DeleteSliceFromNodes)(self.auth, slice_id_or_name, node_id_or_hostname)
def start_multicall(self):
- self.threadlocal.mc = xmlrpclib.MultiCall(self.mcapi)
+ self.threadlocal.mc = xmlrpc_client.MultiCall(self.mcapi)
def finish_multicall(self):
mc = self.threadlocal.mc