Chapter 12: DHCP Server Leases

Using the REST API, a list of cOS Core's current DHCP server leases can be retrieved. The information is sent back by cOS Core in JSON format and consists of the values that might also be provided by using the cOS Core CLI dhcp command.

Sending the Request

To the DHCP information, an HTTP GET should be sent with the following URI:
/api/oper/dhcpserver

The GET URI can take the optional parameter of a server name. For example:

/api/oper/dhcpserver?name=DHCP_core

Example JSON Replies

Below is an example of a typical JSON reply for a GET with no option showing leases for all servers:

{
  "error":false,
  "active_leases":[
    {
      "server":"DHCP_LAN",
      "interface":"lan",
      "client_ip":"192.168.2.100",
      "hostname":"VM-WIN10",
      "mac_address":"00-50-56-27-53-0A",
      "timeout":787
    },
    {
      "server":"DHCP_core",
      "interface":"core",
      "client_ip":"192.168.1.203",
      "hostname":"eth000000000000",
      "mac_address":"00-00-00-00-00-00",
      "timeout":754
    },
    {
      "server":"DHCP_core",
      "interface":"core",
      "client_ip":"192.168.1.202",
      "hostname":"eth000000000000",
      "mac_address":"00-00-00-00-00-00","timeout":754
    }
  ]
}

Below is an example of a typical JSON reply with the named single server option used in the URI for a server called DHCP_core:

{
  "error":false,
  "dhcpserver":{
    "server_name":"DHCP_core",
    "pool_usage_count":2,
    "pool_size":16,
    "pool_usage_percent":18
  },
  "active_leases":[
		{
      "server":"DHCP_core",
      "interface":"core",
      "client_ip":"192.168.1.203",
      "hostname":"eth000000000000",
      "mac_address":"00-00-00-00-00-00",
      "timeout":530
    },
    {
      "server":"DHCP_core",
      "interface":"core",
      "client_ip":"192.168.1.202",
      "hostname":"eth000000000000",
      "mac_address":"00-00-00-00-00-00",
      "timeout":530
    }
  ]
}