Skip to content

Automatically derive device-type from package meta data

Kristian Larsson requested to merge 79-auto-derive-device-type into master

To add a new device to NSO we have to specify the device-type together with a ned-id. This information is already available in the package meta data file in the NED so all we have to do is move it to the right place. As both the package meta data and the add-device.xml template are XML files this isn't entirely straight forward (as working with any deeply structured data is). xmlstarlet to the rescue.

It might be worthwhile to explain what is going on here;

  • we determine the package meta data file dynamically by looking for either package-meta-data.xml or a package-meta-data.xml.in file.
  • we look at the NSO version, for on NSO 4 we should not specify the ned-id for NETCONF devices
  • then we run "the one-liner" - a freakish nightmare of a one-liner, which does get the job done
    • find the parent of the ned-id node (will be either netconf/cli/generic) in the package-meta-data file and join it together with the add-device xml file, adding a fake root called xsl-select (otherwise it's not a valid XML document)
    • find the parent of ned-id and remove any child nodes that are not "ned-id" - this is to remove things like java-class-name etc that might be in the package-meta-data file
    • move the parent of ned-id (i.e. netconf/cli/generic node) with children in under the device-type node in the add-device.xml file (which is at this point just a part of a common XML document)
      • note how the original namespace is NOT preserved but it is for child nodes, which is crucial as the ned-id line uses namespaces
    • possible strip the ned-id (STRIP_NED) in case we are on NSO 4
    • do some tail / head / cut to fix indent and remove the fake root node
      • xmlstarlet can also strip stuff but would inject loads of xmlns in the result making it look uglier, so opted for basic solution which for such a simple operation still has very low risk of failure

Also install xmlstarlet since we now depend on it.

Closes #79 (closed)

Merge request reports