noc.core.interface.parameter

Module Contents

class noc.core.interface.parameter.BaseParameter(required=True, default=None)

Bases: object

Abstract parameter

__or__(self, other)

ORParameter syntax sugar

raise_error(self, value, msg='')

Raise InterfaceTypeError

Parameters:
  • value (Arbitrary python type) – Value where error detected
  • msg (String) – Optional message

:raises InterfaceTypeError

clean(self, value)

Input parameter normalization

Parameters:value (Arbitrary python type) – Input parameter
Returns:Normalized value
script_clean_input(self, profile, value)

Clean up script input parameters. Can be overloaded to handle profile specific.

Parameters:
  • profile (Profile instance) – Profile
  • value (Arbitrary python type) – Input parameter
Returns:

Normalized value

script_clean_result(self, profile, value)

Clean up script result parameters. Can be overloaded to handle profile specific.

Parameters:
  • profile (Profile instance) – Profile
  • value (Arbitrary python type) – Input parameter
Returns:

Normalized value

form_clean(self, value)

Clean up form field

Parameters:value (Arbitrary python type) – Input parameter
Returns:Normalized value
get_form_field(self, label=None)

Get appropriative form field

class noc.core.interface.parameter.ORParameter(left, right)

Bases: noc.core.interface.parameter.BaseParameter

>>> ORParameter(IntParameter(),IPv4Parameter()).clean(10)
10
>>> ORParameter(IntParameter(),IPv4Parameter()).clean("192.168.1.1")
'192.168.1.1'
>>> ORParameter(IntParameter(),IPv4Parameter()).clean("xxx") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
InterfaceTypeError: IPv4Parameter: 'xxx'
>>> (IntParameter()|IPv4Parameter()).clean(10)
10
>>> (IntParameter()|IPv4Parameter()).clean("192.168.1.1")
'192.168.1.1'
>>> (IntParameter()|IPv4Parameter()).clean("xxx") #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
InterfaceTypeError: IPv4Parameter: 'xxx'
>>> (IntParameter()|IPv4Parameter()).clean(None) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
InterfaceTypeError: IPv4Parameter: None.
>>> (IntParameter(required=False)|IPv4Parameter(required=False)).clean(None)
>>> (IntParameter(required=False)|IPv4Parameter()).clean(None) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
InterfaceTypeError: IPv4Parameter: None.
clean(self, value)
script_clean_input(self, profile, value)
script_clean_result(self, profile, value)