Remove all usage of six library
Convert all code to not require six library and instead use python 3.x logic. Created one helper method in common.utils for binary representation to limit code changes. Change-Id: I2716ce93691d11100ee951a3a3f491329a4073f0changes/90/701290/11
parent
e0d4c98556
commit
f6b957e8ee
|
@ -15,10 +15,4 @@
|
|||
|
||||
import gettext
|
||||
|
||||
import six
|
||||
|
||||
if six.PY2:
|
||||
gettext.install('octavia', # pylint: disable=unexpected-keyword-arg
|
||||
unicode=1)
|
||||
else:
|
||||
gettext.install('octavia')
|
||||
gettext.install('octavia')
|
||||
|
|
|
@ -19,7 +19,6 @@ import socket
|
|||
import subprocess
|
||||
|
||||
import pyroute2
|
||||
import six
|
||||
import webob
|
||||
|
||||
import netifaces
|
||||
|
@ -178,7 +177,7 @@ class AmphoraInfo(object):
|
|||
def get_interface(self, ip_addr):
|
||||
|
||||
try:
|
||||
ip_version = ipaddress.ip_address(six.text_type(ip_addr)).version
|
||||
ip_version = ipaddress.ip_address(ip_addr).version
|
||||
except Exception:
|
||||
return webob.Response(
|
||||
json=dict(message="Invalid IP address"), status=400)
|
||||
|
|
|
@ -24,7 +24,6 @@ import flask
|
|||
import jinja2
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
import webob
|
||||
from werkzeug import exceptions
|
||||
|
||||
|
@ -86,7 +85,8 @@ class Loadbalancer(object):
|
|||
with open(util.config_path(lb_id), 'r') as file:
|
||||
cfg = file.read()
|
||||
resp = webob.Response(cfg, content_type='text/plain')
|
||||
resp.headers['ETag'] = hashlib.md5(six.b(cfg)).hexdigest() # nosec
|
||||
resp.headers['ETag'] = (
|
||||
hashlib.md5(octavia_utils.b(cfg)).hexdigest()) # nosec
|
||||
return resp
|
||||
|
||||
def upload_haproxy_config(self, amphora_id, lb_id):
|
||||
|
@ -408,7 +408,7 @@ class Loadbalancer(object):
|
|||
|
||||
with open(cert_path, 'r') as crt_file:
|
||||
cert = crt_file.read()
|
||||
md5 = hashlib.md5(six.b(cert)).hexdigest() # nosec
|
||||
md5 = hashlib.md5(octavia_utils.b(cert)).hexdigest() # nosec
|
||||
resp = webob.Response(json=dict(md5sum=md5))
|
||||
resp.headers['ETag'] = md5
|
||||
return resp
|
||||
|
|
|
@ -23,7 +23,6 @@ import distro
|
|||
import jinja2
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
import webob
|
||||
from werkzeug import exceptions
|
||||
|
||||
|
@ -162,11 +161,8 @@ class BaseOS(object):
|
|||
try:
|
||||
ip_addr = fixed_ip['ip_address']
|
||||
cidr = fixed_ip['subnet_cidr']
|
||||
ip = ipaddress.ip_address(ip_addr if isinstance(
|
||||
ip_addr, six.text_type) else six.u(ip_addr))
|
||||
network = ipaddress.ip_network(
|
||||
cidr if isinstance(
|
||||
cidr, six.text_type) else six.u(cidr))
|
||||
ip = ipaddress.ip_address(ip_addr)
|
||||
network = ipaddress.ip_network(cidr)
|
||||
broadcast = network.broadcast_address.exploded
|
||||
netmask = (network.prefixlen if ip.version == 6
|
||||
else network.netmask.exploded)
|
||||
|
@ -189,10 +185,7 @@ class BaseOS(object):
|
|||
def get_host_routes(cls, fixed_ip):
|
||||
host_routes = []
|
||||
for hr in fixed_ip.get('host_routes', []):
|
||||
network = ipaddress.ip_network(
|
||||
hr['destination'] if isinstance(
|
||||
hr['destination'], six.text_type) else
|
||||
six.u(hr['destination']))
|
||||
network = ipaddress.ip_network(hr['destination'])
|
||||
host_routes.append({'network': network, 'gw': hr['nexthop']})
|
||||
return host_routes
|
||||
|
||||
|
@ -502,8 +495,7 @@ class RH(BaseOS):
|
|||
host_routes_ipv6 = []
|
||||
for fixed_ip in fixed_ips:
|
||||
ip_addr = fixed_ip['ip_address']
|
||||
ip = ipaddress.ip_address(ip_addr if isinstance(
|
||||
ip_addr, six.text_type) else six.u(ip_addr))
|
||||
ip = ipaddress.ip_address(ip_addr)
|
||||
if ip.version == 6:
|
||||
host_routes_ipv6.extend(self.get_host_routes(fixed_ip))
|
||||
else:
|
||||
|
|
|
@ -22,7 +22,6 @@ import subprocess
|
|||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import pyroute2
|
||||
import six
|
||||
import webob
|
||||
from werkzeug import exceptions
|
||||
|
||||
|
@ -46,28 +45,19 @@ class Plug(object):
|
|||
# Validate vip and subnet_cidr, calculate broadcast address and netmask
|
||||
try:
|
||||
render_host_routes = []
|
||||
ip = ipaddress.ip_address(
|
||||
vip if isinstance(vip, six.text_type) else six.u(vip))
|
||||
network = ipaddress.ip_network(
|
||||
subnet_cidr if isinstance(subnet_cidr, six.text_type)
|
||||
else six.u(subnet_cidr))
|
||||
ip = ipaddress.ip_address(vip)
|
||||
network = ipaddress.ip_network(subnet_cidr)
|
||||
vip = ip.exploded
|
||||
broadcast = network.broadcast_address.exploded
|
||||
netmask = (network.prefixlen if ip.version == 6
|
||||
else network.netmask.exploded)
|
||||
vrrp_version = None
|
||||
if vrrp_ip:
|
||||
vrrp_ip_obj = ipaddress.ip_address(
|
||||
vrrp_ip if isinstance(vrrp_ip, six.text_type)
|
||||
else six.u(vrrp_ip)
|
||||
)
|
||||
vrrp_ip_obj = ipaddress.ip_address(vrrp_ip)
|
||||
vrrp_version = vrrp_ip_obj.version
|
||||
if host_routes:
|
||||
for hr in host_routes:
|
||||
network = ipaddress.ip_network(
|
||||
hr['destination'] if isinstance(
|
||||
hr['destination'], six.text_type) else
|
||||
six.u(hr['destination']))
|
||||
network = ipaddress.ip_network(hr['destination'])
|
||||
render_host_routes.append({'network': network,
|
||||
'gw': hr['nexthop']})
|
||||
except ValueError:
|
||||
|
|
|
@ -18,7 +18,6 @@ import stat
|
|||
import flask
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
import webob
|
||||
from werkzeug import exceptions
|
||||
|
||||
|
@ -47,7 +46,7 @@ def make_json_error(ex):
|
|||
|
||||
|
||||
def register_app_error_handler(app):
|
||||
for code in six.iterkeys(exceptions.default_exceptions):
|
||||
for code in exceptions.default_exceptions:
|
||||
app.register_error_handler(code, make_json_error)
|
||||
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
from oslo_config import cfg
|
||||
from stevedore import driver as stevedore_driver
|
||||
|
||||
|
@ -24,8 +22,7 @@ CONF = cfg.CONF
|
|||
UDP_SERVER_NAMESPACE = 'octavia.amphora.udp_api_server'
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class UdpListenerApiServerBase(object):
|
||||
class UdpListenerApiServerBase(object, metaclass=abc.ABCMeta):
|
||||
"""Base UDP Listener Server API
|
||||
|
||||
"""
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
import errno
|
||||
import os
|
||||
import queue
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from octavia.amphorae.backends.agent.api_server import util
|
||||
from octavia.amphorae.backends.health_daemon import health_sender
|
||||
|
@ -28,12 +28,6 @@ from octavia.amphorae.backends.utils import haproxy_query
|
|||
from octavia.amphorae.backends.utils import keepalivedlvs_query
|
||||
|
||||
|
||||
if six.PY2:
|
||||
import Queue as queue # pylint: disable=wrong-import-order
|
||||
else:
|
||||
import queue # pylint: disable=wrong-import-order
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
SEQ = 0
|
||||
|
|
|
@ -15,9 +15,8 @@
|
|||
import csv
|
||||
import socket
|
||||
|
||||
import six
|
||||
|
||||
from octavia.common import constants as consts
|
||||
from octavia.common import utils as octavia_utils
|
||||
from octavia.i18n import _
|
||||
|
||||
|
||||
|
@ -52,14 +51,14 @@ class HAProxyQuery(object):
|
|||
raise Exception(_("HAProxy '{0}' query failed.").format(query))
|
||||
|
||||
try:
|
||||
sock.send(six.b(query + '\n'))
|
||||
sock.send(octavia_utils.b(query + '\n'))
|
||||
data = u''
|
||||
while True:
|
||||
x = sock.recv(1024)
|
||||
if not x:
|
||||
break
|
||||
data += x.decode('ascii') if (
|
||||
isinstance(x, six.binary_type)) else x
|
||||
isinstance(x, bytes)) else x
|
||||
return data.rstrip()
|
||||
finally:
|
||||
sock.close()
|
||||
|
|
|
@ -15,7 +15,6 @@ import re
|
|||
import subprocess
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from octavia.amphorae.backends.agent.api_server import util
|
||||
from octavia.common import constants
|
||||
|
@ -70,7 +69,7 @@ def get_listener_realserver_mapping(ns_name, listener_ip_port,
|
|||
# 'InActConn': 0
|
||||
# }}
|
||||
listener_ip, listener_port = listener_ip_port.rsplit(':', 1)
|
||||
ip_obj = ipaddress.ip_address(six.text_type(listener_ip.strip('[]')))
|
||||
ip_obj = ipaddress.ip_address(listener_ip.strip('[]'))
|
||||
output = read_kernel_file(ns_name, KERNEL_LVS_PATH).split('\n')
|
||||
if ip_obj.version == 4:
|
||||
ip_to_hex_format = "0%X" % ip_obj._ip
|
||||
|
@ -195,7 +194,7 @@ def get_udp_listener_resource_ipports_nsname(listener_id):
|
|||
rs_ip_port_count = len(rs_ip_port_list)
|
||||
for index in range(rs_ip_port_count):
|
||||
if ipaddress.ip_address(
|
||||
six.text_type(rs_ip_port_list[index][0])).version == 6:
|
||||
rs_ip_port_list[index][0]).version == 6:
|
||||
rs_ip_port_list[index] = (
|
||||
'[' + rs_ip_port_list[index][0] + ']',
|
||||
rs_ip_port_list[index][1])
|
||||
|
@ -204,7 +203,7 @@ def get_udp_listener_resource_ipports_nsname(listener_id):
|
|||
rs_ip_port_list[index][1])
|
||||
|
||||
if ipaddress.ip_address(
|
||||
six.text_type(listener_ip_port[0])).version == 6:
|
||||
listener_ip_port[0]).version == 6:
|
||||
listener_ip_port = (
|
||||
'[' + listener_ip_port[0] + ']', listener_ip_port[1])
|
||||
resource_ipport_mapping['Listener']['ipport'] = (
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from oslo_utils import excutils
|
||||
|
||||
from octavia.i18n import _
|
||||
|
@ -35,7 +33,7 @@ class AmphoraDriverError(Exception):
|
|||
super(AmphoraDriverError, self).__init__(self.message)
|
||||
|
||||
def __unicode__(self):
|
||||
return six.text_type(self.msg)
|
||||
return self.msg
|
||||
|
||||
@staticmethod
|
||||
def use_fatal_exceptions():
|
||||
|
|
|
@ -15,12 +15,8 @@
|
|||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class AmphoraLoadBalancerDriver(object):
|
||||
|
||||
class AmphoraLoadBalancerDriver(object, metaclass=abc.ABCMeta):
|
||||
@abc.abstractmethod
|
||||
def update_amphora_listeners(self, loadbalancer, amphora,
|
||||
timeout_dict):
|
||||
|
@ -207,8 +203,7 @@ class AmphoraLoadBalancerDriver(object):
|
|||
"""
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class HealthMixin(object):
|
||||
class HealthMixin(object, metaclass=abc.ABCMeta):
|
||||
@abc.abstractmethod
|
||||
def update_health(self, health):
|
||||
"""Return ceilometer ready health
|
||||
|
@ -229,8 +224,7 @@ class HealthMixin(object):
|
|||
"""
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class StatsMixin(object):
|
||||
class StatsMixin(object, metaclass=abc.ABCMeta):
|
||||
@abc.abstractmethod
|
||||
def update_stats(self, stats):
|
||||
"""Return ceilometer ready stats
|
||||
|
@ -250,8 +244,7 @@ class StatsMixin(object):
|
|||
"""
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class VRRPDriverMixin(object):
|
||||
class VRRPDriverMixin(object, metaclass=abc.ABCMeta):
|
||||
"""Abstract mixin class for VRRP support in loadbalancer amphorae
|
||||
|
||||
Usage: To plug VRRP support in another service driver XYZ, use:
|
||||
|
|
|
@ -23,7 +23,6 @@ from oslo_context import context as oslo_context
|
|||
from oslo_log import log as logging
|
||||
import requests
|
||||
import simplejson
|
||||
import six
|
||||
from stevedore import driver as stevedore_driver
|
||||
|
||||
from octavia.amphorae.driver_exceptions import exceptions as driver_except
|
||||
|
@ -664,7 +663,7 @@ class AmphoraAPIClientBase(object):
|
|||
self.ssl_adapter.uuid = amp.id
|
||||
exception = None
|
||||
# Keep retrying
|
||||
for dummy in six.moves.xrange(conn_max_retries):
|
||||
for dummy in range(conn_max_retries):
|
||||
try:
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings(
|
||||
|
@ -705,9 +704,8 @@ class AmphoraAPIClientBase(object):
|
|||
# For taskflow persistence cause attribute should
|
||||
# be serializable to JSON. Pass None, as cause exception
|
||||
# is described in the expection message.
|
||||
six.raise_from(
|
||||
driver_except.AmpConnectionRetry(exception=str(e)),
|
||||
None)
|
||||
raise driver_except.AmpConnectionRetry(
|
||||
exception=str(e)) from None
|
||||
LOG.error("Connection retries (currently set to %(max_retries)s) "
|
||||
"exhausted. The amphora is unavailable. Reason: "
|
||||
"%(exception)s",
|
||||
|
|
|
@ -17,7 +17,6 @@ import os
|
|||
|
||||
import jinja2
|
||||
from oslo_config import cfg
|
||||
import six
|
||||
|
||||
from octavia.amphorae.backends.agent.api_server import util
|
||||
from octavia.common import constants
|
||||
|
@ -72,20 +71,17 @@ class KeepalivedJinjaTemplater(object):
|
|||
|
||||
# Validate the VIP address and see if it is IPv6
|
||||
vip = loadbalancer.vip.ip_address
|
||||
vip_addr = ipaddress.ip_address(
|
||||
vip if isinstance(vip, six.text_type) else six.u(vip))
|
||||
vip_addr = ipaddress.ip_address(vip)
|
||||
vip_ipv6 = vip_addr.version == 6
|
||||
|
||||
# Normalize and validate the VIP subnet CIDR
|
||||
vip_network_cidr = None
|
||||
vip_cidr = (vip_cidr if isinstance(vip_cidr, six.text_type) else
|
||||
six.u(vip_cidr))
|
||||
if vip_ipv6:
|
||||
vip_network_cidr = ipaddress.IPv6Network(vip_cidr).with_prefixlen
|
||||
else:
|
||||
vip_network_cidr = ipaddress.IPv4Network(vip_cidr).with_prefixlen
|
||||
|
||||
for amp in six.moves.filter(
|
||||
for amp in filter(
|
||||
lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
|
||||
loadbalancer.amphorae):
|
||||
if amp.vrrp_ip != amphora.vrrp_ip:
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from octavia.amphorae.drivers import driver_base
|
||||
from octavia.amphorae.drivers.keepalived.jinja import jinja_cfg
|
||||
|
@ -41,7 +40,7 @@ class KeepalivedAmphoraDriverMixin(driver_base.VRRPDriverMixin):
|
|||
LOG.debug("Update loadbalancer %s amphora VRRP configuration.",
|
||||
loadbalancer.id)
|
||||
|
||||
for amp in six.moves.filter(
|
||||
for amp in filter(
|
||||
lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
|
||||
loadbalancer.amphorae):
|
||||
|
||||
|
@ -67,7 +66,7 @@ class KeepalivedAmphoraDriverMixin(driver_base.VRRPDriverMixin):
|
|||
LOG.info("Stop loadbalancer %s amphora VRRP Service.",
|
||||
loadbalancer.id)
|
||||
|
||||
for amp in six.moves.filter(
|
||||
for amp in filter(
|
||||
lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
|
||||
loadbalancer.amphorae):
|
||||
|
||||
|
@ -82,7 +81,7 @@ class KeepalivedAmphoraDriverMixin(driver_base.VRRPDriverMixin):
|
|||
LOG.info("Start loadbalancer %s amphora VRRP Service.",
|
||||
loadbalancer.id)
|
||||
|
||||
for amp in six.moves.filter(
|
||||
for amp in filter(
|
||||
lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
|
||||
loadbalancer.amphorae):
|
||||
|
||||
|
@ -98,7 +97,7 @@ class KeepalivedAmphoraDriverMixin(driver_base.VRRPDriverMixin):
|
|||
LOG.info("Reload loadbalancer %s amphora VRRP Service.",
|
||||
loadbalancer.id)
|
||||
|
||||
for amp in six.moves.filter(
|
||||
for amp in filter(
|
||||
lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
|
||||
loadbalancer.amphorae):
|
||||
|
||||
|
|
|
@ -15,18 +15,14 @@
|
|||
import copy
|
||||
|
||||
import netaddr
|
||||
import six
|
||||
from wsme import types as wtypes
|
||||
|
||||
from octavia.common import exceptions
|
||||
from octavia.common import validate
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
|
||||
class IPAddressType(wtypes.UserType):
|
||||
basetype = unicode
|
||||
basetype = str
|
||||
name = 'ipaddress'
|
||||
|
||||
@staticmethod
|
||||
|
@ -45,7 +41,7 @@ class IPAddressType(wtypes.UserType):
|
|||
|
||||
|
||||
class CidrType(wtypes.UserType):
|
||||
basetype = unicode
|
||||
basetype = str
|
||||
name = 'cidr'
|
||||
|
||||
@staticmethod
|
||||
|
@ -59,7 +55,7 @@ class CidrType(wtypes.UserType):
|
|||
|
||||
|
||||
class URLType(wtypes.UserType):
|
||||
basetype = unicode
|
||||
basetype = str
|
||||
name = 'url'
|
||||
|
||||
def __init__(self, require_scheme=True):
|
||||
|
@ -76,7 +72,7 @@ class URLType(wtypes.UserType):
|
|||
|
||||
|
||||
class URLPathType(wtypes.UserType):
|
||||
basetype = unicode
|
||||
basetype = str
|
||||
name = 'url_path'
|
||||
|
||||
@staticmethod
|
||||
|
@ -119,8 +115,7 @@ class BaseMeta(wtypes.BaseMeta):
|
|||
return super(BaseMeta, cls).__new__(cls, name, bases, dct)
|
||||
|
||||
|
||||
@six.add_metaclass(BaseMeta)
|
||||
class BaseType(wtypes.Base):
|
||||
class BaseType(wtypes.Base, metaclass=BaseMeta):
|
||||
@classmethod
|
||||
def _full_response(cls):
|
||||
return False
|
||||
|
|
|
@ -53,7 +53,7 @@ class AmphoraProviderDriver(driver_base.ProviderDriver):
|
|||
topic=consts.TOPIC_AMPHORA_V2, version="2.0", fanout=False)
|
||||
self.client = rpc.get_client(self.target)
|
||||
self.repositories = repositories.Repositories()
|
||||
key = utils.get_six_compatible_server_certs_key_passphrase()
|
||||
key = utils.get_compatible_server_certs_key_passphrase()
|
||||
self.fernet = fernet.Fernet(key)
|
||||
|
||||
def _validate_pool_algorithm(self, pool):
|
||||
|
|
|
@ -15,10 +15,9 @@
|
|||
|
||||
import errno
|
||||
import os
|
||||
import socketserver
|
||||
import threading
|
||||
|
||||
import six.moves.socketserver as socketserver
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
import copy
|
||||
|
||||
import six
|
||||
|
||||
from octavia_lib.api.drivers import data_models as driver_dm
|
||||
from octavia_lib.api.drivers import exceptions as lib_exceptions
|
||||
from oslo_config import cfg
|
||||
|
@ -255,7 +253,7 @@ def listener_dict_to_provider_dict(listener_dict, for_delete=False):
|
|||
del sni['listener']
|
||||
sni_obj = data_models.SNI(**sni)
|
||||
SNI_objs.append(sni_obj)
|
||||
elif isinstance(sni, six.string_types):
|
||||
elif isinstance(sni, str):
|
||||
sni_obj = data_models.SNI(tls_container_id=sni)
|
||||
SNI_objs.append(sni_obj)
|
||||
else:
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import pecan
|
||||
import six
|
||||
from wsme import types as wtypes
|
||||
from wsmeext import pecan as wsme_pecan
|
||||
|
||||
|
@ -49,7 +48,7 @@ class ProviderController(base.BaseController):
|
|||
enabled_providers = CONF.api_settings.enabled_provider_drivers
|
||||
response_list = [
|
||||
provider_types.ProviderResponse(name=key, description=value) for
|
||||
key, value in six.iteritems(enabled_providers)]
|
||||
key, value in enabled_providers.items()]
|
||||
if fields is not None:
|
||||
response_list = self._filter_fields(response_list, fields)
|
||||
return provider_types.ProvidersRootResponse(providers=response_list)
|
||||
|
@ -106,16 +105,16 @@ class FlavorCapabilitiesController(base.BaseController):
|
|||
constants.DESCRIPTION)
|
||||
if name_filter:
|
||||
metadata_dict = {
|
||||
key: value for key, value in six.iteritems(metadata_dict) if
|
||||
key: value for key, value in metadata_dict.items() if
|
||||
key == name_filter}
|
||||
if description_filter:
|
||||
metadata_dict = {
|
||||
key: value for key, value in six.iteritems(metadata_dict) if
|
||||
key: value for key, value in metadata_dict.items() if
|
||||
value == description_filter}
|
||||
|
||||
response_list = [
|
||||
provider_types.ProviderResponse(name=key, description=value) for
|
||||
key, value in six.iteritems(metadata_dict)]
|
||||
key, value in metadata_dict.items()]
|
||||
if fields is not None:
|
||||
response_list = self._filter_fields(response_list, fields)
|
||||
return provider_types.FlavorCapabilitiesResponse(
|
||||
|
@ -158,16 +157,16 @@ class AvailabilityZoneCapabilitiesController(base.BaseController):
|
|||
constants.DESCRIPTION)
|
||||
if name_filter:
|
||||
metadata_dict = {
|
||||
key: value for key, value in six.iteritems(metadata_dict) if
|
||||
key: value for key, value in metadata_dict.items() if
|
||||
key == name_filter}
|
||||
if description_filter:
|
||||
metadata_dict = {
|
||||
key: value for key, value in six.iteritems(metadata_dict) if
|
||||
key: value for key, value in metadata_dict.items() if
|
||||
value == description_filter}
|
||||
|
||||
response_list = [
|
||||
provider_types.ProviderResponse(name=key, description=value) for
|
||||
key, value in six.iteritems(metadata_dict)]
|
||||
key, value in metadata_dict.items()]
|
||||
if fields is not None:
|
||||
response_list = self._filter_fields(response_list, fields)
|
||||
return provider_types.AvailabilityZoneCapabilitiesResponse(
|
||||
|
|
|
@ -21,7 +21,6 @@ import abc
|
|||
|
||||
from barbicanclient.v1 import containers
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
|
||||
from octavia.certificates.common import cert
|
||||
from octavia.common.tls_utils import cert_parser
|
||||
|
@ -62,8 +61,7 @@ class BarbicanCert(cert.Cert):
|
|||
return None
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class BarbicanAuth(object):
|
||||
class BarbicanAuth(object, metaclass=abc.ABCMeta):
|
||||
@abc.abstractmethod
|
||||
def get_barbican_client(self, project_id):
|
||||
"""Creates a Barbican client object.
|
||||
|
|
|
@ -15,11 +15,8 @@
|
|||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Cert(object):
|
||||
class Cert(object, metaclass=abc.ABCMeta):
|
||||
"""Base class to represent all certificates."""
|
||||
|
||||
@abc.abstractmethod
|
||||
|
|
|
@ -18,11 +18,8 @@ Certificate Generator API
|
|||
"""
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class CertGenerator(object):
|
||||
class CertGenerator(object, metaclass=abc.ABCMeta):
|
||||
"""Base Cert Generator Interface
|
||||
|
||||
A Certificate Generator is responsible for generating private keys,
|
||||
|
|
|
@ -23,7 +23,6 @@ from cryptography.hazmat.primitives import serialization
|
|||
from cryptography import x509
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from octavia.certificates.common import local as local_common
|
||||
from octavia.certificates.generator import cert_gen
|
||||
|
@ -186,7 +185,6 @@ class LocalCertGenerator(cert_gen.CertGenerator):
|
|||
|
||||
@classmethod
|
||||
def _generate_csr(cls, cn, private_key, passphrase=None):
|
||||
cn = six.text_type(cn)
|
||||
pk = serialization.load_pem_private_key(
|
||||
data=private_key, password=passphrase,
|
||||
backend=backends.default_backend())
|
||||
|
|
|
@ -18,11 +18,8 @@ Certificate manager API
|
|||
"""
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class CertManager(object):
|
||||
class CertManager(object, metaclass=abc.ABCMeta):
|
||||
"""Base Cert Manager Interface
|
||||
|
||||
A Cert Manager is responsible for managing certificates for TLS.
|
||||
|
|
|
@ -18,7 +18,6 @@ import uuid
|
|||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from octavia.certificates.common import local as local_common
|
||||
from octavia.certificates.manager import cert_mgr
|
||||
|
@ -51,9 +50,9 @@ class LocalCertManager(cert_mgr.CertManager):
|
|||
"""
|
||||
cert_ref = str(uuid.uuid4())
|
||||
filename_base = os.path.join(CONF.certificates.storage_path, cert_ref)
|
||||
if type(certificate) == six.binary_type:
|
||||
if type(certificate) == bytes:
|
||||
certificate = certificate.decode('utf-8')
|
||||
if type(private_key) == six.binary_type:
|
||||
if type(private_key) == bytes:
|
||||
private_key = private_key.decode('utf-8')
|
||||
|
||||
LOG.info("Storing certificate data on the local filesystem.")
|
||||
|
@ -72,7 +71,7 @@ class LocalCertManager(cert_mgr.CertManager):
|
|||
|
||||
if intermediates:
|
||||
filename_intermediates = "{0}.int".format(filename_base)
|
||||
if type(intermediates) == six.binary_type:
|
||||
if type(intermediates) == bytes:
|
||||
intermediates = intermediates.decode('utf-8')
|
||||
with os.fdopen(os.open(
|
||||
filename_intermediates, flags, mode), 'w') as int_file:
|
||||
|
@ -80,7 +79,7 @@ class LocalCertManager(cert_mgr.CertManager):
|
|||
|
||||
if private_key_passphrase:
|
||||
filename_pkp = "{0}.pass".format(filename_base)
|
||||
if type(private_key_passphrase) == six.binary_type:
|
||||
if type(private_key_passphrase) == bytes:
|
||||
private_key_passphrase = private_key_passphrase.decode(
|
||||
'utf-8')
|
||||
with os.fdopen(os.open(
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
import re
|
||||
|
||||
import six
|
||||
from sqlalchemy.orm import collections
|
||||
|
||||
from octavia.common import constants
|
||||
|
@ -63,8 +62,6 @@ class BaseDataModel(object):
|
|||
recurse=recurse)
|
||||
else:
|
||||
ret[attr] = None
|
||||
elif six.PY2 and isinstance(value, six.text_type):
|
||||
ret[attr.encode('utf8')] = value.encode('utf8')
|
||||
else:
|
||||
ret[attr] = value
|
||||
else:
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
Octavia base exception handling.
|
||||
"""
|
||||
|
||||
import six
|
||||
|
||||
from oslo_utils import excutils
|
||||
from webob import exc
|
||||
|
||||
|
@ -52,7 +50,7 @@ class OctaviaException(Exception):
|
|||
super(OctaviaException, self).__init__(self.message)
|
||||
|
||||
def __unicode__(self):
|
||||
return six.text_type(self.msg)
|
||||
return self.msg
|
||||
|
||||
@staticmethod
|
||||
def use_fatal_exceptions():
|
||||
|
|
|
@ -16,7 +16,6 @@ import os
|
|||
import re
|
||||
|
||||
import jinja2
|
||||
import six
|
||||
|
||||
from octavia.common.config import cfg
|
||||
from octavia.common import constants
|
||||
|
@ -492,7 +491,7 @@ class JinjaTemplater(object):
|
|||
if '-' in code:
|
||||
low, hi = code.split('-')[:2]
|
||||
retval.update(
|
||||
str(i) for i in six.moves.xrange(int(low), int(hi) + 1))
|
||||
str(i) for i in range(int(low), int(hi) + 1))
|
||||
else:
|
||||
retval.add(code)
|
||||
return sorted(retval)
|
||||
|
|
|
@ -16,7 +16,6 @@ import os
|
|||
import re
|
||||
|
||||
import jinja2
|
||||
import six
|
||||
|
||||
from octavia.common.config import cfg
|
||||
from octavia.common import constants
|
||||
|
@ -482,7 +481,7 @@ class JinjaTemplater(object):
|
|||
if '-' in code:
|
||||
low, hi = code.split('-')[:2]
|
||||
retval.update(
|
||||
str(i) for i in six.moves.xrange(int(low), int(hi) + 1))
|
||||
str(i) for i in range(int(low), int(hi) + 1))
|
||||
else:
|
||||
retval.add(code)
|
||||
return sorted(retval)
|
||||
|
|
|
@ -24,10 +24,10 @@ from oslo_log import log as logging
|
|||
from pyasn1.codec.der import decoder as der_decoder
|
||||
from pyasn1.codec.der import encoder as der_encoder
|
||||
from pyasn1_modules import rfc2315
|
||||
import six
|
||||
|
||||
from octavia.common import data_models
|
||||
from octavia.common import exceptions
|
||||
from octavia.common import utils as octavia_utils
|
||||
|
||||
X509_BEG = b'-----BEGIN CERTIFICATE-----'
|
||||
X509_END = b'-----END CERTIFICATE-----'
|
||||
|
@ -72,9 +72,9 @@ def _read_private_key(private_key_pem, passphrase=None):
|
|||
:param passphrase: Optional passphrase needed to decrypt the private key
|
||||
:returns: a RSAPrivatekey object
|
||||
"""
|
||||
if passphrase and type(passphrase) == six.text_type:
|
||||
if passphrase and isinstance(passphrase, str):
|
||||
passphrase = passphrase.encode("utf-8")
|
||||
if type(private_key_pem) == six.text_type:
|
||||
if isinstance(private_key_pem, str):
|
||||
private_key_pem = private_key_pem.encode('utf-8')
|
||||
|
||||
try:
|
||||
|
@ -106,7 +106,7 @@ def get_intermediates_pems(intermediates=None):
|
|||
X509 pem block surrounded by BEGIN CERTIFICATE,
|
||||
END CERTIFICATE block tags
|
||||
"""
|
||||
if isinstance(intermediates, six.string_types):
|
||||
if isinstance(intermediates, str):
|
||||
try:
|
||||
intermediates = intermediates.encode("utf-8")
|
||||
except UnicodeDecodeError:
|
||||
|
@ -139,13 +139,13 @@ def _split_x509s(xstr):
|
|||
"""
|
||||
curr_pem_block = []
|
||||
inside_x509 = False
|
||||
if type(xstr) == six.binary_type:
|
||||
if isinstance(xstr, bytes):
|
||||
xstr = xstr.decode('utf-8')
|
||||
for line in xstr.replace("\r", "").split("\n"):
|
||||
if inside_x509:
|
||||
curr_pem_block.append(line)
|
||||
if line == X509_END.decode('utf-8'):
|
||||
yield six.b("\n".join(curr_pem_block))
|
||||
yield octavia_utils.b("\n".join(curr_pem_block))
|
||||
curr_pem_block = []
|
||||
inside_x509 = False
|
||||
continue
|
||||
|
@ -193,7 +193,7 @@ def _read_pem_blocks(data):
|
|||
stopMarkers = {PKCS7_END.decode('utf-8'): 0}
|
||||
idx = -1
|
||||
state = stSpam
|
||||
if type(data) == six.binary_type:
|
||||
if isinstance(data, bytes):
|
||||
data = data.decode('utf-8')
|
||||
for certLine in data.replace('\r', '').split('\n'):
|
||||
if not certLine:
|
||||
|
@ -254,7 +254,7 @@ def get_host_names(certificate):
|
|||
certificate, and 'dns_names' is a list of dNSNames
|
||||
(possibly empty) from the SubjectAltNames of the certificate.
|
||||
"""
|
||||
if isinstance(certificate, six.string_types):
|
||||
if isinstance(certificate, str):
|
||||
certificate = certificate.encode('utf-8')
|
||||
try:
|
||||
cert = x509.load_pem_x509_certificate(certificate,
|
||||
|
@ -301,7 +301,7 @@ def _get_x509_from_pem_bytes(certificate_pem):
|
|||
:param certificate_pem: Certificate in PEM format
|
||||
:returns: crypto high-level x509 data from the PEM string
|
||||
"""
|
||||
if type(certificate_pem) == six.text_type:
|
||||
if isinstance(certificate_pem, str):
|
||||
certificate_pem = certificate_pem.encode('utf-8')
|
||||
try:
|
||||
x509cert = x509.load_pem_x509_certificate(certificate_pem,
|
||||
|
@ -386,15 +386,15 @@ def _map_cert_tls_container(cert):
|
|||
private_key = cert.get_private_key()
|
||||
private_key_passphrase = cert.get_private_key_passphrase()
|
||||
intermediates = cert.get_intermediates()
|
||||
if isinstance(certificate, six.string_types):
|
||||
if isinstance(certificate, str):
|
||||
certificate = certificate.encode('utf-8')
|
||||
if isinstance(private_key, six.string_types):
|
||||
if isinstance(private_key, str):
|
||||
private_key = private_key.encode('utf-8')
|
||||
if isinstance(private_key_passphrase, six.string_types):
|
||||
if isinstance(private_key_passphrase, str):
|
||||
private_key_passphrase = private_key_passphrase.encode('utf-8')
|
||||
if intermediates:
|
||||
intermediates = [
|
||||
(imd.encode('utf-8') if isinstance(imd, six.string_types) else imd)
|
||||
(imd.encode('utf-8') if isinstance(imd, str) else imd)
|
||||
for imd in intermediates
|
||||
]
|
||||
else:
|
||||
|
|
|
@ -26,7 +26,6 @@ import netaddr
|
|||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
from stevedore import driver as stevedore_driver
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
@ -97,15 +96,15 @@ def ip_netmask_to_cidr(ip, netmask):
|
|||
return "{ip}/{netmask}".format(ip=net.network, netmask=net.prefixlen)
|
||||
|
||||
|
||||
def get_six_compatible_value(value, six_type=six.string_types):
|
||||
if six.PY3 and isinstance(value, six_type):
|
||||
def get_compatible_value(value):
|
||||
if isinstance(value, str):
|
||||
value = value.encode('utf-8')
|
||||
return value
|
||||
|
||||
|
||||
def get_six_compatible_server_certs_key_passphrase():
|
||||
def get_compatible_server_certs_key_passphrase():
|
||||
key = CONF.certificates.server_certs_key_passphrase
|
||||
if six.PY3 and isinstance(key, six.string_types):
|
||||
if isinstance(key, str):
|
||||
key = key.encode('utf-8')
|
||||
return base64.urlsafe_b64encode(key)
|
||||
|
||||
|
@ -117,6 +116,10 @@ def subnet_ip_availability(nw_ip_avail, subnet_id, req_num_ips):
|
|||
return None
|
||||
|
||||
|
||||
def b(s):
|
||||
return s.encode('utf-8')
|
||||
|
||||
|
||||
class exception_logger(object):
|
||||
"""Wrap a function and log raised exception
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import re
|
|||
import netaddr
|
||||
from oslo_config import cfg
|
||||
import rfc3986
|
||||
import six
|
||||
from wsme import types as wtypes
|
||||
|
||||
from octavia.common import constants
|
||||
|
@ -419,7 +418,7 @@ def check_session_persistence(SP_dict):
|
|||
|
||||
def ip_not_reserved(ip_address):
|
||||
ip_address = (
|
||||
ipaddress.ip_address(six.text_type(ip_address)).exploded.upper())
|
||||
ipaddress.ip_address(ip_address).exploded.upper())
|
||||
if ip_address in CONF.networking.reserved_ips:
|
||||
raise exceptions.InvalidOption(value=ip_address,
|
||||
option='member address')
|
||||
|
|
|
@ -14,11 +14,8 @@
|
|||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class ComputeBase(object):
|
||||
class ComputeBase(object, metaclass=abc.ABCMeta):
|
||||
|
||||
@abc.abstractmethod
|
||||
def build(self, name="amphora_name", amphora_flavor=None,
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
from cryptography import fernet
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
from stevedore import driver as stevedore_driver
|
||||
from taskflow import task
|
||||
from taskflow.types import failure
|
||||
|
@ -184,7 +183,7 @@ class AmphoraePostNetworkPlug(BaseAmphoraTask):
|
|||
if isinstance(result, failure.Failure):
|
||||
return
|
||||
LOG.warning("Reverting post network plug.")
|
||||
for amphora in six.moves.filter(
|
||||
for amphora in filter(
|
||||
lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
|
||||
loadbalancer.amphorae):
|
||||
|
||||
|
@ -234,7 +233,7 @@ class AmphoraCertUpload(BaseAmphoraTask):
|
|||
def execute(self, amphora, server_pem):
|
||||
"""Execute cert_update_amphora routine."""
|
||||
LOG.debug("Upload cert in amphora REST driver")
|
||||
key = utils.get_six_compatible_server_certs_key_passphrase()
|
||||
key = utils.get_compatible_server_certs_key_passphrase()
|
||||
fer = fernet.Fernet(key)
|
||||
self.amphora_driver.upload_cert_amp(amphora, fer.decrypt(server_pem))
|
||||
|
||||
|
@ -250,7 +249,7 @@ class AmphoraUpdateVRRPInterface(BaseAmphoraTask):
|
|||
CONF.haproxy_amphora.active_connection_max_retries,
|
||||
constants.CONN_RETRY_INTERVAL:
|
||||
CONF.haproxy_amphora.active_connection_rety_interval}
|
||||
for amp in six.moves.filter(
|
||||
for amp in filter(
|
||||
lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
|
||||
loadbalancer.amphorae):
|
||||
|
||||
|
@ -278,7 +277,7 @@ class AmphoraUpdateVRRPInterface(BaseAmphoraTask):
|
|||
if isinstance(result, failure.Failure):
|
||||
return
|
||||
LOG.warning("Reverting Get Amphora VRRP Interface.")
|
||||
for amp in six.moves.filter(
|
||||
for amp in filter(
|
||||
lambda amp: amp.status == constants.AMPHORA_ALLOCATED,
|
||||
loadbalancer.amphorae):
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class GenerateServerPEMTask(BaseCertTask):
|
|||
cert = self.cert_generator.generate_cert_key_pair(
|
||||
cn=amphora_id,
|
||||
validity=CONF.certificates.cert_validity_time)
|
||||
key = utils.get_six_compatible_server_certs_key_passphrase()
|
||||
key = utils.get_compatible_server_certs_key_passphrase()
|
||||
fer = fernet.Fernet(key)
|
||||
|
||||
return fer.encrypt(cert.certificate + cert.private_key)
|
||||
|
|
|
@ -160,7 +160,7 @@ class CertComputeCreate(ComputeCreate):
|
|||
with open(CONF.controller_worker.client_ca, 'r') as client_ca:
|
||||
ca = client_ca.read()
|
||||
|
||||
key = utils.get_six_compatible_server_certs_key_passphrase()
|
||||
key = utils.get_compatible_server_certs_key_passphrase()
|
||||
fer = fernet.Fernet(key)
|
||||
config_drive_files = {
|
||||
'/etc/octavia/certs/server.pem': fer.decrypt(server_pem),
|
||||
|
|
|
@ -19,7 +19,6 @@ from oslo_db import exception as odb_exceptions
|
|||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
import sqlalchemy
|
||||
from sqlalchemy.orm import exc
|
||||
from taskflow import task
|
||||
|
@ -936,7 +935,7 @@ class UpdateAmphoraDBCertExpiration(BaseDatabaseTask):
|
|||
|
||||
LOG.debug("Update DB cert expiry date of amphora id: %s", amphora_id)
|
||||
|
||||
key = utils.get_six_compatible_server_certs_key_passphrase()
|
||||
key = utils.get_compatible_server_certs_key_passphrase()
|
||||
fer = fernet.Fernet(key)
|
||||
cert_expiration = cert_parser.get_cert_expiration(
|
||||
fer.decrypt(server_pem))
|
||||
|
@ -2631,7 +2630,7 @@ class DecrementPoolQuota(BaseDatabaseTask):
|
|||
# This is separate calls to maximize the correction
|
||||
# should other factors have increased the in use quota
|
||||
# before this point in the revert flow
|
||||
for i in six.moves.range(pool_child_count['member']):
|
||||
for i in range(pool_child_count['member']):
|
||||
lock_session = db_apis.get_session(autocommit=False)
|
||||
try:
|
||||
self.repos.check_quota_met(session,
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
from taskflow import task
|
||||
from taskflow.types import failure
|
||||
|
||||
|