Skip to content

Commit

Permalink
Merge pull request ClusterLabs#445 from nirarg/fence-kubevirt
Browse files Browse the repository at this point in the history
fence_kubevirt: Fix kubevirt VM status
  • Loading branch information
oalbrigt authored Nov 2, 2021
2 parents 1c423ab + c23bfc3 commit 04e0832
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions agents/kubevirt/fence_kubevirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
from fencing import fail, fail_usage, run_delay, EC_STATUS
from fencing import fail, fail_usage, run_delay, EC_STATUS, EC_FETCH_VM_UUID

try:
from kubernetes.client.exceptions import ApiException
Expand Down Expand Up @@ -35,20 +35,27 @@ def get_power_status(conn, options):
vmi_api = conn.resources.get(api_version=apiversion,
kind='VirtualMachineInstance')
vmi = vmi_api.get(name=name, namespace=namespace)
if vmi is not None:
phase = vmi.status.phase
if phase == "Running":
return "on"
return "off"
return translate_status(vmi.status.phase)
except ApiException as e:
if e.status == 404:
try:
vm_api = conn.resources.get(api_version=apiversion, kind='VirtualMachine')
vm = vm_api.get(name=name, namespace=namespace)
except ApiException as e:
logging.error("VM %s doesn't exist", name)
fail(EC_FETCH_VM_UUID)
return "off"
logging.error("Failed to get power status, with API Exception: %s", e)
fail(EC_STATUS)
except Exception as e:
logging.error("Failed to get power status, with Exception: %s", e)
fail(EC_STATUS)

def translate_status(instance_status):
if instance_status == "Running":
return "on"
return "unknown"

def set_power_status(conn, options):
logging.debug("Starting set status operation")
try:
Expand Down

0 comments on commit 04e0832

Please sign in to comment.