Package syspolicy :: Package modules :: Module module :: Class Module
[hide private]
[frames] | no frames]

Class Module

source code

Known Subclasses:

This is the base Module class that all other modules must extend.

This provides the basic functionality that is expected from a module, which includes the name of the module, handled attributes and diff operation handler functions, change operations and event hooks.

Instance Methods [hide private]
 
__init__(self) source code
 
cs_check_diff(self, policy, operation, path, value, diff)
This function checks a difference in the policy and it's state at the location identified by `path` and `operation`.
source code
 
cs_set_default(self, attribute, value, diff)
Null handler for setting a new default value in the policy.
source code
 
cs_new_attribute(self, group, attribute, value, diff)
Default handler for setting a new attribute in the policy, which calls the cs_set_attribute and returns it's return value.
source code
 
cs_set_attribute(self, group, attribute, value, diff)
Null handler for modifying a value in the policy.
source code
 
cs_rem_attribute(self, group, attribute, value, diff)
Null handler for removing an attribute from the policy.
source code
 
perform_change(self, change)
This function accepts a Change object to be implemented and finds the respective function in the change_operations dict and calls it.
source code
 
edit_configfile(self, change)
This function implements the edit_configfile Change operation.
source code
 
append_lines_to_file(self, configfile, before, after, id, lines)
This function inserts lines to an existing configuration file.
source code
 
execute(self, cmd=[])
This function executes a system command.
source code
Class Variables [hide private]
  name = None
the name of the module
  pt = None
the PolicyTool instance that has loaded this module
  handled_attributes = None
the attributes that this module handles
  diff_operations = None
handlers for the various diff operations
  change_operations = None
handlers for the various change operations
  event_hooks = None
various event hooks that this module registers
Method Details [hide private]

cs_check_diff(self, policy, operation, path, value, diff)

source code 

This function checks a difference in the policy and it's state at the location identified by `path` and `operation`. The function will attempt to find a handler for this change among the registered diff handlers in the PolicyTool.

In case the handler is found, it is called and a ChangeSet is expected as the return value. If the ChangeSet is returned, an additional Change operation is appended to the list of changes for updating the internal state of that policy.

Since that Change is appended to the end of the list, it is also executed last and only in the case the previous changes have succeeded.

Parameters:
  • policy - Policy in which the difference was detected
  • operation - type of the difference
  • path - Location of the difference in the tree
  • value - The new value that was set (None when it was removed)
  • diff - The difference from the old value
Returns:
This function always returns a ChangeSet

cs_set_default(self, attribute, value, diff)

source code 

Null handler for setting a new default value in the policy.

Parameters:
  • attribute - The attribute in the policy that is being set
  • value - The new value
  • diff - The difference from the old value
Returns:
None

cs_new_attribute(self, group, attribute, value, diff)

source code 

Default handler for setting a new attribute in the policy, which calls the cs_set_attribute and returns it's return value. This is a safe default, since usually there is no difference whether an attribute was added or simply modified.

Parameters:
  • group - The group for which the attribute is being set
  • attribute - The attribute in the policy that is being set
  • value - The new value
  • diff - The difference from the old value
Returns:
A ChangeSet or None

cs_set_attribute(self, group, attribute, value, diff)

source code 

Null handler for modifying a value in the policy.

Parameters:
  • group - The group for which the attribute is being set
  • attribute - The attribute in the policy that is being set
  • value - The new value
  • diff - The difference from the old value
Returns:
A ChangeSet or None

cs_rem_attribute(self, group, attribute, value, diff)

source code 

Null handler for removing an attribute from the policy.

Parameters:
  • group - The group for which the attribute is being set
  • attribute - The attribute in the policy that is being set
  • value - The new value
  • diff - The difference from the old value
Returns:
A ChangeSet or None

perform_change(self, change)

source code 

This function accepts a Change object to be implemented and finds the respective function in the change_operations dict and calls it.

In case the handler function is not found, STATE_NOT_HANDLED is returned.

Parameters:
  • change - The Change that is to be implemented
Returns:
Returns a state indicatation code or STATE_NOT_HANDLED

edit_configfile(self, change)

source code 

This function implements the edit_configfile Change operation.

It extracts the attributes from the Change element and calls the append_lines_to_file function.

Parameters:
  • change - Change element to be implemented
Returns:
STATE_COMPLETED on success, STATE_FAILED otherwise

append_lines_to_file(self, configfile, before, after, id, lines)

source code 

This function inserts lines to an existing configuration file.

The new lines are surrounded with identifier tags which are detected in successive runs and so any previous countent with the same identifier tags is replaced.

Parameters:
  • configfile - Path to the configuration file
  • before - Regular expression to find before which line to add the new lines
  • after - Regular expression to find after which line to add the new lines
  • id - A simple identifier text to uniquely identify this section
  • lines - List of strings to be inserted to the file
Returns:
Returns True on success

execute(self, cmd=[])

source code 

This function executes a system command.

If the debug mode has been enabled, then the command is echoed back to the shell instead of executing it.

Parameters:
  • cmd - The command to be executed with all the arguments as a list
Returns:
STATE_COMPLETED when the return value is 0, otherwise STATE_FAILED