fora.types
Provides a mockup of loadable module types. They are used to store metadata that can be accessed by the module that is currently being loaded. These types also help the static type checker, as it then has a better understanding of the expected contents of the dynamically loaded modules.
class types.RemoteDefaultsContext
types.RemoteDefaultsContext
A context manager to overlay remote defaults on a stack of defaults.
class types.VariableActionSnapshot
types.VariableActionSnapshot
A snapshot for variable tracking.
Attributes
attr action
action
Whether the variable was modified or redefined
attr actor
actor
The owner of this variable
attr value
value
The snapshot value.
class types.ModuleWrapper
types.ModuleWrapper
A module wrapper, that defaults attribute lookups to this object if the module doesn't define it. Derived classes must be annotated with @dataclass.
Attributes
attr module
module
The dynamically loaded inventory module
def ModuleWrapper.is_exported_variable()
ModuleWrapper.is_exported_variable()
Returns True if the the given variable doesn't inherently belong to this group.
def ModuleWrapper.exported_variables()
ModuleWrapper.exported_variables()
Returns a list of exported variables, which are variables that don't inherently belong to this group.
Returns
dict[str, Any]: Global exported variables of the wrapped module
def ModuleWrapper.is_overloaded()
ModuleWrapper.is_overloaded()
Returns NonoTrue if the given attribute exists as a variable on this wrapper but is overloaded by the wrapped module, False if the attribute exists on this wrapper but isn't overloaded and None if the attribute doesn't exist on this wrapper.
def ModuleWrapper.is_overridden()
ModuleWrapper.is_overridden()
Returns True if a variable has both been overloaded and changed.
def ModuleWrapper.wrap()
ModuleWrapper.wrap()
Replaces the currently wrapped module (if any) with the given object. The module should be an instance of ModuleType in most cases, but doesn't need to be. Any object is supported.
Parameters
module: The new module to wrap.
copy_members: Copy all current member variables of this wrapper to the wrapped module. Excludes members starting with an underscore (
_
) and members of ModuleWrapper.copy_functions: Copy all current member functions of this wrapper to the wrapped module, such that calling module.function(...) is forwarded to this wrapper's self.function(...). Excludes functions starting with an underscore (
_
) and functions of ModuleWrapper.
def ModuleWrapper.definition_file()
ModuleWrapper.definition_file()
Returns the file from where the associated module has been loaded, or "" if no module file is associated with this wrapper.
Returns
str: The file.
class types.GroupWrapper
types.GroupWrapper
A wrapper class for group modules. This will wrap any instanciated group to provide default attributes and methods for the group.
All functions and members from this wrapper will be implicitly available on the wrapped group module. This means you can do the following
instead of having to first import the wrapper API:
Attributes
attr name
name
The name of the group. Must not be changed.
class types.HostWrapper
types.HostWrapper
A wrapper class for host modules. This will wrap any instanciated host to provide default attributes and methods for the host.
All functions and members from this wrapper will be implicitly available on the wrapped host module. This means you can do the following
instead of having to first import the wrapper API:
Attributes
attr inventory
inventory
A back reference to the parent inventory which created this host.
attr name
name
The name that used to refer to this specific host. Must not be changed.
attr url
url
The url used to connect to this host. The schema in this url will be used to determine which connector implementation is used to establish a connection, if the connector
has not been explicitly overridden by the module. This is determined just before a connection is initiated.
By default, this field will reflect the value specified in the inventory, after url qualification. If this is None, connector
must be set explicitly.
attr groups
groups
The set of groups this host belongs to.
attr connector
connector
The connector class to use. If None
, the connector will be determined by the schema in the url
when needed.
attr connection
connection
The active connection to this host, if one is opened.
def HostWrapper.create_connector()
HostWrapper.create_connector()
Creates a connector for this host.
Returns
Connector: A connector for this host
Raises
FatalError: The connector could not resolved because either an invalid connector was specified or the scheme could not be matched against existing connectors.
def HostWrapper.vars_hierarchical()
HostWrapper.vars_hierarchical()
Returns vars(self)
but adds all variables defined by the current script that are not overwritten by this host.
Returns
dict[str, Any]: The variables of this object.
class types.ScriptWrapper
types.ScriptWrapper
A mockup type for script modules. This is not the actual type of an instanciated module, but will reflect some of it's properties better than ModuleType. While this class is mainly used to aid type-checking, its properties are transferred to the actual instanciated module before the module is executed.
When writing a script module, you can use the API exposed in fora.script
to access/change meta information about your module.
Attributes
attr name
name
The name of the script. Must not be changed.
def ScriptWrapper.defaults()
ScriptWrapper.defaults()
Returns a context manager to incrementally change the remote execution defaults.
This function is implicitly available on the wrapped script module. This means you can do the following
instead of having to first import the wrapper API:
def ScriptWrapper.current_defaults()
ScriptWrapper.current_defaults()
Returns the fully resolved currently active defaults.
Returns
RemoteSettings: The currently active remote defaults.
def ScriptWrapper.Params()
ScriptWrapper.Params()
Decorator used to declare script parameters.
This function is implicitly available on the wrapped script module. This means you can do the following
instead of having to first import the wrapper API:
Last updated