本文整理汇总了Python中storlever.lib.logger.log函数的典型用法代码示例。如果您正苦于以下问题:Python log函数的具体用法?Python log怎么用?Python log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add_community_conf
def add_community_conf(self, community_name,
ipv6=False, source="", oid="", read_only=True,
operator="unknown"):
new_community_conf = {
"community_name": community_name,
"ipv6": ipv6,
"source": source,
"oid": oid,
"read_only": read_only,
}
new_community_conf = self.community_conf_schema.validate(new_community_conf)
with self.lock:
snmp_conf = self._load_conf()
community_list = snmp_conf["community_list"]
# check duplicate
for community_conf in community_list:
if community_conf["community_name"] == community_name:
raise StorLeverError("Community (%s) Already exist" % community_name, 400)
community_list.append(new_community_conf)
# save new conf
self._save_conf(snmp_conf)
self._sync_to_system_conf(snmp_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"SNMP New Community (%s) is added by operator(%s)" %
(community_name, operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:30,代码来源:snmpagent.py
示例2: set_selinux_state
def set_selinux_state(self, state, user="unknown"):
state_str_to_int = {
"enforcing": 1,
"permissive": 0,
"disabled": 0
}
param = state_str_to_int.get(state)
if param is not None:
old_state = check_output(["/usr/sbin/getenforce"]).lower().strip()
if old_state != "disabled":
check_output(["/usr/sbin/setenforce", str(param)])
if not os.path.exists(SELINUX_CONF_DIR):
os.makedirs(SELINUX_CONF_DIR)
conf_path = os.path.join(SELINUX_CONF_DIR, SELINUX_CONF_FILE)
conf = properties()
conf.delete("SELINUX")
conf.apply_to(conf_path)
with open(conf_path, "r") as f:
content = f.read()
if content.endswith("\n") or len(content) == 0:
content += "SELINUX=%s\n" % state
else:
content += "\nSELINUX=%s\n" % state
with open(conf_path, "w") as f:
f.write(content)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"selinux state is set to %s by user(%s)" %
(state, user))
开发者ID:OpenSight,项目名称:StorLever,代码行数:30,代码来源:sysinfo.py
示例3: append_export_conf
def append_export_conf(self, name, path="/", clients=[], operator="unkown"):
if path != "" and not os.path.exists(path):
raise StorLeverError("path(%s) does not exists" % (path), 400)
new_export_point = {
"name": name,
"path": path,
"clients": clients,
}
new_export_point = self.export_point_conf_schema.validate(new_export_point)
with self.lock:
nfs_conf = self._load_conf()
# check duplication
for point in nfs_conf["export_point_list"]:
if path == point["path"]:
raise StorLeverError("export with path(%s) already in nfs export table" % (path), 400)
if name == point["name"]:
raise StorLeverError("export with name(%s) already in nfs export table" % (name), 400)
nfs_conf["export_point_list"].append(new_export_point)
# save new conf
self._save_conf(nfs_conf)
self._sync_to_system_conf(nfs_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"NFS export with path(%s) config is added by operator(%s)" %
(path, operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:31,代码来源:nfsmgr.py
示例4: delete
def delete(self, md_name):
"""
Destroy a RAID device.
WARNING This will zero the superblock of all members of the RAID array..
CLI Example:
.. code-block:: bash
salt '*' raid.destroy /dev/md0
"""
md = MD(md_name, self._lock)
md_device = _md_name_to_dev_file(md_name)
stop_cmd = '/sbin/mdadm --stop {0}'.format(md_device)
zero_cmd = '/sbin/mdadm --zero-superblock {0}'
with self._lock:
check_output(stop_cmd.split())
for _, member in md.members.iteritems():
try:
check_output(zero_cmd.format(member['device']).split())
except StorLeverError:
logger.log(logging.WARNING, logger.LOG_TYPE_ERROR,
"Failed zero superblock of device {0}".format(md_device),
exc_info=True)
self._update_mdadm_conf()
self.refresh()
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"MD {0} removed successfully".format(md_device))
开发者ID:OpenSight,项目名称:StorLever,代码行数:32,代码来源:md.py
示例5: grow_raid
def grow_raid(self, device):
grow_cmd = '/sbin/mdadm --grow {0} --raid-device={1}'.format(self.dev_file, device)
with self._lock:
check_output(grow_cmd.split())
self.refresh()
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"MD {0} grows successfully with block device {1}".format(self.dev_file, device))
开发者ID:OpenSight,项目名称:StorLever,代码行数:7,代码来源:md.py
示例6: add_component
def add_component(self, device):
add_cmd = '/sbin/mdadm {0} --add {1}'.format(self.dev_file, device)
with self._lock:
check_output(add_cmd.split())
self.refresh()
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"Block device {0} added to MD {1} successfully".format(device, self.dev_file))
开发者ID:OpenSight,项目名称:StorLever,代码行数:7,代码来源:md.py
示例7: set_export_conf
def set_export_conf(self, name, path=None, clients=None, operator="unkown"):
if path is not None and path != "" and not os.path.exists(path):
raise StorLeverError("path(%s) does not exists" % (path), 400)
with self.lock:
nfs_conf = self._load_conf()
for index, point in enumerate(nfs_conf["export_point_list"]):
if name == point["name"]:
break
else:
raise StorLeverError("export(%s) not found" % (name), 404)
if path is not None:
point["path"] = path
if clients is not None:
point["clients"] = clients
nfs_conf["export_point_list"][index] = self.export_point_conf_schema.validate(point)
# save new conf
self._save_conf(nfs_conf)
self._sync_to_system_conf(nfs_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"NFS export (name:%s) config is updated by operator(%s)" %
(name, operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:27,代码来源:nfsmgr.py
示例8: set_ip_config
def set_ip_config(self, ip=None, netmask=None, gateway=None, user="unknown"):
if ip is None:
ip = self.conf.get("IPADDR", "")
if netmask is None:
netmask = self.conf.get("NETMASK", "")
if gateway is None:
gateway = self.conf.get("GATEWAY", "")
self.conf["IPADDR"] = ip
self.conf["NETMASK"] = netmask
self.conf["GATEWAY"] = gateway
self.conf["BOOTPROTO"] = "none"
# write to config file
self.conf.apply_to(self.conf_file_path)
# restart this interface
if self.ifconfig_interface.is_up():
check_output([IFDOWN, self.name])
check_output([IFUP, self.name])
# log the operation
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"Network interface (%s) is configured with (IP:%s, Netmask:%s, \
Gateway:%s) by user(%s)" %
(self.name, ip, netmask, gateway, user))
开发者ID:OpenSight,项目名称:StorLever,代码行数:27,代码来源:netif.py
示例9: update_community_conf
def update_community_conf(self, community_name,
ipv6=None, source=None, oid=None, read_only=None,
operator="unknown"):
with self.lock:
snmp_conf = self._load_conf()
community_list = snmp_conf["community_list"]
update_comunity_index = 0
for index, community_conf in enumerate(community_list):
if community_conf["community_name"] == community_name:
update_comunity_index = index
break
else:
raise StorLeverError("Community (%s) Not Found" % (community_name), 404)
community_conf = community_list[update_comunity_index]
if ipv6 is not None:
community_conf["ipv6"] = ipv6
if source is not None:
community_conf["source"] = source
if oid is not None:
community_conf["oid"] = oid
if read_only is not None:
community_conf["read_only"] = read_only
community_list[update_comunity_index] = \
self.community_conf_schema.validate(community_conf)
# save new conf
self._save_conf(snmp_conf)
self._sync_to_system_conf(snmp_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"SNMP Community (%s) config is updated by operator(%s)" %
(community_name, operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:35,代码来源:snmpagent.py
示例10: set_mail_conf
def set_mail_conf(self, config={}, operator="unkown", *args, **kwargs):
if not isinstance(config, dict):
raise StorLeverError("Parameter type error", 500)
if len(config) == 0 and len(kwargs) == 0:
return
config.update(kwargs)
with self.lock:
mail_conf = self._load_conf()
for name, value in config.items():
if name in mail_conf and value is not None:
mail_conf[name] = value
# check config conflict
mail_conf = self.mail_conf_schema.validate(mail_conf)
if mail_conf["smtp_server"] != "":
if mail_conf["email_addr"] == "":
raise StorLeverError("email_addr cannot be empty if smtp_server exists", 400)
if mail_conf["password"] == "":
raise StorLeverError("password cannot be empty if smtp_server exists", 400)
# save new conf
self._save_conf(mail_conf)
self._sync_to_system_conf(mail_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"Mail config is updated by operator(%s)" %
(operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:28,代码来源:mailmgr.py
示例11: del_fs
def del_fs(self, fs_name, user="unknown"):
"""delete a filesystem from storlever
the file would be deleted from the storlever's config file and
would be unmount from linux system
"""
with self.lock:
fs_dict = self._load_conf()
if fs_name not in fs_dict:
raise StorLeverError("filesystem(%s) does not exist" % fs_name, 400)
fs_conf = fs_dict[fs_name]
del fs_dict[fs_name]
#umount fs first. if it failed, don't delete it in the config
self._umount_fs(fs_name, fs_conf)
self._save_conf(fs_dict)
self._sync_to_fstab(fs_dict)
try:
os.rmdir(fs_conf["mount_point"])
except OSError as e:
pass
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"filesystem %s (dev:%s, mount_point:%s, option:%s) "
"is deleted by user(%s)" %
(fs_name, fs_conf['dev_file'],
fs_conf['mount_point'], fs_conf['mount_option'],
user))
开发者ID:OpenSight,项目名称:StorLever,代码行数:32,代码来源:fsmgr.py
示例12: logout
def logout(self, operator="unkown"):
cmd = [ISCSIADM_CMD, "-m", "node","--logout", "-T", self.target, "-p", self.portal]
outlines = check_output(cmd, input_ret=[2, 6, 7, 21, 22]).splitlines()
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"iscsi initiator node (%s, %s) is logout by operator(%s)" %
(self.target, self.portal, operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:7,代码来源:node.py
示例13: set_agent_conf
def set_agent_conf(self, config={}, operator="unkown", *args, **kwargs):
if not isinstance(config, dict):
raise StorLeverError("Parameter type error", 500)
if len(config) == 0 and len(kwargs) == 0:
return
config.update(kwargs)
not_allow_keys = (
"active_check_server_list",
"passive_check_server_list"
)
config = filter_dict(config, not_allow_keys, True)
with self.lock:
zabbix_agent_conf = self._load_conf()
for name, value in config.items():
if name in zabbix_agent_conf and value is not None:
zabbix_agent_conf[name] = value
# check config conflict
zabbix_agent_conf = self.zabbix_agentd_conf_schema.validate(zabbix_agent_conf)
# save new conf
self._save_conf(zabbix_agent_conf)
self._sync_to_system_conf(zabbix_agent_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"Zabbix agent config is updated by operator(%s)" %
(operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:28,代码来源:zabbixagent.py
示例14: add_monitor_conf
def add_monitor_conf(self, monitor_name, expression, option="",
operator="unknown"):
new_monitor_conf = {
"monitor_name": monitor_name,
"expression": expression,
"option": option,
}
new_monitor_conf = self.monitor_conf_schema.validate(new_monitor_conf)
with self.lock:
snmp_conf = self._load_conf()
monitor_list = snmp_conf["monitor_list"]
# check duplicate
for monitor_conf in monitor_list:
if monitor_conf["monitor_name"] == monitor_name:
raise StorLeverError("monitor_name (%s) Already exist" % monitor_name, 400)
monitor_list.append(new_monitor_conf)
# save new conf
self._save_conf(snmp_conf)
self._sync_to_system_conf(snmp_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"SNMP New Monitor (%s) is added by operator(%s)" %
(monitor_name, operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:28,代码来源:snmpagent.py
示例15: quota_group_set
def quota_group_set(self, group,
block_softlimit=0,
block_hardlimit=0,
inode_softlimit=0,
inode_hardlimit=0,
operator="unknown"):
if not self.is_available():
raise StorLeverError("File system is unavailable", 500)
setquota_agrs = [
SETQUOTA_BIN,
"-g",
group,
str(block_softlimit),
str(block_hardlimit),
str(inode_softlimit),
str(inode_hardlimit),
self.fs_conf["mount_point"]
]
check_output(setquota_agrs)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"File System(%s) quota for group(%s) is changed to "
"(%d,%d,%d,%d)"
" by user(%s)" %
(self.name, group,
block_softlimit, block_hardlimit,
inode_softlimit, inode_hardlimit,
operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:28,代码来源:fs.py
示例16: update_monitor_conf
def update_monitor_conf(self, monitor_name, expression=None, option=None,
operator="unknown"):
with self.lock:
snmp_conf = self._load_conf()
monitor_list = snmp_conf["monitor_list"]
update_monitor_index = 0
for index, monitor_conf in enumerate(monitor_list):
if monitor_conf["monitor_name"] == monitor_name:
update_monitor_index = index
break
else:
raise StorLeverError("Monitor (%s) Not Found" % (monitor_name), 404)
if expression is not None:
monitor_conf["expression"] = expression
if option is not None:
monitor_conf["option"] = option
monitor_list[update_monitor_index] = \
self.monitor_conf_schema.validate(monitor_conf)
# save new conf
self._save_conf(snmp_conf)
self._sync_to_system_conf(snmp_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"SNMP Monitor (%s) config is updated by operator(%s)" %
(monitor_name, operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:29,代码来源:snmpagent.py
示例17: set_host_list
def set_host_list(self, host_list, user="unknown"):
host_list = HOST_LIST_SCHEMA.validate(host_list)
if os.path.exists(ETC_HOSTS_FILE):
with open(ETC_HOSTS_FILE, "r") as f:
lines = f.readlines()
else:
lines = []
if "# begin storlever\n" in lines:
before_storlever = lines[0:lines.index("# begin storlever\n")]
else:
before_storlever = lines[0:]
if before_storlever and (not before_storlever[-1].endswith("\n")):
before_storlever[-1] += "\n"
if "# end storlever\n" in lines:
after_storlever = lines[lines.index("# end storlever\n") + 1:]
else:
after_storlever = []
with open(ETC_HOSTS_FILE, "w") as f:
f.writelines(before_storlever)
f.write("# begin storlever\n")
for host in host_list:
f.write("%s %s %s\n" % (
host["addr"],
host["hostname"],
host["alias"]
))
f.write("# end storlever\n")
f.writelines(after_storlever)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"Host list is updated by user(%s)" % user)
开发者ID:OpenSight,项目名称:StorLever,代码行数:35,代码来源:sysinfo.py
示例18: set_basic_conf
def set_basic_conf(self, config={}, operator="unkown", **kwargs):
if not isinstance(config, dict):
raise StorLeverError("Parameter type error", 500)
if len(config) == 0 and len(kwargs) == 0:
return
config.update(kwargs)
not_allowed_keys = (
"community_list",
"trapsink_list",
"monitor_list"
)
config = filter_dict(config, not_allowed_keys, True)
with self.lock:
snmp_conf = self._load_conf()
for name, value in config.items():
if name in snmp_conf and value is not None:
snmp_conf[name] = value
# check config conflict
snmp_conf = self.snmp_conf_schema.validate(snmp_conf)
# save new conf
self._save_conf(snmp_conf)
self._sync_to_system_conf(snmp_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"SNMP basic config is updated by operator(%s)" %
(operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:28,代码来源:snmpagent.py
示例19: create_target
def create_target(self, iqn, operator="unkown"):
target_conf ={
"iqn": iqn,
"initiator_addr_list": [],
"initiator_name_list": [],
"incominguser_list": [],
"outgoinguser_list": [],
}
target_conf = self.target_conf_schema.validate(target_conf)
with self.lock:
tgt_conf = self._load_conf()
# check duplicate
for target_conf in tgt_conf["target_list"]:
if target_conf["iqn"] == iqn:
raise StorLeverError("Target (iqn:%s) Already exist" % iqn, 400)
tgt_conf["target_list"].append(target_conf)
# save new conf
self._save_conf(tgt_conf)
self._sync_to_system_conf(tgt_conf)
try:
check_output([TGTADMIN_CMD, "--execute"])
except StorLeverError:
pass
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"tgt target (iqn:%s) config is added by operator(%s)" %
(iqn, operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:31,代码来源:tgtmgr.py
示例20: set_monitor_list
def set_monitor_list(self, monitor_list=[], operator="unkown"):
monitor_list = Schema([self.smartd_monitor_conf_schema]).validate(monitor_list)
for i, monitor_conf in enumerate(monitor_list[:]):
monitor_list[i] = filter_dict(monitor_conf, ("dev", "mail_to",
"mail_test", "mail_exec",
"schedule_regexp"))
with self.lock:
smartd_conf = self._load_conf()
smartd_conf["monitor_list"] = monitor_list
# check validation
for monitor_conf in smartd_conf["monitor_list"]:
if not os.path.exists(monitor_conf["dev"]):
raise StorLeverError("Device (%s) not found" % (monitor_conf["dev"]), 404)
else:
mode = os.stat(monitor_conf["dev"])[ST_MODE]
if not S_ISBLK(mode):
raise StorLeverError("Device (%s) not block device" % (monitor_conf["dev"]), 400)
if monitor_conf["mail_exec"] != "" and not os.path.exists(monitor_conf["mail_exec"]):
raise StorLeverError("mail_exec (%s) not found" % (monitor_conf["mail_exec"]), 404)
# save new conf
self._save_conf(smartd_conf)
self._sync_to_system_conf(smartd_conf)
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"Smartd monitor list is updated by operator(%s)" %
(operator))
开发者ID:OpenSight,项目名称:StorLever,代码行数:30,代码来源:smartdmgr.py
注:本文中的storlever.lib.logger.log函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论