本文整理汇总了Python中pysandesh.sandesh_base.Sandesh类的典型用法代码示例。如果您正苦于以下问题:Python Sandesh类的具体用法?Python Sandesh怎么用?Python Sandesh使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sandesh类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: sandesh_init
def sandesh_init(self):
""" Init Sandesh """
self._sandesh = Sandesh()
# Register custom sandesh request handlers.
self._redefine_sandesh_handles()
# Initialize Sandesh generator.
self._sandesh.init_generator(
self._module["name"], self._module["hostname"],
self._module["node_type_name"], self._module["instance_id"],
self._args.random_collectors, 'kube_manager_context',
int(self._args.http_server_port),
['cfgm_common', 'kube_manager'],
logger_class=self._args.logger_class,
logger_config_file=self._args.logging_conf,
config=self._args.sandesh_config)
# Set Sandesh logging params.
self._sandesh.set_logging_params(
enable_local_log=self._args.log_local,
category=self._args.log_category, level=self._args.log_level,
file=self._args.log_file, enable_syslog=self._args.use_syslog,
syslog_facility=self._args.syslog_facility)
# Connect to collector.
ConnectionState.init(
self._sandesh, self._module["hostname"], self._module["name"],
self._module["instance_id"],
staticmethod(ConnectionState.get_process_state_cb),
NodeStatusUVE, NodeStatus, self._module["table"])
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:31,代码来源:logger.py
示例2: sandesh_init
def sandesh_init(self, http_server_port=None):
""" Init sandesh """
self._sandesh = Sandesh()
self.redefine_sandesh_handles()
if not http_server_port:
http_server_port = self._args.http_server_port
self._sandesh.init_generator(
self._module_name, self._hostname, self._node_type_name,
self._instance_id, self._args.random_collectors,
'%s_context' % self.context, int(http_server_port),
['cfgm_common', '%s.sandesh' % self.module_pkg],
logger_class=self._args.logger_class,
logger_config_file=self._args.logging_conf,
config=self._args.sandesh_config)
self._sandesh.set_logging_params(
enable_local_log=self._args.log_local,
category=self._args.log_category,
level=self._args.log_level,
file=self._args.log_file,
enable_syslog=self._args.use_syslog,
syslog_facility=self._args.syslog_facility)
# connection state init
ConnectionState.init(
self._sandesh, self._hostname, self._module_name,
self._instance_id,
staticmethod(ConnectionState.get_conn_state_cb),
NodeStatusUVE, NodeStatus, self.table)
VncGreenlet.register_sandesh_handler()
开发者ID:Juniper,项目名称:contrail-controller,代码行数:30,代码来源:vnc_logger.py
示例3: sandesh_init
def sandesh_init(self, http_server_port=None):
""" Init sandesh """
if self._sandesh is not None:
return
self._sandesh = Sandesh()
self.redefine_sandesh_handles()
if not http_server_port:
http_server_port = self._args.http_server_port
self._instance_id = self.sandesh_instance_id
self._sandesh.init_generator(
self._module_name, self._hostname, self._node_type_name,
self.sandesh_instance_id, self._args.random_collectors,
'%s_context' % self.context, int(http_server_port),
['cfgm_common'],
logger_class=self._args.logger_class,
logger_config_file=self._args.logging_conf,
config=self._args.sandesh_config)
self._sandesh.set_logging_params(
enable_local_log=self._args.log_local,
category=self._args.log_category,
level=self._args.log_level,
file=self._args.log_file,
enable_syslog=self._args.use_syslog,
syslog_facility=self._args.syslog_facility)
VncGreenlet.register_sandesh_handler()
self._sandesh.trace_buffer_create(name="MessageBusNotifyTraceBuf",
size=1000)
开发者ID:Juniper,项目名称:contrail-controller,代码行数:33,代码来源:logger.py
示例4: sandesh_init
def sandesh_init(self):
""" Init Sandesh """
self._sandesh = Sandesh()
# Initialize Sandesh generator.
self._sandesh.init_generator(
self.module['name'], self.module['hostname'],
self.module['node_type_name'], self.module['instance_id'],
self._args.collectors, 'mesos_manager_context',
int(self._args.http_server_port),
['cfgm_common', 'mesos_manager.sandesh'],
logger_class=self._args.logger_class,
logger_config_file=self._args.logging_conf,
config=self._args.sandesh_config)
# Set Sandesh logging params.
self._sandesh.set_logging_params(
enable_local_log=self._args.log_local,
category=self._args.log_category,
level=self._args.log_level, file=self._args.log_file,
enable_syslog=self._args.use_syslog,
syslog_facility=self._args.syslog_facility)
# Connect to collector.
ConnectionState.init(self._sandesh, self.module['hostname'],
self.module['name'], self.module['instance_id'],
staticmethod(ConnectionState.get_process_state_cb),
NodeStatusUVE, NodeStatus, self.module['table'])
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:28,代码来源:logger.py
示例5: setUp
def setUp(self):
self.maxDiff = None
self._sandesh = Sandesh()
http_port = test_utils.get_free_port()
self._sandesh.init_generator(
"conn_info_test", socket.gethostname(), "Test", "Test", None, "conn_info_test_ctxt", http_port
)
开发者ID:rombie,项目名称:contrail-sandesh,代码行数:7,代码来源:conn_info_test.py
示例6: __init__
def __init__(self, vnc_lib, args=None):
self._args = args
# api server and cassandra init
self._vnc_lib = vnc_lib
self._cassandra_init()
# dictionary for nova
self._nova = {}
# 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, client_type="Service Monitor"
)
# sandesh init
self._sandesh = Sandesh()
sandesh.ServiceInstanceList.handle_request = self.sandesh_si_handle_request
module = Module.SVC_MONITOR
module_name = ModuleNames[module]
node_type = Module2NodeType[module]
node_type_name = NodeTypeNames[node_type]
instance_id = INSTANCE_ID_DEFAULT
self._sandesh.init_generator(
module_name,
socket.gethostname(),
node_type_name,
instance_id,
self._args.collectors,
"svc_monitor_context",
int(self._args.http_server_port),
["cfgm_common", "sandesh"],
self._disc,
)
self._sandesh.set_logging_params(
enable_local_log=self._args.log_local,
category=self._args.log_category,
level=self._args.log_level,
file=self._args.log_file,
)
# create default analyzer template
self._create_default_template("analyzer-template", "analyzer", "analyzer")
self._create_default_template("nat-template", "nat-service", "firewall", "in-network-nat")
# create cpu_info object to send periodic updates
sysinfo_req = False
cpu_info = vnc_cpu_info.CpuInfo(module_name, instance_id, sysinfo_req, self._sandesh, 60)
self._cpu_info = cpu_info
# logging
self._err_file = "/var/log/contrail/svc-monitor.err"
self._tmp_file = "/var/log/contrail/svc-monitor.tmp"
self._svc_err_logger = logging.getLogger("SvcErrLogger")
self._svc_err_logger.setLevel(logging.ERROR)
handler = logging.handlers.RotatingFileHandler(self._err_file, maxBytes=64 * 1024, backupCount=2)
self._svc_err_logger.addHandler(handler)
开发者ID:ndramesh,项目名称:contrail-controller,代码行数:59,代码来源:svc_monitor.py
示例7: _sandesh_init
def _sandesh_init(self, discovery):
sandesh_instance = Sandesh()
sandesh.ServiceInstanceList.handle_request =\
self.sandesh_si_handle_request
sandesh_instance.init_generator(
self._module_name, self._hostname, self._node_type_name,
self._instance_id, self._args.collectors, 'svc_monitor_context',
int(self._args.http_server_port), ['cfgm_common', 'svc_monitor.sandesh'],
discovery)
sandesh_instance.set_logging_params(
enable_local_log=self._args.log_local,
category=self._args.log_category,
level=self._args.log_level,
file=self._args.log_file,
enable_syslog=self._args.use_syslog,
syslog_facility=self._args.syslog_facility)
return sandesh_instance
开发者ID:Juniper,项目名称:contrail-dev-controller,代码行数:17,代码来源:logger.py
示例8: __init__
def __init__(self, vnc_lib, args=None):
self._args = args
# api server and cassandra init
self._vnc_lib = vnc_lib
self._cassandra_init()
# dictionary for nova
self._nova = {}
#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,
client_type='Service Monitor')
#sandesh init
collectors = None
if self._args.collector and self._args.collector_port:
collectors = [(self._args.collector,
int(self._args.collector_port))]
self._sandesh = Sandesh()
sandesh.ServiceInstanceList.handle_request =\
self.sandesh_si_handle_request
self._sandesh.init_generator(
ModuleNames[Module.SVC_MONITOR], socket.gethostname(),
collectors, 'svc_monitor_context',
int(self._args.http_server_port), ['cfgm_common', 'sandesh'],
self._disc)
self._sandesh.set_logging_params(enable_local_log=self._args.log_local,
category=self._args.log_category,
level=self._args.log_level,
file=self._args.log_file)
#create default analyzer template
self._create_default_template('analyzer-template', 'analyzer',
'analyzer')
self._create_default_template('nat-template', 'nat-service',
'firewall', 'in-network-nat')
#create cpu_info object to send periodic updates
sysinfo_req = False
cpu_info = vnc_cpu_info.CpuInfo(
Module.SVC_MONITOR, sysinfo_req, self._sandesh, 60)
self._cpu_info = cpu_info
# logging
self._err_file = '/var/log/contrail/svc-monitor.err'
self._tmp_file = '/var/log/contrail/svc-monitor.tmp'
self._svc_err_logger = logging.getLogger('SvcErrLogger')
self._svc_err_logger.setLevel(logging.ERROR)
handler = logging.handlers.RotatingFileHandler(
self._err_file, maxBytes=64*1024, backupCount=2)
self._svc_err_logger.addHandler(handler)
开发者ID:mdoi,项目名称:contrail-controller,代码行数:55,代码来源:svc_monitor.py
示例9: KubeManagerLogger
class KubeManagerLogger(object):
def __init__(self, args=None):
self._args = args
# Initialize module parameters.
self._module = {}
self._module["id"] = Module.KUBE_MANAGER
self._module["name"] = ModuleNames[self._module["id"]]
self._module["node_type"] = Module2NodeType[self._module["id"]]
self._module["node_type_name"] =\
NodeTypeNames[self._module["node_type"]]
self._module["hostname"] = socket.gethostname()
self._module["table"] = "ObjectKubernetesManagerNode"
if self._args.worker_id:
self._module["instance_id"] = self._args.worker_id
else:
self._module["instance_id"] = INSTANCE_ID_DEFAULT
# Init Sandesh.
self.sandesh_init()
def syslog(self, log_msg, level):
""" Log to syslog. """
self._sandesh.logger().log(
SandeshLogger.get_py_logger_level(level), log_msg)
def log(self, log_msg, level=SandeshLevel.SYS_DEBUG, fun=None):
"""
If a sandesh function is provided, use the function.
If not, revert to syslog.
"""
if fun:
log = fun(level=level, log_msg=log_msg, sandesh=self._sandesh)
log.send(sandesh=self._sandesh)
else:
self.syslog(log_msg, level)
# EMERGENCY.
def emergency(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_EMERG
logging_fun = log_fun if log_fun else sandesh.KubeManagerEmergencyLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# ALERT.
def alert(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_ALERT
logging_fun = log_fun if log_fun else sandesh.KubeManagerAlertLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# CRITICAL.
def critical(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_CRIT
logging_fun = log_fun if log_fun else sandesh.KubeManagerCriticalLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# ERROR.
def error(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_ERR
logging_fun = log_fun if log_fun else sandesh.KubeManagerErrorLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# WARNING.
def warning(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_WARN
logging_fun = log_fun if log_fun else sandesh.KubeManagerWarningLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# NOTICE.
def notice(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_NOTICE
logging_fun = log_fun if log_fun else sandesh.KubeManagerNoticeLog
# Log to syslog.
self.syslog(log_msg, log_level)
#.........这里部分代码省略.........
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:101,代码来源:logger.py
示例10: ConfigServiceLogger
class ConfigServiceLogger(object):
_LOGGER_LEVEL_TO_SANDESH_LEVEL = {
logging.CRITICAL: SandeshLevel.SYS_EMERG,
logging.CRITICAL: SandeshLevel.SYS_ALERT,
logging.CRITICAL: SandeshLevel.SYS_CRIT,
logging.ERROR: SandeshLevel.SYS_ERR,
logging.WARNING: SandeshLevel.SYS_WARN,
logging.WARNING: SandeshLevel.SYS_NOTICE,
logging.INFO: SandeshLevel.SYS_INFO,
logging.DEBUG: SandeshLevel.SYS_DEBUG
}
def __init__(self, module, module_pkg, args=None, http_server_port=None):
self.module_pkg = module_pkg
if not hasattr(self, 'context'):
self.context = module_pkg
self._args = args
if 'host_ip' in args:
host_ip = args.host_ip
else:
host_ip = socket.gethostbyname(socket.getfqdn())
node_type = Module2NodeType[module]
self._module_name = ModuleNames[module]
self._node_type_name = NodeTypeNames[node_type]
self.table = "ObjectConfigNode"
self._instance_id = INSTANCE_ID_DEFAULT
self._hostname = socket.getfqdn(host_ip)
# sandesh init
self.sandesh_init(http_server_port)
def _get_sandesh_logger_level(self, sandesh_level):
return self._LOGGER_LEVEL_TO_SANDESH_LEVEL[sandesh_level]
def log(self, log_msg, level=SandeshLevel.SYS_DEBUG, fun=None):
if fun:
log = fun(level=level, og_msg=log_msg, sandesh=self._sandesh)
log.send(sandesh=self._sandesh)
else:
self._sandesh.logger().log(
SandeshLogger.get_py_logger_level(level), log_msg)
def emergency(self, log_msg, log_fun=None):
self.log(log_msg, level=SandeshLevel.SYS_EMERG, fun=log_fun)
def alert(self, log_msg, log_fun=None):
self.log(log_msg, level=SandeshLevel.SYS_ALERT, fun=log_fun)
def critical(self, log_msg, log_fun=None):
self.log(log_msg, level=SandeshLevel.SYS_CRIT, fun=log_fun)
def error(self, log_msg, log_fun=None):
self.log(log_msg, level=SandeshLevel.SYS_ERR, fun=log_fun)
def cgitb_error(self):
string_buf = cStringIO.StringIO()
cgitb_hook(file=string_buf, format="text")
self.error(string_buf.getvalue())
def warning(self, log_msg, log_fun=None):
self.log(log_msg, level=SandeshLevel.SYS_WARN, fun=log_fun)
def notice(self, log_msg, log_fun=None):
self.log(log_msg, level=SandeshLevel.SYS_NOTICE, fun=log_fun)
def info(self, log_msg, log_fun=None):
self.log(log_msg, level=SandeshLevel.SYS_INFO, fun=log_fun)
def debug(self, log_msg, log_fun=None):
self.log(log_msg, level=SandeshLevel.SYS_DEBUG, fun=log_fun)
def _utc_timestamp_usec(self):
epoch = datetime.datetime.utcfromtimestamp(0)
now = datetime.datetime.utcnow()
delta = now - epoch
return (delta.microseconds +
(delta.seconds + delta.days * 24 * 3600) * 10 ** 6)
def redefine_sandesh_handles(self):
""" Redefine sandesh handle requests for various object types. """
pass
def sandesh_init(self, http_server_port=None):
""" Init sandesh """
self._sandesh = Sandesh()
self.redefine_sandesh_handles()
if not http_server_port:
http_server_port = self._args.http_server_port
self._sandesh.init_generator(
self._module_name, self._hostname, self._node_type_name,
self._instance_id, self._args.random_collectors,
'%s_context' % self.context, int(http_server_port),
['cfgm_common', '%s.sandesh' % self.module_pkg],
logger_class=self._args.logger_class,
logger_config_file=self._args.logging_conf,
config=self._args.sandesh_config)
self._sandesh.set_logging_params(
#.........这里部分代码省略.........
开发者ID:Juniper,项目名称:contrail-controller,代码行数:101,代码来源:vnc_logger.py
示例11: SvcMonitor
class SvcMonitor(object):
"""
data + methods used/referred to by ssrc and arc greenlets
"""
_KEYSPACE = 'svc_monitor_keyspace'
_SVC_VM_CF = 'svc_vm_table'
_SVC_SI_CF = 'svc_si_table'
_SVC_CLEANUP_CF = 'svc_cleanup_table'
def __init__(self, vnc_lib, args=None):
self._args = args
# api server and cassandra init
self._vnc_lib = vnc_lib
self._cassandra_init()
# dictionary for nova
self._nova = {}
#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,
client_type='Service Monitor')
#sandesh init
self._sandesh = Sandesh()
sandesh.ServiceInstanceList.handle_request =\
self.sandesh_si_handle_request
self._sandesh.init_generator(
ModuleNames[Module.SVC_MONITOR], socket.gethostname(),
self._args.collectors, 'svc_monitor_context',
int(self._args.http_server_port), ['cfgm_common', 'sandesh'],
self._disc)
self._sandesh.set_logging_params(enable_local_log=self._args.log_local,
category=self._args.log_category,
level=self._args.log_level,
file=self._args.log_file)
#create default analyzer template
self._create_default_template('analyzer-template', 'analyzer',
'analyzer')
self._create_default_template('nat-template', 'nat-service',
'firewall', 'in-network-nat')
#create cpu_info object to send periodic updates
sysinfo_req = False
cpu_info = vnc_cpu_info.CpuInfo(
Module.SVC_MONITOR, sysinfo_req, self._sandesh, 60)
self._cpu_info = cpu_info
# logging
self._err_file = '/var/log/contrail/svc-monitor.err'
self._tmp_file = '/var/log/contrail/svc-monitor.tmp'
self._svc_err_logger = logging.getLogger('SvcErrLogger')
self._svc_err_logger.setLevel(logging.ERROR)
handler = logging.handlers.RotatingFileHandler(
self._err_file, maxBytes=64*1024, backupCount=2)
self._svc_err_logger.addHandler(handler)
# end __init__
# create service template
def _create_default_template(self, st_name, image_name,
svc_type, svc_mode=None):
domain_name = 'default-domain'
domain_fq_name = [domain_name]
st_fq_name = [domain_name, st_name]
self._svc_syslog("Creating %s %s image %s" %
(domain_name, st_name, image_name))
try:
st_obj = self._vnc_lib.service_template_read(fq_name=st_fq_name)
st_uuid = st_obj.uuid
except NoIdError:
domain = self._vnc_lib.domain_read(fq_name=domain_fq_name)
st_obj = ServiceTemplate(name=st_name, domain_obj=domain)
st_uuid = self._vnc_lib.service_template_create(st_obj)
svc_properties = ServiceTemplateType()
svc_properties.set_image_name(image_name)
svc_properties.set_service_type(svc_type)
# set interface list
if svc_type == 'analyzer':
if_list = [['left', False]]
else:
if_list = [
['left', False], ['right', False], ['management', False]]
svc_properties.set_service_mode(svc_mode)
for itf in if_list:
if_type = ServiceTemplateInterfaceType(shared_ip=itf[1])
if_type.set_service_interface_type(itf[0])
svc_properties.add_interface_type(if_type)
try:
st_obj.set_service_template_properties(svc_properties)
#.........这里部分代码省略.........
开发者ID:linbiyi,项目名称:contrail-controller,代码行数:101,代码来源:svc_monitor.py
示例12: MesosManagerLogger
class MesosManagerLogger(object):
def __init__(self, args=None):
self._args = args
# Initialize module parameters.
self.module = {}
self.module["id"] = Module.MESOS_MANAGER
self.module["name"] = ModuleNames[self.module["id"]]
self.module["node_type"] = Module2NodeType[self.module["id"]]
self.module["node_type_name"] = NodeTypeNames[self.module["node_type"]]
if 'host_ip' in self._args:
host_ip = self._args.host_ip
else:
host_ip = socket.gethostbyname(socket.getfqdn())
self.module["hostname"] = socket.getfqdn(host_ip)
self.module["table"] = "ObjectConfigNode"
if self._args.worker_id:
self.module["instance_id"] = self._args.worker_id
else:
self.module["instance_id"] = INSTANCE_ID_DEFAULT
# Init Sandesh.
self.sandesh_init()
def syslog(self, log_msg, level):
# Log to syslog.
self._sandesh.logger().log(
SandeshLogger.get_py_logger_level(level), log_msg)
def log(self, log_msg, level=SandeshLevel.SYS_DEBUG, fun=None):
# If a sandesh function is provided, use the function.
# If not, revert to syslog.
if fun:
log = fun(level=level, log_msg=log_msg, sandesh=self._sandesh)
log.send(sandesh=self._sandesh)
else:
self.syslog(log_msg, level)
# EMERGENCY.
def emergency(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_EMERG
logging_fun = log_fun if log_fun else sandesh.MesosManagerEmergencyLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# ALERT.
def alert(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_ALERT
logging_fun = log_fun if log_fun else sandesh.MesosManagerAlertLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# CRITICAL.
def critical(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_CRIT
logging_fun = log_fun if log_fun else sandesh.MesosManagerCriticalLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# CRITICAL.
def error(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_ERR
logging_fun = log_fun if log_fun else sandesh.MesosManagerErrorLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# WARNING.
def warning(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_WARN
logging_fun = log_fun if log_fun else sandesh.MesosManagerWarningLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# NOTICE.
def notice(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_NOTICE
logging_fun = log_fun if log_fun else sandesh.MesosManagerNoticeLog
# Log to syslog.
#.........这里部分代码省略.........
开发者ID:Juniper,项目名称:contrail-controller,代码行数:101,代码来源:logger.py
示例13: MesosManagerLogger
class MesosManagerLogger(object):
def __init__(self, args=None):
self._args = args
# Initialize module parameters.
self.module = {}
self.module["id"] = Module.MESOS_MANAGER
self.module["name"] = ModuleNames[self.module["id"]]
self.module["node_type"] = Module2NodeType[self.module["id"]]
self.module["node_type_name"] = NodeTypeNames[self.module["node_type"]]
self.module["hostname"] = socket.gethostname()
self.module["table"] = "ObjectConfigNode"
if self._args.worker_id:
self.module["instance_id"] = self._args.worker_id
else:
self.module["instance_id"] = INSTANCE_ID_DEFAULT
# Init Sandesh.
self.sandesh_init()
def syslog(self, log_msg, level):
# Log to syslog.
self._sandesh.logger().log(
SandeshLogger.get_py_logger_level(level), log_msg)
def log(self, log_msg, level=SandeshLevel.SYS_DEBUG, fun=None):
# If a sandesh function is provided, use the function.
# If not, revert to syslog.
if fun:
log = fun(level=level, log_msg=log_msg, sandesh=self._sandesh)
log.send(sandesh=self._sandesh)
else:
self.syslog(log_msg, level)
# EMERGENCY.
def emergency(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_EMERG
logging_fun = log_fun if log_fun else sandesh.MesosManagerEmergencyLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# ALERT.
def alert(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_ALERT
logging_fun = log_fun if log_fun else sandesh.MesosManagerAlertLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# CRITICAL.
def critical(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_CRIT
logging_fun = log_fun if log_fun else sandesh.MesosManagerCriticalLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# CRITICAL.
def error(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_ERR
logging_fun = log_fun if log_fun else sandesh.MesosManagerErrorLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# WARNING.
def warning(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_WARN
logging_fun = log_fun if log_fun else sandesh.MesosManagerWarningLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
# NOTICE.
def notice(self, log_msg, log_fun=None):
log_level = SandeshLevel.SYS_NOTICE
logging_fun = log_fun if log_fun else sandesh.MesosManagerNoticeLog
# Log to syslog.
self.syslog(log_msg, log_level)
# Log using the desired logging function.
self.log(log_msg, level=log_level, fun=logging_fun)
#.........这里部分代码省略.........
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:101,代码来源:logger.py
示例14: ConnInfoTest
class ConnInfoTest(unittest.TestCase):
def setUp(self):
self.maxDiff = None
self._sandesh = Sandesh()
http_port = test_utils.get_free_port()
self._sandesh.init_generator('conn_info_test', socket.gethostname(),
'Test', 'Test', None, 'conn_info_test_ctxt', http_port)
#end setUp
def _check_process_status_cb(self, vcinfos):
self._expected_vcinfos.sort()
vcinfos.sort()
self.assertEqual(self._expected_vcinfos, vcinfos)
return (ProcessState.FUNCTIONAL, '')
#end _check_process_status_cb
def _update_conn_info(self, name, status, description, vcinfos):
cinfo = ConnectionInfo()
cinfo.name = name
cinfo.status = ConnectionStatusNames[status]
cinfo.description = description
cinfo.type = ConnectionTypeNames[ConnectionType.TEST]
cinfo.server_addrs = ['127.0.0.1:0']
vcinfos.append(cinfo)
#end _update_conn_info
def _update_conn_state(self, name, status, description, vcinfos):
self._expected_vcinfos = vcinfos
ConnectionState.update(ConnectionType.TEST, name, status,
['127.0.0.1:0'], description)
#end _update_conn_state
def _delete_conn_info(self, name, vcinfos):
return [cinfo for cinfo in vcinfos if cinfo.name != name]
#end _delete_conn_info
def _delete_conn_state(self, name, vcinfos):
self._expected_vcinfos = vcinfos
ConnectionState.delete(ConnectionType.TEST, name)
#end _delete_conn_state
def test_basic(self):
ConnectionState.init(sandesh = self._sandesh, hostname = "TestHost",
module_id = "TestModule", instance_id = "0",
status_cb = self._check_process_status_cb,
uve_type_cls = NodeStatusTestUVE,
uve_data_type_cls = NodeStatusTest)
vcinfos = []
self._update_conn_info("Test1", ConnectionStatus.UP, "Test1 UP",
vcinfos)
self._update_conn_state("Test1", ConnectionStatus.UP, "Test1 UP",
vcinfos)
self._update_conn_info("Test2", ConnectionStatus.UP, "Test2 UP",
vcinfos)
self._update_conn_state("Test2", ConnectionStatus.UP, "Test2 UP",
vcinfos)
vcinfos = self._delete_conn_info("Test2", vcinfos)
self._delete_conn_state("Test2", vcinfos)
#end test_basic
def test_callback(self):
vcinfos = []
self._update_conn_info("Test1", ConnectionStatus.UP, "Test1 UP",
vcinfos);
(pstate, message) = ConnectionState.get_process_state_cb(vcinfos)
self.assertEqual(ProcessState.FUNCTIONAL, pstate)
self.assertEqual('', message)
self._update_conn_info("Test2", ConnectionStatus.DOWN, "Test2 DOWN",
vcinfos);
(pstate, message) = ConnectionState.get_process_state_cb(vcinfos)
self.assertEqual(ProcessState.NON_FUNCTIONAL, pstate)
self.assertEqual("Test:Test2[Test2 DOWN] connection down", message);
self._update_conn_info("Test3", ConnectionStatus.DOWN, "Test3 DOWN",
vcinfos);
(pstate, message) = ConnectionState.get_process_state_cb(vcinfos);
self.assertEqual(ProcessState.NON_FUNCTIONAL, pstate);
self.assertEqual("Test:Test2[Test2 DOWN], Test:Test3[Test3 DOWN] connection down", message);
开发者ID:dattamiruke,项目名称:contrail-sandesh,代码行数:78,代码来源:conn_info_test.py
注:本文中的pysandesh.sandesh_base.Sandesh类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论