Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

Configure MX router using REST API

‎03-04-2019 03:39 AM

Hi Team, 

 

I want to configure MX router ge-0/0/1 interface IP address using REST API through 'curl' request. 

Please any one provide complete code for this.?

 

3 REPLIES 3
Junos Automation (Scripting)

Re: Configure MX router using REST API

‎03-04-2019 04:25 PM
Junos Automation (Scripting)

Re: Configure MX router using REST API

‎03-06-2019 01:44 AM

Hi naisamuddin,

 

Please find a working example of a REST API using Curl command and corresponding MX config here:

 

root@MX> show version | grep Junos:
Junos: 16.1

 

root@MX> show interfaces terse lo0
Interface Admin Link Proto Local Remote
lo0 up up
lo0.0 up up inet 10.0.6.25 --> 0/0
lo0.16384 up up inet 127.0.0.1 --> 0/0
lo0.16385 up up inet

 

root@MX> show configuration system services
rest {
http {
port 1234;
}
enable-explorer;
}


From Server:
==============
C:\>curl http://labroot:lab123@10.1.1.1:1234/rpc?stop-on-error=1 -d "<lock-configuration/><load-configuration><configuration><interfaces><interface><name>lo0</name><unit><name>0</name><description>Somethinghere</description><family><inet><address><name>2.0.0.6/32</name></address></inet></family></unit></interface></interfaces></configuration></load-configuration><commit/><unlock-configuration/>"

 

RESULT:
-------------
--nwlrbbmqbhcdarz

--nwlrbbmqbhcdarz
Content-Type: application/xml; charset=utf-8

<load-configuration-results>
<load-success/>
</load-configuration-results>
--nwlrbbmqbhcdarz
Content-Type: application/xml; charset=utf-8

<commit-results xmlns:junos="http://xml.juniper.net/junos/*/junos">
<routing-engine junos:style="normal">
<name>re0</name>
<commit-success/>
<commit-revision-information>
<new-db-revision>re0-1551864399-284</new-db-revision>
<old-db-revision>re0-1551761092-283</old-db-revision>
</commit-revision-information>
</routing-engine>
</commit-results>
--nwlrbbmqbhcdarz

--nwlrbbmqbhcdarz--


AFTER the commit via Curl:
============================

root@MX> show interfaces terse lo0
Interface Admin Link Proto Local Remote
lo0 up up
lo0.0 up up inet 2.0.0.6 --> 0/0
10.0.6.25 --> 0/0
lo0.16384 up up inet 127.0.0.1 --> 0/0
lo0.16385 up up inet

 

root@MX> show interfaces descriptions lo0.0
Interface Admin Link Description
lo0.0 up up Somethinghere

 

Hope this helps.

 

Regards,
-r.

--------------------------------------------------

If this solves your problem, please mark this post as "Accepted Solution."
Kudos are always appreciated Smiley Happy.

 

Junos Automation (Scripting)

Re: Configure MX router using REST API

‎03-06-2019 08:27 PM

Hello niasamuddin, also look at the new post its relevant and you might find it interesting:

 

https://forums.juniper.net/t5/Junos-Space-Developer/Announcing-SpaceEZ-a-new-Python-module-for-easy-...

 

Hope this helps.

 

Regards,
-r.

--------------------------------------------------

If this solves your problem, please mark this post as "Accepted Solution."
Kudos are always appreciated Smiley Happy.