I am trying to make a script with python to duplicate VMs however I am getting the following error:
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
my code:
#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
Does anyone know if this is the right way to use the function call or subprocess in python? Because it works fine with the ls -l command for example.
I also print out the command that is executed, namely: sudo lvcreate -L3072 -s -n TestPrestashop1-disk /dev/ls2018-vg/Prestashop-disk (in variable S). If I manually execute the command it works just fine... Any suggestion would be greatly appreciated!!