[j-nsp] NetConf - get_config filter

Serge Vautour sergevautour at yahoo.ca
Wed Jan 14 12:51:29 EST 2009


Just in case someone else has the same problem, here's the solution. 

get_configuration seems to be part of JunoScript. For NetConf, the method looks like:

    'get_config' => {
        'source' => $DOM_STRING,
        'source_url' => $URL_STRING,
        'filter' => $DOM
    },

A DOM object is simply xml code. So to get this to work I did:

my $xml_string = "
<filter type=\"subtree\">
<configuration>
  <protocols>
    <bgp></bgp>
  </protocols>
</configuration>
</filter>
"; 

my %queryargs = (
 'source' => "running",
 'filter' => $xml_string,
);

This generates the correct RPC request:

Server request: 
 <rpc message-id='1'><get-config> <source><running/> </source>
<filter type="subtree">
<configuration>
  <protocols>
    <bgp></bgp>
  </protocols>
</configuration>
</filter>
</get-config> </rpc>

Hope this helps someone. Could've saved me a few hours ;)

Serge


--- On Fri, 1/9/09, Serge Vautour <sergevautour at yahoo.ca> wrote:

> From: Serge Vautour <sergevautour at yahoo.ca>
> Subject: [j-nsp] NetConf - get_config filter
> To: juniper-nsp at puck.nether.net
> Received: Friday, January 9, 2009, 2:40 PM
> Hello,
> 
> I'm trying to use the NetConf Perl API provided on the
> Juniper site. I can successfully create a connection to the
> router and retrieve the entire configuration using
> "get_config".
> 
> Does anyone know if the NetConf Perl API provides a way to
> filter the request to retrieve a certain part of the config?
> Per the NetConf docs, the RPC request should look like:
> 
> <rpc>
>  <get-config>
>   <source>
>     <!- - tag specifying the source configuration -
> ->
>   </source>
>   <filter type="subtree">
>    <configuration>
>     <!- - opening tags for each parent of the requested
> object type - ->
>      <object-type/>
>       <!- - closing tags for each parent of the
> requested object type - ->
>    </configuration>
>   </filter>
>  </get-config>
> </rpc>
> 
> The get_configuration perl function only seems to have the
> following attributes:
> 
>     get_configuration => {
>         configuration => $DOM,
>         format => $ATTRIBUTE,
>         inherit => $ATTRIBUTE,
>         database => $ATTRIBUTE,
>     },
> 
> How does on request the "<filter
> type="subtree">"? Here's an example of
> the queryargs I use when calling get_config:
> 
> my $parser = new XML::DOM::Parser;
> my %queryargs = (
>  'source' => "running",
>  'format' => "xml",
>  'configuration' =>
> $parser->parsefile("protocols.xml") ,
> );
> 
> Where "protocols.xml" is a text file containing:
> 
> <configuration>
>   <protocols>
>     <bgp></bgp>
>   </protocols>
> </configuration>
> 
> When I run the script and echo the request, we get:
> 
> Server request: 
>  <rpc message-id='1'><get-config>
> <source><running/>
> </source></get-config> </rpc>
> 
> The API is creating the RPC call correctly for the
> "source". How do I get it to create the filter
> section? I've tried:
> 
> my $parser = new XML::DOM::Parser;
> my %queryargs = (
>  'source' => "running",
>  'format' => "xml",
>  'filter' => "subtree",
>  'configuration' =>
> $parser->parsefile("protocols.xml") ,
> );
> 
> However this creates:
> 
> Server request: 
>  <rpc message-id='1'><get-config>
> <source><running/>
> </source>subtree</get-config> </rpc>
> 
> This generates an error as the xml isn't formatted
> correctly. I've tried several other combinations without
> any luck. 
> 
> Can anyone point me in the right direction to filter the
> config output to a certain section?
> 
> Thanks,
> Serge Vautour
> SergeVautour at yahoo.ca
> 
> 
>      
> __________________________________________________________________
> Yahoo! Canada Toolbar: Search from anywhere on the web, and
> bookmark your favourite sites. Download it now at
> http://ca.toolbar.yahoo.com.
> _______________________________________________
> juniper-nsp mailing list juniper-nsp at puck.nether.net
> https://puck.nether.net/mailman/listinfo/juniper-nsp


      __________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now at
http://ca.toolbar.yahoo.com.


More information about the juniper-nsp mailing list