Use custom strtobool to handle weird edge cases

This commit is contained in:
Joshua Boniface 2020-03-06 09:40:13 -05:00
parent 36588a3a81
commit d36d8e0637
3 changed files with 24 additions and 3 deletions

View File

@ -28,7 +28,7 @@ import gevent.pywsgi
import flask
from distutils.util import strtobool
from distutils.util import strtobool as dustrtobool
from functools import wraps
@ -45,6 +45,13 @@ from flask_sqlalchemy import SQLAlchemy
API_VERSION = 1.0
def strtobool(stringv):
if stringv is None:
return False
if isinstance(stringv, bool):
return bool(stringv)
return bool(dustrtobool(stringv))
# Parse the configuration file
try:
pvc_config_file = os.environ['PVC_CONFIG_FILE']

View File

@ -24,7 +24,7 @@ import flask
import json
import lxml.etree as etree
from distutils.util import strtobool
from distutils.util import strtobool as dustrtobool
import daemon_lib.common as pvc_common
import daemon_lib.cluster as pvc_cluster
@ -33,6 +33,13 @@ import daemon_lib.vm as pvc_vm
import daemon_lib.network as pvc_network
import daemon_lib.ceph as pvc_ceph
def strtobool(stringv):
if stringv is None:
return False
if isinstance(stringv, bool):
return bool(stringv)
return bool(dustrtobool(stringv))
#
# Initialization function
#

View File

@ -30,7 +30,7 @@ import time
import shlex
import subprocess
from distutils.util import strtobool
from distutils.util import strtobool as dustrtobool
import daemon_lib.common as pvc_common
import daemon_lib.node as pvc_node
@ -42,6 +42,13 @@ import pvcapid.libvirt_schema as libvirt_schema
from pvcapid.ova import list_ova
def strtobool(stringv):
if stringv is None:
return False
if isinstance(stringv, bool):
return bool(stringv)
return bool(dustrtobool(stringv))
#
# Exceptions (used by Celery tasks)
#