How to get the outter viewid when the nested loops are more than 2?

75 views
Skip to first unread message

xy l

unread,
Mar 5, 2020, 2:39:48 AM3/5/20
to klish
Hello, guys
I have three nested views, but I found that the 3rd view can't find the 1st view's id.
My xml is as below.
<?xml version="1.0" encoding="utf-8"?>
<CLISH_MODULE xmlns="http://clish.sourceforge.net/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://clish.sourceforge.net/XMLSchema                      http://clish.sourceforge.net/XMLSchema/clish.xsd">
 
<VIEW name="configure-view">
 
<COMMAND help="System operation configuration." name="system"></COMMAND>
 
<COMMAND help="System operation configuration." name="no system"></COMMAND>
 
<COMMAND help="Configure interfaces." viewid="interface=${name}" name="system interface" view="configure-system-interface-view">
 
<PARAM help="Name." name="name" ptype="STRING"></PARAM>
 
<ACTION>echo /api/v2/cmdb/system/interface/${interface}</ACTION>
 
<CONFIG pattern="^${__line}$"></CONFIG>
 
</COMMAND>
 
<COMMAND help="Configure interfaces." name="no system interface">
 
<ACTION>echo ${name}</ACTION>
 
<CONFIG operation="unset" pattern="^system interface ${name}"></CONFIG>
 
<PARAM help="Name." name="name" ptype="STRING"></PARAM>
 
</COMMAND>
 
<VIEW name="configure-system-interface-view" prompt="(config-system-interface-${interface})# " depth="1">
 
<NAMESPACE completion="true" ref="configure-view" help="false"></NAMESPACE>
 
<COMMAND lock="false" help="Exit from current mode" name="exit">
 
<ACTION builtin="clish_nested_up"></ACTION>
 
</COMMAND>
 
<COMMAND help="Negate a command or set its defaults" name="no"></COMMAND>
 
<COMMAND help="VRRP configuration." viewid="vrrp=${vrid}" name="vrrp" view="configure-system-interface-vrrp-view">
 
<PARAM help="Virtual router identifier (1 - 255)." name="vrid" ptype="INTEGER"></PARAM>
 
<ACTION>echo /api/v2/cmdb/system/interface/${interface}/vrrp/${vrrp}</ACTION>
 
<CONFIG pattern="^${__line}$"></CONFIG>
 
</COMMAND>
 
<COMMAND help="VRRP configuration." name="no vrrp">
 
<ACTION>echo ${vrid}</ACTION>
 
<CONFIG operation="unset" pattern="^vrrp ${vrid}"></CONFIG>
 
<PARAM help="Virtual router identifier (1 - 255)." name="vrid" ptype="INTEGER"></PARAM>
 
</COMMAND>
 
<VIEW name="configure-system-interface-vrrp-view" prompt="(config-system-interface-vrrp-${vrrp})# " depth="2">
 
<NAMESPACE completion="true" ref="configure-system-interface-view" help="false"></NAMESPACE>
 
<COMMAND lock="false" help="Exit from current mode" name="exit">
 
<ACTION builtin="clish_nested_up"></ACTION>
 
</COMMAND>
 
<COMMAND help="Negate a command or set its defaults" name="no"></COMMAND>
 
<COMMAND help="VRRP Proxy ARP configuration." viewid="proxy-arp=${id}" name="proxy-arp" view="configure-system-interface-vrrp-proxy-arp-view">
 
<PARAM help="ID." name="id" ptype="INTEGER"></PARAM>
 
<ACTION>echo /api/v2/cmdb/system/interface/${interface}/vrrp/${vrrp}/proxy-arp/${proxy-arp}</ACTION>
 
<CONFIG pattern="^${__line}$"></CONFIG>
 
</COMMAND>
 
<COMMAND help="VRRP Proxy ARP configuration." name="no proxy-arp">
 
<ACTION>echo ${id}</ACTION>
 
<CONFIG operation="unset" pattern="^proxy-arp ${id}"></CONFIG>
 
<PARAM help="ID." name="id" ptype="INTEGER"></PARAM>
 
</COMMAND>
 
<VIEW name="configure-system-interface-vrrp-proxy-arp-view" prompt="(config-system-interface-vrrp-proxy-arp-${proxy-arp})# " depth="3">
 
<NAMESPACE completion="true" ref="configure-system-interface-vrrp-view" help="false"></NAMESPACE>
 
<COMMAND lock="false" help="Exit from current mode" name="exit">
 
<ACTION builtin="clish_nested_up"></ACTION>
 
</COMMAND>
 
<COMMAND help="Negate a command or set its defaults" name="no"></COMMAND>
 
</VIEW>
 
</VIEW>
 
</VIEW>
 
</VIEW>
</CLISH_MODULE>
 
And the operation flow is as below.
/ # konfd
/ # clish -x /etc/klish
# configure terminal 
(config)# 
  !         Comments
  do        To run exec commands in config mode
  exit      Exit from configure mode
  hostname  Set system's network name
  ip        Global IP configuration subcommands
  no        Negate a command or set its defaults
  system    System operation configuration.

(config)# system interface 
  String  Name.

(config)# system interface mgmt
/api/v2/cmdb/system/interface/
(config-system-interface-mgmt)# 
  !     Comments
  exit  Exit from current mode
  no    Negate a command or set its defaults
  vrrp  VRRP configuration.

(config-system-interface-mgmt)# vrrp 1
/api/v2/cmdb/system/interface/mgmt/vrrp/
(config-system-interface-vrrp-1)# 
  !          Comments
  exit       Exit from current mode
  no         Negate a command or set its defaults
  proxy-arp  VRRP Proxy ARP configuration.

(config-system-interface-vrrp-1)# proxy-arp 
  Integer  ID.

(config-system-interface-vrrp-1)# proxy-arp 2
/api/v2/cmdb/system/interface//vrrp/1/proxy-arp/
(config-system-interface-vrrp-proxy-arp-2)# 
 
 It is bad that the inner ”configure-system-interface-vrrp-proxy-arp-view“ can't get the outter ”configure-system-interface-view“ viewid mgmt.

So what can I do? I didn't find any useful informations from the wiki.  

serj.kalichev

unread,
Mar 5, 2020, 4:02:35 AM3/5/20
to kl...@googlegroups.com

Hello

The viewid vars is active on the current level only i.e. within the target VIEW only.

You need something like this:

<COMMAND help="Configure interfaces." viewid="interface=${name}" name="system interface" view="configure-system-interface-view">

...


<COMMAND help="VRRP configuration." viewid="interface=${interface};vrrp=${vrid}" name="vrrp" view="configure-system-interface-vrrp-view">

...



05.03.2020 10:39, xy l пишет:
--
You received this message because you are subscribed to the Google Groups "klish" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klish+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/klish/47ef8628-de0e-4e14-9e04-3cfc549af603%40googlegroups.com.

xy l

unread,
Mar 5, 2020, 4:37:16 AM3/5/20
to klish
Thank you very much! It is very helpful!

在 2020年3月5日星期四 UTC+8下午5:02:35,Serj Kalichev写道:
To unsubscribe from this group and stop receiving emails from it, send an email to kl...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages