TOOL: op-mode-definition XML Generator

I created a tool to help with XML creation when developing custom op mode commands. The script can be found here:

Detailed usage instructions can be found on the github page.

As an example usage, here is the VyOS article for creating custom commands:

I’m going to recreate one of the commands they created.

We can start with just the outline of the command, which is “show calendar year”. This let’s us see the general format of the command easier. Here would be the basic outline:
show//calendar//!year@

Output
Enter your command: show//calendar//!year@

<?xml version="1.0" ?>
<interfaceDefinition>
  <node name="show">
    <children>
      <node name="calendar">
        <children>
          <leafNode name="year"/>
        </children>
      </node>
    </children>
  </node>
</interfaceDefinition>

Once everything looks good, we can complete the command. Here would be our command:
show//calendar@properties:help=Show the monthly calendar@command:=/usr/bin/cal//!year@properties:help=Show the yearly calendar@command:=/usr/bin/cal -y

Output
Enter your command: show//calendar@properties:help=Show the monthly calendar@command:=/usr/bin/cal//!year@properties:help=Show the yearly calendar@command:=/usr/bin/cal -y

<?xml version="1.0" ?>
<interfaceDefinition>
  <node name="show">
    <children>
      <node name="calendar">
        <properties>
          <help>Show the monthly calendar</help>
        </properties>
        <command>/usr/bin/cal</command>
        <children>
          <leafNode name="year">
            <properties>
              <help>Show the yearly calendar</help>
            </properties>
            <command>/usr/bin/cal -y</command>
          </leafNode>
        </children>
      </node>
    </children>
  </node>
</interfaceDefinition>

Hopefully this is useful to you!

6 Likes

Here’s a real world example I added that I find useful.

I like to be able to send commands directly to containers without needing to enter an interactive shell.

I run the script to create my command:

Output
Enter your command: connect//<container>@properties:help=Attach to a running container:completionHelp:path=container name@command:=sudo podman exec --interactive --tty $3 /bin/sh//<sendcmd>@properties:help=Send command to container@command:=sudo podman container exec $3 $5

<?xml version="1.0" ?>
<interfaceDefinition>
  <node name="connect">
    <children>
      <tagNode name="container">
        <properties>
          <help>Attach to a running container</help>
          <completionHelp>
            <path>container name</path>
          </completionHelp>
        </properties>
        <command>sudo podman exec --interactive --tty $3 /bin/sh</command>
        <children>
          <tagNode name="sendcmd">
            <properties>
              <help>Send command to container</help>
            </properties>
            <command>sudo podman container exec $3 $5</command>
          </tagNode>
        </children>
      </tagNode>
    </children>
  </node>
</interfaceDefinition>

After building the VyOS package, I now have something to send commands directly to containers:

vyos@vyos:~$ connect container zt1
Possible completions:
  <Enter>               Execute the current command
  sendcmd               Send command to container

vyos@vyos:~$ connect container zt1 sendcmd
Possible completions:
  <text>                Send command to container

vyos@vyos:~$ connect container zt1 sendcmd hostname
zt1
2 Likes

That is cool stuff! Check this out @dmbaturin

1 Like

Really cool @L0crian I didn’t see this sooner and wrote an XML op def by hand yesterday and it was a lot of trial and error to get it right. This is really useful!