Skip to content

Commit

Permalink
Merge "Contrail-API should write config information into UVEs when pu…
Browse files Browse the repository at this point in the history
…blishing to ifmap"
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 12, 2015
2 parents 1fdec16 + b0d4711 commit d67c61a
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/analytics/OpServerProxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ OpServerProxy::DeleteUVEs(const string &source, const string &module,
string genstr = ss.str();

std::stringstream collss;
collss << impl_->redis_uve_.GetIp() << ":" <<
collss << Collector::GetSelfIp() << ":" <<
impl_->redis_uve_.GetPort();
string collstr = collss.str();

Expand Down
1 change: 1 addition & 0 deletions src/config/api-server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ netifaces
bottle
stevedore
kazoo
xmltodict
83 changes: 81 additions & 2 deletions src/config/api-server/vnc_cfg_ifmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pprint import pformat

from lxml import etree, objectify
import xmltodict
import cgitb
import StringIO
import re
Expand All @@ -27,6 +28,7 @@
from netaddr import IPNetwork
from bitarray import bitarray

from cfgm_common.uve.vnc_api.ttypes import *
from cfgm_common import ignore_exceptions, utils
from cfgm_common.ifmap.client import client, namespaces
from cfgm_common.ifmap.request import NewSessionRequest, RenewSessionRequest,\
Expand Down Expand Up @@ -118,7 +120,7 @@ def __init__(self, db_client_mgr, ifmap_srv_ip, ifmap_srv_port,
self._IPAMS_NAME = "contrail:ipams"
self._SG_RULE_NAME = "contrail:sg_rules"
self._POLICY_ENTRY_NAME = "contrail:policy_entry"

self._NAMESPACES = {
'env': "http://www.w3.org/2003/05/soap-envelope",
'ifmap': "http://www.trustedcomputinggroup.org/2010/IFMAP/2",
Expand All @@ -127,6 +129,28 @@ def __init__(self, db_client_mgr, ifmap_srv_ip, ifmap_srv_port,
'contrail': self._CONTRAIL_XSD
}

self._UVEMAP = {
"virtual-network" : "ObjectVNTable",
"virtual-machine" : "ObjectVMTable",
"service-instance" : "ObjectSITable",
"virtual-router" : "ObjectVRouter",
"control-node" : "ObjectBgpRouter",
"analytics-node" : "ObjectCollectorInfo",
"database-node" : "ObjectDatabaseInfo",
"config-node" : "ObjectConfigNode",
"service-chain" : "ServiceChain",
"physical-router" : "ObjectPRouter",
}

self._UVEGLOBAL = {
"virtual-router",
"control-node",
"analytics-node",
"database-node",
"config-node",
"physical-router"
}

self._db_client_mgr = db_client_mgr
self._sandesh = db_client_mgr._sandesh

Expand Down Expand Up @@ -290,6 +314,58 @@ def _generate_ifmap_trace(self, oper, body):
return ifmap_trace
# end _generate_ifmap_trace

@ignore_exceptions
def _generate_ifmap_uve(self, oper, body):
msgs = []
msgstr = "<__M__>" + body + "</__M__>"
msg = xmltodict.parse(msgstr)["__M__"]
for opr,entries in msg.iteritems():
if not isinstance(entries,list):
entries=[entries]
for entry in entries:
if not isinstance(entry["identity"],basestring) and\
isinstance(entry["identity"],list):
cfg_key = entry["identity"][0]['@name']
attr_name = entry["identity"][1]['@name']
attr_contents = None
if opr == "update":
attr_contents = json.dumps(entry["metadata"].keys()[0])
else:
cfg_key = entry["identity"]['@name']
attr_contents = None
attr_name = None
if opr == "update":
attr_name = entry["metadata"].keys()[0]
attr_contents = json.dumps(entry["metadata"].values()[0])

utype = cfg_key.split(":",2)[1]
urawkey = cfg_key.split(":",2)[2]
ukey = None
utab = None
if self._UVEMAP.has_key(utype):
utab = self._UVEMAP[utype]
if utype in self._UVEGLOBAL:
ukey = urawkey.split(":",1)[1]
else:
ukey = urawkey
else:
continue
cce = None
if attr_contents:
cce = ContrailConfigElem(attr_name,attr_contents)
cc = None
if cce:
cc = ContrailConfig(name = ukey, properties = [cce])
else:
cc = ContrailConfig(name = ukey, properties = [],\
deleted = True)
cfg_msg = ContrailConfigTrace(data=cc, table=utab,
sandesh=self._sandesh)
msgs.append(cfg_msg)

return msgs

# end _generate_ifmap_trace
def publish_accumulated(self):
if self.accumulated_request_len:
upd_str = ''.join(''.join(request) \
Expand All @@ -305,7 +381,7 @@ def _publish_to_ifmap(self, oper, oper_body, async, do_trace=True):
# asking for update|delete in publish
if not oper_body:
return

ifmap_uves = self._generate_ifmap_uve(oper, oper_body)
if do_trace:
trace = self._generate_ifmap_trace(oper, oper_body)

Expand Down Expand Up @@ -357,6 +433,9 @@ def _publish_to_ifmap(self, oper, oper_body, async, do_trace=True):
if do_trace:
trace_msg(trace, 'IfmapTraceBuf', self._sandesh)

for cfg_msg in ifmap_uves:
cfg_msg.send(sandesh=self._sandesh)

return resp_xml
except Exception as e:
if (isinstance(e, socket.error) and
Expand Down
2 changes: 1 addition & 1 deletion src/config/test/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pip_pkgs = ['greenlet==0.4.1', 'gevent==0.13.8', 'eventlet==0.9.17', 'coverage',
'kazoo==1.3.1','stevedore==0.12','netifaces==0.8', 'python_keystoneclient==0.6.0',
'psutil==0.4.1', 'redis==2.7.1', 'xmltodict==0.2', 'thrift==0.8.0',
'librabbitmq==1.0.3', 'amqp==1.4.1', 'anyjson==0.3.3', 'kombu==3.0.9',
'python-novaclient==2.13.0', 'flexmock==0.9.7', "bottle",
'python-novaclient==2.13.0', 'flexmock==0.9.7', "bottle", "xmltodict",
Dir(env['TOP']).abspath + '/config/api-server/dist/vnc_cfg_api_server-0.1dev.tar.gz',
Dir(env['TOP']).abspath + '/config/common/dist/cfgm_common-0.1dev.tar.gz',
Dir(env['TOP']).abspath + '/config/schema-transformer/dist/schema_transformer-0.1dev.tar.gz',
Expand Down
15 changes: 15 additions & 0 deletions src/config/uve/vnc_api.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ objectlog sandesh VncApiConfigLog {
systemlog sandesh VncApiError {
1: string api_error_msg;
}

struct ContrailConfigElem {
1: string attribute
2: string value // This holds the JSON-encoded value of the attribute
}

struct ContrailConfig {
1: string name (key="none")
2: list<ContrailConfigElem> properties
3: bool deleted
}

uve sandesh ContrailConfigTrace {
1: ContrailConfig data
}
8 changes: 3 additions & 5 deletions src/opserver/alarmgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ def handle_uve_notif(self, uves, remove = False):
self._logger.info("UVE %s deleted" % uv)
if self.tab_alarms[tab].has_key(uv):
del self.tab_alarms[tab][uv]
uname = uv.split(":",1)[1]
ustruct = UVEAlarms(name = uname, deleted = True)
ustruct = UVEAlarms(name = uve_name, deleted = True)
alarm_msg = AlarmTrace(data=ustruct, table=tab)
self._logger.info('send del alarm: %s' % (alarm_msg.log()))
alarm_msg.send()
Expand Down Expand Up @@ -285,14 +284,13 @@ def handle_uve_notif(self, uves, remove = False):
for dnm in del_types:
del self.tab_alarms[tab][uv][dnm]

uname = uv.split(":")[1]
ustruct = None
if len(self.tab_alarms[tab][uv]) == 0:
ustruct = UVEAlarms(name = uname,
ustruct = UVEAlarms(name = uve_name,
deleted = True)
del self.tab_alarms[tab][uv]
else:
ustruct = UVEAlarms(name = uname,
ustruct = UVEAlarms(name = uve_name,
alarms = self.tab_alarms[tab][uv].values(),
deleted = False)
alarm_msg = AlarmTrace(data=ustruct, table=tab)
Expand Down
4 changes: 3 additions & 1 deletion src/opserver/partition_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import json
import copy
import traceback

class PartitionHandler(gevent.Greenlet):
def __init__(self, brokers, partition, group, topic, logger, limit):
Expand Down Expand Up @@ -93,7 +94,8 @@ def _run(self):
except Exception as ex:
template = "An exception of type {0} occured. Arguments:\n{1!r}"
messag = template.format(type(ex).__name__, ex.args)
self._logger.info("%s" % messag)
self._logger.info("%s : traceback %s" % \
(messag, traceback.format_exc()))
self.stop_partition()
gevent.sleep(2)
self._logger.info("Stopping %d pcount %d" % (self._partition, pcount))
Expand Down

0 comments on commit d67c61a

Please sign in to comment.