Package ganeti :: Module ht
[hide private]
[frames] | no frames]

Module ht

source code

Module implementing the parameter types code.

Classes [hide private]
  _WrapperBase
  _DescWrapper
Wrapper class for description text.
  _CommentWrapper
Wrapper class for comment.
Functions [hide private]
 
Parens(text)
Enclose text in parens if necessary.
source code
 
WithDesc(text)
Builds wrapper class with description text.
source code
 
Comment(text)
Builds wrapper for adding comment to description text.
source code
 
CombinationDesc(op, args, fn)
Build description for combinating operator.
source code
 
EmptyList()
Returns an empty list.
source code
 
EmptyDict()
Returns an empty dict.
source code
 
TAny(_)
Accepts any value.
source code
 
TNotNone(val)
Checks if the given value is not None.
source code
 
TNone(val)
Checks if the given value is None.
source code
 
TValueNone(val)
Checks if the given value is constants.VALUE_NONE.
source code
 
TBool(val)
Checks if the given value is a boolean.
source code
 
TInt(val)
Checks if the given value is an integer.
source code
 
TFloat(val)
Checks if the given value is a float.
source code
 
TString(val)
Checks if the given value is a string.
source code
 
TTrue(val)
Checks if a given value evaluates to a boolean True value.
source code
 
TElemOf(target_list)
Builds a function that checks if a given value is a member of a list.
source code
 
TList(val)
Checks if the given value is a list.
source code
 
TTuple(val)
Checks if the given value is a tuple.
source code
 
TDict(val)
Checks if the given value is a dictionary.
source code
 
TIsLength(size)
Check is the given container is of the given size.
source code
 
TAnd(*args)
Combine multiple functions using an AND operation.
source code
 
TOr(*args)
Combine multiple functions using an OR operation.
source code
 
TMap(fn, test)
Checks that a modified version of the argument passes the given test.
source code
 
TRegex(pobj)
Checks whether a string matches a specific regular expression.
source code
 
TMaybe(test)
Wrap a test in a TOr(TNone, test).
source code
 
TMaybeValueNone(test)
Used for unsetting values.
source code
 
TMaybeBool(val)
a maybe boolean (bool or none)
source code
 
TMaybeDict(val)
Maybe a dictionary (dict or None)
source code
 
TMaybeList(val)
Maybe a list (list or None)
source code
 
TNonNegative(val_type)
a non-negative number (value > 0)
source code
 
TPositive(val_type)
a positive number (value >= 0)
source code
 
TNonNegativeInt(val)
a non-negative integer (value >= 0)
source code
 
TPositiveInt(val)
a positive integer (value > 0)
source code
 
TMaybePositiveInt(val)
a maybe positive integer (positive integer or None)
source code
 
TDouble(val)
Double (== Float)
source code
 
TInstanceOf(cls)
Checks if a given value is an instance of cls.
source code
 
TPrivate(val_type)
Checks if a given value is an instance of Private.
source code
 
TListOf(my_type)
Checks if a given value is a list with all elements of the same type.
source code
 
TTupleOf(*val_types)
Checks if a given value is a list with the proper size and its elements match the given types.
source code
 
TSetOf(val_type)
Checks if a given value is a list with all elements of the same type and eliminates duplicated elements.
source code
 
TDictOf(key_type, val_type)
Checks a dict type for the type of its key/values.
source code
 
_TStrictDictCheck(require_all, exclusive, items, val)
Helper function for TStrictDict.
source code
 
TStrictDict(require_all, exclusive, items)
Strict dictionary check with specific keys.
source code
 
TItems(items)
Checks individual items of a container.
source code
 
TSetParamsMods(fn)
Generates a check for modification lists.
source code
 
TStorageType(val)
Builds a function that checks if a given value is a valid storage type.
source code
 
_CheckCIDRNetNotation(value)
Ensure a given CIDR notation type is valid.
source code
 
_CheckCIDRAddrNotation(value)
Ensure a given CIDR notation type is valid.
source code
 
_CheckCIDR6AddrNotation(value)
Ensure a given CIDR notation type is valid.
source code
 
_CheckCIDR6NetNotation(value)
Ensure a given CIDR notation type is valid.
source code
 
TObject(val_type) source code
 
TObjectCheck(obj, fields_types)
Helper to generate type checks for objects.
source code
Variables [hide private]
  _PAREN_RE = re.compile("^[a-zA-Z0-9_-]+$")
  NoDefault = object()
The without-default default value
  TNonEmptyString = WithDesc("NonEmptyString")(TAnd(TString, TTr...
a non-empty string
  TMaybeString = TMaybe(TNonEmptyString)
a maybe non-empty string
  TNegativeInt = TAnd(TInt, WithDesc("LessThanZero")(compat.part...
a negative integer (value < 0)
  TNonNegativeFloat = TAnd(TFloat, WithDesc("EqualOrGreaterThanZ...
a positive float
  TJobId = WithDesc("JobId")(TOr(TNonNegativeInt, TRegex(re.comp...
Job ID
  TNumber = TOr(TInt, TFloat)
Number
  TRelativeJobId = WithDesc("RelativeJobId")(TNegativeInt)
Relative job ID
  TMaybeListOf = lambda item_type:
  TMaxValue = lambda max:
  TAllocPolicy = TElemOf(constants.VALID_ALLOC_POLICIES)
  TCVErrorCode = TElemOf(constants.CV_ALL_ECODES_STRINGS)
  TQueryResultCode = TElemOf(constants.RS_ALL)
  TExportTarget = TOr(TNonEmptyString, TList)
  TExportMode = TElemOf(constants.EXPORT_MODES)
  TDiskIndex = TAnd(TNonNegativeInt, TMaxValue(constants.MAX_DIS...
  TReplaceDisksMode = TElemOf(constants.REPLACE_MODES)
  TDiskTemplate = TElemOf(constants.DISK_TEMPLATES)
  TEvacMode = TElemOf(constants.NODE_EVAC_MODES)
  TIAllocatorTestDir = TElemOf(constants.VALID_IALLOCATOR_DIRECT...
  TIAllocatorMode = TElemOf(constants.VALID_IALLOCATOR_MODES)
  TImportExportCompression = TElemOf(constants.IEC_ALL)
  TAdminStateSource = TElemOf(constants.ADMIN_STATE_SOURCES)
  TINicParams = Comment("NIC parameters")(TDictOf(TElemOf(consta...
  TIDiskParams = Comment("Disk parameters")(TDictOf(TNonEmptyStr...
  THypervisor = TElemOf(constants.HYPER_TYPES)
  TMigrationMode = TElemOf(constants.HT_MIGRATION_MODES)
  TNICMode = TElemOf(constants.NIC_VALID_MODES)
  TInstCreateMode = TElemOf(constants.INSTANCE_CREATE_MODES)
  TRebootType = TElemOf(constants.REBOOT_TYPES)
  TFileDriver = TElemOf(constants.FILE_DRIVER)
  TOobCommand = TElemOf(constants.OOB_COMMANDS)
  TQueryTypeOp = TElemOf(set(constants.QR_VIA_OP).union(set(cons...
  TDiskParams = Comment("Disk parameters")(TDictOf(TNonEmptyStri...
  TDiskChanges = TAnd(TIsLength(2), TItems([Comment("Disk index"...
  TRecreateDisksInfo = TOr(TListOf(TNonNegativeInt), TListOf(TDi...
  TTagKind = TElemOf(constants.VALID_TAG_TYPES)
  TDdmSimple = TElemOf(constants.DDMS_VALUES)
  TVerifyOptionalChecks = TElemOf(constants.VERIFY_OPTIONAL_CHECKS)
  TIPv4Address = TAnd(TString, _CheckCIDRAddrNotation)
  TIPv6Address = TAnd(TString, _CheckCIDR6AddrNotation)
  TIPv4Network = TAnd(TString, _CheckCIDRNetNotation)
  TIPv6Network = TAnd(TString, _CheckCIDR6NetNotation)
  TQueryFieldDef = TObjectCheck(objects.QueryFieldDefinition, {"...
  TQueryRow = TListOf(TAnd(TIsLength(2), TItems([TElemOf(constan...
  TQueryResult = TListOf(TQueryRow)
  TQueryResponse = TObjectCheck(objects.QueryResponse, {"fields"...
  TQueryFieldsResponse = TObjectCheck(objects.QueryFieldsRespons...
  TJobIdListItem = TAnd(TIsLength(2), TItems([Comment("success")...
  TJobIdList = TListOf(TJobIdListItem)
  TJobIdListOnly = TStrictDict(True, True, {constants.JOB_IDS_KE...
  TInstanceMultiAllocResponse = TStrictDict(True, True, {constan...

Imports: re, operator, ipaddr, compat, utils, constants, objects, Private


Function Details [hide private]

Parens(text)

source code 

Enclose text in parens if necessary.

Parameters:
  • text - Text

WithDesc(text)

source code 

Builds wrapper class with description text.

Parameters:
  • text (string) - Description text
Returns:
Callable class

Comment(text)

source code 

Builds wrapper for adding comment to description text.

Parameters:
  • text (string) - Comment text
Returns:
Callable class

CombinationDesc(op, args, fn)

source code 

Build description for combinating operator.

Parameters:
  • op (string) - Operator as text (e.g. "and")
  • args (list) - Operator arguments
  • fn (callable) - Wrapped function

EmptyList()

source code 

Returns an empty list.

Decorators:
  • @WithDesc(str([]))

EmptyDict()

source code 

Returns an empty dict.

Decorators:
  • @WithDesc(str({}))

TAny(_)

source code 

Accepts any value.

Decorators:
  • @WithDesc("Anything")

TNotNone(val)

source code 

Checks if the given value is not None.

Decorators:
  • @WithDesc("NotNone")

TNone(val)

source code 

Checks if the given value is None.

Decorators:
  • @WithDesc("None")

TValueNone(val)

source code 

Checks if the given value is constants.VALUE_NONE.

Decorators:
  • @WithDesc("ValueNone")

TBool(val)

source code 

Checks if the given value is a boolean.

Decorators:
  • @WithDesc("Boolean")

TInt(val)

source code 

Checks if the given value is an integer.

Decorators:
  • @WithDesc("Integer")

TFloat(val)

source code 

Checks if the given value is a float.

Decorators:
  • @WithDesc("Float")

TString(val)

source code 

Checks if the given value is a string.

Decorators:
  • @WithDesc("String")

TTrue(val)

source code 

Checks if a given value evaluates to a boolean True value.

Decorators:
  • @WithDesc("EvalToTrue")

TList(val)

source code 

Checks if the given value is a list.

Decorators:
  • @WithDesc("List")

TTuple(val)

source code 

Checks if the given value is a tuple.

Decorators:
  • @WithDesc("Tuple")

TDict(val)

source code 

Checks if the given value is a dictionary.

Note that PrivateDicts subclass dict and pass this check.

Decorators:
  • @WithDesc("Dictionary")

TRegex(pobj)

source code 

Checks whether a string matches a specific regular expression.

Parameters:
  • pobj - Compiled regular expression as returned by re.compile

TMaybe(test)

source code 

Wrap a test in a TOr(TNone, test).

This makes it easier to define TMaybe* types.

TMaybeBool(val)

source code 

a maybe boolean (bool or none)

Decorators:
  • @WithDesc("Boolean")

TMaybeDict(val)

source code 

Maybe a dictionary (dict or None)

Decorators:
  • @WithDesc("Dictionary")

TMaybeList(val)

source code 

Maybe a list (list or None)

Decorators:
  • @WithDesc("List")

TNonNegativeInt(val)

source code 

a non-negative integer (value >= 0)

Decorators:
  • @WithDesc("Integer")

TPositiveInt(val)

source code 

a positive integer (value > 0)

Decorators:
  • @WithDesc("Integer")

TMaybePositiveInt(val)

source code 

a maybe positive integer (positive integer or None)

Decorators:
  • @WithDesc("Integer")

TDouble(val)

source code 

Double (== Float)

Decorators:
  • @WithDesc("Float")

TInstanceOf(cls)

source code 

Checks if a given value is an instance of cls.

Parameters:
  • cls (class) - Class object

TStrictDict(require_all, exclusive, items)

source code 

Strict dictionary check with specific keys.

Parameters:
  • require_all (boolean) - Whether all keys in items are required
  • exclusive (boolean) - Whether only keys listed in items should be accepted
  • items (dictionary) - Mapping from key (string) to verification function

TItems(items)

source code 

Checks individual items of a container.

If the verified value and the list of expected items differ in length, this check considers only as many items as are contained in the shorter list. Use TIsLength to enforce a certain length.

Parameters:
  • items (list) - List of checks

_CheckCIDRNetNotation(value)

source code 

Ensure a given CIDR notation type is valid.

Decorators:
  • @WithDesc("IPv4 network")

_CheckCIDRAddrNotation(value)

source code 

Ensure a given CIDR notation type is valid.

Decorators:
  • @WithDesc("IPv4 address")

_CheckCIDR6AddrNotation(value)

source code 

Ensure a given CIDR notation type is valid.

Decorators:
  • @WithDesc("IPv6 address")

_CheckCIDR6NetNotation(value)

source code 

Ensure a given CIDR notation type is valid.

Decorators:
  • @WithDesc("IPv6 network")

TObjectCheck(obj, fields_types)

source code 

Helper to generate type checks for objects.

Parameters:
  • obj - The object to generate type checks
  • fields_types - The fields and their types as a dict
Returns:
A ht type check function

Variables Details [hide private]

TNonEmptyString

a non-empty string

Value:
WithDesc("NonEmptyString")(TAnd(TString, TTrue))

TNegativeInt

a negative integer (value < 0)

Value:
TAnd(TInt, WithDesc("LessThanZero")(compat.partial(operator.gt, 0)))

TNonNegativeFloat

a positive float

Value:
TAnd(TFloat, WithDesc("EqualOrGreaterThanZero")(lambda v: v >= 0.0))

TJobId

Job ID

Value:
WithDesc("JobId")(TOr(TNonNegativeInt, TRegex(re.compile("^%s$" % cons\
tants.JOB_ID_TEMPLATE))))

TDiskIndex

Value:
TAnd(TNonNegativeInt, TMaxValue(constants.MAX_DISKS))

TIAllocatorTestDir

Value:
TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS)

TINicParams

Value:
Comment("NIC parameters")(TDictOf(TElemOf(constants.INIC_PARAMS), TMay\
be(TString)))

TIDiskParams

Value:
Comment("Disk parameters")(TDictOf(TNonEmptyString, TOr(TNonEmptyStrin\
g, TInt)))

TQueryTypeOp

Value:
TElemOf(set(constants.QR_VIA_OP).union(set(constants.QR_VIA_LUXI)))

TDiskParams

Value:
Comment("Disk parameters")(TDictOf(TNonEmptyString, TOr(TNonEmptyStrin\
g, TInt)))

TDiskChanges

Value:
TAnd(TIsLength(2), TItems([Comment("Disk index")(TNonNegativeInt), Com\
ment("Parameters")(TDiskParams)]))

TRecreateDisksInfo

Value:
TOr(TListOf(TNonNegativeInt), TListOf(TDiskChanges))

TQueryFieldDef

Value:
TObjectCheck(objects.QueryFieldDefinition, {"name": TNonEmptyString, "\
title": TNonEmptyString, "kind": TElemOf(constants.QFT_ALL), "doc": TN\
onEmptyString})

TQueryRow

Value:
TListOf(TAnd(TIsLength(2), TItems([TElemOf(constants.RS_ALL), TAny])))

TQueryResponse

Value:
TObjectCheck(objects.QueryResponse, {"fields": TListOf(TQueryFieldDef)\
, "data": TQueryResult})

TQueryFieldsResponse

Value:
TObjectCheck(objects.QueryFieldsResponse, {"fields": TListOf(TQueryFie\
ldDef)})

TJobIdListItem

Value:
TAnd(TIsLength(2), TItems([Comment("success")(TBool), Comment("Job ID \
if successful, error message" " otherwise")(TOr(TString, TJobId))]))

TJobIdListOnly

Value:
TStrictDict(True, True, {constants.JOB_IDS_KEY: Comment("List of submi\
tted jobs")(TJobIdList)})

TInstanceMultiAllocResponse

Value:
TStrictDict(True, True, {constants.JOB_IDS_KEY: Comment("List of submi\
tted jobs")(TJobIdList), constants.ALLOCATABLE_KEY: TListOf(TNonEmptyS\
tring), constants.FAILED_KEY: TListOf(TNonEmptyString)})