openstack 声卡重定向代码修改
声卡重定向代码修改,这样使用Remote viewer软件就可以播放虚拟机的声音的
/nova/virt/libvirt/config.py 文件末尾添加
class LibvirtConfigGuestSound(LibvirtConfigObject):
def __init__(self, **kwargs):
super(LibvirtConfigGuestSound,
self).__init__(root_name='sound')
self.model = 'ich6'
def format_dom(self):
meta = self._new_node('sound')
meta.set('model', str(self.model))
return meta
nova/virt/libvirt/driver.py 把_guest_add_spice_sound方法添加上
@staticmethod
def _guest_add_memory_balloon(guest):
# Memory balloon device only support 'qemu/kvm' hypervisor
if (
CONF.libvirt.virt_type in ('qemu', 'kvm') and
CONF.libvirt.mem_stats_period_seconds > 0
):
balloon = vconfig.LibvirtConfigMemoryBalloon()
balloon.model = 'virtio'
balloon.period = CONF.libvirt.mem_stats_period_seconds
guest.add_device(balloon)
#add 添加这个方法
@staticmethod
def _guest_add_spice_sound(guest):
if (
CONF.spice.enabled and
CONF.libvirt.virt_type != 'lxc'
):
sounddev = vconfig.LibvirtConfigGuestSound()
guest.add_device(sounddev)
#end
@staticmethod
def _guest_add_watchdog_action(guest, flavor, image_meta):
# image meta takes precedence over flavor extra specs; disable the
# watchdog action by default
watchdog_action = (flavor.extra_specs.get('hw:watchdog_action') or
'disabled')
watchdog_action = image_meta.properties.get('hw_watchdog_action',
watchdog_action)
# NB(sross): currently only actually supported by KVM/QEmu
if watchdog_action != 'disabled':
if watchdog_action in fields.WatchdogAction.ALL:
bark = vconfig.LibvirtConfigGuestWatchdog()
bark.action = watchdog_action
guest.add_device(bark)
else:
raise exception.InvalidWatchdogAction(action=watchdog_action)
nova/virt/libvirt/driver.py 在 self._guest_add_spice_channel(guest)下边添加 self._guest_add_spice_sound(guest)这个方法即可
self._guest_add_spice_channel(guest)
self._guest_add_spice_sound(guest)
参考github