libvirt: Extract method _guest_add_watchdog_action

Partial-Bug: #1494374
Change-Id: Iff818bcd2416e57e8724a07f158b577e1a60a8fd
Signed-off-by: Maciej Kucia <maciej@kucia.net>
This commit is contained in:
Maciej Kucia 2017-06-04 23:55:45 +02:00
parent 81ab39e21f
commit d3aae9684c
1 changed files with 18 additions and 15 deletions

View File

@ -4814,21 +4814,7 @@ class LibvirtDriver(driver.ComputeDriver):
self._guest_add_pci_devices(guest, instance)
# 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)
self._guest_add_watchdog_action(guest, flavor, image_meta)
# Memory balloon device only support 'qemu/kvm' and 'xen' hypervisor
if (virt_type in ('xen', 'qemu', 'kvm') and
@ -4843,6 +4829,23 @@ class LibvirtDriver(driver.ComputeDriver):
return guest
@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)
def _guest_add_pci_devices(self, guest, instance):
virt_type = guest.virt_type
if virt_type in ('xen', 'qemu', 'kvm'):