python - 使用 python 创建 LVM 存储
问题描述
我正在尝试使用 python 制作一个脚本来复制虚拟机,但是我收到以下错误:
sudo lvcreate -L3072 -s -n TestPrestashop1-disk /dev/ls2018-vg/Prestashop-disk
Traceback (most recent call last):
File "VMDuplicator.py", line 74, in <module>
main()
File "VMDuplicator.py", line 62, in main
createLV(True, amount)
File "VMDuplicator.py", line 37, in createLV
output = call(s)
File "/usr/lib/python2.7/subprocess.py", line 172, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
我的代码:
#create a new LVM storage and duplicate the prestashop disk into it and name it Prestashop[i]-disk / swap
def createLV(swap, amount):
i = 1
if(swap == False):
while(i < int(amount)):
try:
output = subprocess.check_output(["sudo lvcreate -L3072 -s -n TestPrestashop" + str(i) + " -disk /dev/ls2018-vg/Prestashop-disk"])
except subprocess.CalledProcessError, e:
return False
i += 1
return true
elif(swap == True):
while(i < int(amount)):
try:
s = "sudo lvcreate -L3072 -s -n TestPrestashop" + str(i) + "-disk /dev/ls2018-vg/Prestashop-disk"
print(s)
output = call(s)
#output = subprocess.check_output(["sudo lvcreate -L3072 -s -n TestPrestashop" + str(i) + "-disk /dev/ls2018-vg/Prestashop-disk"])
#output = subprocess.check_output([s])
#output = subprocess.check_output(["sudo lvcreate -L3072 -s -n TestPrestashop" + str(i) + "-swap /dev/ls2018-vg/Prestashop-swap"])
except subprocess.CalledProcessError, e:
return False
i += 1
return True
有谁知道这是否是在 python 中使用函数调用或子进程的正确方法?因为它适用于例如 ls -l 命令。
我还打印出执行的命令,即:sudo lvcreate -L3072 -s -n TestPrestashop1-disk /dev/ls2018-vg/Prestashop-disk(在变量 S 中)。如果我手动执行命令它工作得很好......任何建议将不胜感激!
解决方案
我用 os.system 调用修复了它。
推荐阅读
- javascript - DatatTables 列搜索逗号分隔 ID 的组合
- webpack - Webpack 块加载机制和安全性
- drupal-7 - 当 Paypal 退货状态为 Completed_Funds_Held 时,Drupal 无法创建订单
- python - 关于 pygame 使用 pyinstaller “执行脚本失败”错误
- ruby-on-rails - 在 Rails 上按日期然后按城市分组
- python - IndexError:列表索引超出范围:
- dagster - Dagster 配置 YAML 中的环境变量
- android - 在当前光标位置将文本插入 SearchView 查询
- javascript - 没有提供“id”的参数。角 11
- arrays - C语言指针问题