Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Settings.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2020 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 /*
20  * File: Settings.h
21  *
22  */
23 
24 #ifndef SETTINGS_H
25 #define SETTINGS_H
26 
27 #include <IDobbySettings.h>
28 
29 #if defined(RDK)
30 # include <json/json.h>
31 #else
32 # include <jsoncpp/json.h>
33 #endif
34 
35 #include <memory>
36 
37 
38 // -----------------------------------------------------------------------------
48 class Settings final : public IDobbySettings
49 {
50 private:
51  Settings();
52  explicit Settings(const Json::Value& settings);
53 
54 public:
55  ~Settings() final = default;
56 
57  static std::shared_ptr<Settings> fromJsonFile(const std::string& filePath);
58  static std::shared_ptr<Settings> defaultSettings();
59 
60 public:
61  std::string workspaceDir() const override;
62  std::string persistentDir() const override;
63 
64  std::string consoleSocketPath() const override;
65 
66  std::map<std::string, std::string> extraEnvVariables() const override;
67 
68 public:
69  std::shared_ptr<HardwareAccessSettings> gpuAccessSettings() const override;
70  std::shared_ptr<HardwareAccessSettings> vpuAccessSettings() const override;
71 
72  std::vector<std::string> externalInterfaces() const override;
73  std::string addressRangeStr() const override;
74  in_addr_t addressRange() const override;
75  std::vector<std::string> defaultPlugins() const override;
76 
77  Json::Value rdkPluginsData() const override;
78 
79  LogRelaySettings logRelaySettings() const override;
80  StraceSettings straceSettings() const override;
81  ApparmorSettings apparmorSettings() const override;
82  PidsSettings pidsSettings() const override;
83 
84  void dump(int aiLogLevel = -1) const;
85 
86 private:
87  void setDefaults();
88 
89  bool isDir(const std::string& path, int accessFlags = 0) const;
90 
91  int getGroupId(const std::string& name) const;
92  std::set<int> getGroupIds(const Json::Value& field) const;
93 
94  std::string getPathFromEnv(const char* env,
95  const char* fallbackPath) const;
96  std::list<std::string> getPathsFromJson(const Json::Value& value) const;
97 
98  std::map<std::string, std::string> getEnvVarsFromJson(const Json::Value& root,
99  const Json::Path& path) const;
100 
101  std::list<std::string> getDevNodes(const Json::Value& root,
102  const Json::Path& path) const;
103 
104  std::list<ExtraMount> getExtraMounts(const Json::Value& root,
105  const Json::Path& path) const;
106 
107  bool processMountObject(const Json::Value& value,
108  ExtraMount* mount) const;
109 
110  std::shared_ptr<HardwareAccessSettings> getHardwareAccess(const Json::Value& root,
111  const Json::Path& path) const;
112 
113  void dumpHardwareAccess(int aiLogLevel, const std::string& name,
114  const std::shared_ptr<const HardwareAccessSettings>& hwAccess) const;
115 
116 private:
117  std::string mWorkspaceDir;
118  std::string mPersistentDir;
119  std::string mConsoleSocketPath;
120 
121  std::map<std::string, std::string> mExtraEnvVars;
122 
123  std::shared_ptr<HardwareAccessSettings> mGpuHardwareAccess;
124  std::shared_ptr<HardwareAccessSettings> mVpuHardwareAccess;
125 
126  std::vector<std::string> mExternalInterfaces;
127  std::pair<std::string, in_addr_t> mAddressRange;
128  std::vector<std::string> mDefaultPlugins;
129 
130  Json::Value mRdkPluginsData;
131 
132  LogRelaySettings mLogRelaySettings;
133  StraceSettings mStraceSettings;
134  ApparmorSettings mApparmorSettings;
135  PidsSettings mPidsSettings;
136 };
137 
138 #endif // !defined(SETTINGS_H)
Interface provided to the library at startup, contains the configuration options for Dobby.
Definition: IDobbySettings.h:50
Object containing the settings to pass to the Dobby.
Definition: Settings.h:49
void dump(int aiLogLevel=-1) const
Debugging function to dump the settings to the log - info level.
Definition: Settings.cpp:557
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.
Definition: Settings.cpp:603
void setDefaults()
Sets the default values for all settings.
Definition: Settings.cpp:395
std::shared_ptr< HardwareAccessSettings > vpuAccessSettings() const override
Returns any extra details needed to access the VPU (video pipeline) inside the container.
Definition: Settings.cpp:471
in_addr_t addressRange() const override
Returns the Dobby network address range in in_addr_t format.
Definition: Settings.cpp:501
int getGroupId(const std::string &name) const
Returns the group id associated with the name.
Definition: Settings.cpp:681
std::shared_ptr< HardwareAccessSettings > gpuAccessSettings() const override
Returns any extra details needed to access the GPU inside the container.
Definition: Settings.cpp:461
std::map< std::string, std::string > extraEnvVariables() const override
A list of extra environment variables that will be set for all containers.
Definition: Settings.cpp:451
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.
Definition: Settings.cpp:907
static std::shared_ptr< Settings > fromJsonFile(const std::string &filePath)
Sets the default values for all settings.
Definition: Settings.cpp:59
std::list< ExtraMount > getExtraMounts(const Json::Value &root, const Json::Path &path) const
Attempts to read the mount JSON structure(s) from the object.
Definition: Settings.cpp:952
std::vector< std::string > defaultPlugins() const override
Returns any default plugins the platform should run.
Definition: Settings.cpp:511
std::string getPathFromEnv(const char *env, const char *fallbackPath) const
Attempts to get and validate a path from environment vars.
Definition: Settings.cpp:761
std::string addressRangeStr() const override
Returns the Dobby network address range in string format.
Definition: Settings.cpp:491
std::set< int > getGroupIds(const Json::Value &field) const
Processes a JSON array containing numbers and names of user groups.
Definition: Settings.cpp:708
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.
Definition: Settings.cpp:849
std::list< std::string > getPathsFromJson(const Json::Value &value) const
Attempts to read a path from the JSON object.
Definition: Settings.cpp:805
bool isDir(const std::string &path, int accessFlags=0) const
Checks if path is a directory and has the given access flags.
Definition: Settings.cpp:652
std::shared_ptr< HardwareAccessSettings > getHardwareAccess(const Json::Value &root, const Json::Path &path) const
Processes a json 'gpu' or 'vpu' object.
Definition: Settings.cpp:1081
Settings()
Constructs the settings object with the default settings.
Definition: Settings.cpp:97
bool processMountObject(const Json::Value &value, ExtraMount *mount) const
Processes a json 'mount' object.
Definition: Settings.cpp:997
std::string consoleSocketPath() const override
Location to create the socket used for capturing container logs.
Definition: Settings.cpp:441
std::string workspaceDir() const override
Should return the path to a directory used to store temporary data like runc bundles.
Definition: Settings.cpp:421
std::string persistentDir() const override
Should return a path to a directory on a persistent storage mount.
Definition: Settings.cpp:431
std::vector< std::string > externalInterfaces() const override
Returns the set of external interface that container traffic maybe routed through.
Definition: Settings.cpp:481
Definition: IDobbySettings.h:241
Definition: IDobbySettings.h:107
Definition: IDobbySettings.h:201
Definition: IDobbySettings.h:261
Definition: IDobbySettings.h:223