Package syspolicy :: Module policytool :: Class PolicyTool
[hide private]
[frames] | no frames]

Class PolicyTool

source code

This is the main interface class for SysPolicy that's designed to be used from the user interface side, eg. from the CLI interface packages.

This intends to provide all the features of the core library that need to be exposed to the developers of user interfaces or other software based on SysPolicy's functionality.

Instance Methods [hide private]
 
__init__(self, configfile, debug=False)
Initialize the PolicyTool by loading the configuration and all policies, modules, setting up locking mechanisms and starting the background Worker process.
source code
 
set_state(self, type, path, value)
This function updates the state of one of the policies.
source code
 
save_state(self)
This function saves the internal state for each policy.
source code
 
clear_state(self)
This function clears all the internal states of all policies.
source code
 
add_module(self, module)
This function loads a new module to the PolicyTool.
source code
 
register_attribute_handler(self, policy_type, attribute, module)
This function registers a new attribute handler for a module.
source code
 
register_event_handler(self, event, handler)
This function registers a new event hook for the event type `event`.
source code
 
emit_event(self, event, changeset=None)
This function emits an event of type `event`, calling all the registered handler functions for this event type.
source code
 
get_policy_diff(self)
This function returns the difference between the policies and their previously known states, finding changed values.
source code
 
get_policy_updates(self)
This function returns a list of ChangeSets that must be implemented to accommodate the changes the user has made to the policy files.
source code
 
get_cs_lock(self, changeset)
This function returns the Lock object for a known ChangeSet.
source code
 
get_module_lock(self, module_name)
This function returns a Lock object for the given module.
source code
 
add_changeset(self, changeset)
This function appends a new ChangeSet to the list.
source code
 
accept_changeset(self, changeset, accepted=True)
This module updates the state of a ChangeSet to either be STATE_ACCEPTED if accepted is True or STATE_REJECTED otherwise.
source code
 
accept_state_changes(self)
This function automatically accepts all proposed ChangeSets that contain only 'set_state' operations in the 'state' subsystem.
source code
 
changesets_with_state(self, state)
This function queries the stored list of ChangeSet for the ones with the state `state` and returns this list.
source code
 
enqueue_changesets(self, changesets)
This function enqueue's the provided ChangeSets with the Worker.
source code
Class Variables [hide private]
  conf = None
main configuration object (Config class instance)
  debug = False
whether or not SysPolicy is running in debug mode
  policy = None
dictionary of all the policies defined in the main conf
  state = None
respective state objects for the policies
  handler = None
attribute handlers for all the policies
  events = None
event hooks by event type
  module = None
loaded extension modules
  module_locks = None
locks for the loaded modules
  changesets = None
ChangeSets that have been proposed or worked on
  cs_mlock = None
master lock for the changesets
  cs_locks = None
dictionary of individial locks for all ChangeSets
  worker = None
Worker instance for background processing of ChangeSets
Method Details [hide private]

set_state(self, type, path, value)

source code 

This function updates the state of one of the policies.

Parameters:
  • type - The policy in which the state is set
  • path - The path to the changed value
  • value - the new value

add_module(self, module)

source code 

This function loads a new module to the PolicyTool.

Parameters:
  • module - The module to be loaded. Must be an instance of the Module class or one of it's subclasses.

register_attribute_handler(self, policy_type, attribute, module)

source code 

This function registers a new attribute handler for a module.

In case the attribute has already been assigned a handler, an exception is raised and the this request is refused.

Parameters:
  • policy_type - The type (name) of the policy of the attribute
  • attribute - The name of the handled attribute
  • module - The Module instance claiming the attribute

register_event_handler(self, event, handler)

source code 

This function registers a new event hook for the event type `event`. There can be many hooks for the same event type.

Parameters:
  • event - The event which is hooked into
  • handler - The function that must be called when the event fires

emit_event(self, event, changeset=None)

source code 

This function emits an event of type `event`, calling all the registered handler functions for this event type.

Parameters:
  • event - Type of the event that is being emitted
  • changeset - A ChangeSet that is triggering the event

get_policy_diff(self)

source code 

This function returns the difference between the policies and their previously known states, finding changed values.

Returns:
Difference between all policies and their saved states

get_policy_updates(self)

source code 

This function returns a list of ChangeSets that must be implemented to accommodate the changes the user has made to the policy files.

The function works by detecting the policy differences and handling each difference with the registered attribute handler module. Each handler call may return a ChangeSet which is then recorded.

Returns:
A list of ChangeSet elements

get_cs_lock(self, changeset)

source code 

This function returns the Lock object for a known ChangeSet.

Parameters:
  • changeset - The ChangeSet for which the Lock is to be obtained
Returns:
A Lock object or None if not found

get_module_lock(self, module_name)

source code 

This function returns a Lock object for the given module.

Parameters:
  • module_name - The module for which the Lock is to be obtained
Returns:
A Lock objet or None if not found

add_changeset(self, changeset)

source code 

This function appends a new ChangeSet to the list. Additionally, a threading.Lock object is created for this ChangeSet.

Parameters:
  • changeset - The new ChangeSets

accept_changeset(self, changeset, accepted=True)

source code 

This module updates the state of a ChangeSet to either be STATE_ACCEPTED if accepted is True or STATE_REJECTED otherwise.

Parameters:
  • changeset - The ChangeSet which's status is changed
  • accepted - Whether the ChangeSet is accepted or not

accept_state_changes(self)

source code 

This function automatically accepts all proposed ChangeSets that contain only 'set_state' operations in the 'state' subsystem.

This can be called to auto-accept all policy changes that don't need any review from the user's side.

changesets_with_state(self, state)

source code 

This function queries the stored list of ChangeSet for the ones with the state `state` and returns this list. For example, it can be used to find all the accepted ChangeSets like this:

pt.changesets_with_state(syspolicy.change.STATE_ACCEPTED)

Parameters:
  • state - The state which is being matched to ChangeSets
Returns:
A list of ChangeSets with the state `state`

enqueue_changesets(self, changesets)

source code 

This function enqueue's the provided ChangeSets with the Worker.

Parameters:
  • changesets - A list of ChangeSets for processing