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.grub
-
- Last updated 31 Aug 2023
- Revision Library version 0.3
Simple library for managing Linux kernel configuration via GRUB.
This library is only used for setting additional parameters that will be stored in the "/etc/default/grub.d/95-juju-charm.cfg" config file and not for editing other configuration files. It's intended to be used in charms to help configure the machine.
Configurations for individual charms will be stored in "/etc/default/grub.d/90-juju-
Example of use:
class UbuntuCharm(CharmBase):
def __init__(self, *args):
...
self.framework.observe(self.on.install, self._on_install)
self.framework.observe(self.on.update_status, self._on_update_status)
self.framework.observe(self.on.remove, self._on_remove)
self.grub = grub.GrubConfig(self.meta.name)
log.debug("found keys %s in GRUB config file", self.grub.keys())
def _on_install(self, _):
try:
self.grub.update(
{"GRUB_CMDLINE_LINUX_DEFAULT": "$GRUB_CMDLINE_LINUX_DEFAULT hugepagesz=1G"}
)
except grub.ValidationError as error:
self.unit.status = BlockedStatus(f"[{error.key}] {error.message}")
def _on_update_status(self, _):
if self.grub["GRUB_CMDLINE_LINUX_DEFAULT"] != "$GRUB_CMDLINE_LINUX_DEFAULT hugepagesz=1G":
self.unit.status = BlockedStatus("wrong GRUB configuration")
def _on_remove(self, _):
self.grub.remove()
Index
class ValidationError
Description
Exception representing value validation error. None
Methods
ValidationError. __init__( self , key: str , message: str )
ValidationError. __str__( self )
Description
Return string representation of error. None
class IsContainerError
Description
Exception if local machine is container. None
class ApplyError
Description
Exception if applying new config failed. None
def check_update_grub()
Description
Report whether an update to /boot/grub/grub.cfg is available. None
def is_container()
Description
Report whether the local machine is a container. None
class Config
Manages GRUB configuration.
Description
This object will load current configuration option for GRUB and provide option to update it with simple validation, remove charm option and apply those changes.
Methods
Config. __init__( self , charm_name: str )
Description
Initialize the GRUB config. None
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. applied_configs( self )
Description
Return list of charms configs which registered config in LIB_CONFIG_DIRECTORY. None
Config. blocked_keys( self )
Description
Get set of configured keys by other charms. None
Config. charm_name( self )
Description
Get charm name or use value obtained from JUJU_UNIT_NAME env. None
Config. path( self )
Description
Return path for charm config. None
Config. apply( self )
Description
Check if an update to /boot/grub/grub.cfg is available. None
Config. remove( self , apply: bool )
Remove config for charm.
Description
This function will remove config file for charm and re-create the 95-juju-charm.cfg
GRUB config file without changes made by this charm.
Config. update( self , config , apply: bool )
Description
Update the Grub configuration. None