WINDOWS:
1.分析镜像
>>> import guestfs
>>> g = guestfs.GuestFS()
>>> g.add_drive_opts("/datapool/w2k3.qcow2")
>>> g.launth()
>>> root = g.inspect_os()
>>> root
['/dev/vda1']
>>> type = g.inspect_get_type(root[0])
>>> type
'windows'
>>> root_partition = g.inspect_get_roots()
>>> root_partition
['/dev/vda1']
>>> product_name = g.inspect_get_product_name(root[0])
>>> product_name
'Microsoft Windows Server 2003'
>>> system_root=g.inspect_get_windows_systemroot(root[0])
>>> system_root
'/WINDOWS'
>>> g.kill_subprocess()
2 . 准备Windows-Nic-ini
ipsetup:0
ip: 180.96.41.147
mask:255.255.255.0
gw:
mac:
ip:
mask:
gw:
mac:
3. virt-resize
virt-resize /datapool/w2k3.qcow2.bak /dev/vg/lv-created –expand /dev/vda1
4. 分新新卷,上传ini文件
g = guestfs.GuestFS()
g.add_drive_opts(“/dev/vg/lv-created”)
g.launch()
g.mount('/dev/vda1", '/')
g.upload(ini,'/WINDOWS/nicinfo.ini')
g.sync()
LINUX:
1.分析镜像
>>> g = guestfs.GuestFS()
>>> g.add_drive_opts("/datapool/cent6.qcow2.bak")
>>> g.launch()
>>> root = g.inspect_os()
>>> root
['/dev/VolGroup/lv_root']
>>> type = g.inspect_get_type(root[0])
>>> type
'linux'
>>> root_partition = g.inspect_get_roots()
>>> root_partition
['/dev/VolGroup/lv_root']
>>> product_name = g.inspect_get_product_name(root[0])
>>> product_name
'CentOS Linux release 6.0 (Final)'
>>> lvs = g.lvs()
>>> lvs
['/dev/VolGroup/lv_root', '/dev/VolGroup/lv_swap']
>>> vgs = g.vgs()
>>> vgs
['VolGroup']
>>> pvs = g.pvs_full()
>>> pvs
[{'pv_free': 0L, 'pv_uuid': 'RjdD6vFv1LjBgtamWKSoXbzJ4FyX3CcR', 'pv_attr': 'a--', 'pv_name': '/dev/vda2', 'pv_size': 20946354176L, 'pv_mda_count': 1L, 'pv_pe_count': 4994L, 'pv_pe_alloc_count': 4994L, 'pv_fmt': 'lvm2', 'pv_tags': '', 'dev_size': 20949499904L, 'pe_start': 1048576L, 'pv_used': 20946354176L, 'pv_mda_free': 520192L}]
>>> pvs[0]['pv_name'] 即 pv_partition
'/dev/vda2'
>>> mount_points=g.inspect_get_mountpoints(root[0])
>>> mount_points
[('/', '/dev/mapper/VolGroup-lv_root'), ('/boot', '/dev/vda1')]
Boot_partition = '/dev/vda1'
2 . 准备Linux- ifcfg-eth0
cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.93.2
NETMASK=255.255.255.0
GATEWAY=192.168.93.1
HWADDR=
3. virt-resize
有pv-partion:
virt-resize /datapool/cent6.qcow2.bak /dev/vg/lv-created –expand /dev/vda2 –lv-expand /dev/VolGroup/lv_root
4. 分新新卷,上传ini文件
g = guestfs.GuestFS()
g.add_drive_opts(“/dev/vg/lv-created”)
g.launch()
g.mount(“/dev/VolGroup/lv_root”, '/')
g.mount('/dev/vda1'”, '/boot')
tmp=g.list_devices()
g.grub_install('/',tmp[0])
g.upload(nic_cfg[k],'/etc/sysconfig/network-scripts/ifcfg-eth%d'%k)
COMPUTENODE
之后,对于linux和windows处理的流程是一样的:
1. virt-install命令创建虚拟机,并生成相应的XML文件。
2. 修改XML文件,修改devices->graphics->passwd及video等其他参数。
3. virsh define xml; virsh start name 开启虚拟机。
4. 从XML文件中获取vncport和uuid,更新数据库中的instance信息(s_Id,vnc_pwd, vnc_port, status, uuid)。