Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Settings Class Referencefinal

Object containing the settings to pass to the Dobby. More...

#include <Settings.h>

Inheritance diagram for Settings:
Inheritance graph
[legend]
Collaboration diagram for Settings:
Collaboration graph
[legend]

Public Member Functions

std::string workspaceDir () const override
 Should return the path to a directory used to store temporary data like runc bundles. More...
 
std::string persistentDir () const override
 Should return a path to a directory on a persistent storage mount. More...
 
std::string consoleSocketPath () const override
 Location to create the socket used for capturing container logs. More...
 
std::map< std::string, std::string > extraEnvVariables () const override
 A list of extra environment variables that will be set for all containers. More...
 
std::shared_ptr< HardwareAccessSettingsgpuAccessSettings () const override
 Returns any extra details needed to access the GPU inside the container.
 
std::shared_ptr< HardwareAccessSettingsvpuAccessSettings () const override
 Returns any extra details needed to access the VPU (video pipeline) inside the container.
 
std::vector< std::string > externalInterfaces () const override
 Returns the set of external interface that container traffic maybe routed through. More...
 
std::string addressRangeStr () const override
 Returns the Dobby network address range in string format. More...
 
in_addr_t addressRange () const override
 Returns the Dobby network address range in in_addr_t format. More...
 
std::vector< std::string > defaultPlugins () const override
 Returns any default plugins the platform should run. More...
 
Json::Value rdkPluginsData () const override
 
LogRelaySettings logRelaySettings () const override
 
StraceSettings straceSettings () const override
 
ApparmorSettings apparmorSettings () const override
 
PidsSettings pidsSettings () const override
 
void dump (int aiLogLevel=-1) const
 Debugging function to dump the settings to the log - info level.
 

Static Public Member Functions

static std::shared_ptr< SettingsfromJsonFile (const std::string &filePath)
 Sets the default values for all settings.
 
static std::shared_ptr< SettingsdefaultSettings ()
 

Private Member Functions

 Settings ()
 Constructs the settings object with the default settings.
 
 Settings (const Json::Value &settings)
 Constructs the settings source the data from the supplied JSON object.
 
void setDefaults ()
 Sets the default values for all settings.
 
bool isDir (const std::string &path, int accessFlags=0) const
 Checks if path is a directory and has the given access flags. More...
 
int getGroupId (const std::string &name) const
 Returns the group id associated with the name. More...
 
std::set< int > getGroupIds (const Json::Value &field) const
 Processes a JSON array containing numbers and names of user groups. More...
 
std::string getPathFromEnv (const char *env, const char *fallbackPath) const
 Attempts to get and validate a path from environment vars. More...
 
std::list< std::string > getPathsFromJson (const Json::Value &value) const
 Attempts to read a path from the JSON object. More...
 
std::map< std::string, std::string > getEnvVarsFromJson (const Json::Value &root, const Json::Path &path) const
 Returns a map of strings to strings as read from the JSON. More...
 
std::list< std::string > getDevNodes (const Json::Value &root, const Json::Path &path) const
 Attempts to read the list of GPU device nodes that are needed for apps. More...
 
std::list< ExtraMountgetExtraMounts (const Json::Value &root, const Json::Path &path) const
 Attempts to read the mount JSON structure(s) from the object. More...
 
bool processMountObject (const Json::Value &value, ExtraMount *mount) const
 Processes a json 'mount' object. More...
 
std::shared_ptr< HardwareAccessSettingsgetHardwareAccess (const Json::Value &root, const Json::Path &path) const
 Processes a json 'gpu' or 'vpu' object. More...
 
void dumpHardwareAccess (int aiLogLevel, const std::string &name, const std::shared_ptr< const HardwareAccessSettings > &hwAccess) const
 Debugging function to dump the settings to access certain H/W.
 

Private Attributes

std::string mWorkspaceDir
 
std::string mPersistentDir
 
std::string mConsoleSocketPath
 
std::map< std::string, std::string > mExtraEnvVars
 
std::shared_ptr< HardwareAccessSettingsmGpuHardwareAccess
 
std::shared_ptr< HardwareAccessSettingsmVpuHardwareAccess
 
std::vector< std::string > mExternalInterfaces
 
std::pair< std::string, in_addr_t > mAddressRange
 
std::vector< std::string > mDefaultPlugins
 
Json::Value mRdkPluginsData
 
LogRelaySettings mLogRelaySettings
 
StraceSettings mStraceSettings
 
ApparmorSettings mApparmorSettings
 
PidsSettings mPidsSettings
 

Detailed Description

Object containing the settings to pass to the Dobby.

Usually this is the parsed content of a JSON file and contains the platform specific details that Dobby needs to setup some stuff in the container.

Member Function Documentation

◆ addressRange()

in_addr_t Settings::addressRange ( ) const
overridevirtual

Returns the Dobby network address range in in_addr_t format.

IPv4 address, masked with /24, i.e. address can be nnn.nnn.nnn.0

Implements IDobbySettings.

◆ addressRangeStr()

std::string Settings::addressRangeStr ( ) const
overridevirtual

Returns the Dobby network address range in string format.

IPv4 address, masked with /24, i.e. address can be nnn.nnn.nnn.0

Implements IDobbySettings.

◆ consoleSocketPath()

std::string Settings::consoleSocketPath ( ) const
overridevirtual

Location to create the socket used for capturing container logs.

This needs to be somewhere writable

Implements IDobbySettings.

◆ defaultPlugins()

std::vector< std::string > Settings::defaultPlugins ( ) const
overridevirtual

Returns any default plugins the platform should run.

It's assumed the plugins will have an empty data section (i.e. {}) and that the default plugin options will always be suitable

Implements IDobbySettings.

◆ externalInterfaces()

std::vector< std::string > Settings::externalInterfaces ( ) const
overridevirtual

Returns the set of external interface that container traffic maybe routed through.

On every RDK platform this is { "eth0", "wlan0" } but it may change.

Implements IDobbySettings.

◆ extraEnvVariables()

std::map< std::string, std::string > Settings::extraEnvVariables ( ) const
overridevirtual

A list of extra environment variables that will be set for all containers.

This would typically define platform specific variables.

Implements IDobbySettings.

◆ getDevNodes()

std::list< std::string > Settings::getDevNodes ( const Json::Value &  root,
const Json::Path &  path 
) const
private

Attempts to read the list of GPU device nodes that are needed for apps.

Returns

◆ getEnvVarsFromJson()

std::map< std::string, std::string > Settings::getEnvVarsFromJson ( const Json::Value &  root,
const Json::Path &  path 
) const
private

Returns a map of strings to strings as read from the JSON.

This expects the json value to contain an array of strings, each string in the array should be formatted as a "<NAME>=<VALUE>" and follow the same rules as for standard environment variables.

Returns
a map of key value environment variable pairs.

◆ getExtraMounts()

std::list< Settings::ExtraMount > Settings::getExtraMounts ( const Json::Value &  root,
const Json::Path &  path 
) const
private

Attempts to read the mount JSON structure(s) from the object.

Returns

◆ getGroupId()

int Settings::getGroupId ( const std::string &  name) const
private

Returns the group id associated with the name.

Returns
the group id on success, -1 on error.

◆ getGroupIds()

std::set< int > Settings::getGroupIds ( const Json::Value &  field) const
private

Processes a JSON array containing numbers and names of user groups.

Returns
the set of user group ids in the field, or an empty set on error.

◆ getHardwareAccess()

std::shared_ptr< IDobbySettings::HardwareAccessSettings > Settings::getHardwareAccess ( const Json::Value &  root,
const Json::Path &  path 
) const
private

Processes a json 'gpu' or 'vpu' object.

The JSON is expected to look like the following:

{
    "groupIds": [ "video" ],
    "devNodes": [
        "/dev/ion",
        "/dev/rpc[0-7]"
    ],
    "extraEnvVariables": [
        "ENABLE_MEDIAINFO=0"
    ],
    "extraMounts": [
        {
            "source": "/etc/xdg/gstomx.conf",
            "destination": "/etc/xdg/gstomx.conf",
            "type": "bind",
            "options": [ "bind", "ro", "nosuid", "nodev", "noexec" ]
        },
        ...
    ]
}
Returns

◆ getPathFromEnv()

std::string Settings::getPathFromEnv ( const char *  env,
const char *  fallbackPath 
) const
private

Attempts to get and validate a path from environment vars.

If the env var is not set or points to an non-existing directory then the function falls back to fallbackPath.

Either way this function guarantees that the returned string will point to a valid directory.

Returns
a string containing the path to the directory.

◆ getPathsFromJson()

std::list< std::string > Settings::getPathsFromJson ( const Json::Value &  value) const
private

Attempts to read a path from the JSON object.

The path(s) are expanded using the wordexp() function, meaning that glob and environment variable expansion are performed on the string stored in the json object.

Returns
a list of expanded paths in the json.

◆ isDir()

bool Settings::isDir ( const std::string &  path,
int  accessFlags = 0 
) const
private

Checks if path is a directory and has the given access flags.

Returns
true if the path is a directory and accessible.

◆ persistentDir()

std::string Settings::persistentDir ( ) const
overridevirtual

Should return a path to a directory on a persistent storage mount.

This is currently not used, but maybe in the future.

Implements IDobbySettings.

◆ processMountObject()

bool Settings::processMountObject ( const Json::Value &  value,
ExtraMount mount 
) const
private

Processes a json 'mount' object.

Returns

◆ workspaceDir()

std::string Settings::workspaceDir ( ) const
overridevirtual

Should return the path to a directory used to store temporary data like runc bundles.

This should be non-persistent storage and will be used for transient data. If the directory doesn't exist the library will try and create it. If the directory (and any leading dirs) has to be created it will be created with 1755 permissions.

Because of the way container setup works, this directory needs to be accessible - but not writable - by un-privileged processes.

Implements IDobbySettings.


The documentation for this class was generated from the following files: