本文整理汇总了Python中karesansui.lib.dict_op.DictOp.cdp_set方法的典型用法代码示例。如果您正苦于以下问题:Python DictOp.cdp_set方法的具体用法?Python DictOp.cdp_set怎么用?Python DictOp.cdp_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karesansui.lib.dict_op.DictOp
的用法示例。
在下文中一共展示了DictOp.cdp_set方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pre_write_conf
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import cdp_set [as 别名]
def _pre_write_conf(self,conf_arr={}):
# Change permission to be able to read/write data kss group.
if os.path.exists(COLLECTD_DATA_DIR):
if os.getuid() == 0:
r_chgrp(COLLECTD_DATA_DIR,KARESANSUI_GROUP)
r_chmod(COLLECTD_DATA_DIR,"g+rwx")
r_chmod(COLLECTD_DATA_DIR,"o-rwx")
dop = DictOp()
dop.addconf("__",conf_arr)
if dop.isset("__",["python"]) is True:
dop.cdp_unset("__",["python","Plugin","python","@ORDERS"],multiple_file=True)
orders = []
orders.append(['Encoding'])
orders.append(['LogTraces'])
orders.append(['Interactive'])
orders.append(['ModulePath'])
orders.append(['Import'])
orders.append(['Module'])
dop.cdp_set("__",["python","Plugin","python","@ORDERS"],orders,is_opt_multi=True,multiple_file=True)
return dop.getconf("__")
示例2: process
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import cdp_set [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
original_parser = iscsidParser()
new_parser = iscsidParser()
dop = DictOp()
dop.addconf("original", original_parser.read_conf())
dop.addconf("new", new_parser.read_conf())
self.up_progress(10)
dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth)
if opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP:
password = ""
if opts.password is not None:
password = opts.password
elif opts.password_file is not None and is_readable(opts.password_file):
try:
fp = open(opts.password_file, "r")
try:
fcntl.lockf(fp.fileno(), fcntl.LOCK_SH)
try:
password = fp.readline().strip("\n")
finally:
fcntl.lockf(fp.fileno(), fcntl.LOCK_UN)
self.up_progress(10)
finally:
fp.close()
except:
raise KssCommandException('Failed to read file. - target host=%s password_file=%s' \
% (opts.host,opts.password_file))
try:
os.remove(opts.password_file)
except:
raise KssCommandException('Failed to remove file. - target host=%s password_file=%s' \
% (opts.host,opts.password_file))
dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth)
dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_USER, opts.user)
dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD, password)
else:
dop.comment("new", ISCSI_CONFIG_KEY_AUTH_USER)
dop.comment("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD)
self.up_progress(10)
if opts.autostart:
dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_ON)
else:
dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_OFF)
new_parser.write_conf(dop.getconf("new"))
self.up_progress(10)
discovery_command_args = (ISCSI_CMD,
ISCSI_CMD_OPTION_MODE,
ISCSI_CMD_OPTION_MODE_DISCOVERY,
ISCSI_CMD_OPTION_TYPE,
ISCSI_CMD_OPTION_TYPE_SENDTARGETS,
ISCSI_CMD_OPTION_PORTAL,
opts.host
)
(discovery_rc,discovery_res) = execute_command(discovery_command_args)
self.up_progress(10)
original_parser.write_conf(dop.getconf("original"))
self.up_progress(10)
if discovery_rc != 0:
raise KssCommandException('Failed to add iSCSI. - host=%s message=%s' % (opts.host, discovery_res))
if discovery_res == []:
raise KssCommandException('Failed to add iSCSI. - host=%s message=No exist permit iSCSI disk for target.' % (opts.host))
for node_line in discovery_res:
if not node_line:
continue
try:
node = iscsi_parse_node(node_line)
except:
self.logger.warn('Failed to parse iSCSI discovery command response. message="%s"' % (node_line))
continue
self.logger.info("%s" % (iscsi_print_format_node(node)))
print >>sys.stdout, _("%s") % (iscsi_print_format_node(node))
return True
示例3: __init__
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import cdp_set [as 别名]
#.........这里部分代码省略.........
is_opt_multi = False
if _k2[0] in self.opt_multi:
_tmp_conf = self.dop.get(self._module,_search_key)
# multiとsectがかぶったオプションの対応 strならmulti
if type(_tmp_conf[0]) == str:
is_opt_multi = True
if is_opt_multi is True:
_k2.pop()
new_lines = self._new_lines(_search_key,_k2)
lines = lines + new_lines
self.dop.unset(self._module,_search_key)
except:
pass
# オーダにないものは最後に追加
for _k2,_v2 in self.dop.get(self._module,[_path]).iteritems():
#if _k2 != orders_key:
m = re.match(exclude_regex,_k2)
if not m:
try:
if type(_k2) == str:
_k2 = [_k2]
_search_key = [_path] + _k2
if _k2[0] in self.opt_multi:
for _k3,_v3 in self.dop.get(self._module,_search_key).iteritems():
_search_key.append(_k3)
new_lines = self._new_lines(_search_key,_k2)
lines = lines + new_lines
else:
new_lines = self._new_lines(_search_key,_k2)
lines = lines + new_lines
except:
pass
# 最後のコメント用の処理
if self._footer != "":
if self.dop.isset(self._module,[_path,eof_key]) is False:
self.dop.cdp_set(self._module,[_path,eof_key],"",force=True)
eof_val = self.dop.get(self._module,[_path,eof_key])
eof_action = self.dop.action(self._module,[_path,eof_key])
eof_comment = self.dop.comment(self._module,[_path,eof_key])
try:
key = " %s - %s on %s" % (self._footer,self._module,time.strftime("%c",time.localtime()))
value = {}
value[key] = {}
value[key]["value"] = eof_val
value[key]["action"] = eof_action
value[key]["comment"] = eof_comment
self.set_new_delim(delim=" ")
lines = lines + self._value_to_lines(value)
except:
pass
if dryrun is False:
if len(lines) > 0:
ConfigFile(_path).write("\n".join(lines) + "\n")
else:
print "%s -- filename: %s" % (self._comment,_path,)
print "\n".join(lines)
return retval
def _new_lines(self,search_key,new_key):
try:
attrs = self.dop.get(self._module,search_key,with_attr=True)
action = attrs['action']
iscomment = attrs['comment']
val = attrs['value']
except:
action = self.dop.action(self._module,search_key)
iscomment = self.dop.iscomment(self._module,search_key)
val = self.dop.get(self._module,search_key)
pass
#print val
dop = DictOp()
dop.addconf('__',{})
if action == "delete":
dop.add('__',new_key,val)
dop.delete('__',new_key)
elif action == "set":
dop.set('__',new_key,val)
else:
dop.add('__',new_key,val)
if iscomment is True:
dop.comment('__',new_key)
#preprint_r(dop.getconf('__'))
new_lines = self._value_to_lines(dop.getconf('__'))
#print "\n".join(new_lines)
return new_lines
示例4: hostsParser
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import cdp_set [as 别名]
try:
self.dop.addconf("parser",{})
self.dop.set("parser",[PARSER_HOSTS_CONF],conf_arr)
#self.dop.preprint_r("parser")
arr = self.dop.getconf("parser")
self.parser.write_conf(arr,dryrun=dryrun)
except:
pass
return retval
"""
"""
if __name__ == '__main__':
"""Testing
"""
parser = hostsParser()
dop = DictOp()
dop.addconf("dum",parser.read_conf())
dop.add("dum",['key'],['value',[['comment foo','comment bar'],'comment hoge']])
print dop.cdp_get("dum",['key'])
print dop.cdp_get_pre_comment("dum",['key'])
print dop.cdp_get_post_comment("dum",['key'])
print dop.cdp_set("dum",['key'],"value2")
print dop.cdp_set_pre_comment("dum",['key'],["comment foo2","comment bar2","a"])
print dop.cdp_set_post_comment("dum",['key'],"comment fuga")
conf = dop.getconf("dum")
preprint_r(conf)
parser.write_conf(conf,dryrun=True)
示例5: DictOp
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import cdp_set [as 别名]
# 読み込み
dop = DictOp()
dop.addconf("dum",parser.read_conf())
##########################################################
# Uniオプション (一箇所しか設定できないオプション) の追加
##########################################################
# 'Foo foo' を追加(設定値リスト形式モードよる addメソッド)
dop.add("dum",["Foo"],["foo",[["comment foo1","comment foo2"],"comment foo3"]])
#print dop.cdp_get("dum",["Foo"])
#print dop.cdp_get_pre_comment("dum",["Foo"])
#print dop.cdp_get_post_comment("dum",["Foo"])
dop.insert_order("dum",["Foo"])
# 'Bar bar' を追加(設定値文字列形式モードによる cdp_setメソッド)
dop.cdp_set("dum",["Bar"],"bar")
dop.cdp_set_pre_comment("dum",["Bar"],["","comment bar1","comment bar2"])
dop.cdp_set_post_comment("dum",["Bar"],"comment bar3")
dop.insert_order("dum",["Bar"])
##########################################################
# Multiオプション (複数設定できるオプション) の追加
##########################################################
# 'LoadPlugin target_hoge' を追加
dop.cdp_set("dum",["LoadPlugin","target_hoge"],"target_hoge",is_opt_multi=True)
dop.cdp_set_pre_comment("dum",["LoadPlugin","target_hoge"],["","Dis is target_hoge"])
##########################################################
# Sectオプション (<ブラケット>ディレクティブオプション) の追加
##########################################################
# 下記 を追加
示例6: collectdpluginParser
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import cdp_set [as 别名]
parser = collectdpluginParser()
# 読み込み
dop = DictOp()
dop.addconf("dum",parser.read_conf())
new_plugin_name = "takuma"
##########################################################
# Uniオプション (一箇所しか設定できないオプション) の追加
##########################################################
# 'Foo foo' を追加(設定値リスト形式モードよる addメソッド)
dop.add("dum",[new_plugin_name,"Foo"],["foo",[["comment foo1","comment foo2"],"comment foo3"]])
# 'Bar bar' を追加(設定値文字列形式モードによる cdp_setメソッド)
dop.cdp_set("dum",[new_plugin_name,"Bar"],"bar",multiple_file=True)
dop.cdp_set_pre_comment("dum",[new_plugin_name,"Bar"],["","comment bar1","comment bar2"],multiple_file=True)
dop.cdp_set_post_comment("dum",[new_plugin_name,"Bar"],"comment bar3",multiple_file=True)
##########################################################
# Multiオプション (複数設定できるオプション) の追加
##########################################################
# 'LoadPlugin target_hoge' を追加
dop.cdp_set("dum",[new_plugin_name,"LoadPlugin","target_hoge"],"target_hoge",multiple_file=True,is_opt_multi=True)
dop.cdp_set_pre_comment("dum",[new_plugin_name,"LoadPlugin","target_hoge"],["","Dis is target_hoge"],multiple_file=True)
##########################################################
# Sectオプション (<ブラケット>ディレクティブオプション) の追加
##########################################################
# 下記 を追加
# <Plugin "foobar">
示例7: process
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import cdp_set [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
config_path = iscsi_get_config_path(opts.host, opts.iqn, opts.port, opts.tpgt)
parser = iscsidParser()
dop = DictOp()
dop.addconf("new", parser.read_conf(config_path))
self.up_progress(10)
dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_METHOD, opts.auth)
if opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP:
password = ""
if opts.password is not None:
password = opts.password
elif opts.password_file is not None and is_readable(opts.password_file):
try:
fp = open(opts.password_file, "r")
try:
fcntl.lockf(fp.fileno(), fcntl.LOCK_SH)
try:
password = fp.readline().strip("\n")
finally:
fcntl.lockf(fp.fileno(), fcntl.LOCK_UN)
self.up_progress(10)
finally:
fp.close()
except:
raise KssCommandException('Failed to read file. - target host=%s password_file=%s' \
% (opts.host,opts.password_file))
try:
os.remove(opts.password_file)
except:
raise KssCommandException('Failed to remove file. - target host=%s password_file=%s' \
% (opts.host,opts.password_file))
dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_USER, opts.user)
dop.cdp_set("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD, password)
else:
dop.comment("new", ISCSI_CONFIG_KEY_AUTH_USER)
dop.comment("new", ISCSI_CONFIG_KEY_AUTH_PASSWORD)
self.up_progress(10)
if opts.autostart:
dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_ON)
else:
dop.cdp_set("new", ISCSI_CONFIG_KEY_SATRTUP, ISCSI_CONFIG_VALUE_SATRTUP_OFF)
self.up_progress(10)
parser.write_conf(dop.getconf("new"), config_path)
self.up_progress(30)
self.logger.info("Updated iSCSI node. - host=%s iqn=%s" % (opts.host, opts.iqn))
print >>sys.stdout, _("Updated iSCSI node. - host=%s iqn=%s") % (opts.host, opts.iqn)
return True
示例8: __init__
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import cdp_set [as 别名]
#.........这里部分代码省略.........
pass
elif com1_aline[0:1] != self._comment:
com1_aline = "%s %s" % (self._comment,com1_aline,)
comment_1.append(com1_aline)
except:
pass
comment_2 = _v['value'][1][1]
try:
if comment_2[0:1] != self._comment:
comment_2 = "%s %s" % (self._comment,comment_2,)
except:
pass
lines = lines + comment_1
aline = "%s%s%s%s" % (_prefix,_k,self._new_delim,val,)
if comment_2 is not None:
aline = "%s %s" % (aline,comment_2,)
lines.append(aline)
except:
pass
return lines
def write_conf(self,conf_arr={},dryrun=False):
retval = True
self.dop.addconf(self._module,conf_arr)
orders_key = "%sORDERS" % (self._reserved_key_prefix,)
eof_key = "%sEOF" % (self._reserved_key_prefix,)
for _path,_v in conf_arr.iteritems():
if _path[0:1] != "/":
continue
lines = []
try:
_v['value']
except:
continue
exclude_regex = "^%s[A-Z0-9\_]+$" % self._reserved_key_prefix
# まずはオーダの順
if self.dop.isset(self._module,[_path,orders_key]) is True:
for _k2 in self.dop.get(self._module,[_path,orders_key]):
m = re.match(exclude_regex,_k2)
if not m:
try:
if type(_k2) == list:
_k2 = _k2.pop()
value = {}
value[_k2] = _v['value'][_k2]
lines = lines + self._value_to_lines(value)
self.dop.unset(self._module,[_path,_k2])
except:
pass
# オーダにないものは最後に追加
for _k2,_v2 in self.dop.get(self._module,[_path]).iteritems():
#if _k2 != orders_key and _k2 != eof_key:
m = re.match(exclude_regex,_k2)
if not m:
try:
value = {}
value[_k2] = _v2
lines = lines + self._value_to_lines(value)
except:
pass
# 最後のコメント用の処理
if self._footer != "":
if self.dop.isset(self._module,[_path,eof_key]) is False:
self.dop.cdp_set(self._module,[_path,eof_key],"",force=True)
eof_val = self.dop.get(self._module,[_path,eof_key])
eof_action = self.dop.action(self._module,[_path,eof_key])
eof_comment = self.dop.comment(self._module,[_path,eof_key])
try:
key = " %s - %s on %s" % (self._footer,self._module,time.strftime("%c",time.localtime()))
value = {}
value[key] = {}
value[key]["value"] = eof_val
value[key]["action"] = eof_action
value[key]["comment"] = eof_comment
self.set_new_delim(delim=" ")
lines = lines + self._value_to_lines(value)
except:
pass
if dryrun is False:
if len(lines) > 0:
ConfigFile(_path).write("\n".join(lines) + "\n")
else:
#pass
print "\n".join(lines)
return retval