Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DOC and version 7.4.0-7.4.6

...

DHCP Management Version 2 integrates DHCP management with ProVision's resource and permissions hierarchy, as well as the IP Management system.  Individual DHCP servers can be assigned via Resource Permissions  to different internal user groups, to be managed by only the appropriate parties.

...

The DHCPv2 system builds upon the ProVision Resource APIWith the exception of a few configuration commands all DHCPv2 API commands use the Resource family of API endpoints.

 

Expand
titleHow to attach the DHCP Module as a child

As described above, DHCPv2 functionality is enabled on a particular resource by attaching a DHCP Module as a child.  A command to do this is as follows:

Code Block
            [ProVision root]/api/v1/api.php?target=resource&action=add
 
            data:
meta[type]: dhcp_module
meta[name]: [parent resource id] DHCP Module
meta[parent_id]: [parent resource id]


The special resource type “dhcp_module” indicates to ProVision that the DHCP system is enabled for the parent object.  The attributes associated with the “dhcp_module” resource govern the DHCP system's behavior. 


Updating the attributes of a DHCP Server uses a Resource Update command:


Code Block
[ProVision root]/api/v1/api.php?target=resource&action=update&meta[id]=2178 &meta[type]=dhcp_module&fields[_dhcp_attributes][]={"type":"ISC","notes":"notes go here","username":"username","port":"port","config_test":"/etc/init.d/dhcpd configtest","server_stop":"/etc/init.d/dhcpd stop","server_start":"/etc/init.d/dhcpd start","config_path":"/tmp/dhcpd.conf","option_routers":"192.168.0.0","option_domain_name_servers":"ns1.6connectexample.com","option_domain_name":"6connectexample.com","authoritative":"1","default_lease_time":"600","max_lease_time":"7200","local_port":"67","log_facility":"local7","password":"password","server_ip":"192.168.0.1","freeLines":3,"freeLine1":"free line 1","freeLine2":"free line 2","freeLine3":"free line 3"}


This command appears rather complicated, but can be broken apart into reasonable pieces.  The first section:


Code Block
target=resource&action=update&meta[id]=2178&meta[type]=dhcp_module


is familiar from other parts of ProVision.  We are updating a resource of type “dhcp_module” whose resource id is 2178.  The second section of the command details the update values, starting with

           

Code Block
 fields[_dhcp_attributes][]=


which contains a JSON-encoded string of all the fields specific to a DHCP server's function.  When expanded into its full object form it is substantially easier to digest:


Code Block
{
            "type":"ISC",
            "notes":"notes go here",
            "username":"username",
            "port":"port",
            "config_test":"/etc/init.d/dhcpd configtest",
            "server_stop":"/etc/init.d/dhcpd stop",
            "server_start":"/etc/init.d/dhcpd start",
            "config_path":"/tmp/dhcpd.conf",
            "option_routers":"192.168.0.0",
            "option_domain_name_servers":"ns1.6connectexample.com",
            "option_domain_name":"6connectexample.com",
            "authoritative":"1",
            "default_lease_time":"600",
            "max_lease_time":"7200",
            "local_port":"67",
            "log_facility":"local7",
            "password":"password",
            "server_ip":"192.168.0.1",
            "freeLines":3,
            "freeLine1":"free line 1",
            "freeLine2":"free line 2",
            "freeLine3":"free line 3"
}


This object describes all the most common DHCP server configuration options.  For a full explanation of each of the fields, see the Detailed API Specification later in this document. 


Please note that the object above must be passed to the DHCP system as a JSON-encoded string.  It must be passed into the special “_dhcp_attributes” attribute for it to be functional, as in the example URL.

...

For details on how to manage IP aggregates using ProVision's IPAM API, see API Module - IPAM.

Of particular interest to DHCP management is the addition of DHCP aggregates, which are sections of IP space marked as available for use by the DHCPv2 system. 

...

Expand
titleHow to add a DHCP Aggregate

An example command to add a DHCP Aggregate is: 


Code Block
[ProVision root]/api/v1/api.php?target=ipam&action=add&block=192.168.0.0/24&rir= 1918&vlan=&tags=&region=&resourceId=1282&allowSubAssignments=true

 

The important part to note is that the IP block is being assigned to resourceId 1282, which corresponds to the DHCP Available resource.  The DHCP Available resource is a system-level resource which is used to hold all unassigned DHCP IP addresses.  Every instance has its own DHCP Available resource, whose id can be found with the following command:


Code Block
[ProVision root]/api/v1/api.php?target=resource&action=get&slug=dhcp-available


New DHCP subnets and hosts draw their IPs from this pool.  If there are no IPs in the DHCP Available pool new subnets and hosts will not be able to be created.


DHCP IP aggregates are fetched, updated, split, and deleted using the standard IPAM management API endpoints.  Please see the IPAM API Documentation. for details.

Subnets and Hosts

...

Expand
titleHow to create DHCP Pools

 Similar to how the “dhcp_module” resource was created above, the command to create a DHCP Pool is as follows: 

Code Block
[ProVision root]/api/v1/api.php?target=resource&action=add&meta[type]=dhcp_pool &meta[name]=New Subnet&fields[_dhcp_type][]=subnet&fields[_dhcp_pool_attributes][]={"mac":"","rangeStart":"","rangeEnd":"","freeLines":3,"freeLine1":"Free Line 1","freeLine2":"Free Line 2","freeLine3":"Free Line 3"}


The first half of this command is relatively straightforward:


Code Block
target=resource&action=add&meta[type]=dhcp_pool&meta[name]=New Subnet

This section informs the API that we wish to create a new, empty “dhcp_pool” resource whose name is “New Subnet.”

 

Code Block
fields[_dhcp_type][]=subnet&fields[_dhcp_pool_attributes][]={"mac":"","rangeStart":"", "rangeEnd":"","freeLines":3,"freeLine1":"Free Line 1","freeLine2":"Free Line 2","freeLine3":"Free Line 3"}


The second half of the command behaves in a similar manner to the “dhcp_module.”  The “_dhcp_pool_attributes” field holds a JSON-encoded string which describes the dhcp_pool resource.  When expanded, the JSON string becomes the following object:

Code Block
{
            "mac":"",
            "rangeStart":"",
            "rangeEnd":"",
            "freeLines":3,
            "freeLine1":"Free Line 1",
            "freeLine2":"Free Line 2",
            "freeLine3":"Free Line 3"
}


For a full explanation of each of the fields, see the Detailed API Specification


Note
Please note that the object above must be passed to the DHCP system as a JSON-encoded string.  It must be passed into the “_dhcp_pool_attributes” attribute for it to be functional, as in the example URL.

 

Once a dhcp_pool resource is in the system it can be updated with IP data obtained from the IP Management system.  Under DHCPv2, the DHCP system uses all the standard IPAM API endpoints and can make use of both the smartAssign and the directAssign methods.  Please see the IPAM API documentation for details.

Expand
titleHow to smart-assign a DHCP IP range from the DHCP Available resource to a dhcp_pool resource

An example command for smart-assigning a DHCP IP range from the DHCP Available resource to a newly-created dhcp_pool resource is as follows:

Code Block
[ProVision root]/api/v1/api.php?target=ipam&action=smartAssign&resourceId=2180& type=ipv4&mask=31&rir=1918&assignedResourceId=1282

In this example we are using the IPAM API endpoint to smart-assign an IPv4 /31 from the DHCP Available resource (resource id 1282) to the newly-created dhcp_pool object (resource id 2180).  This action removes this IP range from the available pool and prevents it from being used by other parts of ProVision.


Once an IP block is assigned to a dhcp_pool it should be updated with the proper range start and range end.  A Resource Update command is used for this.


Code Block
[ProVision root]/api/v1/api.php?target=resource&action=update&meta[type]=dhcp_pool& meta[name]=Another Test&fields[_dhcp_type][]=subnet&fields[_dhcp_pool_attributes][]={"mac":"","rangeStart":"10.10.10.4","rangeEnd":"10.10.10.5","freeLines":3,"freeLine1":"example1","freeLine2":"example2","freeLine3":"example3"}&fields[_dhcp_ip_id][]=92430&meta[id]=2180

The key information here is that the “rangeStart” and the “rangeEnd” fields in the JSON-encoded '_dhcp_pool_attributes' attribute have been populated with the beginning and end of the IP range assigned by smart-assign.  Also note that a new field is being populated as '_dhcp_ip_id', which contains the IPAM id of the newly-assigned IP block. 

When assigning dhcp_pools covering a single host the steps are much the same, but the 'mac' field in the '_dhcp_pool_attributes' object must be populated with the MAC address of the host in question.


...