我的任务是使用virt install创建虚拟设备,方法是将其编写为shell脚本。如何在python脚本中实现相同的目标?我对virt安装和python都是新手。谢谢!在
virt-install \
--name centos7 \
--ram 1024 \
--disk path=./centos7.qcow2,size=8 \
--vcpus 1 \
--os-type linux \
--os-variant centos7 \
--network bridge=virbr0 \
--graphics none \
--console pty,target_type=serial \
--location 'http://mirror.i3d.net/pub/centos/7/os/x86_64/' \
--extra-args 'console=ttyS0,115200n8 serial'
在(virtinstall.sh版)运行良好。在
使用python
os.system()
os.system('virt-install name centos7 ram 1024 disk path=./centos7.qcow2,size=8 vcpus 1 os-type linux os-variant centos7 network bridge=virbr0 graphics none console pty,target_type=serial location 'http://mirror.i3d.net/pub/centos/7/os/x86_64/' extra-args 'console=ttyS0,115200n8 serial'')
或使用^{
例如:
from subprocess import call
call('ls')
您可以使用子流程。 下面是一个示例:
libvirt有一个python接口。因此,如果您计划使用Python—可以直接使用Python接口。在
http://www.ibm.com/developerworks/library/os-python-kvm-scripting1/
相关问题 更多 >
编程相关推荐