Revamp ordering and spacing of libvirt XML
This commit is contained in:
parent
1377c15948
commit
911965c1f3
|
@ -28,8 +28,7 @@
|
||||||
# * vm_memory
|
# * vm_memory
|
||||||
# * vm_vcpus
|
# * vm_vcpus
|
||||||
# * vm_architecture
|
# * vm_architecture
|
||||||
libvirt_header = """
|
libvirt_header = """<domain type='kvm'>
|
||||||
<domain type='kvm'>
|
|
||||||
<name>{vm_name}</name>
|
<name>{vm_name}</name>
|
||||||
<uuid>{vm_uuid}</uuid>
|
<uuid>{vm_uuid}</uuid>
|
||||||
<description>{vm_description}</description>
|
<description>{vm_description}</description>
|
||||||
|
@ -57,14 +56,11 @@ libvirt_header = """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# File footer, closing devices and domain elements
|
# File footer, closing devices and domain elements
|
||||||
libvirt_footer = """
|
libvirt_footer = """ </devices>
|
||||||
</devices>
|
</domain>"""
|
||||||
</domain>
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Default devices for all VMs
|
# Default devices for all VMs
|
||||||
devices_default = """
|
devices_default = """ <emulator>/usr/bin/kvm</emulator>
|
||||||
<emulator>/usr/bin/kvm</emulator>
|
|
||||||
<controller type='usb' index='0'/>
|
<controller type='usb' index='0'/>
|
||||||
<controller type='pci' index='0' model='pci-root'/>
|
<controller type='pci' index='0' model='pci-root'/>
|
||||||
<rng model='virtio'>
|
<rng model='virtio'>
|
||||||
|
@ -76,8 +72,7 @@ devices_default = """
|
||||||
# Serial device
|
# Serial device
|
||||||
# Variables:
|
# Variables:
|
||||||
# * vm_name
|
# * vm_name
|
||||||
devices_serial = """
|
devices_serial = """ <serial type='pty'>
|
||||||
<serial type='pty'>
|
|
||||||
<log file='/var/log/libvirt/{vm_name}.log' append='on'/>
|
<log file='/var/log/libvirt/{vm_name}.log' append='on'/>
|
||||||
</serial>
|
</serial>
|
||||||
<console type='pty'/>
|
<console type='pty'/>
|
||||||
|
@ -88,13 +83,11 @@ devices_serial = """
|
||||||
# * vm_vncport
|
# * vm_vncport
|
||||||
# * vm_vnc_autoport
|
# * vm_vnc_autoport
|
||||||
# * vm_vnc_bind
|
# * vm_vnc_bind
|
||||||
devices_vnc = """
|
devices_vnc = """ <graphics type='vnc' port='{vm_vncport}' autoport='{vm_vnc_autoport}' listen='{vm_vnc_bind}'/>
|
||||||
<graphics type='vnc' port='{vm_vncport}' autoport='{vm_vnc_autoport}' listen='{vm_vnc_bind}'/>
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# VirtIO SCSI device
|
# VirtIO SCSI device
|
||||||
devices_scsi_controller = """
|
devices_scsi_controller = """ <controller type='scsi' index='0' model='virtio-scsi'/>
|
||||||
<controller type='scsi' index='0' model='virtio-scsi'/>
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Disk device header
|
# Disk device header
|
||||||
|
@ -103,8 +96,7 @@ devices_scsi_controller = """
|
||||||
# * disk_pool
|
# * disk_pool
|
||||||
# * vm_name
|
# * vm_name
|
||||||
# * disk_id
|
# * disk_id
|
||||||
devices_disk_header = """
|
devices_disk_header = """ <disk type='network' device='disk'>
|
||||||
<disk type='network' device='disk'>
|
|
||||||
<driver name='qemu' discard='unmap'/>
|
<driver name='qemu' discard='unmap'/>
|
||||||
<target dev='{disk_id}' bus='scsi'/>
|
<target dev='{disk_id}' bus='scsi'/>
|
||||||
<auth username='libvirt'>
|
<auth username='libvirt'>
|
||||||
|
@ -117,19 +109,16 @@ devices_disk_header = """
|
||||||
# Variables:
|
# Variables:
|
||||||
# * coordinator_name
|
# * coordinator_name
|
||||||
# * coordinator_ceph_mon_port
|
# * coordinator_ceph_mon_port
|
||||||
devices_disk_coordinator = """
|
devices_disk_coordinator = """ <host name='{coordinator_name}' port='{coordinator_ceph_mon_port}'/>
|
||||||
<host name='{coordinator_name}' port='{coordinator_ceph_mon_port}'/>
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Disk device footer
|
# Disk device footer
|
||||||
devices_disk_footer = """
|
devices_disk_footer = """ </source>
|
||||||
</source>
|
|
||||||
</disk>
|
</disk>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# vhostmd virtualization passthrough device
|
# vhostmd virtualization passthrough device
|
||||||
devices_vhostmd = """
|
devices_vhostmd = """ <disk type='file' device='disk'>
|
||||||
<disk type='file' device='disk'>
|
|
||||||
<drive name='qemu' type='raw'/>
|
<drive name='qemu' type='raw'/>
|
||||||
<source file='/dev/shm/vhostmd0'/>
|
<source file='/dev/shm/vhostmd0'/>
|
||||||
<target dev='sdz' bus='usb'/>
|
<target dev='sdz' bus='usb'/>
|
||||||
|
@ -141,8 +130,7 @@ devices_vhostmd = """
|
||||||
# Variables:
|
# Variables:
|
||||||
# * eth_macaddr
|
# * eth_macaddr
|
||||||
# * eth_bridge
|
# * eth_bridge
|
||||||
devices_net_interface = """
|
devices_net_interface = """ <interface type='bridge'>
|
||||||
<interface type='bridge'>
|
|
||||||
<mac address='{eth_macaddr}'/>
|
<mac address='{eth_macaddr}'/>
|
||||||
<source bridge='{eth_bridge}'/>
|
<source bridge='{eth_bridge}'/>
|
||||||
<model type='virtio'/>
|
<model type='virtio'/>
|
||||||
|
|
|
@ -781,7 +781,7 @@ def create_vm(self, vm_name, vm_profile):
|
||||||
if not target_node:
|
if not target_node:
|
||||||
raise ClusterError("No ready cluster node contains at least {}+512 MB of free RAM".format(vm_data['system_details']['vram_mb']))
|
raise ClusterError("No ready cluster node contains at least {}+512 MB of free RAM".format(vm_data['system_details']['vram_mb']))
|
||||||
|
|
||||||
print("Selecting target node {} with {} MB free ram".format(target_node, last_free))
|
print("Selecting target node {} with {} MB free RAM".format(target_node, last_free))
|
||||||
|
|
||||||
# Verify that all configured networks are present on the cluster
|
# Verify that all configured networks are present on the cluster
|
||||||
cluster_networks, _discard = pvc_network.getClusterNetworkList(zk_conn)
|
cluster_networks, _discard = pvc_network.getClusterNetworkList(zk_conn)
|
||||||
|
@ -1005,59 +1005,7 @@ def create_vm(self, vm_name, vm_profile):
|
||||||
vm_memory=vm_data['system_details']['vram_mb'],
|
vm_memory=vm_data['system_details']['vram_mb'],
|
||||||
vm_vcpus=vm_data['system_details']['vcpu_count'],
|
vm_vcpus=vm_data['system_details']['vcpu_count'],
|
||||||
vm_architecture=system_architecture
|
vm_architecture=system_architecture
|
||||||
).strip()
|
)
|
||||||
|
|
||||||
# Add default devices
|
|
||||||
vm_schema += libvirt_schema.devices_default.strip()
|
|
||||||
|
|
||||||
# Add serial device
|
|
||||||
if vm_data['system_details']['serial']:
|
|
||||||
vm_schema += libvirt_schema.devices_serial.format(
|
|
||||||
vm_name=vm_name
|
|
||||||
).strip()
|
|
||||||
|
|
||||||
# Add VNC device
|
|
||||||
if vm_data['system_details']['vnc']:
|
|
||||||
if vm_data['system_details']['vnc_bind']:
|
|
||||||
vm_vnc_bind = vm_data['system_details']['vnc_bind']
|
|
||||||
else:
|
|
||||||
vm_vnc_bind = "127.0.0.1"
|
|
||||||
|
|
||||||
vm_vncport = 5900
|
|
||||||
vm_vnc_autoport = "yes"
|
|
||||||
|
|
||||||
vm_schema += libvirt_schema.devices_vnc.format(
|
|
||||||
vm_vncport=vm_vncport,
|
|
||||||
vm_vnc_autoport=vm_vnc_autoport,
|
|
||||||
vm_vnc_bind=vm_vnc_bind
|
|
||||||
).strip()
|
|
||||||
|
|
||||||
# Add SCSI controller
|
|
||||||
vm_schema += libvirt_schema.devices_scsi_controller.strip()
|
|
||||||
|
|
||||||
# Add disk devices
|
|
||||||
monitor_list = list()
|
|
||||||
coordinator_names = config['storage_hosts']
|
|
||||||
for coordinator in coordinator_names:
|
|
||||||
monitor_list.append("{}.{}".format(coordinator, config['storage_domain']))
|
|
||||||
|
|
||||||
ceph_storage_secret = config['ceph_storage_secret_uuid']
|
|
||||||
|
|
||||||
for volume in vm_data['volumes']:
|
|
||||||
vm_schema += libvirt_schema.devices_disk_header.format(
|
|
||||||
ceph_storage_secret=ceph_storage_secret,
|
|
||||||
disk_pool=volume['pool'],
|
|
||||||
vm_name=vm_name,
|
|
||||||
disk_id=volume['disk_id']
|
|
||||||
).strip()
|
|
||||||
for monitor in monitor_list:
|
|
||||||
vm_schema += libvirt_schema.devices_disk_coordinator.format(
|
|
||||||
coordinator_name=monitor,
|
|
||||||
coordinator_ceph_mon_port=config['ceph_monitor_port']
|
|
||||||
).strip()
|
|
||||||
vm_schema += libvirt_schema.devices_disk_footer.strip()
|
|
||||||
|
|
||||||
vm_schema += libvirt_schema.devices_vhostmd.strip()
|
|
||||||
|
|
||||||
# Add network devices
|
# Add network devices
|
||||||
network_id = 0
|
network_id = 0
|
||||||
|
@ -1093,11 +1041,64 @@ def create_vm(self, vm_name, vm_profile):
|
||||||
vm_schema += libvirt_schema.devices_net_interface.format(
|
vm_schema += libvirt_schema.devices_net_interface.format(
|
||||||
eth_macaddr=eth_macaddr,
|
eth_macaddr=eth_macaddr,
|
||||||
eth_bridge=eth_bridge
|
eth_bridge=eth_bridge
|
||||||
).strip()
|
)
|
||||||
|
|
||||||
network_id += 1
|
network_id += 1
|
||||||
|
|
||||||
vm_schema += libvirt_schema.libvirt_footer.strip()
|
# Add disk devices
|
||||||
|
monitor_list = list()
|
||||||
|
coordinator_names = config['storage_hosts']
|
||||||
|
for coordinator in coordinator_names:
|
||||||
|
monitor_list.append("{}.{}".format(coordinator, config['storage_domain']))
|
||||||
|
|
||||||
|
ceph_storage_secret = config['ceph_storage_secret_uuid']
|
||||||
|
|
||||||
|
for volume in vm_data['volumes']:
|
||||||
|
vm_schema += libvirt_schema.devices_disk_header.format(
|
||||||
|
ceph_storage_secret=ceph_storage_secret,
|
||||||
|
disk_pool=volume['pool'],
|
||||||
|
vm_name=vm_name,
|
||||||
|
disk_id=volume['disk_id']
|
||||||
|
)
|
||||||
|
for monitor in monitor_list:
|
||||||
|
vm_schema += libvirt_schema.devices_disk_coordinator.format(
|
||||||
|
coordinator_name=monitor,
|
||||||
|
coordinator_ceph_mon_port=config['ceph_monitor_port']
|
||||||
|
)
|
||||||
|
vm_schema += libvirt_schema.devices_disk_footer
|
||||||
|
|
||||||
|
vm_schema += libvirt_schema.devices_vhostmd
|
||||||
|
|
||||||
|
# Add default devices
|
||||||
|
vm_schema += libvirt_schema.devices_default
|
||||||
|
|
||||||
|
# Add serial device
|
||||||
|
if vm_data['system_details']['serial']:
|
||||||
|
vm_schema += libvirt_schema.devices_serial.format(
|
||||||
|
vm_name=vm_name
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add VNC device
|
||||||
|
if vm_data['system_details']['vnc']:
|
||||||
|
if vm_data['system_details']['vnc_bind']:
|
||||||
|
vm_vnc_bind = vm_data['system_details']['vnc_bind']
|
||||||
|
else:
|
||||||
|
vm_vnc_bind = "127.0.0.1"
|
||||||
|
|
||||||
|
vm_vncport = 5900
|
||||||
|
vm_vnc_autoport = "yes"
|
||||||
|
|
||||||
|
vm_schema += libvirt_schema.devices_vnc.format(
|
||||||
|
vm_vncport=vm_vncport,
|
||||||
|
vm_vnc_autoport=vm_vnc_autoport,
|
||||||
|
vm_vnc_bind=vm_vnc_bind
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add SCSI controller
|
||||||
|
vm_schema += libvirt_schema.devices_scsi_controller
|
||||||
|
|
||||||
|
# Add footer
|
||||||
|
vm_schema += libvirt_schema.libvirt_footer
|
||||||
|
|
||||||
print("Final VM schema:\n{}\n".format(vm_schema))
|
print("Final VM schema:\n{}\n".format(vm_schema))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue