Question abou Loading initial data using a XML file

I want to load an initial data into CDB using a XML file. The problem here is that I need to create this XML dynamically in my application when ConfD is in phase0, so it could be commited when it enters in phase1.

In ConfD manual it is stated that “All files ending in .xml will be loaded (in an undefined order) and committed in a single transaction when CDB enters start phase 1”. From this I understood that the the loading and the commit would be performed on phase1, but it appears that the loading is performed in phase0, so I cannot create a dynamic XML in my application for the ConfD to load.

I could load the xml using maapi_load_file() but that would overwrite previous configurations performed by the user.

Do you know if it would be possible to do that somehow?

See examples.confd/cdb_subscription/trigger/start_system.sh for a detailed example.

A simplified variant that play Coldplay’s new album “Everyday Life” that is released tomorrow :wink:

$ pwd
$CONFD_DIR/examples.confd/restconf/yang-patch
$ make all
$ ls -1 confd-cdb
A.cdb
C.cdb
O.cdb
aaa_init.xml
jukebox_init.xml

$ confd --start-phase0 -c confd.conf --addloadpath $CONFD_DIR/etc/confd
$ confd_cmd -dd -c 'get_phase'
get_phase
TRACE Connected (cdb) to ConfD
TRACE CDB_GET_PHASE  --> CONFD_OK
phase: 0 flags: 0x0

$ confd_load -dd -i -Fp | head -n 10
TRACE Connected (maapi) to ConfD
attaching to init session...
TRACE MAAPI_ATTACH  --> CONFD_OK
TRACE MAAPI_SAVE_CONFIG  --> CONFD_OK
TRACE Connected (stream) to ConfD
TRACE MAAPI_SAVE_CONFIG_RESULT  --> CONFD_OK
<config xmlns="http://tail-f.com/ns/config/1.0">
  <jukebox xmlns="http://example.com/ns/example-jukebox">
    <library>
      <artist>
        <name>Foo Fighters</name>
        <album>
          <name>Wasting Light</name>
          <genre>alternative</genre>
          <year>2012</year>
          <admin>

$ confd_cmd -dd -c 'mattach_init; mcreate /jukebox/library/artist{"Coldplay"}; mcreate /jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"}; mset /jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"}/year " 2019";'
mattach_init ; mcreate "/jukebox/library/artist{"Coldplay"}" ; mcreate "/jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"}" ; mset "/jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"}/year" " 2019"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_ATTACH  --> CONFD_OK
TRACE MAAPI_CREATE /jukebox/library/artist{"Coldplay"} --> CONFD_OK
TRACE MAAPI_CREATE /jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"} --> CONFD_OK
TRACE MAAPI_SET_ELEM2 /jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"}/year --> CONFD_OK
TRACE MAAPI_END_USER_SESSION  --> CONFD_OK

$ confd --start-phase2
$ netconf-console --get-config -x '/jukebox/library/artist[name="Coldplay"]'
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <data>
    <jukebox xmlns="http://example.com/ns/example-jukebox">
      <library>
        <artist>
          <name>Coldplay</name>
          <album>
            <name>Everyday_Life</name>
            <year>2019</year>
          </album>
        </artist>
      </library>
    </jukebox>
  </data>
</rpc-reply>

$ netconf-console --rpc=- <<< '<play xmlns="http://example.com/ns/example-jukebox"><playlist>Coldplay</playlist><song-number>1</song-number></play>'
...

Maybe I wasn’t clear enough. In your example, suppose the following line is always executed by an application:

 confd_cmd -dd -c 'mattach_init; mcreate /jukebox/library/artist{"Coldplay"}; mcreate /jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"}; mset /jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"}/year " 2019";'
mattach_init ; mcreate "/jukebox/library/artist{"Coldplay"}" ; mcreate "/jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"}" ; mset "/jukebox/library/artist{"Coldplay"}/album{"Everyday_Life"}/year" " 2019"

Then the user removes all the coldplay information and restarts the ConfD. The coldplay information would be added back by the application to the CDB. But In this case I’d like to be able to check that the CDB was not recreated and keep the user configuration, i.e., don’t overwrite what the user configured. Is it possible?

The application I have must create different DEFAULT configurations based on the device ConfD is running. But after the user changes the config, that is the configuration that must be kept.

In the confd_load application step before that I read the config
Also, the maapi_create() call (see mcreate) that I did with the confd_cmd application will fail if that config already exists.
See the confd_cmd tool help text and man page and the MAAPI man page for more.