2 LuCI UCI model library.
4 The typical workflow for UCI is: Get a cursor instance from the
5 cursor factory, modify data (via Cursor.add, Cursor.delete, etc.),
6 save the changes to the staging area via Cursor.save and finally
7 Cursor.commit the data to the actual config files.
8 LuCI then needs to Cursor.apply the changes so daemons etc. are
12 module "luci.model.uci"
15 Create a new UCI-Cursor.
23 Create a new Cursor initialized to the state directory.
31 Applies UCI configuration changes.
33 If the rollback parameter is set to true, the apply function will invoke the
34 rollback mechanism which causes the configuration to be automatically reverted
35 if no confirm() call occurs within a certain timeout.
37 The current default timeout is 30s and can be increased using the
38 "luci.apply.timeout" uci configuration key.
42 @param rollback Enable rollback mechanism
43 @return Boolean whether operation succeeded
47 Confirms UCI apply process.
49 If a previous UCI apply with rollback has been invoked using apply(true),
50 this function confirms the process and cancels the pending rollback timer.
52 If no apply with rollback session is active, the function has no effect and
53 returns with a "No data" error.
57 @return Boolean whether operation succeeded
61 Cancels UCI apply process.
63 If a previous UCI apply with rollback has been invoked using apply(true),
64 this function cancels the process and rolls back the configuration to the
67 If no apply with rollback session is active, the function has no effect and
68 returns with a "No data" error.
72 @return Boolean whether operation succeeded
76 Checks whether a pending rollback is scheduled.
78 If a previous UCI apply with rollback has been invoked using apply(true),
79 and has not been confirmed or rolled back yet, this function returns true
80 and the remaining time until rollback in seconds. If no rollback is pending,
81 the function returns false. On error, the function returns false and an
82 additional string describing the error.
85 @name Cursor.rollback_pending
86 @return Boolean whether rollback is pending
87 @return Remaining time in seconds
91 Delete all sections of a given type that match certain criteria.
94 @name Cursor.delete_all
95 @param config UCI config
96 @param type UCI section type
97 @param comparator Function that will be called for each section and returns
98 a boolean whether to delete the current section (optional)
102 Create a new section and initialize it with data.
106 @param config UCI config
107 @param type UCI section type
108 @param name UCI section name (optional)
109 @param values Table of key - value pairs to initialize the section with
110 @return Name of created section
114 Updated the data of a section using data from a table.
118 @param config UCI config
119 @param section UCI section name (optional)
120 @param values Table of key - value pairs to update the section with
124 Get a boolean option and return it's value as true or false.
127 @name Cursor.get_bool
128 @param config UCI config
129 @param section UCI section name
130 @param option UCI option
135 Get an option or list and return values as table.
138 @name Cursor.get_list
139 @param config UCI config
140 @param section UCI section name
141 @param option UCI option
142 @return table. If the option was not found, you will simply get an empty
147 Get the given option from the first section with the given type.
150 @name Cursor.get_first
151 @param config UCI config
152 @param type UCI section type
153 @param option UCI option (optional)
154 @param default Default value (optional)
159 Set given values as list. Setting a list option to an empty list
160 has the same effect as deleting the option.
163 @name Cursor.set_list
164 @param config UCI config
165 @param section UCI section name
166 @param option UCI option
167 @param value Value or table. Non-table values will be set as single
169 @return Boolean whether operation succeeded
173 Create a sub-state of this cursor.
175 The sub-state is tied to the parent cursor, means it the parent unloads or
176 loads configs, the sub state will do so as well.
179 @name Cursor.substate
180 @return UCI state cursor tied to the parent cursor
184 Add an anonymous section.
188 @param config UCI config
189 @param type UCI section type
190 @return Name of created section
194 Get a table of saved but uncommitted changes.
198 @param config UCI config
199 @return Table of changes
204 Commit saved changes.
208 @param config UCI config
209 @return Boolean whether operation succeeded
215 Deletes a section or an option.
219 @param config UCI config
220 @param section UCI section name
221 @param option UCI option (optional)
222 @return Boolean whether operation succeeded
226 Call a function for every section of a certain type.
230 @param config UCI config
231 @param type UCI section type
232 @param callback Function to be called
233 @return Boolean whether operation succeeded
237 Get a section type or an option
241 @param config UCI config
242 @param section UCI section name
243 @param option UCI option (optional)
248 Get all sections of a config or all values of a section.
252 @param config UCI config
253 @param section UCI section name (optional)
254 @return Table of UCI sections or table of UCI values
258 Manually load a config.
262 @param config UCI config
263 @return Boolean whether operation succeeded
269 Revert saved but uncommitted changes.
273 @param config UCI config
274 @return Boolean whether operation succeeded
280 Saves changes made to a config to make them committable.
284 @param config UCI config
285 @return Boolean whether operation succeeded
291 Set a value or create a named section.
293 When invoked with three arguments `config`, `sectionname`, `sectiontype`,
294 then a named section of the given type is created.
296 When invoked with four arguments `config`, `sectionname`, `optionname` and
297 `optionvalue` then the value of the specified option is set to the given value.
301 @param config UCI config
302 @param section UCI section name
303 @param option UCI option or UCI section type
304 @param value UCI value or nothing if you want to create a section
305 @return Boolean whether operation succeeded
309 Get the configuration directory.
312 @name Cursor.get_confdir
313 @return Configuration directory
317 Get the directory for uncomitted changes.
320 @name Cursor.get_savedir
321 @return Save directory
325 Get the effective session ID.
328 @name Cursor.get_session_id
329 @return String containing the session ID
333 Set the configuration directory.
336 @name Cursor.set_confdir
337 @param directory UCI configuration directory
338 @return Boolean whether operation succeeded
342 Set the directory for uncommitted changes.
345 @name Cursor.set_savedir
346 @param directory UCI changes directory
347 @return Boolean whether operation succeeded
351 Set the effective session ID.
354 @name Cursor.set_session_id
355 @param id String containing the session ID to set
356 @return Boolean whether operation succeeded
360 Discard changes made to a config.
364 @param config UCI config
365 @return Boolean whether operation succeeded