Operator Libs Linux
- Jon Seager
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 2 | 09 Mar 2023 | |
latest/stable | 1 | 28 Oct 2021 |
juju deploy operator-libs-linux
Deploy universal operators easily with Juju, the Universal Operator Lifecycle Manager.
Platform:
charms.operator_libs_linux.v0.sysctl
-
- Last updated 06 Aug 2023
- Revision Library version 0.4
Handler for the sysctl config.
This library allows your charm to create and configure sysctl options to the machine.
Validation and merge capabilities are added, for situations where more than one application are setting values. The following files can be created:
/etc/sysctl.d/90-juju-
Requirements from one application requesting to configure the values. /etc/sysctl.d/95-juju-sysctl.conf Merged file resulting from all other
90-juju-*
application files.
A charm using the sysctl lib will need a data structure like the following:
{
"vm.swappiness": "1",
"vm.max_map_count": "262144",
"vm.dirty_ratio": "80",
"vm.dirty_background_ratio": "5",
"net.ipv4.tcp_max_syn_backlog": "4096",
}
Now, it can use that template within the charm, or just declare the values directly:
from charms.operator_libs_linux.v0 import sysctl
class MyCharm(CharmBase):
def __init__(self, *args):
...
self.sysctl = sysctl.Config(self.meta.name)
self.framework.observe(self.on.install, self._on_install)
self.framework.observe(self.on.remove, self._on_remove)
def _on_install(self, _):
# Altenatively, read the values from a template
sysctl_data = {"net.ipv4.tcp_max_syn_backlog": "4096"}}
try:
self.sysctl.configure(config=sysctl_data)
except (sysctl.ApplyError, sysctl.ValidationError) as e:
logger.error(f"Error setting values on sysctl: {e.message}")
self.unit.status = BlockedStatus("Sysctl config not possible")
except sysctl.CommandError:
logger.error("Error on sysctl")
def _on_remove(self, _):
self.sysctl.remove()
Index
class Error
Description
Base class of most errors raised by this library. None
Methods
Error. message( self )
Description
Return the message passed as an argument. None
class CommandError
Description
Raised when there's an error running sysctl command. None
class ApplyError
Description
Raised when there's an error applying values in sysctl. None
class ValidationError
Description
Exception representing value validation error. None
class Config
Description
Represents the state of the config that a charm wants to enforce. None
Methods
Config. __init__( self , name: str )
Config. __contains__( self , key: str )
Description
Check if key is in config. None
Config. __len__( self )
Description
Get size of config. None
Config. __iter__( self )
Description
Iterate over config. None
Config. __getitem__( self , key: str )
Description
Get value for key form config. None
Config. charm_filepath( self )
Description
Name for resulting charm config file. None
Config. configure( self , config )
Configure sysctl options with a desired set of params.
Arguments
dictionary with keys to configure:
Config. remove( self )
Remove config for charm.
Description
The removal process won't apply any sysctl configuration. It will only merge files from remaining charms.