本文整理汇总了Python中cfgm_common.vnc_db.DBBase类的典型用法代码示例。如果您正苦于以下问题:Python DBBase类的具体用法?Python DBBase怎么用?Python DBBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBBase类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.vnc_lib = mock.Mock()
self.cassandra = mock.Mock()
self.logger = mock.Mock()
self.svc = mock.Mock()
self.svc.netns_manager = instance_manager.NetworkNamespaceManager(
self.vnc_lib, self.cassandra, self.logger, None, None, None)
self.snat_agent = snat_agent.SNATAgent(self.svc, self.vnc_lib,
self.cassandra, None)
DBBase.init(self, self.logger, self.cassandra)
# register the project
proj_fq_name = ['default-domain', 'demo']
config_db.ProjectSM.locate(
ROUTER_1['parent_uuid'],
{'fq_name': proj_fq_name})
project = Project(name=proj_fq_name[-1])
self.vnc_lib.project_read = mock.Mock(
return_value=project)
# register the public network
config_db.VirtualNetworkSM.locate(
ROUTER_1['virtual_network_refs'][0]['uuid'],
{'fq_name': ROUTER_1['virtual_network_refs'][0]['to']})
# register interfaces
config_db.VirtualMachineInterfaceSM.locate(
ROUTER_1['virtual_machine_interface_refs'][0]['uuid'],
{'fq_name': ROUTER_1['virtual_machine_interface_refs'][0]['to'],
'virtual_network_refs': [{'uuid': 'private1-uuid'}]})
示例2: setUp
def setUp(self):
self.vnc_lib = mock.Mock()
self.cassandra = mock.Mock()
self.logger = mock.Mock()
self.svc = mock.Mock()
mocked_gsc = mock.MagicMock()
mocked_gsc.uuid = 'fake-gsc-uuid'
self.vnc_lib.service_appliance_set_create.return_value = "opencontrail"
self.vnc_lib.global_system_config_read.return_value = mocked_gsc
def no_id_side_effect(fq_name):
raise NoIdError("xxx")
self.vnc_lib.service_appliance_set_read = mock.Mock(side_effect=no_id_side_effect)
conf_parser = argparse.ArgumentParser(add_help=False)
config = ConfigParser.SafeConfigParser({'admin_token': None})
self._args, remaining_argv = conf_parser.parse_known_args()
self._args.config_sections = config
def sas_read_side_effect(obj_type, uuids):
if obj_type == 'service_appliance_set':
return (True, [{
'fq_name': ['default-global-system-config', 'opencontrail'],
'service_appliance_driver': 'svc_monitor.services.loadbalancer.drivers.ha_proxy.driver.OpencontrailLoadbalancerDriver'
}])
return (False, None)
self.cassandra.read = mock.Mock(
side_effect=sas_read_side_effect)
DBBase.init(self.svc, None, self.cassandra)
self.lb_agent = loadbalancer_agent.LoadbalancerAgent(self.svc, self.vnc_lib,
self.cassandra, self._args)
self.svc.loadbalancer_agent = self.lb_agent
sas = config_db.ServiceApplianceSetSM.get('opencontrail')
self.assertEqual(sas.driver, "svc_monitor.services.loadbalancer.drivers.ha_proxy.driver.OpencontrailLoadbalancerDriver")
sas.add()
self.assertIsNotNone(self.lb_agent._loadbalancer_driver['opencontrail'])
示例3: setUp
def setUp(self):
self.vnc_lib = mock.Mock()
self.cassandra = mock.Mock()
self.logger = mock.Mock()
self.svc = mock.Mock()
self.svc.netns_manager = instance_manager.NetworkNamespaceManager(
self.vnc_lib, self.cassandra, self.logger, None, None, None
)
self.snat_agent = snat_agent.SNATAgent(self.svc, self.vnc_lib, self.cassandra, None)
DBBase.init(self, None, self.cassandra)
# register the project
proj_fq_name = ["default-domain", "demo"]
config_db.ProjectSM.locate(ROUTER_1["parent_uuid"], {"fq_name": proj_fq_name})
project = Project(name=proj_fq_name[-1])
self.vnc_lib.project_read = mock.Mock(return_value=project)
# register the public network
config_db.VirtualNetworkSM.locate(
ROUTER_1["virtual_network_refs"][0]["uuid"], {"fq_name": ROUTER_1["virtual_network_refs"][0]["to"]}
)
# register interfaces
config_db.VirtualMachineInterfaceSM.locate(
ROUTER_1["virtual_machine_interface_refs"][0]["uuid"],
{
"fq_name": ROUTER_1["virtual_machine_interface_refs"][0]["to"],
"virtual_network_refs": [{"uuid": "private1-uuid"}],
},
)
示例4: destroy_instance
def destroy_instance(cls):
inst = cls.get_instance()
if not inst:
return
inst._vnc_amqp.close()
for obj_cls in DBBaseDM.get_obj_type_map().values():
obj_cls.reset()
DBBase.clear()
cls._instance = None
示例5: destroy_instance
def destroy_instance(cls):
inst = cls.get_instance()
if not inst:
return
inst._vnc_amqp.close()
for obj_cls in DBBaseDM.get_obj_type_map().values():
obj_cls.reset()
DBBase.clear()
DMCassandraDB.clear_instance()
inst._object_db = None
cls._device_manager = None
示例6: destroy_instance
def destroy_instance(cls):
inst = cls.get_instance()
if not inst:
return
inst._vnc_amqp.close()
if PushConfigState.is_push_mode_ansible():
FabricManager.destroy_instance()
for obj_cls in DBBaseDM.get_obj_type_map().values():
obj_cls.reset()
DBBase.clear()
DMCassandraDB.clear_instance()
cls._instance = None
示例7: setUp
def setUp(self):
self.vnc_lib = mock.Mock()
self.cassandra = mock.Mock()
self.logger = mock.Mock()
self.svc = mock.Mock()
self.svc.netns_manager = instance_manager.NetworkNamespaceManager(
self.vnc_lib, self.cassandra, self.logger, None, None, None)
# Mock service module logger.
self.logger = mock.MagicMock()
self.module_logger = ServiceMonitorModuleLogger(self.logger)
self.snat_agent = snat_agent.SNATAgent(self.svc, self.vnc_lib,
self.cassandra, None,
logger = self.module_logger)
DBBase.init(self, self.logger, self.cassandra)
# register the project
config_db.ProjectSM.locate(PROJECT_UUID, {'fq_name': PROJECT_FQ_NAME})
project = Project(name=PROJECT_FQ_NAME[-1])
self.vnc_lib.project_read = mock.Mock(return_value=project)
for router in ROUTERS:
# register the public network
config_db.VirtualNetworkSM.locate(
router['virtual_network_refs'][0]['uuid'],
{'fq_name': router['virtual_network_refs'][0]['to'], 'parent_type': 'project'})
for vmi_ref in router['virtual_machine_interface_refs']:
# register interfaces
config_db.VirtualMachineInterfaceSM.locate(
vmi_ref['uuid'],
{
'fq_name': vmi_ref['to'],
'virtual_network_refs': [{'uuid': 'private1-uuid'}],
'parent_type': 'project',
},
)
示例8: _connect_rabbit
def _connect_rabbit(self):
rabbit_server = self._args.rabbit_server
rabbit_port = self._args.rabbit_port
rabbit_user = self._args.rabbit_user
rabbit_password = self._args.rabbit_password
rabbit_vhost = self._args.rabbit_vhost
self._db_resync_done = gevent.event.Event()
q_name = 'svc_mon.%s' % (socket.gethostname())
self._vnc_kombu = VncKombuClient(rabbit_server, rabbit_port,
rabbit_user, rabbit_password,
rabbit_vhost, q_name,
self._vnc_subscribe_callback,
self.config_log)
cass_server_list = self._args.cassandra_server_list
reset_config = self._args.reset_config
self._cassandra = VncCassandraClient(cass_server_list, reset_config,
self._args.cluster_id, None,
self.config_log)
DBBase.init(self, self.logger, self._cassandra)
示例9: setUp
def setUp(self):
self.vnc_lib = mock.Mock()
self.cassandra = mock.Mock()
self.logger = mock.Mock()
self.svc = mock.Mock()
self._db = {}
def read_db(id):
if id in self._db:
return self._db[id]
def put_db_config(id, data):
if id not in self._db:
self._db[id] = {}
self._db[id]['config_info'] = data
def put_db_driver(id, data):
if id not in self._db:
self._db[id] = {}
self._db[id]['driver_info'] = data
def remove_db(id, data=None):
if data is None:
del self._db[id]
return
if self._db[id]['driver_info'][data[0]]:
del self._db[id]['driver_info'][data[0]]
def list_pools():
ret_list = []
for each_entry_id, each_entry_data in self._db.iteritems() or []:
config_info_obj_dict = each_entry_data['config_info']
driver_info_obj_dict = None
if 'driver_info' in each_entry_data:
driver_info_obj_dict = each_entry_data['driver_info']
ret_list.append((each_entry_id, config_info_obj_dict, driver_info_obj_dict))
return ret_list
def list_loadbalancers():
res_list = []
return res_list
def list_health_monitors():
res_list = []
return res_list
self.cassandra.loadbalancer_list = mock.Mock(side_effect=list_loadbalancers)
self.cassandra.pool_list = mock.Mock(side_effect=list_pools)
self.cassandra.pool_remove = mock.Mock(side_effect=remove_db)
self.cassandra.pool_driver_info_get = mock.Mock(side_effect=read_db)
self.cassandra.pool_driver_info_insert = mock.Mock(side_effect=put_db_driver)
self.cassandra.pool_config_insert = mock.Mock(side_effect=put_db_config)
self.cassandra.health_monitor_list = mock.Mock(side_effect=list_health_monitors)
mocked_gsc = mock.MagicMock()
mocked_gsc.uuid = 'fake-gsc-uuid'
self.vnc_lib.service_appliance_set_create.return_value = "opencontrail"
self.vnc_lib.global_system_config_read.return_value = mocked_gsc
def no_id_side_effect(fq_name):
raise NoIdError("xxx")
self.vnc_lib.service_appliance_set_read = mock.Mock(side_effect=no_id_side_effect)
conf_parser = argparse.ArgumentParser(add_help=False)
config = ConfigParser.SafeConfigParser({'admin_token': None})
self._args, remaining_argv = conf_parser.parse_known_args()
self._args.config_sections = config
def sas_read_side_effect(obj_type, uuids, **kwargs):
if obj_type == 'service_appliance_set':
return (True, [{
'fq_name': ['default-global-system-config', 'opencontrail'],
'service_appliance_driver': 'svc_monitor.services.loadbalancer.drivers.ha_proxy.driver.OpencontrailLoadbalancerDriver'
}])
return (False, None)
self.cassandra.object_read = mock.Mock(
side_effect=sas_read_side_effect)
DBBase.init(self.svc, None, self.cassandra)
self.lb_agent = loadbalancer_agent.LoadbalancerAgent(self.svc, self.vnc_lib,
self.cassandra, self._args)
self.svc.loadbalancer_agent = self.lb_agent
sas = config_db.ServiceApplianceSetSM.get('opencontrail')
self.assertEqual(sas.driver, "svc_monitor.services.loadbalancer.drivers.ha_proxy.driver.OpencontrailLoadbalancerDriver")
sas.add()
self.assertIsNotNone(self.lb_agent._loadbalancer_driver['opencontrail'])
示例10: setUp
def setUp(self):
self.vnc_lib = mock.Mock()
self.object_db = mock.Mock()
self.logger = mock.Mock()
self.svc = mock.Mock()
DBBase.init(self.svc, None, self.object_db)
示例11: setUp
def setUp(self):
self.vnc_lib = mock.Mock()
self.cassandra = mock.Mock()
self.logger = mock.Mock()
self.svc = mock.Mock()
DBBase.init(self.svc, None, self.cassandra)
示例12: setUp
def setUp(self):
self.vnc_lib = mock.Mock()
self.cassandra = mock.Mock()
self.logger = mock.Mock()
self.svc = mock.Mock()
self._si_pool = {}
mocked_gsc = mock.MagicMock()
mocked_gsc.uuid = "fake-gsc-uuid"
self.vnc_lib.global_system_config_read.return_value = mocked_gsc
def no_id_side_effect(fq_name):
raise NoIdError("xxx")
# Return NoIdError while si is read for first time
self.vnc_lib.service_instance_read = mock.Mock(side_effect=no_id_side_effect)
self.vnc_lib.kv_retrieve.return_value = "fake-pool-vn 40.1.1.0/24"
self.vnc_lib.service_appliance_set_create.return_value = "opencontrail"
self.vnc_lib.service_appliance_set_read = mock.Mock(side_effect=no_id_side_effect)
self._store_si = {}
def read_si(obj_type, uuid):
return (True, [self.obj_to_dict(self._store_si[uuid[0]])])
def store_si_create(obj):
config_db.ServiceInstanceSM._cassandra.object_read = mock.Mock(side_effect=read_si)
obj.uuid = "pool-si"
self._store_si[obj.uuid] = obj
def update_si_side_effect(obj):
self._store_si[obj.uuid] = obj
self.vnc_lib.service_instance_create = mock.Mock(side_effect=store_si_create)
self.vnc_lib.service_instance_update = mock.Mock(side_effect=update_si_side_effect)
self._db = {}
def read_db(id):
if id in self._db:
return self._db[id]
def put_db(id, data):
self._db[id] = data
def remove_db(id, data=None):
if data is None:
del self._db[id]
return
if self._db[id][data[0]]:
del self._db[id][data[0]]
self.cassandra.pool_driver_info_get = mock.Mock(side_effect=read_db)
self.cassandra.pool_driver_info_insert = mock.Mock(side_effect=put_db)
self.cassandra.pool_remove = mock.Mock(side_effect=remove_db)
def validate_pool_update(obj_type, obj_uuid, ref_type, ref_uuid, ref_fq_name, operation):
self.assertEqual(obj_type, "loadbalancer-pool")
self.assertEqual(ref_type, "service_instance_refs")
pool = config_db.LoadbalancerPoolSM.get(obj_uuid)
if operation is "ADD":
si = config_db.ServiceInstanceSM.get(ref_uuid)
self.assertIsNotNone(si)
pool.service_instance = si.uuid
si.loadbalancer_pool = pool.uuid
self._si_pool[pool.uuid] = si.uuid
self.assertEqual(si.uuid, "pool-si")
elif operation is "DELETE":
pool.service_instance = None
del self._si_pool[pool.uuid]
else:
self.assertTrue(False)
return
self.vnc_lib.ref_update = mock.Mock(side_effect=validate_pool_update)
conf_parser = argparse.ArgumentParser(add_help=False)
config = ConfigParser.SafeConfigParser({"admin_token": None})
self._args, remaining_argv = conf_parser.parse_known_args()
self._args.config_sections = config
def sas_read_side_effect(obj_type, uuids):
if obj_type == "service_appliance_set":
return (
True,
[
{
"fq_name": ["default-global-system-config", "opencontrail"],
"service_appliance_driver": "svc_monitor.services.loadbalancer\
.drivers.ha_proxy.driver.OpencontrailLoadbalancerDriver",
}
],
)
return (False, None)
DBBase.init(self.svc, None, self.cassandra)
config_db.ServiceApplianceSetSM._cassandra.object_read = mock.Mock(side_effect=sas_read_side_effect)
self.lb_agent = loadbalancer_agent.LoadbalancerAgent(self.svc, self.vnc_lib, self.cassandra, self._args)
#.........这里部分代码省略.........
示例13: setUp
def setUp(self):
self.vnc_lib = mock.Mock()
self.object_db = mock.Mock()
self.logger = mock.Mock()
self.svc = mock.Mock()
mocked_gsc = mock.MagicMock()
mocked_gsc.uuid = 'fake-gsc-uuid'
self.vnc_lib.global_system_config_read.return_value = mocked_gsc
def mock_kv_retrieve(subnet_id):
if subnet_id == "pool_subnet_id":
return "fake-pool-vn 40.1.1.0/24"
elif subnet_id == "vip_subnet_id":
return "fake-vip-vn 1.1.1.0/24"
self.assertTrue(False)
#end
self.vnc_lib.kv_retrieve = mock.Mock(side_effect=mock_kv_retrieve)
self.vnc_lib.service_appliance_set_create.return_value = "opencontrail"
self._mock_bigip_interfaces = None
self._mock_BigIp = None
self._db = {}
def read_db(id):
if id in self._db:
return self._db[id].get('driver_info', None)
def put_db(id, data):
from copy import deepcopy
self._db[id] = {'driver_info': deepcopy(data)}
def remove_db(id, data=None):
if data is None:
del self._db[id]
return
if self._db[id][data[0]]:
del self._db[id][data[0]]
self.object_db.pool_driver_info_get = mock.Mock(side_effect=read_db)
self.object_db.pool_driver_info_insert = mock.Mock(side_effect=put_db)
self.object_db.pool_remove = mock.Mock(side_effect=remove_db)
conf_parser = argparse.ArgumentParser(add_help=False)
config = ConfigParser.SafeConfigParser({'admin_token': None})
self._args, remaining_argv = conf_parser.parse_known_args()
self._args.config_sections = config
def sas_read_side_effect(obj_type, uuids, **kwargs):
if obj_type == 'service_appliance_set':
return (True, [{
'fq_name': ['default-global-system-config', 'opencontrail'],
'service_appliance_driver': 'svc_monitor.services.loadbalancer\
.drivers.ha_proxy.driver.OpencontrailLoadbalancerDriver'
}])
return (False, None)
DBBase.init(self.svc, None, self.object_db)
config_db.ServiceApplianceSetSM._object_db.object_read = \
mock.Mock(side_effect=sas_read_side_effect)
# return NoIdError exception for first query
def no_id_side_effect(fq_name):
raise NoIdError("xxx")
self.vnc_lib.service_appliance_set_read = \
mock.Mock(side_effect=no_id_side_effect)
self.lb_agent = loadbalancer_agent.LoadbalancerAgent(self.svc,
self.vnc_lib, self.object_db, self._args)
self.svc.loadbalancer_agent = self.lb_agent
sas = config_db.ServiceApplianceSetSM.get('opencontrail')
self.assertEqual(sas.driver,
"svc_monitor.services.loadbalancer.drivers.ha_proxy.driver.\
OpencontrailLoadbalancerDriver")
sas.add()
DBBase.init(self.svc, None, self.object_db)
config_db.ServiceApplianceSetSM._object_db.object_read = \
mock.Mock(side_effect=sas_read_side_effect)
import sys
sys.modules['f5'] = mock.Mock()
sys.modules['f5.bigip'] = mock.Mock()
self.create_f5_service_appliance_set()
示例14: __init__
def __init__(self, args=None):
self._args = args
# Initialize discovery client
self._disc = None
if self._args.disc_server_ip and self._args.disc_server_port:
self._disc = client.DiscoveryClient(
self._args.disc_server_ip,
self._args.disc_server_port,
ModuleNames[Module.DEVICE_MANAGER])
self._sandesh = Sandesh()
module = Module.DEVICE_MANAGER
module_name = ModuleNames[module]
node_type = Module2NodeType[module]
node_type_name = NodeTypeNames[node_type]
instance_id = INSTANCE_ID_DEFAULT
hostname = socket.gethostname()
self._sandesh.init_generator(
module_name, hostname, node_type_name, instance_id,
self._args.collectors, 'to_bgp_context',
int(args.http_server_port),
['cfgm_common', 'device_manager.sandesh'], self._disc)
self._sandesh.set_logging_params(enable_local_log=args.log_local,
category=args.log_category,
level=args.log_level,
file=args.log_file,
enable_syslog=args.use_syslog,
syslog_facility=args.syslog_facility)
ConnectionState.init(
self._sandesh, hostname, module_name, instance_id,
staticmethod(ConnectionState.get_process_state_cb),
NodeStatusUVE, NodeStatus)
# Retry till API server is up
connected = False
self.connection_state_update(ConnectionStatus.INIT)
while not connected:
try:
self._vnc_lib = VncApi(
args.admin_user, args.admin_password,
args.admin_tenant_name, args.api_server_ip,
args.api_server_port)
connected = True
self.connection_state_update(ConnectionStatus.UP)
except requests.exceptions.ConnectionError as e:
# Update connection info
self.connection_state_update(ConnectionStatus.DOWN, str(e))
time.sleep(3)
except ResourceExhaustionError: # haproxy throws 503
time.sleep(3)
rabbit_servers = self._args.rabbit_server
rabbit_port = self._args.rabbit_port
rabbit_user = self._args.rabbit_user
rabbit_password = self._args.rabbit_password
rabbit_vhost = self._args.rabbit_vhost
rabbit_ha_mode = self._args.rabbit_ha_mode
self._db_resync_done = gevent.event.Event()
q_name = 'device_manager.%s' % (socket.gethostname())
self._vnc_kombu = VncKombuClient(rabbit_servers, rabbit_port,
rabbit_user, rabbit_password,
rabbit_vhost, rabbit_ha_mode,
q_name, self._vnc_subscribe_callback,
self.config_log)
cass_server_list = self._args.cassandra_server_list
reset_config = self._args.reset_config
self._cassandra = VncCassandraClient(cass_server_list, reset_config,
self._args.cluster_id, None,
self.config_log)
DBBase.init(self, self._sandesh.logger(), self._cassandra)
ok, global_system_config_list = self._cassandra._cassandra_global_system_config_list()
if not ok:
self.config_log('global system config list returned error: %s' %
global_system_config_list)
else:
for fq_name, uuid in global_system_config_list:
GlobalSystemConfigDM.locate(uuid)
ok, vn_list = self._cassandra._cassandra_virtual_network_list()
if not ok:
self.config_log('virtual network list returned error: %s' %
vn_list)
else:
for fq_name, uuid in vn_list:
vn = VirtualNetworkDM.locate(uuid)
if vn is not None and vn.routing_instances is not None:
for ri_id in vn.routing_instances:
ri_obj = RoutingInstanceDM.locate(ri_id)
ok, bgp_list = self._cassandra._cassandra_bgp_router_list()
if not ok:
self.config_log('bgp router list returned error: %s' %
bgp_list)
else:
for fq_name, uuid in bgp_list:
#.........这里部分代码省略.........