Junos OS

last person joined: 15 hours ago 

Ask questions and share experiences about Junos OS.
  • 1.  Template output question

     
    Posted 04-14-2010 03:51

    Hi, I'm trying to use templates in order to write more modulare code.

    My question is: is possible to have a template returning an xml element, or at least more than just one variable?

    I tried to use the copy-of statement but it doesn't seem to work properly.

    As an example I paste here the code of my template;

     

    template print-mcast-route($ip-address) {
    	var $rpc = <get-multicast-route-information>{<extensive>;}
    	var $results = jcs:invoke($rpc);
    	
    	for-each($results/route-family/multicast-route[multicast-group-address == $ip-address])
    	{
    	var $multicast-source-address = multicast-source-address;
    	var $multicast-source-prefix-length = multicast-source-prefix-length;
    	var $multicast-source = $multicast-source-address _ "/" _ $multicast-source-prefix-length;
    	var $multicast-route-state = multicast-route-state;
            }
    
            copy-of $multicast-source;
            copy-of $multicast-route-state;
    }

    If I call this template, it returns only the $multicast-route-state, but not the $multicast-source variable.

     

    I dont' think I am using the correct syntax, and I already tried several workarounds without any success....The documentation about templates did not help me so much (I studied the day-One books as well as the "configuration and diagnostic automation guide").

     

    Thanks in advance for your help,

     

    Mattia

     

     



  • 2.  RE: Template output question
    Best Answer

    Posted 04-14-2010 08:38

    Try this in the template instead of copy-of:

     

    <source> $multicast-source;

    <route-state> $multicast-route-state;

     

    Then, when you call the template, make sure you use the := conversion operator rather than just the = assignment operator:

     

    var $results := { call print-mcast-route( $ip-address ); }

     

    That way you can reference the values like this:

     

    $results/source

     

    or

     

    $results/route-state

     

     



  • 3.  RE: Template output question

     
    Posted 04-14-2010 09:20

    Thank you very much Curtis, I had already tried the syntax you suggest me but without using the conversion operator... 

    Now it works perfectly Smiley Happy