本文整理汇总了Python中karesansui.lib.dict_op.DictOp.unset方法的典型用法代码示例。如果您正苦于以下问题:Python DictOp.unset方法的具体用法?Python DictOp.unset怎么用?Python DictOp.unset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karesansui.lib.dict_op.DictOp
的用法示例。
在下文中一共展示了DictOp.unset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import unset [as 别名]
#.........这里部分代码省略.........
orders_key = "%sORDERS" % (self._reserved_key_prefix,)
self.dop.set(self._module,[_afile,orders_key],orders)
#self.dop.preprint_r(self._module)
return self.dop.getconf(self._module)
def _value_to_lines(self,value):
lines = []
for _k,_v in value.iteritems():
try:
if _v['action'] == "delete":
continue
except:
pass
try:
val = _v['value']
comment = False
try:
if _v['comment'] is True:
comment = True
except:
pass
if type(val) == list:
for _val in val:
aline = "%s%s%s" % (_k,self._new_delim,_val,)
if comment is True:
aline = "%s%s" % (self._comment,aline,)
lines.append(aline)
else:
aline = "%s%s%s" % (_k,self._new_delim,val,)
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,)
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():
m = re.match(exclude_regex,_k2)
if not m:
try:
value = {}
value[_k2] = _v2
lines = lines + self._value_to_lines(value)
except:
pass
if dryrun is False:
if len(lines) > 0:
ConfigFile(_path).write("\n".join(lines) + "\n")
if len(lines) == 0:
ConfigFile(_path).write("")
else:
if len(lines) > 0:
print "\n".join(lines)
if len(lines) == 0:
print ""
return retval
示例2: __init__
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import unset [as 别名]
#.........这里部分代码省略.........
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]):
try:
if type(_k2) == str:
_k2 = [_k2]
_search_key = [_path] + _k2
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)
示例3: process
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import unset [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
dev_list = comma_split(opts.dev)
if len(dev_list) < 2:
# TRANSLATORS:
# bondingするためのdeviceが少ないです
raise KssCommandOptException('ERROR: Small device for bonding. - dev=%s' % (opts.dev))
interface_list = get_ifconfig_info()
for dev in dev_list:
if dev not in interface_list:
raise KssCommandOptException('ERROR: Bonding target device not found. - dev=%s' % (dev))
if opts.primary not in dev_list:
raise KssCommandOptException('ERROR: Primary device not found in bonding device. - primary=%s dev=%s' % (opts.primary, opts.dev))
exist_bond_max_num = -1
exist_bond_list = get_ifconfig_info("regex:^bond")
for bond_name in exist_bond_list.keys():
try:
num = int(bond_name.replace("bond",""))
except ValueError:
continue
if exist_bond_max_num < num:
exist_bond_max_num = num
self.up_progress(10)
physical_bond_name = "bond%s" % (exist_bond_max_num + 1)
bridge_bond_name = "bondbr%s" % (exist_bond_max_num + 1)
bond_options = '"mode=%s primary=%s miimon=%s"' % (opts.mode, opts.primary, BONDING_CONFIG_MII_DEFAULT)
self.up_progress(10)
dop = DictOp()
ifcfg_parser = ifcfgParser()
modprobe_parser = modprobe_confParser()
dop.addconf("ifcfg", ifcfg_parser.read_conf())
if dop.getconf("ifcfg") == {}:
raise KssCommandException('Failure read network config file.')
dop.addconf("modprobe_conf", modprobe_parser.read_conf())
if dop.getconf("modprobe_conf") == {}:
raise KssCommandException('Failure read modprobe config file.')
self.up_progress(10)
eth_conf_copykey = ["HWADDR",
"BOOTPROTO",
"ONBOOT",
"USERCTL",
]
bond_conf_nocopykey = ["TYPE",
"HWADDR",
"MACADDR",
"ETHTOOL_OPTS",
"ESSID",
"CHANNEL",
]
self.up_progress(10)
for dev in dev_list:
conf = dop.get("ifcfg", dev)
if dev == opts.primary:
primary_conf = copy.deepcopy(conf)
dop.unset("ifcfg", dev)
dop.set("ifcfg", [dev, "DEVICE"], conf["DEVICE"]["value"])
for key in eth_conf_copykey:
if key in conf:
dop.set("ifcfg", [dev, key], conf[key]["value"])
dop.set("ifcfg", [dev, "MASTER"], physical_bond_name)
dop.set("ifcfg", [dev, "SLAVE"], "yes")
dop.set("ifcfg", [dev, "BOOTPROTO"], "none")
if dop.get("ifcfg", "p%s" % (dev)):
hwaddr = dop.get("ifcfg", ["p%s" % (dev), "HWADDR"])
if hwaddr:
dop.set("ifcfg", [dev, "HWADDR"], hwaddr)
dop.unset("ifcfg", "p%s" % (dev))
for key in bond_conf_nocopykey:
if key in primary_conf:
del primary_conf[key]
dop.set("ifcfg", bridge_bond_name, primary_conf)
dop.set("ifcfg", [bridge_bond_name, "DEVICE"], bridge_bond_name)
dop.set("ifcfg", [bridge_bond_name, "TYPE"], "Bridge")
dop.set("ifcfg", [physical_bond_name, "DEVICE"], physical_bond_name)
dop.set("ifcfg", [physical_bond_name, "BRIDGE"], bridge_bond_name)
dop.set("ifcfg", [physical_bond_name, "BOOTPROTO"], "none")
dop.set("ifcfg", [physical_bond_name, "ONBOOT"], dop.get("ifcfg", [bridge_bond_name, "ONBOOT"]))
dop.set("ifcfg", [physical_bond_name, "BONDING_OPTS"], bond_options)
self.up_progress(10)
dop.set("modprobe_conf", ["alias", physical_bond_name], "bonding")
#.........这里部分代码省略.........
示例4: process
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import unset [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
exist_bond_list = get_ifconfig_info("regex:^bond")
if opts.dev not in exist_bond_list:
raise KssCommandOptException('Target bonding device not found. target=%s' % opts.dev)
self.up_progress(10)
dop = DictOp()
ifcfg_parser = ifcfgParser()
dop.addconf("ifcfg", ifcfg_parser.read_conf())
if dop.getconf("ifcfg") == {}:
raise KssCommandException('Failure read network config file.')
if dop.get("ifcfg", opts.dev) is False:
raise KssCommandException('Target device ifcfg file not found.')
self.up_progress(10)
restore_dev_list = []
for dev in dop.getconf("ifcfg").keys():
if dop.get("ifcfg", [dev, "MASTER"]) == opts.dev:
restore_dev_list.append(dev)
self.up_progress(10)
if opts.succession is True:
bond_bridge = dop.get("ifcfg", [opts.dev, "BRIDGE"])
bond_dev = opts.dev
if bond_bridge:
bond_dev = bond_bridge
ipaddr = dop.get("ifcfg", [bond_dev, "IPADDR"])
netmask = dop.get("ifcfg", [bond_dev, "NETMASK"])
gateway = dop.get("ifcfg", [bond_dev, "GATEWAY"])
bonding_opts = dop.get("ifcfg", [opts.dev, "BONDING_OPTS"])
bonding_opts = bonding_opts.strip('"')
primary_dev = None
for combination in bonding_opts.split(" "):
if re.match("primary", combination):
(key,val) = combination.split("=")
val = val.strip()
primary_dev = val
self.up_progress(10)
for restore_dev in restore_dev_list:
if move_file("%s/ifcfg-%s" % (VENDOR_DATA_BONDING_EVACUATION_DIR, restore_dev), NETWORK_IFCFG_DIR) is False:
raise KssCommandException('Failure restore ifcfg file.')
if os.path.isfile("%s/ifcfg-p%s" % (VENDOR_DATA_BONDING_EVACUATION_DIR, restore_dev)):
if move_file("%s/ifcfg-p%s" % (VENDOR_DATA_BONDING_EVACUATION_DIR, restore_dev), NETWORK_IFCFG_DIR) is False:
raise KssCommandException('Failure restore ifcfg file.')
self.up_progress(10)
if opts.succession is True and primary_dev is not None:
dop = DictOp()
ifcfg_parser = ifcfgParser()
dop.addconf("ifcfg", ifcfg_parser.read_conf())
if dop.getconf("ifcfg") == {}:
raise KssCommandException('Failure read network config file.')
if ipaddr:
dop.set("ifcfg", [primary_dev, "IPADDR"], ipaddr)
if netmask:
dop.set("ifcfg", [primary_dev, "NETMASK"], netmask)
if gateway:
dop.set("ifcfg", [primary_dev, "GATEWAY"], gateway)
if ifcfg_parser.write_conf(dop.getconf("ifcfg")) is False:
raise KssCommandException('Failure write network config file.')
self.up_progress(10)
remove_file("%s/ifcfg-%s" % (NETWORK_IFCFG_DIR, opts.dev))
self.up_progress(10)
dop = DictOp()
modprobe_parser = modprobe_confParser()
dop.addconf("modprobe_conf", modprobe_parser.read_conf())
if dop.getconf("modprobe_conf") == {}:
raise KssCommandException('Failure read modprobe config file.')
dop.unset("modprobe_conf", ["alias", opts.dev])
if modprobe_parser.write_conf(dop.getconf("modprobe_conf")) is False:
raise KssCommandException('Failure write modprobe config file.')
self.up_progress(10)
#
# Delete bridge device
#
bridge_list = get_bridge_info()
bond_bridge = None
for bridge in bridge_list:
if opts.dev in bridge_list[bridge]:
bond_bridge = bridge
if bond_bridge:
ifdown_cmd = (NETWORK_IFDOWN_COMMAND,
bond_bridge,
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from karesansui.lib.dict_op import DictOp [as 别名]
# 或者: from karesansui.lib.dict_op.DictOp import unset [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