Merge "pyupgrade changes for Python3.8+ (1)"
This commit is contained in:
commit
29880ec667
@ -25,7 +25,7 @@ TEMPLATES_DIR = (os.path.dirname(os.path.realpath(__file__)) +
|
|||||||
constants.AGENT_API_TEMPLATES + '/')
|
constants.AGENT_API_TEMPLATES + '/')
|
||||||
|
|
||||||
|
|
||||||
class AgentJinjaTemplater(object):
|
class AgentJinjaTemplater:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
template_loader = jinja2.FileSystemLoader(searchpath=os.path.dirname(
|
template_loader = jinja2.FileSystemLoader(searchpath=os.path.dirname(
|
||||||
|
@ -30,7 +30,7 @@ from octavia.common import exceptions
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AmphoraInfo(object):
|
class AmphoraInfo:
|
||||||
def __init__(self, osutils):
|
def __init__(self, osutils):
|
||||||
self._osutils = osutils
|
self._osutils = osutils
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ class AmphoraInfo(object):
|
|||||||
def _get_meminfo(self):
|
def _get_meminfo(self):
|
||||||
re_parser = re.compile(r'^(?P<key>\S*):\s*(?P<value>\d*)\s*kB')
|
re_parser = re.compile(r'^(?P<key>\S*):\s*(?P<value>\d*)\s*kB')
|
||||||
result = {}
|
result = {}
|
||||||
with open('/proc/meminfo', 'r', encoding='utf-8') as meminfo:
|
with open('/proc/meminfo', encoding='utf-8') as meminfo:
|
||||||
for line in meminfo:
|
for line in meminfo:
|
||||||
match = re_parser.match(line)
|
match = re_parser.match(line)
|
||||||
if not match:
|
if not match:
|
||||||
@ -199,7 +199,7 @@ class AmphoraInfo(object):
|
|||||||
def _get_active_tuned_profiles(self) -> str:
|
def _get_active_tuned_profiles(self) -> str:
|
||||||
"""Returns the active TuneD profile(s)"""
|
"""Returns the active TuneD profile(s)"""
|
||||||
try:
|
try:
|
||||||
with open("/etc/tuned/active_profile", "r", encoding="utf-8") as f:
|
with open("/etc/tuned/active_profile", encoding="utf-8") as f:
|
||||||
return f.read(1024).strip()
|
return f.read(1024).strip()
|
||||||
except OSError as ex:
|
except OSError as ex:
|
||||||
LOG.debug("Reading active TuneD profiles failed: %r", ex)
|
LOG.debug("Reading active TuneD profiles failed: %r", ex)
|
||||||
|
@ -40,7 +40,7 @@ SYSTEMD_TEMPLATE = j2_env.get_template(consts.KEEPALIVED_JINJA2_SYSTEMD)
|
|||||||
check_script_template = j2_env.get_template(consts.CHECK_SCRIPT_CONF)
|
check_script_template = j2_env.get_template(consts.CHECK_SCRIPT_CONF)
|
||||||
|
|
||||||
|
|
||||||
class Keepalived(object):
|
class Keepalived:
|
||||||
|
|
||||||
def upload_keepalived_config(self):
|
def upload_keepalived_config(self):
|
||||||
stream = loadbalancer.Wrapped(flask.request.stream)
|
stream = loadbalancer.Wrapped(flask.request.stream)
|
||||||
@ -76,7 +76,7 @@ class Keepalived(object):
|
|||||||
template = UPSTART_TEMPLATE
|
template = UPSTART_TEMPLATE
|
||||||
elif init_system == consts.INIT_SYSVINIT:
|
elif init_system == consts.INIT_SYSVINIT:
|
||||||
template = SYSVINIT_TEMPLATE
|
template = SYSVINIT_TEMPLATE
|
||||||
init_enable_cmd = "insserv {file}".format(file=file_path)
|
init_enable_cmd = f"insserv {file_path}"
|
||||||
else:
|
else:
|
||||||
raise util.UnknownInitError()
|
raise util.UnknownInitError()
|
||||||
|
|
||||||
@ -140,25 +140,23 @@ class Keepalived(object):
|
|||||||
consts.AMP_ACTION_RELOAD]:
|
consts.AMP_ACTION_RELOAD]:
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': 'Invalid Request',
|
'message': 'Invalid Request',
|
||||||
'details': "Unknown action: {0}".format(action)}, status=400)
|
'details': f"Unknown action: {action}"}, status=400)
|
||||||
|
|
||||||
if action == consts.AMP_ACTION_START:
|
if action == consts.AMP_ACTION_START:
|
||||||
keepalived_pid_path = util.keepalived_pid_path()
|
keepalived_pid_path = util.keepalived_pid_path()
|
||||||
try:
|
try:
|
||||||
# Is there a pid file for keepalived?
|
# Is there a pid file for keepalived?
|
||||||
with open(keepalived_pid_path,
|
with open(keepalived_pid_path, encoding='utf-8') as pid_file:
|
||||||
'r', encoding='utf-8') as pid_file:
|
|
||||||
pid = int(pid_file.readline())
|
pid = int(pid_file.readline())
|
||||||
os.kill(pid, 0)
|
os.kill(pid, 0)
|
||||||
|
|
||||||
# If we got here, it means the keepalived process is running.
|
# If we got here, it means the keepalived process is running.
|
||||||
# We should reload it instead of trying to start it again.
|
# We should reload it instead of trying to start it again.
|
||||||
action = consts.AMP_ACTION_RELOAD
|
action = consts.AMP_ACTION_RELOAD
|
||||||
except (IOError, OSError):
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
cmd = ("/usr/sbin/service octavia-keepalived {action}".format(
|
cmd = f"/usr/sbin/service octavia-keepalived {action}"
|
||||||
action=action))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
||||||
@ -166,11 +164,10 @@ class Keepalived(object):
|
|||||||
LOG.debug('Failed to %s octavia-keepalived service: %s %s',
|
LOG.debug('Failed to %s octavia-keepalived service: %s %s',
|
||||||
action, e, e.output)
|
action, e, e.output)
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': "Failed to {0} octavia-keepalived service".format(
|
'message': f"Failed to {action} octavia-keepalived service",
|
||||||
action),
|
|
||||||
'details': e.output}, status=500)
|
'details': e.output}, status=500)
|
||||||
|
|
||||||
return webob.Response(
|
return webob.Response(
|
||||||
json={'message': 'OK',
|
json={'message': 'OK',
|
||||||
'details': 'keepalived {action}ed'.format(action=action)},
|
'details': f'keepalived {action}ed'},
|
||||||
status=202)
|
status=202)
|
||||||
|
@ -140,7 +140,7 @@ class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
|
|||||||
util.run_systemctl_command(
|
util.run_systemctl_command(
|
||||||
consts.ENABLE, "octavia-keepalivedlvs-%s" % str(listener_id))
|
consts.ENABLE, "octavia-keepalivedlvs-%s" % str(listener_id))
|
||||||
elif init_system == consts.INIT_SYSVINIT:
|
elif init_system == consts.INIT_SYSVINIT:
|
||||||
init_enable_cmd = "insserv {file}".format(file=file_path)
|
init_enable_cmd = f"insserv {file_path}"
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(init_enable_cmd.split(),
|
subprocess.check_output(init_enable_cmd.split(),
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
@ -180,8 +180,8 @@ class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
|
|||||||
raise exceptions.HTTPException(
|
raise exceptions.HTTPException(
|
||||||
response=webob.Response(json={
|
response=webob.Response(json={
|
||||||
'message': 'UDP Listener Not Found',
|
'message': 'UDP Listener Not Found',
|
||||||
'details': "No UDP listener with UUID: {0}".format(
|
'details': f"No UDP listener with UUID: {listener_id}"},
|
||||||
listener_id)}, status=404))
|
status=404))
|
||||||
|
|
||||||
def get_lvs_listener_config(self, listener_id):
|
def get_lvs_listener_config(self, listener_id):
|
||||||
"""Gets the keepalivedlvs config
|
"""Gets the keepalivedlvs config
|
||||||
@ -190,7 +190,7 @@ class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
|
|||||||
"""
|
"""
|
||||||
self._check_lvs_listener_exists(listener_id)
|
self._check_lvs_listener_exists(listener_id)
|
||||||
with open(util.keepalived_lvs_cfg_path(listener_id),
|
with open(util.keepalived_lvs_cfg_path(listener_id),
|
||||||
'r', encoding='utf-8') as file:
|
encoding='utf-8') as file:
|
||||||
cfg = file.read()
|
cfg = file.read()
|
||||||
resp = webob.Response(cfg, content_type='text/plain')
|
resp = webob.Response(cfg, content_type='text/plain')
|
||||||
return resp
|
return resp
|
||||||
@ -202,7 +202,7 @@ class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
|
|||||||
consts.AMP_ACTION_RELOAD]:
|
consts.AMP_ACTION_RELOAD]:
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': 'Invalid Request',
|
'message': 'Invalid Request',
|
||||||
'details': "Unknown action: {0}".format(action)}, status=400)
|
'details': f"Unknown action: {action}"}, status=400)
|
||||||
|
|
||||||
# When octavia requests a reload of keepalived, force a restart since
|
# When octavia requests a reload of keepalived, force a restart since
|
||||||
# a keepalived reload doesn't restore members in their initial state.
|
# a keepalived reload doesn't restore members in their initial state.
|
||||||
@ -217,24 +217,22 @@ class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
|
|||||||
action = consts.AMP_ACTION_START
|
action = consts.AMP_ACTION_START
|
||||||
|
|
||||||
cmd = ("/usr/sbin/service "
|
cmd = ("/usr/sbin/service "
|
||||||
"octavia-keepalivedlvs-{listener_id} "
|
f"octavia-keepalivedlvs-{listener_id} {action}")
|
||||||
"{action}".format(listener_id=listener_id, action=action))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
LOG.debug('Failed to %s keepalivedlvs listener %s',
|
LOG.debug('Failed to %s keepalivedlvs listener %s',
|
||||||
listener_id + ' : ' + action, str(e))
|
listener_id + ' : ' + action, e)
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': ("Failed to {0} keepalivedlvs listener {1}"
|
'message': (f"Failed to {action} keepalivedlvs listener "
|
||||||
.format(action, listener_id)),
|
f"{listener_id}"),
|
||||||
'details': e.output}, status=500)
|
'details': e.output}, status=500)
|
||||||
|
|
||||||
return webob.Response(
|
return webob.Response(
|
||||||
json={'message': 'OK',
|
json={'message': 'OK',
|
||||||
'details': 'keepalivedlvs listener {listener_id} '
|
'details': (f'keepalivedlvs listener {listener_id} '
|
||||||
'{action}ed'.format(listener_id=listener_id,
|
f'{action}ed')},
|
||||||
action=action)},
|
|
||||||
status=202)
|
status=202)
|
||||||
|
|
||||||
def _check_lvs_listener_status(self, listener_id):
|
def _check_lvs_listener_status(self, listener_id):
|
||||||
@ -243,7 +241,7 @@ class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
|
|||||||
'/proc', util.get_keepalivedlvs_pid(listener_id))):
|
'/proc', util.get_keepalivedlvs_pid(listener_id))):
|
||||||
# Check if the listener is disabled
|
# Check if the listener is disabled
|
||||||
with open(util.keepalived_lvs_cfg_path(listener_id),
|
with open(util.keepalived_lvs_cfg_path(listener_id),
|
||||||
'r', encoding='utf-8') as file:
|
encoding='utf-8') as file:
|
||||||
cfg = file.read()
|
cfg = file.read()
|
||||||
m = re.search('virtual_server', cfg)
|
m = re.search('virtual_server', cfg)
|
||||||
if m:
|
if m:
|
||||||
@ -280,12 +278,12 @@ class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
|
|||||||
if os.path.exists(keepalived_pid) and os.path.exists(
|
if os.path.exists(keepalived_pid) and os.path.exists(
|
||||||
os.path.join('/proc',
|
os.path.join('/proc',
|
||||||
util.get_keepalivedlvs_pid(listener_id))):
|
util.get_keepalivedlvs_pid(listener_id))):
|
||||||
cmd = ("/usr/sbin/service "
|
cmd = (f"/usr/sbin/service "
|
||||||
"octavia-keepalivedlvs-{0} stop".format(listener_id))
|
f"octavia-keepalivedlvs-{listener_id} stop")
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
LOG.error("Failed to stop keepalivedlvs service: %s", str(e))
|
LOG.error("Failed to stop keepalivedlvs service: %s", e)
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': "Error stopping keepalivedlvs",
|
'message': "Error stopping keepalivedlvs",
|
||||||
'details': e.output}, status=500)
|
'details': e.output}, status=500)
|
||||||
@ -305,9 +303,9 @@ class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
|
|||||||
|
|
||||||
if init_system == consts.INIT_SYSTEMD:
|
if init_system == consts.INIT_SYSTEMD:
|
||||||
util.run_systemctl_command(
|
util.run_systemctl_command(
|
||||||
consts.DISABLE, "octavia-keepalivedlvs-%s" % str(listener_id))
|
consts.DISABLE, f"octavia-keepalivedlvs-{listener_id}")
|
||||||
elif init_system == consts.INIT_SYSVINIT:
|
elif init_system == consts.INIT_SYSVINIT:
|
||||||
init_disable_cmd = "insserv -r {file}".format(file=init_path)
|
init_disable_cmd = f"insserv -r {init_path}"
|
||||||
elif init_system != consts.INIT_UPSTART:
|
elif init_system != consts.INIT_UPSTART:
|
||||||
raise util.UnknownInitError()
|
raise util.UnknownInitError()
|
||||||
|
|
||||||
@ -322,7 +320,7 @@ class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
|
|||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': (
|
'message': (
|
||||||
"Error disabling octavia-keepalivedlvs-"
|
"Error disabling octavia-keepalivedlvs-"
|
||||||
"{0} service".format(listener_id)),
|
"{} service".format(listener_id)),
|
||||||
'details': e.output}, status=500)
|
'details': e.output}, status=500)
|
||||||
|
|
||||||
# delete init script ,config file and log file for that listener
|
# delete init script ,config file and log file for that listener
|
||||||
|
@ -53,7 +53,7 @@ SYSTEMD_TEMPLATE = JINJA_ENV.get_template(SYSTEMD_CONF)
|
|||||||
|
|
||||||
|
|
||||||
# Wrap a stream so we can compute the md5 while reading
|
# Wrap a stream so we can compute the md5 while reading
|
||||||
class Wrapped(object):
|
class Wrapped:
|
||||||
def __init__(self, stream_):
|
def __init__(self, stream_):
|
||||||
self.stream = stream_
|
self.stream = stream_
|
||||||
self.hash = md5(usedforsecurity=False) # nosec
|
self.hash = md5(usedforsecurity=False) # nosec
|
||||||
@ -71,7 +71,7 @@ class Wrapped(object):
|
|||||||
return getattr(self.stream, attr)
|
return getattr(self.stream, attr)
|
||||||
|
|
||||||
|
|
||||||
class Loadbalancer(object):
|
class Loadbalancer:
|
||||||
|
|
||||||
def get_haproxy_config(self, lb_id):
|
def get_haproxy_config(self, lb_id):
|
||||||
"""Gets the haproxy config
|
"""Gets the haproxy config
|
||||||
@ -79,7 +79,7 @@ class Loadbalancer(object):
|
|||||||
:param listener_id: the id of the listener
|
:param listener_id: the id of the listener
|
||||||
"""
|
"""
|
||||||
self._check_lb_exists(lb_id)
|
self._check_lb_exists(lb_id)
|
||||||
with open(util.config_path(lb_id), 'r', encoding='utf-8') as file:
|
with open(util.config_path(lb_id), encoding='utf-8') as file:
|
||||||
cfg = file.read()
|
cfg = file.read()
|
||||||
resp = webob.Response(cfg, content_type='text/plain')
|
resp = webob.Response(cfg, content_type='text/plain')
|
||||||
resp.headers['ETag'] = (
|
resp.headers['ETag'] = (
|
||||||
@ -161,7 +161,7 @@ class Loadbalancer(object):
|
|||||||
template = UPSTART_TEMPLATE
|
template = UPSTART_TEMPLATE
|
||||||
elif init_system == consts.INIT_SYSVINIT:
|
elif init_system == consts.INIT_SYSVINIT:
|
||||||
template = SYSVINIT_TEMPLATE
|
template = SYSVINIT_TEMPLATE
|
||||||
init_enable_cmd = "insserv {file}".format(file=init_path)
|
init_enable_cmd = f"insserv {init_path}"
|
||||||
else:
|
else:
|
||||||
raise util.UnknownInitError()
|
raise util.UnknownInitError()
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ class Loadbalancer(object):
|
|||||||
# Make sure the new service is enabled on boot
|
# Make sure the new service is enabled on boot
|
||||||
if init_system == consts.INIT_SYSTEMD:
|
if init_system == consts.INIT_SYSTEMD:
|
||||||
util.run_systemctl_command(
|
util.run_systemctl_command(
|
||||||
consts.ENABLE, "haproxy-{lb_id}".format(lb_id=lb_id))
|
consts.ENABLE, f"haproxy-{lb_id}")
|
||||||
elif init_system == consts.INIT_SYSVINIT:
|
elif init_system == consts.INIT_SYSVINIT:
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(init_enable_cmd.split(),
|
subprocess.check_output(init_enable_cmd.split(),
|
||||||
@ -216,7 +216,7 @@ class Loadbalancer(object):
|
|||||||
"%(err)s %(out)s", {'lb_id': lb_id, 'err': e,
|
"%(err)s %(out)s", {'lb_id': lb_id, 'err': e,
|
||||||
'out': e.output})
|
'out': e.output})
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': "Error enabling haproxy-{0} service".format(
|
'message': "Error enabling haproxy-{} service".format(
|
||||||
lb_id), 'details': e.output}, status=500)
|
lb_id), 'details': e.output}, status=500)
|
||||||
|
|
||||||
res = webob.Response(json={'message': 'OK'}, status=202)
|
res = webob.Response(json={'message': 'OK'}, status=202)
|
||||||
@ -231,7 +231,7 @@ class Loadbalancer(object):
|
|||||||
consts.AMP_ACTION_RELOAD]:
|
consts.AMP_ACTION_RELOAD]:
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': 'Invalid Request',
|
'message': 'Invalid Request',
|
||||||
'details': "Unknown action: {0}".format(action)}, status=400)
|
'details': f"Unknown action: {action}"}, status=400)
|
||||||
|
|
||||||
self._check_lb_exists(lb_id)
|
self._check_lb_exists(lb_id)
|
||||||
is_vrrp = (CONF.controller_worker.loadbalancer_topology ==
|
is_vrrp = (CONF.controller_worker.loadbalancer_topology ==
|
||||||
@ -269,7 +269,7 @@ class Loadbalancer(object):
|
|||||||
"%(out)s", {'action': action, 'lb_id': lb_id,
|
"%(out)s", {'action': action, 'lb_id': lb_id,
|
||||||
'err': e, 'out': e.output})
|
'err': e, 'out': e.output})
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': "Error {0}ing haproxy".format(action),
|
'message': f"Error {action}ing haproxy",
|
||||||
'details': e.output}, status=500)
|
'details': e.output}, status=500)
|
||||||
|
|
||||||
# If we are not in active/standby we need to send an IP
|
# If we are not in active/standby we need to send an IP
|
||||||
@ -288,7 +288,7 @@ class Loadbalancer(object):
|
|||||||
|
|
||||||
details = (
|
details = (
|
||||||
'Configuration file is valid\n'
|
'Configuration file is valid\n'
|
||||||
'haproxy daemon for {0} started'.format(lb_id)
|
'haproxy daemon for {} started'.format(lb_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
return webob.Response(json={'message': 'OK', 'details': details},
|
return webob.Response(json={'message': 'OK', 'details': details},
|
||||||
@ -303,7 +303,7 @@ class Loadbalancer(object):
|
|||||||
# check if that haproxy is still running and if stop it
|
# check if that haproxy is still running and if stop it
|
||||||
if os.path.exists(util.pid_path(lb_id)) and os.path.exists(
|
if os.path.exists(util.pid_path(lb_id)) and os.path.exists(
|
||||||
os.path.join('/proc', util.get_haproxy_pid(lb_id))):
|
os.path.join('/proc', util.get_haproxy_pid(lb_id))):
|
||||||
cmd = "/usr/sbin/service haproxy-{0} stop".format(lb_id)
|
cmd = f"/usr/sbin/service haproxy-{lb_id} stop"
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
@ -342,7 +342,7 @@ class Loadbalancer(object):
|
|||||||
consts.DISABLE, "haproxy-{lb_id}".format(
|
consts.DISABLE, "haproxy-{lb_id}".format(
|
||||||
lb_id=lb_id))
|
lb_id=lb_id))
|
||||||
elif init_system == consts.INIT_SYSVINIT:
|
elif init_system == consts.INIT_SYSVINIT:
|
||||||
init_disable_cmd = "insserv -r {file}".format(file=init_path)
|
init_disable_cmd = f"insserv -r {init_path}"
|
||||||
elif init_system != consts.INIT_UPSTART:
|
elif init_system != consts.INIT_UPSTART:
|
||||||
raise util.UnknownInitError()
|
raise util.UnknownInitError()
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ class Loadbalancer(object):
|
|||||||
"%(err)s %(out)s", {'lb_id': lb_id, 'err': e,
|
"%(err)s %(out)s", {'lb_id': lb_id, 'err': e,
|
||||||
'out': e.output})
|
'out': e.output})
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': "Error disabling haproxy-{0} service".format(
|
'message': "Error disabling haproxy-{} service".format(
|
||||||
lb_id), 'details': e.output}, status=500)
|
lb_id), 'details': e.output}, status=500)
|
||||||
|
|
||||||
# delete the directory + init script for that listener
|
# delete the directory + init script for that listener
|
||||||
@ -423,7 +423,7 @@ class Loadbalancer(object):
|
|||||||
'details': "No certificate with filename: {f}".format(
|
'details': "No certificate with filename: {f}".format(
|
||||||
f=filename)}, status=404)
|
f=filename)}, status=404)
|
||||||
|
|
||||||
with open(cert_path, 'r', encoding='utf-8') as crt_file:
|
with open(cert_path, encoding='utf-8') as crt_file:
|
||||||
cert = crt_file.read()
|
cert = crt_file.read()
|
||||||
md5sum = md5(octavia_utils.b(cert),
|
md5sum = md5(octavia_utils.b(cert),
|
||||||
usedforsecurity=False).hexdigest() # nosec
|
usedforsecurity=False).hexdigest() # nosec
|
||||||
@ -442,8 +442,7 @@ class Loadbalancer(object):
|
|||||||
if os.path.exists(
|
if os.path.exists(
|
||||||
os.path.join('/proc', util.get_haproxy_pid(lb_id))):
|
os.path.join('/proc', util.get_haproxy_pid(lb_id))):
|
||||||
# Check if the listener is disabled
|
# Check if the listener is disabled
|
||||||
with open(util.config_path(lb_id),
|
with open(util.config_path(lb_id), encoding='utf-8') as file:
|
||||||
'r', encoding='utf-8') as file:
|
|
||||||
cfg = file.read()
|
cfg = file.read()
|
||||||
m = re.findall('^frontend (.*)$', cfg, re.MULTILINE)
|
m = re.findall('^frontend (.*)$', cfg, re.MULTILINE)
|
||||||
return m or []
|
return m or []
|
||||||
@ -458,7 +457,7 @@ class Loadbalancer(object):
|
|||||||
raise exceptions.HTTPException(
|
raise exceptions.HTTPException(
|
||||||
response=webob.Response(json={
|
response=webob.Response(json={
|
||||||
'message': 'Loadbalancer Not Found',
|
'message': 'Loadbalancer Not Found',
|
||||||
'details': "No loadbalancer with UUID: {0}".format(
|
'details': "No loadbalancer with UUID: {}".format(
|
||||||
lb_id)}, status=404))
|
lb_id)}, status=404))
|
||||||
|
|
||||||
def _check_ssl_filename_format(self, filename):
|
def _check_ssl_filename_format(self, filename):
|
||||||
|
@ -20,7 +20,7 @@ from oslo_config import cfg
|
|||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
class LvsListenerApiServerBase(object, metaclass=abc.ABCMeta):
|
class LvsListenerApiServerBase(metaclass=abc.ABCMeta):
|
||||||
"""Base LVS Listener Server API
|
"""Base LVS Listener Server API
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -29,7 +29,7 @@ CONF = cfg.CONF
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BaseOS(object):
|
class BaseOS:
|
||||||
|
|
||||||
def __init__(self, os_name):
|
def __init__(self, os_name):
|
||||||
self.os_name = os_name
|
self.os_name = os_name
|
||||||
@ -97,7 +97,7 @@ class BaseOS(object):
|
|||||||
e, e.output)
|
e, e.output)
|
||||||
raise exceptions.HTTPException(
|
raise exceptions.HTTPException(
|
||||||
response=webob.Response(json={
|
response=webob.Response(json={
|
||||||
'message': 'Error plugging {0}'.format(name),
|
'message': f'Error plugging {name}',
|
||||||
'details': e.output}, status=500))
|
'details': e.output}, status=500))
|
||||||
|
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ class Ubuntu(BaseOS):
|
|||||||
|
|
||||||
def cmd_get_version_of_installed_package(self, package_name):
|
def cmd_get_version_of_installed_package(self, package_name):
|
||||||
name = self._map_package_name(package_name)
|
name = self._map_package_name(package_name)
|
||||||
return "dpkg-query -W -f=${{Version}} {name}".format(name=name)
|
return f"dpkg-query -W -f=${{Version}} {name}"
|
||||||
|
|
||||||
|
|
||||||
class RH(BaseOS):
|
class RH(BaseOS):
|
||||||
@ -120,7 +120,7 @@ class RH(BaseOS):
|
|||||||
|
|
||||||
def cmd_get_version_of_installed_package(self, package_name):
|
def cmd_get_version_of_installed_package(self, package_name):
|
||||||
name = self._map_package_name(package_name)
|
name = self._map_package_name(package_name)
|
||||||
return "rpm -q --queryformat %{{VERSION}} {name}".format(name=name)
|
return f"rpm -q --queryformat %{{VERSION}} {name}"
|
||||||
|
|
||||||
|
|
||||||
class CentOS(RH):
|
class CentOS(RH):
|
||||||
|
@ -34,7 +34,7 @@ CONF = cfg.CONF
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Plug(object):
|
class Plug:
|
||||||
def __init__(self, osutils):
|
def __init__(self, osutils):
|
||||||
self._osutils = osutils
|
self._osutils = osutils
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ class Plug(object):
|
|||||||
try:
|
try:
|
||||||
rendered_vips = self.render_vips(vips)
|
rendered_vips = self.render_vips(vips)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
vip_error_message = "Invalid VIP: {}".format(e)
|
vip_error_message = f"Invalid VIP: {e}"
|
||||||
return webob.Response(json={'message': vip_error_message},
|
return webob.Response(json={'message': vip_error_message},
|
||||||
status=400)
|
status=400)
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ class Plug(object):
|
|||||||
gateway, host_routes)
|
gateway, host_routes)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return webob.Response(
|
return webob.Response(
|
||||||
json={'message': "Invalid VRRP Address: {}".format(e)},
|
json={'message': f"Invalid VRRP Address: {e}"},
|
||||||
status=400)
|
status=400)
|
||||||
|
|
||||||
# Check if the interface is already in the network namespace
|
# Check if the interface is already in the network namespace
|
||||||
@ -148,14 +148,14 @@ class Plug(object):
|
|||||||
for ip in fixed_ips:
|
for ip in fixed_ips:
|
||||||
try:
|
try:
|
||||||
socket.inet_pton(socket.AF_INET, ip.get('ip_address'))
|
socket.inet_pton(socket.AF_INET, ip.get('ip_address'))
|
||||||
except socket.error:
|
except OSError:
|
||||||
socket.inet_pton(socket.AF_INET6, ip.get('ip_address'))
|
socket.inet_pton(socket.AF_INET6, ip.get('ip_address'))
|
||||||
|
|
||||||
def plug_network(self, mac_address, fixed_ips, mtu=None,
|
def plug_network(self, mac_address, fixed_ips, mtu=None,
|
||||||
vip_net_info=None):
|
vip_net_info=None):
|
||||||
try:
|
try:
|
||||||
self._check_ip_addresses(fixed_ips=fixed_ips)
|
self._check_ip_addresses(fixed_ips=fixed_ips)
|
||||||
except socket.error:
|
except OSError:
|
||||||
return webob.Response(json={
|
return webob.Response(json={
|
||||||
'message': "Invalid network port"}, status=400)
|
'message': "Invalid network port"}, status=400)
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ def register_app_error_handler(app):
|
|||||||
app.register_error_handler(code, make_json_error)
|
app.register_error_handler(code, make_json_error)
|
||||||
|
|
||||||
|
|
||||||
class Server(object):
|
class Server:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.app = flask.Flask(__name__)
|
self.app = flask.Flask(__name__)
|
||||||
self._osutils = osutils.BaseOS.get_os_util()
|
self._osutils = osutils.BaseOS.get_os_util()
|
||||||
|
@ -48,13 +48,13 @@ class UnknownInitError(Exception):
|
|||||||
def init_path(lb_id, init_system):
|
def init_path(lb_id, init_system):
|
||||||
if init_system == consts.INIT_SYSTEMD:
|
if init_system == consts.INIT_SYSTEMD:
|
||||||
return os.path.join(consts.SYSTEMD_DIR,
|
return os.path.join(consts.SYSTEMD_DIR,
|
||||||
'haproxy-{0}.service'.format(lb_id))
|
f'haproxy-{lb_id}.service')
|
||||||
if init_system == consts.INIT_UPSTART:
|
if init_system == consts.INIT_UPSTART:
|
||||||
return os.path.join(consts.UPSTART_DIR,
|
return os.path.join(consts.UPSTART_DIR,
|
||||||
'haproxy-{0}.conf'.format(lb_id))
|
f'haproxy-{lb_id}.conf')
|
||||||
if init_system == consts.INIT_SYSVINIT:
|
if init_system == consts.INIT_SYSVINIT:
|
||||||
return os.path.join(consts.SYSVINIT_DIR,
|
return os.path.join(consts.SYSVINIT_DIR,
|
||||||
'haproxy-{0}'.format(lb_id))
|
f'haproxy-{lb_id}')
|
||||||
raise UnknownInitError()
|
raise UnknownInitError()
|
||||||
|
|
||||||
|
|
||||||
@ -120,13 +120,13 @@ def state_file_path(lb_id):
|
|||||||
|
|
||||||
|
|
||||||
def get_haproxy_pid(lb_id):
|
def get_haproxy_pid(lb_id):
|
||||||
with open(pid_path(lb_id), 'r', encoding='utf-8') as f:
|
with open(pid_path(lb_id), encoding='utf-8') as f:
|
||||||
return f.readline().rstrip()
|
return f.readline().rstrip()
|
||||||
|
|
||||||
|
|
||||||
def get_keepalivedlvs_pid(listener_id):
|
def get_keepalivedlvs_pid(listener_id):
|
||||||
pid_file = keepalived_lvs_pids_path(listener_id)[0]
|
pid_file = keepalived_lvs_pids_path(listener_id)[0]
|
||||||
with open(pid_file, 'r', encoding='utf-8') as f:
|
with open(pid_file, encoding='utf-8') as f:
|
||||||
return f.readline().rstrip()
|
return f.readline().rstrip()
|
||||||
|
|
||||||
|
|
||||||
@ -228,8 +228,7 @@ def is_lvs_listener_running(listener_id):
|
|||||||
|
|
||||||
def get_os_init_system():
|
def get_os_init_system():
|
||||||
if os.path.exists(consts.INIT_PROC_COMM_PATH):
|
if os.path.exists(consts.INIT_PROC_COMM_PATH):
|
||||||
with open(consts.INIT_PROC_COMM_PATH,
|
with open(consts.INIT_PROC_COMM_PATH, encoding='utf-8') as init_comm:
|
||||||
'r', encoding='utf-8') as init_comm:
|
|
||||||
init_proc_name = init_comm.read().rstrip('\n')
|
init_proc_name = init_comm.read().rstrip('\n')
|
||||||
if init_proc_name == consts.INIT_SYSTEMD:
|
if init_proc_name == consts.INIT_SYSTEMD:
|
||||||
return consts.INIT_SYSTEMD
|
return consts.INIT_SYSTEMD
|
||||||
@ -268,7 +267,7 @@ def install_netns_systemd_service():
|
|||||||
|
|
||||||
|
|
||||||
def run_systemctl_command(command, service):
|
def run_systemctl_command(command, service):
|
||||||
cmd = "systemctl {cmd} {srvc}".format(cmd=command, srvc=service)
|
cmd = f"systemctl {command} {service}"
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
@ -295,7 +294,7 @@ def get_backend_for_lb_object(object_id):
|
|||||||
|
|
||||||
|
|
||||||
def parse_haproxy_file(lb_id):
|
def parse_haproxy_file(lb_id):
|
||||||
with open(config_path(lb_id), 'r', encoding='utf-8') as file:
|
with open(config_path(lb_id), encoding='utf-8') as file:
|
||||||
cfg = file.read()
|
cfg = file.read()
|
||||||
|
|
||||||
listeners = {}
|
listeners = {}
|
||||||
@ -376,7 +375,7 @@ def get_haproxy_vip_addresses(lb_id):
|
|||||||
:returns: List of VIP addresses (IPv4 and IPv6)
|
:returns: List of VIP addresses (IPv4 and IPv6)
|
||||||
"""
|
"""
|
||||||
vips = []
|
vips = []
|
||||||
with open(config_path(lb_id), 'r', encoding='utf-8') as file:
|
with open(config_path(lb_id), encoding='utf-8') as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
current_line = line.strip()
|
current_line = line.strip()
|
||||||
if current_line.startswith('bind'):
|
if current_line.startswith('bind'):
|
||||||
|
@ -118,14 +118,13 @@ def run_sender(cmd_queue):
|
|||||||
# heartbeat
|
# heartbeat
|
||||||
if os.path.isfile(keepalived_cfg_path):
|
if os.path.isfile(keepalived_cfg_path):
|
||||||
# Is there a pid file for keepalived?
|
# Is there a pid file for keepalived?
|
||||||
with open(keepalived_pid_path,
|
with open(keepalived_pid_path, encoding='utf-8') as pid_file:
|
||||||
'r', encoding='utf-8') as pid_file:
|
|
||||||
pid = int(pid_file.readline())
|
pid = int(pid_file.readline())
|
||||||
os.kill(pid, 0)
|
os.kill(pid, 0)
|
||||||
|
|
||||||
message = build_stats_message()
|
message = build_stats_message()
|
||||||
sender.dosend(message)
|
sender.dosend(message)
|
||||||
except (IOError, OSError) as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
# Missing PID file, skip health heartbeat.
|
# Missing PID file, skip health heartbeat.
|
||||||
LOG.error('Missing keepalived PID file %s, skipping health '
|
LOG.error('Missing keepalived PID file %s, skipping health '
|
||||||
|
@ -31,7 +31,7 @@ def round_robin_addr(addrinfo_list):
|
|||||||
return addrinfo
|
return addrinfo
|
||||||
|
|
||||||
|
|
||||||
class UDPStatusSender(object):
|
class UDPStatusSender:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._update_dests()
|
self._update_dests()
|
||||||
self.v4sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
self.v4sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
@ -56,7 +56,7 @@ class UDPStatusSender(object):
|
|||||||
self.v4sock.sendto(envelope_str, dest[4])
|
self.v4sock.sendto(envelope_str, dest[4])
|
||||||
elif dest[0] == socket.AF_INET6:
|
elif dest[0] == socket.AF_INET6:
|
||||||
self.v6sock.sendto(envelope_str, dest[4])
|
self.v6sock.sendto(envelope_str, dest[4])
|
||||||
except socket.error:
|
except OSError:
|
||||||
# Pass here as on amp boot it will get one or more
|
# Pass here as on amp boot it will get one or more
|
||||||
# error: [Errno 101] Network is unreachable
|
# error: [Errno 101] Network is unreachable
|
||||||
# while the networks are coming up
|
# while the networks are coming up
|
||||||
|
@ -24,7 +24,7 @@ from octavia.i18n import _
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class HAProxyQuery(object):
|
class HAProxyQuery:
|
||||||
"""Class used for querying the HAProxy statistics socket.
|
"""Class used for querying the HAProxy statistics socket.
|
||||||
|
|
||||||
The CSV output is defined in the HAProxy documentation:
|
The CSV output is defined in the HAProxy documentation:
|
||||||
@ -51,7 +51,7 @@ class HAProxyQuery(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
sock.connect(self.socket)
|
sock.connect(self.socket)
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
_("HAProxy '{0}' query failed.").format(query)) from e
|
_("HAProxy '{0}' query failed.").format(query)) from e
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ CONF = cfg.CONF
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class InterfaceController(object):
|
class InterfaceController:
|
||||||
ADD = 'add'
|
ADD = 'add'
|
||||||
DELETE = 'delete'
|
DELETE = 'delete'
|
||||||
SET = 'set'
|
SET = 'set'
|
||||||
@ -109,7 +109,7 @@ class InterfaceController(object):
|
|||||||
"/var/lib/dhclient/dhclient-{}.leases".format(
|
"/var/lib/dhclient/dhclient-{}.leases".format(
|
||||||
interface_name),
|
interface_name),
|
||||||
"-pf",
|
"-pf",
|
||||||
"/run/dhclient-{}.pid".format(interface_name),
|
f"/run/dhclient-{interface_name}.pid",
|
||||||
interface_name]
|
interface_name]
|
||||||
LOG.debug("Running '%s'", cmd)
|
LOG.debug("Running '%s'", cmd)
|
||||||
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
||||||
@ -121,7 +121,7 @@ class InterfaceController(object):
|
|||||||
"/var/lib/dhclient/dhclient-{}.leases".format(
|
"/var/lib/dhclient/dhclient-{}.leases".format(
|
||||||
interface_name),
|
interface_name),
|
||||||
"-pf",
|
"-pf",
|
||||||
"/run/dhclient-{}.pid".format(interface_name),
|
f"/run/dhclient-{interface_name}.pid",
|
||||||
interface_name]
|
interface_name]
|
||||||
LOG.debug("Running '%s'", cmd)
|
LOG.debug("Running '%s'", cmd)
|
||||||
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
||||||
|
@ -24,7 +24,7 @@ from octavia.common import constants as consts
|
|||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
class InterfaceFile(object):
|
class InterfaceFile:
|
||||||
def __init__(self, name, if_type, mtu=None, addresses=None,
|
def __init__(self, name, if_type, mtu=None, addresses=None,
|
||||||
routes=None, rules=None, scripts=None, is_sriov=False):
|
routes=None, rules=None, scripts=None, is_sriov=False):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -88,7 +88,7 @@ class InterfaceFile(object):
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
interface_file = "{}.json".format(self.name)
|
interface_file = f"{self.name}.json"
|
||||||
|
|
||||||
with os.fdopen(os.open(os.path.join(net_dir, interface_file),
|
with os.fdopen(os.open(os.path.join(net_dir, interface_file),
|
||||||
flags, mode), 'w') as fp:
|
flags, mode), 'w') as fp:
|
||||||
|
@ -147,7 +147,7 @@ def get_lvs_listener_resource_ipports_nsname(listener_id):
|
|||||||
# 'HealthMonitor': {'id': healthmonitor-id}}
|
# 'HealthMonitor': {'id': healthmonitor-id}}
|
||||||
resource_ipport_mapping = {}
|
resource_ipport_mapping = {}
|
||||||
with open(util.keepalived_lvs_cfg_path(listener_id),
|
with open(util.keepalived_lvs_cfg_path(listener_id),
|
||||||
'r', encoding='utf-8') as f:
|
encoding='utf-8') as f:
|
||||||
cfg = f.read()
|
cfg = f.read()
|
||||||
|
|
||||||
ret = VS_ADDRESS_REGEX.findall(cfg)
|
ret = VS_ADDRESS_REGEX.findall(cfg)
|
||||||
@ -260,7 +260,7 @@ def get_lvs_listener_pool_status(listener_id):
|
|||||||
restarting = config_stat.st_mtime > check_pid_stat.st_mtime
|
restarting = config_stat.st_mtime > check_pid_stat.st_mtime
|
||||||
|
|
||||||
with open(util.keepalived_lvs_cfg_path(listener_id),
|
with open(util.keepalived_lvs_cfg_path(listener_id),
|
||||||
'r', encoding='utf-8') as f:
|
encoding='utf-8') as f:
|
||||||
cfg = f.read()
|
cfg = f.read()
|
||||||
hm_enabled = len(CHECKER_REGEX.findall(cfg)) > 0
|
hm_enabled = len(CHECKER_REGEX.findall(cfg)) > 0
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import ctypes
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class NetworkNamespace(object):
|
class NetworkNamespace:
|
||||||
"""A network namespace context manager.
|
"""A network namespace context manager.
|
||||||
|
|
||||||
Runs wrapped code inside the specified network namespace.
|
Runs wrapped code inside the specified network namespace.
|
||||||
@ -32,8 +32,8 @@ class NetworkNamespace(object):
|
|||||||
raise OSError(errno, os.strerror(errno))
|
raise OSError(errno, os.strerror(errno))
|
||||||
|
|
||||||
def __init__(self, netns):
|
def __init__(self, netns):
|
||||||
self.current_netns = '/proc/{pid}/ns/net'.format(pid=os.getpid())
|
self.current_netns = f'/proc/{os.getpid()}/ns/net'
|
||||||
self.target_netns = '/var/run/netns/{netns}'.format(netns=netns)
|
self.target_netns = f'/var/run/netns/{netns}'
|
||||||
# reference: man setns(2)
|
# reference: man setns(2)
|
||||||
self.set_netns = ctypes.CDLL('libc.so.6', use_errno=True).setns
|
self.set_netns = ctypes.CDLL('libc.so.6', use_errno=True).setns
|
||||||
self.set_netns.errcheck = self._error_handler
|
self.set_netns.errcheck = self._error_handler
|
||||||
|
@ -19,7 +19,7 @@ from typing import Optional
|
|||||||
from octavia.db import models as db_models
|
from octavia.db import models as db_models
|
||||||
|
|
||||||
|
|
||||||
class AmphoraLoadBalancerDriver(object, metaclass=abc.ABCMeta):
|
class AmphoraLoadBalancerDriver(metaclass=abc.ABCMeta):
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def update_amphora_listeners(self, loadbalancer, amphora,
|
def update_amphora_listeners(self, loadbalancer, amphora,
|
||||||
timeout_dict):
|
timeout_dict):
|
||||||
@ -264,7 +264,7 @@ class AmphoraLoadBalancerDriver(object, metaclass=abc.ABCMeta):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class VRRPDriverMixin(object, metaclass=abc.ABCMeta):
|
class VRRPDriverMixin(metaclass=abc.ABCMeta):
|
||||||
"""Abstract mixin class for VRRP support in loadbalancer amphorae
|
"""Abstract mixin class for VRRP support in loadbalancer amphorae
|
||||||
|
|
||||||
Usage: To plug VRRP support in another service driver XYZ, use:
|
Usage: To plug VRRP support in another service driver XYZ, use:
|
||||||
|
@ -308,7 +308,7 @@ class HaproxyAmphoraLoadBalancerDriver(
|
|||||||
for cert_id in certs_to_delete:
|
for cert_id in certs_to_delete:
|
||||||
self.clients[amphora.api_version].delete_cert_pem(
|
self.clients[amphora.api_version].delete_cert_pem(
|
||||||
amphora, listener.load_balancer.id,
|
amphora, listener.load_balancer.id,
|
||||||
'{id}.pem'.format(id=cert_id))
|
f'{cert_id}.pem')
|
||||||
|
|
||||||
# See how many non-UDP/SCTP listeners we have left
|
# See how many non-UDP/SCTP listeners we have left
|
||||||
non_lvs_listener_count = len([
|
non_lvs_listener_count = len([
|
||||||
@ -451,7 +451,7 @@ class HaproxyAmphoraLoadBalancerDriver(
|
|||||||
for cert in certs:
|
for cert in certs:
|
||||||
pem = cert_parser.build_pem(cert)
|
pem = cert_parser.build_pem(cert)
|
||||||
md5sum = md5(pem, usedforsecurity=False).hexdigest() # nosec
|
md5sum = md5(pem, usedforsecurity=False).hexdigest() # nosec
|
||||||
name = '{id}.pem'.format(id=cert.id)
|
name = f'{cert.id}.pem'
|
||||||
cert_filename_list.append(
|
cert_filename_list.append(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
CONF.haproxy_amphora.base_cert_dir, obj_id, name))
|
CONF.haproxy_amphora.base_cert_dir, obj_id, name))
|
||||||
@ -460,10 +460,10 @@ class HaproxyAmphoraLoadBalancerDriver(
|
|||||||
if certs:
|
if certs:
|
||||||
# Build and upload the crt-list file for haproxy
|
# Build and upload the crt-list file for haproxy
|
||||||
crt_list = "\n".join(cert_filename_list)
|
crt_list = "\n".join(cert_filename_list)
|
||||||
crt_list = f'{crt_list}\n'.encode('utf-8')
|
crt_list = f'{crt_list}\n'.encode()
|
||||||
md5sum = md5(crt_list,
|
md5sum = md5(crt_list,
|
||||||
usedforsecurity=False).hexdigest() # nosec
|
usedforsecurity=False).hexdigest() # nosec
|
||||||
name = '{id}.pem'.format(id=listener.id)
|
name = f'{listener.id}.pem'
|
||||||
self._upload_cert(amphora, obj_id, crt_list, md5sum, name)
|
self._upload_cert(amphora, obj_id, crt_list, md5sum, name)
|
||||||
return {'tls_cert': tls_cert, 'sni_certs': sni_certs}
|
return {'tls_cert': tls_cert, 'sni_certs': sni_certs}
|
||||||
|
|
||||||
@ -482,7 +482,7 @@ class HaproxyAmphoraLoadBalancerDriver(
|
|||||||
pass
|
pass
|
||||||
md5sum = md5(secret, usedforsecurity=False).hexdigest() # nosec
|
md5sum = md5(secret, usedforsecurity=False).hexdigest() # nosec
|
||||||
id = hashlib.sha1(secret).hexdigest() # nosec
|
id = hashlib.sha1(secret).hexdigest() # nosec
|
||||||
name = '{id}.pem'.format(id=id)
|
name = f'{id}.pem'
|
||||||
|
|
||||||
if amphora and obj_id:
|
if amphora and obj_id:
|
||||||
self._upload_cert(
|
self._upload_cert(
|
||||||
@ -520,7 +520,7 @@ class HaproxyAmphoraLoadBalancerDriver(
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
md5sum = md5(pem, usedforsecurity=False).hexdigest() # nosec
|
md5sum = md5(pem, usedforsecurity=False).hexdigest() # nosec
|
||||||
name = '{id}.pem'.format(id=tls_cert.id)
|
name = f'{tls_cert.id}.pem'
|
||||||
if amphora and obj_id:
|
if amphora and obj_id:
|
||||||
self._upload_cert(amphora, obj_id, pem=pem,
|
self._upload_cert(amphora, obj_id, pem=pem,
|
||||||
md5sum=md5sum, name=name)
|
md5sum=md5sum, name=name)
|
||||||
@ -629,7 +629,7 @@ class CustomHostNameCheckingAdapter(requests.adapters.HTTPAdapter):
|
|||||||
return super().init_poolmanager(*pool_args, **pool_kwargs)
|
return super().init_poolmanager(*pool_args, **pool_kwargs)
|
||||||
|
|
||||||
|
|
||||||
class AmphoraAPIClientBase(object):
|
class AmphoraAPIClientBase:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@ -650,7 +650,7 @@ class AmphoraAPIClientBase(object):
|
|||||||
ip=ip,
|
ip=ip,
|
||||||
interface=CONF.haproxy_amphora.lb_network_interface)
|
interface=CONF.haproxy_amphora.lb_network_interface)
|
||||||
elif utils.is_ipv6(ip):
|
elif utils.is_ipv6(ip):
|
||||||
ip = '[{ip}]'.format(ip=ip)
|
ip = f'[{ip}]'
|
||||||
if api_version:
|
if api_version:
|
||||||
return "https://{ip}:{port}/{version}/".format(
|
return "https://{ip}:{port}/{version}/".format(
|
||||||
ip=ip,
|
ip=ip,
|
||||||
@ -782,7 +782,7 @@ class AmphoraAPIClient1_0(AmphoraAPIClientBase):
|
|||||||
def get_listener_status(self, amp, listener_id):
|
def get_listener_status(self, amp, listener_id):
|
||||||
r = self.get(
|
r = self.get(
|
||||||
amp,
|
amp,
|
||||||
'listeners/{listener_id}'.format(listener_id=listener_id))
|
f'listeners/{listener_id}')
|
||||||
if exc.check_exception(r):
|
if exc.check_exception(r):
|
||||||
return r.json()
|
return r.json()
|
||||||
return None
|
return None
|
||||||
@ -825,7 +825,7 @@ class AmphoraAPIClient1_0(AmphoraAPIClientBase):
|
|||||||
|
|
||||||
def delete_listener(self, amp, object_id):
|
def delete_listener(self, amp, object_id):
|
||||||
r = self.delete(
|
r = self.delete(
|
||||||
amp, 'listeners/{object_id}'.format(object_id=object_id))
|
amp, f'listeners/{object_id}')
|
||||||
return exc.check_exception(r, (404,))
|
return exc.check_exception(r, (404,))
|
||||||
|
|
||||||
def get_info(self, amp, raise_retry_exception=False,
|
def get_info(self, amp, raise_retry_exception=False,
|
||||||
@ -855,7 +855,7 @@ class AmphoraAPIClient1_0(AmphoraAPIClientBase):
|
|||||||
|
|
||||||
def plug_vip(self, amp, vip, net_info):
|
def plug_vip(self, amp, vip, net_info):
|
||||||
r = self.post(amp,
|
r = self.post(amp,
|
||||||
'plug/vip/{vip}'.format(vip=vip),
|
f'plug/vip/{vip}',
|
||||||
json=net_info)
|
json=net_info)
|
||||||
return exc.check_exception(r)
|
return exc.check_exception(r)
|
||||||
|
|
||||||
@ -864,12 +864,12 @@ class AmphoraAPIClient1_0(AmphoraAPIClientBase):
|
|||||||
return exc.check_exception(r)
|
return exc.check_exception(r)
|
||||||
|
|
||||||
def _vrrp_action(self, action, amp, timeout_dict=None):
|
def _vrrp_action(self, action, amp, timeout_dict=None):
|
||||||
r = self.put(amp, 'vrrp/{action}'.format(action=action),
|
r = self.put(amp, f'vrrp/{action}',
|
||||||
timeout_dict=timeout_dict)
|
timeout_dict=timeout_dict)
|
||||||
return exc.check_exception(r)
|
return exc.check_exception(r)
|
||||||
|
|
||||||
def get_interface(self, amp, ip_addr, timeout_dict=None, log_error=True):
|
def get_interface(self, amp, ip_addr, timeout_dict=None, log_error=True):
|
||||||
r = self.get(amp, 'interface/{ip_addr}'.format(ip_addr=ip_addr),
|
r = self.get(amp, f'interface/{ip_addr}',
|
||||||
timeout_dict=timeout_dict)
|
timeout_dict=timeout_dict)
|
||||||
return exc.check_exception(r, log_error=log_error).json()
|
return exc.check_exception(r, log_error=log_error).json()
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ CONF = cfg.CONF
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class UDPStatusGetter(object):
|
class UDPStatusGetter:
|
||||||
"""This class defines methods that will gather heartbeats
|
"""This class defines methods that will gather heartbeats
|
||||||
|
|
||||||
The heartbeats are transmitted via UDP and this class will bind to a port
|
The heartbeats are transmitted via UDP and this class will bind to a port
|
||||||
|
@ -30,7 +30,7 @@ CONF = cfg.CONF
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class KeepalivedJinjaTemplater(object):
|
class KeepalivedJinjaTemplater:
|
||||||
|
|
||||||
def __init__(self, keepalived_template=None):
|
def __init__(self, keepalived_template=None):
|
||||||
"""Keepalived configuration generation
|
"""Keepalived configuration generation
|
||||||
|
@ -23,7 +23,7 @@ from octavia.db import repositories
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class NoopManager(object):
|
class NoopManager:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
Loading…
Reference in New Issue
Block a user