|
|
7a42dc |
From c23bfc3b9fc6e1dc7b1350e340171f3827fb6fb7 Mon Sep 17 00:00:00 2001
|
|
|
7a42dc |
From: Nir Argaman <nargaman@redhat.com>
|
|
|
7a42dc |
Date: Mon, 1 Nov 2021 08:34:00 +0200
|
|
|
7a42dc |
Subject: [PATCH] fence_kubevirt: Fix kubevirt VM status
|
|
|
7a42dc |
|
|
|
7a42dc |
---
|
|
|
7a42dc |
agents/kubevirt/fence_kubevirt.py | 19 +++++++++++++------
|
|
|
7a42dc |
1 file changed, 13 insertions(+), 6 deletions(-)
|
|
|
7a42dc |
|
|
|
7a42dc |
diff --git a/agents/kubevirt/fence_kubevirt.py b/agents/kubevirt/fence_kubevirt.py
|
|
|
7a42dc |
index 70c14d89a..61ffcaa09 100755
|
|
|
7a42dc |
--- a/agents/kubevirt/fence_kubevirt.py
|
|
|
7a42dc |
+++ b/agents/kubevirt/fence_kubevirt.py
|
|
|
7a42dc |
@@ -4,7 +4,7 @@
|
|
|
7a42dc |
import logging
|
|
|
7a42dc |
sys.path.append("@FENCEAGENTSLIBDIR@")
|
|
|
7a42dc |
from fencing import *
|
|
|
7a42dc |
-from fencing import fail, fail_usage, run_delay, EC_STATUS
|
|
|
7a42dc |
+from fencing import fail, fail_usage, run_delay, EC_STATUS, EC_FETCH_VM_UUID
|
|
|
7a42dc |
|
|
|
7a42dc |
try:
|
|
|
7a42dc |
from kubernetes.client.exceptions import ApiException
|
|
|
7a42dc |
@@ -35,13 +35,15 @@ def get_power_status(conn, options):
|
|
|
7a42dc |
vmi_api = conn.resources.get(api_version=apiversion,
|
|
|
7a42dc |
kind='VirtualMachineInstance')
|
|
|
7a42dc |
vmi = vmi_api.get(name=name, namespace=namespace)
|
|
|
7a42dc |
- if vmi is not None:
|
|
|
7a42dc |
- phase = vmi.status.phase
|
|
|
7a42dc |
- if phase == "Running":
|
|
|
7a42dc |
- return "on"
|
|
|
7a42dc |
- return "off"
|
|
|
7a42dc |
+ return translate_status(vmi.status.phase)
|
|
|
7a42dc |
except ApiException as e:
|
|
|
7a42dc |
if e.status == 404:
|
|
|
7a42dc |
+ try:
|
|
|
7a42dc |
+ vm_api = conn.resources.get(api_version=apiversion, kind='VirtualMachine')
|
|
|
7a42dc |
+ vm = vm_api.get(name=name, namespace=namespace)
|
|
|
7a42dc |
+ except ApiException as e:
|
|
|
7a42dc |
+ logging.error("VM %s doesn't exist", name)
|
|
|
7a42dc |
+ fail(EC_FETCH_VM_UUID)
|
|
|
7a42dc |
return "off"
|
|
|
7a42dc |
logging.error("Failed to get power status, with API Exception: %s", e)
|
|
|
7a42dc |
fail(EC_STATUS)
|
|
|
7a42dc |
@@ -49,6 +51,11 @@ def get_power_status(conn, options):
|
|
|
7a42dc |
logging.error("Failed to get power status, with Exception: %s", e)
|
|
|
7a42dc |
fail(EC_STATUS)
|
|
|
7a42dc |
|
|
|
7a42dc |
+def translate_status(instance_status):
|
|
|
7a42dc |
+ if instance_status == "Running":
|
|
|
7a42dc |
+ return "on"
|
|
|
7a42dc |
+ return "unknown"
|
|
|
7a42dc |
+
|
|
|
7a42dc |
def set_power_status(conn, options):
|
|
|
7a42dc |
logging.debug("Starting set status operation")
|
|
|
7a42dc |
try:
|