本文整理汇总了Python中utils.fwrite函数的典型用法代码示例。如果您正苦于以下问题:Python fwrite函数的具体用法?Python fwrite怎么用?Python fwrite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fwrite函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_nexus
def _set_nexus(self, nexus_wwn=None):
'''
Sets the nexus initiator WWN. Raises an exception if the nexus is
already set or if the TPG does not use a nexus.
'''
self._check_self()
if not self.has_feature('nexus'):
raise RTSLibError("The TPG does not use a nexus.")
if self._get_nexus():
raise RTSLibError("The TPG's nexus initiator WWN is already set.")
# Nexus wwn type should match parent target
wwn_type = self.parent_target.wwn_type
if nexus_wwn:
# Not using fabric-specific version of normalize_wwn, since we
# want to make sure wwn conforms to regexp, but don't check
# against target wwn_list, since we're setting the "initiator" here.
nexus_wwn = normalize_wwn((wwn_type,), nexus_wwn)[0]
else:
nexus_wwn = generate_wwn(wwn_type)
fm = self.parent_target.fabric_module
fwrite("%s/nexus" % self.path, fm.to_fabric_wwn(nexus_wwn))
示例2: _set_discovery_password
def _set_discovery_password(self, password):
self._check_self()
self._assert_feature('discovery_auth')
path = "%s/discovery_auth/password" % self.path
if password.strip() == '':
password = "NULL"
fwrite(path, "%s" % password)
示例3: _set_write_protect
def _set_write_protect(self, write_protect):
self._check_self()
path = "%s/write_protect" % self.path
if write_protect:
fwrite(path, "1")
else:
fwrite(path, "0")
示例4: _set_discovery_userid
def _set_discovery_userid(self, userid):
self._check_self()
self._assert_feature('discovery_auth')
path = "%s/discovery_auth/userid" % self.path
if userid.strip() == '':
userid = "NULL"
fwrite(path, "%s" % userid)
示例5: _config_pr_aptpl
def _config_pr_aptpl(self):
"""
LIO actually *writes* pr aptpl info to the filesystem, so we
need to read it in and squirt it back into configfs when we configure
the storage object. BLEH.
"""
aptpl_dir = "/var/target/pr"
try:
lines = fread("%s/aptpl_%s" % (aptpl_dir, self.wwn)).split()
except:
return
if not lines[0].startswith("PR_REG_START:"):
return
reservations = []
for line in lines:
if line.startswith("PR_REG_START:"):
res_list = []
elif line.startswith("PR_REG_END:"):
reservations.append(res_list)
else:
res_list.append(line.strip())
for res in reservations:
fwrite(self.path + "/pr/res_aptpl_metadata", ",".join(res))
示例6: restore_pr_aptpl
def restore_pr_aptpl(self, src_path=None):
'''
Restores StorageObject persistent reservations read from src_path.
If src_path is omitted, uses the default LIO PR APTPL system
path if it exists. This only works if the StorageObject is not
in use currently, else an IO error will occur.
@param src_path: The PR metadata file path.
@type src_path: string or None
'''
dst_path = "%s/pr/res_aptpl_metadata" % self.path
if src_path is None:
src_path = "%s/aptpl_%s" % (self.pr_aptpl_metadata_dir, self.wwn)
if not os.path.isfile(src_path):
return
lines = fread(src_path).split()
if not lines[0].startswith("PR_REG_START:"):
return
for line in lines:
if line.startswith("PR_REG_START:"):
pr_lines = []
elif line.startswith("PR_REG_END:"):
fwrite(dst_path, ",".join(pr_lines))
else:
pr_lines.append(line.strip())
示例7: _set_iser
def _set_iser(self, boolean):
path = "%s/iser" % self.path
try:
fwrite(path, str(int(boolean)))
except IOError:
# b/w compat: don't complain if iser entry is missing
if os.path.isfile(path):
raise RTSLibError("Cannot change iser")
示例8: _set_wwn
def _set_wwn(self, wwn):
self._check_self()
if self.is_configured():
path = "%s/wwn/vpd_unit_serial" % self.path
fwrite(path, "%s\n" % wwn)
else:
raise RTSLibError("Cannot write a T10 WWN Unit Serial to "
+ "an unconfigured StorageObject")
示例9: _set_tcq_depth
def _set_tcq_depth(self, depth):
self._check_self()
path = "%s/cmdsn_depth" % self.path
try:
fwrite(path, "%s" % depth)
except IOError, msg:
msg = msg[1]
raise RTSLibError("Cannot set tcq_depth: %s" % str(msg))
示例10: _set_discovery_enable_auth
def _set_discovery_enable_auth(self, enable):
self._check_self()
self._assert_feature('discovery_auth')
path = "%s/discovery_auth/enforce_discovery_auth" % self.path
if int(enable):
enable = 1
else:
enable = 0
fwrite(path, "%s" % enable)
示例11: _set_iser_attr
def _set_iser_attr(self, iser_attr):
path = "%s/iser" % self.path
if os.path.isfile(path):
if iser_attr:
fwrite(path, "1")
else:
fwrite(path, "0")
else:
raise RTSLibError("iser network portal attribute does not exist.")
示例12: delete
def delete(self):
'''
Delete the NetworkPortal.
'''
path = "%s/iser" % self.path
if os.path.isfile(path):
iser_attr = fread(path).strip()
if iser_attr == "1":
fwrite(path, "0")
super(NetworkPortal, self).delete()
示例13: _set_enable
def _set_enable(self, boolean):
'''
Enables or disables the TPG. Raises an error if trying to disable a TPG
without an enable attribute (but enabling works in that case).
'''
self._check_self()
path = "%s/enable" % self.path
if os.path.isfile(path) and (boolean != self._get_enable()):
try:
fwrite(path, str(int(boolean)))
except IOError, e:
raise RTSLibError("Cannot change enable state: %s" % e)
示例14: _set_enable
def _set_enable(self, boolean):
"""
Enables or disables the TPG. If the TPG doesn't support the enable
attribute, do nothing.
"""
self._check_self()
path = "%s/enable" % self.path
if os.path.isfile(path) and (boolean != self._get_enable()):
try:
fwrite(path, str(int(boolean)))
except IOError as e:
raise RTSLibError("Cannot change enable state: %s" % e)
示例15: _set_enable
def _set_enable(self, boolean):
'''
Enables or disables the TPG. Raises an error if trying to disable a TPG
without en enable attribute (but enabling works in that case).
'''
self._check_self()
path = "%s/enable" % self.path
if os.path.isfile(path):
if boolean and not self._get_enable():
fwrite(path, "1")
elif not boolean and self._get_enable():
fwrite(path, "0")
elif not boolean:
raise RTSLibError("TPG cannot be disabled.")