Skip to content

Commit

Permalink
vrouter-nodemgr change for LBAAS config generation on controller
Browse files Browse the repository at this point in the history
1. loadbalancer directory is set based on the loadbalancer type
2. If vip is present, the loadbalancer stats will be sent to analystics
3. while removing the sandesh objects from uve-cache, each field
   is set to empty value

Change-Id: Id0fe012c9f343982311f9388880a7bc4b3d0d83f
Partial-Bug: #1557222
  • Loading branch information
ymariappan committed May 18, 2016
1 parent bbf6c2b commit be5c941
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 be5c941

Please sign in to comment.