Skip to content

Commit

Permalink
Merge "vrouter-nodemgr change for LBAAS config generation on controll…
Browse files Browse the repository at this point in the history
…er" into R3.0
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 19, 2016
2 parents de315db + be5c941 commit c8d6ffa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/nodemgr/vrouter_nodemgr/haproxy_stats.py
Expand Up @@ -30,10 +30,11 @@

class HaproxyStats(object):
def __init__(self):
self.lbaas_dir = HAPROXY_DIR
pass

def get_stats(self, pool_id):
sock_path = os.path.join(LB_BASE_DIR, pool_id, 'haproxy.sock')
sock_path = os.path.join(self.lbaas_dir, pool_id, 'haproxy.sock')
if not os.path.exists(sock_path):
sys.stderr.write('\nStats socket not found for pool ' + pool_id)
return {}
Expand Down
27 changes: 21 additions & 6 deletions src/nodemgr/vrouter_nodemgr/loadbalancer_stats.py
Expand Up @@ -3,15 +3,17 @@

from haproxy_stats import HaproxyStats
from vrouter.loadbalancer.ttypes import \
UveLoadbalancerTrace, UveLoadbalancer, UveLoadbalancerStats
UveLoadbalancerTrace, UveLoadbalancer, UveLoadbalancerStats

LB_BASE_DIR = '/var/lib/contrail/loadbalancer/'

class LoadbalancerStats(object):
def __init__(self):
self.driver = HaproxyStats()
if not self.driver.lbaas_dir:
self.driver.lbaas_dir = LB_BASE_DIR
try:
self.old_pool_uuids = os.listdir(LB_BASE_DIR)
self.old_pool_uuids = os.listdir(self.driver.lbaas_dir)
except OSError:
self.old_pool_uuids = []

Expand Down Expand Up @@ -44,29 +46,42 @@ def _uve_get_member_stats(self, stats):

def _send_loadbalancer_uve(self):
try:
pool_uuids = os.listdir(LB_BASE_DIR)
pool_uuids = os.listdir(self.driver.lbaas_dir)
except OSError:
return

# delete stale uves
for pool_uuid in self.old_pool_uuids:
if pool_uuid not in pool_uuids:
uve_lb = UveLoadbalancer(name=pool_uuid, deleted=True)
uve_lb.virtual_ip_stats = {}
uve_lb.pool_stats = {}
uve_lb.member_stats = []
uve_trace = UveLoadbalancerTrace(data=uve_lb)
uve_trace.send()
self.old_pool_uuids = pool_uuids

# send stats
for pool_uuid in pool_uuids:
stats = self.driver.get_stats(pool_uuid)
if not len(stats) or not stats.get('vip') or not stats.get('pool'):
if not len(stats) or not 'vip' in stats:
uve_lb = UveLoadbalancer(name=pool_uuid, deleted=True)
uve_lb.virtual_ip_stats = {}
uve_lb.pool_stats = {}
uve_lb.member_stats = []
uve_trace = UveLoadbalancerTrace(data=uve_lb)
uve_trace.send()
continue

uve_lb = UveLoadbalancer()
uve_lb.name = pool_uuid
uve_lb.pool_stats = {}
uve_lb.member_stats = []
uve_lb.virtual_ip_stats = self._uve_get_stats(stats['vip'])
uve_lb.pool_stats = self._uve_get_stats(stats['pool'])
uve_lb.member_stats = self._uve_get_member_stats(stats['members'])
if 'pool' in stats:
uve_lb.pool_stats = self._uve_get_stats(stats['pool'])
if 'members' in stats:
uve_lb.member_stats = self._uve_get_member_stats(stats['members'])
uve_trace = UveLoadbalancerTrace(data=uve_lb)
uve_trace.send()

Expand Down

0 comments on commit c8d6ffa

Please sign in to comment.