"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "octavia/amphorae/backends/agent/api_server/keepalivedlvs.py" between
octavia-7.1.1.tar.gz and octavia-8.0.0.tar.gz

About: OpenStack Octavia is an operator-grade reference implementation for Load Balancing as a Service (LBaaS).
The "Wallaby" series (latest release).

keepalivedlvs.py  (octavia-7.1.1):keepalivedlvs.py  (octavia-8.0.0)
skipping to change at line 29 skipping to change at line 29
import subprocess import subprocess
import flask import flask
import jinja2 import jinja2
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import webob import webob
from werkzeug import exceptions from werkzeug import exceptions
from octavia.amphorae.backends.agent.api_server import loadbalancer from octavia.amphorae.backends.agent.api_server import loadbalancer
from octavia.amphorae.backends.agent.api_server import udp_listener_base from octavia.amphorae.backends.agent.api_server import lvs_listener_base
from octavia.amphorae.backends.agent.api_server import util from octavia.amphorae.backends.agent.api_server import util
from octavia.common import constants as consts from octavia.common import constants as consts
BUFFER = 100 BUFFER = 100
CHECK_SCRIPT_NAME = 'udp_check.sh' CHECK_SCRIPT_NAME = 'udp_check.sh'
CONF = cfg.CONF CONF = cfg.CONF
KEEPALIVED_CHECK_SCRIPT_NAME = 'lvs_udp_check.sh' KEEPALIVED_CHECK_SCRIPT_NAME = 'lvs_udp_check.sh'
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
j2_env = jinja2.Environment(autoescape=True, loader=jinja2.FileSystemLoader( j2_env = jinja2.Environment(autoescape=True, loader=jinja2.FileSystemLoader(
os.path.dirname(os.path.realpath(__file__)) + consts.AGENT_API_TEMPLATES)) os.path.dirname(os.path.realpath(__file__)) + consts.AGENT_API_TEMPLATES))
UPSTART_TEMPLATE = j2_env.get_template(consts.KEEPALIVED_JINJA2_UPSTART) UPSTART_TEMPLATE = j2_env.get_template(consts.KEEPALIVED_JINJA2_UPSTART)
SYSVINIT_TEMPLATE = j2_env.get_template(consts.KEEPALIVED_JINJA2_SYSVINIT) SYSVINIT_TEMPLATE = j2_env.get_template(consts.KEEPALIVED_JINJA2_SYSVINIT)
SYSTEMD_TEMPLATE = j2_env.get_template(consts.KEEPALIVED_JINJA2_SYSTEMD) SYSTEMD_TEMPLATE = j2_env.get_template(consts.KEEPALIVED_JINJA2_SYSTEMD)
check_script_file_template = j2_env.get_template( check_script_file_template = j2_env.get_template(
consts.KEEPALIVED_CHECK_SCRIPT) consts.KEEPALIVED_CHECK_SCRIPT)
class KeepalivedLvs(udp_listener_base.UdpListenerApiServerBase): class KeepalivedLvs(lvs_listener_base.LvsListenerApiServerBase):
_SUBSCRIBED_AMP_COMPILE = ['keepalived', 'ipvsadm'] _SUBSCRIBED_AMP_COMPILE = ['keepalived', 'ipvsadm']
def upload_udp_listener_config(self, listener_id): def upload_lvs_listener_config(self, listener_id):
stream = loadbalancer.Wrapped(flask.request.stream) stream = loadbalancer.Wrapped(flask.request.stream)
NEED_CHECK = True NEED_CHECK = True
if not os.path.exists(util.keepalived_lvs_dir()): if not os.path.exists(util.keepalived_lvs_dir()):
os.makedirs(util.keepalived_lvs_dir()) os.makedirs(util.keepalived_lvs_dir())
if not os.path.exists(util.keepalived_backend_check_script_dir()): if not os.path.exists(util.keepalived_backend_check_script_dir()):
current_file_dir, _ = os.path.split(os.path.abspath(__file__)) current_file_dir, _ = os.path.split(os.path.abspath(__file__))
try: try:
script_dir = os.path.join(os.path.abspath( script_dir = os.path.join(os.path.abspath(
skipping to change at line 177 skipping to change at line 177
init_system=init_system, init_system=init_system,
keepalived_lvs_pid_dir=util.keepalived_lvs_dir() keepalived_lvs_pid_dir=util.keepalived_lvs_dir()
) )
script_file.write(text) script_file.write(text)
util.vrrp_check_script_update(None, consts.AMP_ACTION_START) util.vrrp_check_script_update(None, consts.AMP_ACTION_START)
res = webob.Response(json={'message': 'OK'}, status=200) res = webob.Response(json={'message': 'OK'}, status=200)
res.headers['ETag'] = stream.get_md5() res.headers['ETag'] = stream.get_md5()
return res return res
def _check_udp_listener_exists(self, listener_id): def _check_lvs_listener_exists(self, listener_id):
if not os.path.exists(util.keepalived_lvs_cfg_path(listener_id)): if not os.path.exists(util.keepalived_lvs_cfg_path(listener_id)):
raise exceptions.HTTPException( raise exceptions.HTTPException(
response=webob.Response(json=dict( response=webob.Response(json=dict(
message='UDP Listener Not Found', message='UDP Listener Not Found',
details="No UDP listener with UUID: {0}".format( details="No UDP listener with UUID: {0}".format(
listener_id)), status=404)) listener_id)), status=404))
def get_udp_listener_config(self, listener_id): def get_lvs_listener_config(self, listener_id):
"""Gets the keepalivedlvs config """Gets the keepalivedlvs config
:param listener_id: the id of the listener :param listener_id: the id of the listener
""" """
self._check_udp_listener_exists(listener_id) self._check_lvs_listener_exists(listener_id)
with open(util.keepalived_lvs_cfg_path(listener_id), 'r') as file: with open(util.keepalived_lvs_cfg_path(listener_id), 'r') 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
def manage_udp_listener(self, listener_id, action): def manage_lvs_listener(self, listener_id, action):
action = action.lower() action = action.lower()
if action not in [consts.AMP_ACTION_START, if action not in [consts.AMP_ACTION_START,
consts.AMP_ACTION_STOP, consts.AMP_ACTION_STOP,
consts.AMP_ACTION_RELOAD]: consts.AMP_ACTION_RELOAD]:
return webob.Response(json=dict( return webob.Response(json=dict(
message='Invalid Request', message='Invalid Request',
details="Unknown action: {0}".format(action)), status=400) details="Unknown action: {0}".format(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.
# #
# TODO(gthiemonge) remove this when keepalived>=2.0.14 is widely use # TODO(gthiemonge) remove this when keepalived>=2.0.14 is widely use
if action == consts.AMP_ACTION_RELOAD: if action == consts.AMP_ACTION_RELOAD:
action = consts.AMP_ACTION_RESTART action = consts.AMP_ACTION_RESTART
self._check_udp_listener_exists(listener_id) self._check_lvs_listener_exists(listener_id)
if action == consts.AMP_ACTION_RELOAD: if action == consts.AMP_ACTION_RELOAD:
if consts.OFFLINE == self._check_udp_listener_status(listener_id): if consts.OFFLINE == self._check_lvs_listener_status(listener_id):
action = consts.AMP_ACTION_START action = consts.AMP_ACTION_START
cmd = ("/usr/sbin/service " cmd = ("/usr/sbin/service "
"octavia-keepalivedlvs-{listener_id} " "octavia-keepalivedlvs-{listener_id} "
"{action}".format(listener_id=listener_id, action=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',
skipping to change at line 238 skipping to change at line 238
.format(action, listener_id)), .format(action, listener_id)),
details=e.output), status=500) details=e.output), status=500)
return webob.Response( return webob.Response(
json=dict(message='OK', json=dict(message='OK',
details='keepalivedlvs listener {listener_id} ' details='keepalivedlvs listener {listener_id} '
'{action}ed'.format(listener_id=listener_id, '{action}ed'.format(listener_id=listener_id,
action=action)), action=action)),
status=202) status=202)
def _check_udp_listener_status(self, listener_id): def _check_lvs_listener_status(self, listener_id):
if os.path.exists(util.keepalived_lvs_pids_path(listener_id)[0]): if os.path.exists(util.keepalived_lvs_pids_path(listener_id)[0]):
if os.path.exists(os.path.join( if os.path.exists(os.path.join(
'/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') as file: 'r') as file:
cfg = file.read() cfg = file.read()
m = re.search('virtual_server', cfg) m = re.search('virtual_server', cfg)
if m: if m:
return consts.ACTIVE return consts.ACTIVE
return consts.OFFLINE return consts.OFFLINE
return consts.ERROR return consts.ERROR
return consts.OFFLINE return consts.OFFLINE
def get_all_udp_listeners_status(self): def get_all_lvs_listeners_status(self):
"""Gets the status of all UDP listeners """Gets the status of all UDP listeners
Gets the status of all UDP listeners on the amphora. Gets the status of all UDP listeners on the amphora.
""" """
listeners = list() listeners = list()
for udp_listener in util.get_udp_listeners(): for lvs_listener in util.get_lvs_listeners():
status = self._check_udp_listener_status(udp_listener) status = self._check_lvs_listener_status(lvs_listener)
listeners.append({ listeners.append({
'status': status, 'status': status,
'uuid': udp_listener, 'uuid': lvs_listener,
'type': 'UDP', 'type': 'UDP',
}) })
return listeners return listeners
def delete_udp_listener(self, listener_id): def delete_lvs_listener(self, listener_id):
try: try:
self._check_udp_listener_exists(listener_id) self._check_lvs_listener_exists(listener_id)
except exceptions.HTTPException: except exceptions.HTTPException:
return webob.Response(json={'message': 'OK'}) return webob.Response(json={'message': 'OK'})
# check if that keepalived is still running and if stop it # check if that keepalived is still running and if stop it
keepalived_pid, vrrp_pid, check_pid = util.keepalived_lvs_pids_path( keepalived_pid, vrrp_pid, check_pid = util.keepalived_lvs_pids_path(
listener_id) listener_id)
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 = ("/usr/sbin/service "
 End of changes. 15 change blocks. 
16 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)