Network Computing is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Managing Switches with REST and Thrift APIs: Page 3 of 4

 

To configure the speed of the port, you use the same command but substitute Speed with extra data:

Before:

curl -X GET "http://10.7.1.78:8080/public/v1/config/Port?IntfRef=fpPort2" | python -m json.tool

 

 "Object": {

 "AdminState": "DOWN",

 "Autoneg": "OFF",

 "BreakOutMode": "1x100",

 "Description": "",

 "Duplex": "Full Duplex",

 "EnableFEC": false,

 "IfIndex": 140,

 "IntfRef": "fpPort2",

 "LoopbackMode": "",

 "MacAddr": "00:90:fb:55:e5:11",

 "MediaType": "Media Type",

 "Mtu": 9412,

 "PRBSPolynomial": "",

 "PRBSRxEnable": false,

 "PRBSTxEnable": false,

 "PhyIntfType": "KR4",

 "Speed": 100000

 },

 "ObjectId": "8029f48f-5b1b-492f-73b7-dc879e386508"

}

In the preceding code, you can see that the speed is 100 Gbps or 100 GbE. Now refer to the following code:

curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"IntfRef":"fpPort2","Speed":40000}' 'http://localhost:8080/public/v1/config/Port'| python -m json.tool

 

 "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type,

 Accept",

 "Access-Control-Allow-Methods": "POST, GET, OPTIONS, PATCH, DELETE",

 "Access-Control-Allow-Origin": "*",

 "Access-Control-Max_age": "86400",

 "ObjectId": "8029f48f-5b1b-492f-73b7-dc879e386508",

 "Result": "Success"

}

Here, we sent a command to change the speed to 40 Gbps or 40 GbE.

One thing to note is that integers do not have quotes ("") around them in the RESTful command, whereas strings do:

{"IntfRef":"fpPort2","Speed":40000}

To confirm the change, query the interface again:

curl -X GET "http://localhost:8080/public/v1/config/Port?IntfRef=fpPort2" | python -m json.tool

 

 "Object": {

 "AdminState": "DOWN",

 "Autoneg": "OFF",

 "BreakOutMode": "1x100",

 "Description": "",

 "Duplex": "Full Duplex",

 "EnableFEC": false,

 "IfIndex": 140,

 "IntfRef": "fpPort2",

 "LoopbackMode": "",

 "MacAddr": "00:90:fb:55:e5:11",

 "MediaType": "Media Type",

 "Mtu": 9412,

 "PRBSPolynomial": "",

 "PRBSRxEnable": false,

 "PRBSTxEnable": false,

 "PhyIntfType": "KR4",

 "Speed": 40000

 },

 "ObjectId": "8029f48f-5b1b-492f-73b7-dc879e386508"

}

In the Postman API development program, which we will discuss in depth in Chapter 5, Using Postman for REST API Calls, we can send the same commands via a graphical interface, which will return the same data as we saw via curl. For example, we send the following:

{GET} http://snaproute.router.ip:8080/public/v1/config/Ports

(Click on image for larger view)

 

We see the same output as we do with the curl command.

Configuring an interface

Using curl, you can easily configure an IP address on fpPort1:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"IntfRef":"fpPort1","IpAddr":"100.10.100.1/24"}' 'http://localhost:8080/public/v1/config/IPv4Intf'

 

{

 "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type,

  Accept",

 "Access-Control-Allow-Methods": "POST, GET, OPTIONS, PATCH, DELETE",

 "Access-Control-Allow-Origin": "*",

 "Access-Control-Max_age": "86400",

 "ObjectId": "a5856728-ab49-47b4-4ad4-de6a5e5a1ed3",

 "Result":"Success"

}

To confirm that the interface was properly set up, you can confirm its functionality via ping:

# ping 100.10.100.2

PING 100.10.100.2 (100.10.100.2) 56(84) bytes of data.

64 bytes from 100.10.100.2: icmp_seq=1 ttl=64 time=0.432 ms

64 bytes from 100.10.100.2: icmp_seq=2 ttl=64 time=0.338 ms

You can also look at the ARP table:

curl -X GET --header 'Content-Type: application/json' 'http://localhost:8080/public/v1/state/ArpEntrys' | python -m json.tool

{

 "CurrentMarker": 0,

 "MoreExist": false,

 "NextMarker": 0,

 "ObjCount": 1,

 "Objects": [

 {

 "Object": {

 "ExpiryTimeLeft": "8m23.814811246s",

 "Intf": "fpPort1",

 "IpAddr": "100.10.100.2",

 "MacAddr": "00:90:fb:59:3e:b7",

 "Vlan": "Internal Vlan"

 },

 "ObjectId": ""

 }

 ]

}

 

NEXT Page: Thrift