python脚本中的virtinstall

2024-04-20 11:40:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我的任务是使用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版)运行良好。在


Tags: install方法name脚本目标ostypeserial
2条回答

使用pythonos.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')

您可以使用子流程。 下面是一个示例:

>>> import subprocess
>>> subprocess.call('date')
Wed Jan  4 17:36:58 IST 2017
0
>>> 

libvirt有一个python接口。因此,如果您计划使用Python—可以直接使用Python接口。在

http://www.ibm.com/developerworks/library/os-python-kvm-scripting1/

相关问题 更多 >