本文整理汇总了Python中cfgm_common.vnc_cassandra.VncCassandraClient.add方法的典型用法代码示例。如果您正苦于以下问题:Python VncCassandraClient.add方法的具体用法?Python VncCassandraClient.add怎么用?Python VncCassandraClient.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cfgm_common.vnc_cassandra.VncCassandraClient
的用法示例。
在下文中一共展示了VncCassandraClient.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _issu_basic_function
# 需要导入模块: from cfgm_common.vnc_cassandra import VncCassandraClient [as 别名]
# 或者: from cfgm_common.vnc_cassandra.VncCassandraClient import add [as 别名]
class ICCassandraClient:
def _issu_basic_function(self, kspace, cfam, cols):
return dict(cols)
# end
def __init__(self, oldversion_server_list, newversion_server_list, odb_prefix, ndb_prefix, issu_info, logger):
self._oldversion_server_list = oldversion_server_list
self._newversion_server_list = newversion_server_list
self._odb_prefix = odb_prefix
self._ndb_prefix = ndb_prefix
self._issu_info = issu_info
self._logger = logger
self._ks_issu_func_info = {}
self._nkeyspaces = {}
self._okeyspaces = {}
self._logger("Issu contrail cassandra initialized...", level=SandeshLevel.SYS_INFO)
self.issu_prepare()
# end
def issu_prepare(self):
self._logger("Issu contrail cassandra prepare...", level=SandeshLevel.SYS_INFO)
for issu_func, ks, cflist in self._issu_info:
if issu_func is None:
issu_func = self._issu_basic_function
ks_issu_func_info = {ks: issu_func}
nks = {ks: cflist}
oks = {ks: cflist}
self._nkeyspaces.update(nks)
self._okeyspaces.update(oks)
self._ks_issu_func_info.update(ks_issu_func_info)
self._oldversion_handle = VncCassandraClient(
self._oldversion_server_list, self._odb_prefix, None, self._okeyspaces, self._logger
)
self._newversion_handle = VncCassandraClient(
self._newversion_server_list, self._ndb_prefix, self._nkeyspaces, None, self._logger
)
# end
def _fetch_issu_func(self, ks):
return self._ks_issu_func_info[ks]
# end
# Overwrite what is seen in the newer with the old version.
def _merge_overwrite(self, new, current):
updated = current
updated.update(new)
return updated
# end
# For now this function should be called for only config_db_uuid.
# If we separate out config_db_uuid keyspace from VncCassandraClient,
# then we don't need to pass keyspaces here.
def issu_merge_copy(self, keyspaces):
for ks, cflist in keyspaces.items():
self._logger("Issu contrail cassandra merge copy, keyspace: " + str(ks), level=SandeshLevel.SYS_INFO)
issu_funct = self._fetch_issu_func(ks)
for cf in cflist:
newList = []
newversion_result = self._newversion_handle.get_range(cf)
self._logger("Building New DB memory for columnfamily: " + str(cf), level=SandeshLevel.SYS_INFO)
new_db = dict(newversion_result)
oldversion_result = self._oldversion_handle.get_range(cf)
self._logger("Doing ISSU copy for columnfamily: " + str(cf), level=SandeshLevel.SYS_INFO)
for rows, columns in oldversion_result:
out = issu_funct(ks, cf, columns)
current = new_db.pop(rows, None)
if current is not None:
updated = self._merge_overwrite(out, dict(current))
x = self._newversion_handle.add(cf, rows, updated)
else:
updated = []
x = self._newversion_handle.add(cf, rows, out)
diff = set(updated) - set(out)
y = self._newversion_handle.get_cf(cf).remove(rows, diff)
self._logger(
"Pruning New DB if entires don't exist in old DB column " "family: " + str(cf),
level=SandeshLevel.SYS_INFO,
)
for item in new_db:
# TBD should be catch exception and fail ISSU
self._newversion_handle.delete(cf, item)
# end
# This is issu_copy function.
def issu_copy(self, keyspaces):
for ks, cflist in keyspaces.items():
issu_funct = self._fetch_issu_func(ks)
for cf in cflist:
self._logger(
#.........这里部分代码省略.........
示例2: DatabaseExim
# 需要导入模块: from cfgm_common.vnc_cassandra import VncCassandraClient [as 别名]
# 或者: from cfgm_common.vnc_cassandra.VncCassandraClient import add [as 别名]
class DatabaseExim(object):
def __init__(self, args_str):
self._parse_args(args_str)
self._cassandra = VncCassandraClient(
self._api_args.cassandra_server_list, False,
self._api_args.cluster_id, None, logger=self.log)
self._zookeeper = kazoo.client.KazooClient(
self._api_args.zk_server_ip)
self._zookeeper.start()
# end __init__
def log(self, msg, level):
pass
# end log
def _parse_args(self, args_str):
parser = argparse.ArgumentParser()
help="Path to contrail-api conf file, default /etc/contrail-api.conf"
parser.add_argument(
"--api-conf", help=help, default="/etc/contrail/contrail-api.conf")
parser.add_argument(
"--verbose", help="Run in verbose/INFO mode, default False",
action='store_true', default=False)
parser.add_argument(
"--debug", help="Run in debug mode, default False",
action='store_true', default=False)
parser.add_argument(
"--import-from", help="Import from this json file to database",
metavar='FILE', default='db.json')
parser.add_argument(
"--export-to", help="Export from database to this json file",
metavar='FILE')
args_obj, remaining_argv = parser.parse_known_args(args_str.split())
self._args = args_obj
self._api_args = utils.parse_args('-c %s %s'
%(self._args.api_conf, ' '.join(remaining_argv)))[0]
pass
# end _parse_args
def db_import(self):
if self._args.import_from.endswith('.gz'):
try:
f = gzip.open(self._args.import_from, 'rb')
self.import_data = json.loads(f.read())
finally:
f.close()
else:
with open(self._args.import_from, 'r') as f:
self.import_data = json.loads(f.read())
# refuse import if db already has data
if len(list(self._cassandra.get_cf('obj_uuid_table').get_range(column_count=0))) > 0:
raise CassandraNotEmptyError('obj_uuid_table has entries')
if len(list(self._cassandra.get_cf('obj_fq_name_table').get_range(column_count=0))) > 0:
raise CassandraNotEmptyError('obj_fq_name_table has entries')
zk_nodes = self._zookeeper.get_children('/')
zk_nodes.remove('zookeeper')
if len(zk_nodes) > 0:
raise ZookeeperNotEmptyError('Zookeeper has entries')
# seed cassandra
for cf_name in ['obj_fq_name_table', 'obj_uuid_table']:
for row, column in self.import_data['cassandra'][cf_name].items():
self._cassandra.add(cf_name, row, column)
# seed zookeeper
for path_value_ts in json.loads(self.import_data['zookeeper']):
path = path_value_ts[0]
if path.endswith('/'):
path = path[:-1]
if path.startswith('/zookeeper'):
continue
value = path_value_ts[1][0]
self._zookeeper.create(path, str(value), makepath=True)
# end db_import
def db_export(self):
pass