我正在尝试使用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--L3072 /dev/ls2018-vg/Prestashop-disk (在变量S中)。如果我手动执行这个命令,它就能正常工作...任何建议都将不胜感激!
发布于 2018-12-05 05:10:40
我用一个os.system调用修复了它。
https://stackoverflow.com/questions/53621213
复制相似问题