Repository URL to install this package:
|
Version:
6.0.24.1.dev2 ▾
|
python3-workloadmgrclient
/
usr
/
lib
/
python3
/
dist-packages
/
workloadmgrclient
/
v1
/
validators.py
|
|---|
# Copyright (c) 2014 TrilioData, Inc
# All Rights Reserved.
import re
import uuid
from workloadmgrclient import exceptions
from datetime import datetime
def validate_int_value(value, lower_bound, upper_bound=None, **kwargs):
if isinstance(value, str):
try:
value = int(value)
except ValueError:
return False
if value < lower_bound:
return False
if upper_bound and value > upper_bound:
return False
return True
def validate_uuid(id_val):
"""Check if id is valid UUID.
Raises:
InvalidUUIDException: Raise invalid uuid Exception.
"""
try:
uuid.UUID(id_val)
except (ValueError, TypeError) as ex:
raise exceptions.InvalidUUIDException("Invalid id : '{}'. Error: {}".format(id_val, ex))
def validate_date_value(value, date_formats):
for i in date_formats:
try:
datetime.strptime(value, i)
return True
except (ValueError, TypeError) as ex:
raise exceptions.InvalidDateException("Invalid date :{}. Should be passed in format {}".format(value, i))
def consume_quotes(string_value):
if ("'") in string_value:
return string_value.replace("'", "")
elif ('"') in string_value:
return string_value.replace('"', "")
return string_value
def contains_number_and_hr(input_string):
pattern = r'^\d+ ?hr$'
match = re.search(pattern, input_string)
if bool(match) is False:
raise exceptions.InvalidIntervalException("Invalid interval value: {}. Should be a natural number followed by hr".format(input_string))
def retention_policy_type(input_string):
if input_string.lower() not in ['number of snapshots to keep', 'number of days to retain snapshots']:
raise exceptions.InvalidRetentionPolicyType("Invalid retention_policy_type {}. Should be 'Number of Snapshots to Keep' or 'Number of days to retain Snapshots'".format(input_string))