Commit ed7c9e3c authored by Łukasz Nowak's avatar Łukasz Nowak

slapos: Drop slapos.slap.util for slapos.util

parent 182ccfed
...@@ -35,7 +35,7 @@ from uritemplate import expand ...@@ -35,7 +35,7 @@ from uritemplate import expand
import os import os
import logging import logging
from .util import _addIpv6Brackets from slapos.util import _addIpv6Brackets
from .exception import ResourceNotReady, NotFoundError, \ from .exception import ResourceNotReady, NotFoundError, \
AuthenticationError, ConnectionError AuthenticationError, ConnectionError
......
from six.moves.urllib import parse
import netaddr
def _addIpv6Brackets(url):
# if master_url contains an ipv6 without bracket, add it
# Note that this is mostly to limit specific issues with
# backward compatiblity, not to ensure generic detection.
api_scheme, api_netloc, api_path, api_query, api_fragment = parse.urlsplit(url)
try:
ip = netaddr.IPAddress(api_netloc)
port = None
except netaddr.AddrFormatError:
try:
ip = netaddr.IPAddress(':'.join(api_netloc.split(':')[:-1]))
port = api_netloc.split(':')[-1]
except netaddr.AddrFormatError:
ip = port = None
if ip and ip.version == 6:
api_netloc = '[%s]' % ip
if port:
api_netloc = '%s:%s' % (api_netloc, port)
url = parse.urlunsplit((api_scheme, api_netloc, api_path, api_query, api_fragment))
return url
...@@ -36,8 +36,10 @@ import sqlite3 ...@@ -36,8 +36,10 @@ import sqlite3
from xml_marshaller.xml_marshaller import dumps, loads from xml_marshaller.xml_marshaller import dumps, loads
from lxml import etree from lxml import etree
import six import six
from six.moves.urllib import parse
import hashlib import hashlib
import collections import collections
import netaddr
def mkdir_p(path, mode=0o700): def mkdir_p(path, mode=0o700):
...@@ -191,3 +193,25 @@ def calculate_dict_hash(d): ...@@ -191,3 +193,25 @@ def calculate_dict_hash(d):
) )
) )
))).hexdigest() ))).hexdigest()
def _addIpv6Brackets(url):
# if master_url contains an ipv6 without bracket, add it
# Note that this is mostly to limit specific issues with
# backward compatiblity, not to ensure generic detection.
api_scheme, api_netloc, api_path, api_query, api_fragment = parse.urlsplit(url)
try:
ip = netaddr.IPAddress(api_netloc)
port = None
except netaddr.AddrFormatError:
try:
ip = netaddr.IPAddress(':'.join(api_netloc.split(':')[:-1]))
port = api_netloc.split(':')[-1]
except netaddr.AddrFormatError:
ip = port = None
if ip and ip.version == 6:
api_netloc = '[%s]' % ip
if port:
api_netloc = '%s:%s' % (api_netloc, port)
url = parse.urlunsplit((api_scheme, api_netloc, api_path, api_query, api_fragment))
return url
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment