本文整理汇总了Python中storlever.lib.command.check_output函数的典型用法代码示例。如果您正苦于以下问题:Python check_output函数的具体用法?Python check_output怎么用?Python check_output使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_output函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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))
示例2: 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))
示例3: 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))
示例4: 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))
示例5: 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))
示例6: 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))
示例7: get_module_info
def get_module_info(self, module_name):
""" get the specific module info/state in the storlever Manager layer
"""
if module_name not in self.managed_modules:
raise StorLeverError("Module(%s) Not Found" % (module_name), 404)
module_conf = self.managed_modules[module_name]
deps_info_list = []
for rpm in module_conf["rpms"]:
installed = True
try:
check_output([RPM_CMD, "-q", rpm])
except StorLeverCmdError:
installed = False
deps_info_list.append({
"name": rpm,
"type": "rpm",
"installed": installed
})
for file_path in module_conf["extra_files"]:
deps_info_list.append({
"name": file_path,
"type": "file",
"installed": os.path.exists(file_path)
})
module_info = {
"module_name": module_conf["module_name"],
"requires": deps_info_list,
"comment": module_conf["comment"],
}
return module_info
示例8: get_smart_info
def get_smart_info(self):
if self.dev_file == "":
raise StorLeverError("scsi_id (%s) has not be recognized" % self.scsi_id, 400)
output = check_output([SMARTCTL_CMD, "-i", "-T", "verypermissive", self.dev_file])
smart_enabled = False
auto_offline_enabled = False
if "SMART support is: Enabled" in output:
smart_enabled = True
output = check_output([SMARTCTL_CMD, "-a", "-T", "verypermissive", self.dev_file])
if "Auto Offline Data Collection: Enabled" in output:
auto_offline_enabled = True
# filter the copyright
lines = output.splitlines()
for index, line in enumerate(lines):
if line == "":
break
else:
index = 0
detail = "\n".join(lines[index + 1:])
info = {
"smart_enabled": smart_enabled,
"auto_offline_enabled": auto_offline_enabled,
"detail": detail
}
return info
示例9: 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))
示例10: _is_nfs_service_available
def _is_nfs_service_available(ip, mount_options):
proto = Nfs._get_nfs_transport_proto(mount_options)
if proto == "": # detect automatically
cmd = [RPCINFO_CMD, "-s", ip]
try:
result = check_output(cmd)
if "nfs" in result:
return True
except StorLeverCmdError as e:
if e.return_code == 1:
pass
else:
raise
else:
if proto == "udp":
cmd = [RPCINFO_CMD, "-u", ip, "nfs"]
elif proto == "tcp":
cmd = [RPCINFO_CMD, "-t", ip, "nfs"]
try:
result = check_output(cmd)
return True
except StorLeverCmdError as e:
if e.return_code == 1:
pass
else:
raise
return False
示例11: discovery
def discovery(self, portal, iface_name=None):
# delete the config for this dicovery
try:
check_output([ISCSIADM_CMD, "-m", "discoverydb", "-t", "st",
"-p", portal, "-o", "delete"])
except StorLeverError:
pass
# discovery process
cmd = [ISCSIADM_CMD, "-m", "discovery", "-t", "st", "-p", portal]
if iface_name is not None:
cmd.append("-I")
cmd.append(iface_name)
outlines = check_output(cmd, input_ret=[2, 6, 7, 21, 22]).splitlines()
result = []
for line in outlines:
line_list = line.split()
target = line_list[1]
portal, sep, tag = line_list[0].partition(",")
result.append({
"portal": portal,
"target": target
})
return result
示例12: set_state
def set_state(self, state, operator="unkown"):
if state == "offline":
check_output([TGTADMIN_CMD, "--offline", self.iqn])
elif state == "ready":
check_output([TGTADMIN_CMD, "--ready", self.iqn])
else:
raise StorLeverError("state (%s) is not supported" %
(state), 400)
示例13: group_del_by_name
def group_del_by_name(self, name, user="unknown"):
if name == "root":
raise StorLeverError("cannot del group root", 400)
cmds = ["/usr/sbin/groupdel"]
cmds.append(name)
check_output(cmds, input_ret=[2, 6, 8])
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"System group %s is deleted by user(%s)" %
(name, user))
示例14: remove_component
def remove_component(self, device):
fail_cmd = '/sbin/mdadm {0} --fail {1}'.format(self.dev_file, device)
remove_cmd = '/sbin/mdadm {0} --remove {1}'.format(self.dev_file, device)
with self._lock:
check_output(fail_cmd.split())
check_output(remove_cmd.split())
self.refresh()
logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
"Block device {0} detached from MD {1} created successfully".format(device, self.dev_file))
示例15: move
def move(self, dst_device=None, lv_name=None):
cmd = ["pvmove", "-b"]
if lv_name:
cmd.append("-n")
cmd.append(lv_name)
cmd.append(self.dev_file)
if dst_device:
cmd.append(dst_device)
check_output(cmd)