open-iscsi / targetcli-fb

Command shell for managing Linux LIO kernel target
Apache License 2.0
103 stars 69 forks source link

[RFE] merge configuration files #175

Open ckujau opened 4 years ago

ckujau commented 4 years ago

I'm looking for a way to merge two (more more) configuration files into one, preferably into a live configuration. Example use case: a fileio backstore has already been setup and is being used right now. A previous configuration file (.json) for a block backstore is available and I want to be able to add that configuration to the running one.

While searching for a feature like this, I've come across a patch for SLES12 against Datera/targetcli which appears to do just that:

+    def do_merge(self, options):
+        '''
+        merge live|FILE_PATH
+
+        Merges the contents of FILE_PATH with the current configuration.
+        In case of conflict, values from FILE_PATH will be used.
+        If any error happens while doing so, the current configuration will
+        be fully rolled back.

Maybe something like this can be integrated into targetcli-fb? Looking to past and present issues, I can't help but think that #155 may be related here:

"What I am looking for, is to describe my desired target configuration and then 
switch to it - keeping the already configured targets, removing not-anymore
configured targets and adding new targets."
nf-brentsaner commented 9 months ago

In the meanwhile, you could probably just use any generic JSON merging tool against the saveconfig JSON files, merging the newer one on top of the older one.

One such example is this Python library. The indomitable jq utility can also do this.

Once you have a merged config, you can just load it with a targetcli restoreconfig cmd (or a targetctl restore, etc.).