Add static DHCP for dynamic inventory

In some cases it is simpler to just configure the images being deployed
to use DHCP, rather than teach them how to put the IP address in the
configdrive in the right place. This will setup dnsmasq to send the
static address for the box. It will use that address for the deploy as
well.

Co-Authored-By: Clint Byrum <clint@fewbar.com>
Co-Authored-By: Gregory Haynes <greg@greghaynes.net>
Co-Authored-By: Julia Kreger <juliaashleykreger@gmail.com>
Change-Id: I524958be5e787d42c91278baf2c4a14beb965e7c
This commit is contained in:
Clint Byrum 2015-08-26 13:07:12 -07:00 committed by Julia Kreger
parent 1f3fd7511a
commit b0d8b037fa
10 changed files with 51 additions and 1 deletions

View File

@ -57,3 +57,12 @@ in a trusted environment.
+-------------+ +-----------+
|Ironic Server| | Server |
+-------------+ +-----------+
===============================================================
Setting static DHCP assignments with the integrated DHCP server
===============================================================
You can set up a static DHCP reservation using the ``ipv4_address`` parameter
and setting the ``inventory_dhcp`` setting to a value of ``true``. This will
result in the first MAC address defined in the list of hardware MAC addresses
to receive a static address assignment in dnsmasq.

View File

@ -50,6 +50,10 @@ instance_info: A dictionary containing the information to define an instance.
expected are image_source, image_checksum, root_gb, however,
any supported key/value can be submitted to the API.
inventory_dhcp: A boolean value, defaulted to false, which causes the role
to update a template file and reload dhsmasq upon each update
in order to perform static dhcp assignments utilizing the
ipv4_address parameter.
Dependencies
------------

View File

@ -6,3 +6,4 @@ network_interface: "virbr0"
http_boot_folder: "/httpboot"
deploy_image_filename: "deployment_image.qcow2"
deploy_image: "{{http_boot_folder}}/{{deploy_image_filename}}"
inventory_dhcp: false

View File

@ -17,6 +17,13 @@
# the pass-through could mean that the user could deploy
# things that are not directly accessible or reasonable
# to be inspected.
- name: "Setup DHCP for nodes."
template: src=templates/dhcp-host.j2 dest=/etc/dnsmasq.d/bifrost.dhcp-hosts.d/{{ hostname }}
delegate_to: localhost
when: instance_info is defined and inventory_dhcp | bool
- name: "Sending dnsmasq HUP"
service: name=dnsmasq state=reloaded
when: instance_info is not defined and inventory_dhcp | bool
- name: "Deploy to hardware - Using custom instance_info."
os_ironic_node:
auth_type: None

View File

@ -0,0 +1,2 @@
# This file is managed by bifrost
{{ nics[0]['mac'] }},{{ipv4_address}},{{name}},12h

View File

@ -60,6 +60,12 @@ If you chose to utilize the dhcp server, You may wish to set default ranges:
dhcp_pool_start: 192.168.1.200
dhcp_pool_end: 192.168.1.250
Alternatively, a user can choose to perform static DHCP assignments to nodes.
This can be enabled by setting the ``inventory_dhcp`` setting to ``true``.
This will result in the ``dhcp_pool_start`` and ``dhcp_pool_end`` settings
being ignored and the ``ipv4_address`` setting being bound to the first
listed MAC address for the node.
In case your HW needs a kernel option to boot, set the following variable:
extra_kernel_options: Default undefined.

View File

@ -45,7 +45,8 @@ shade_git_folder: /opt/stack/shade
dib_git_folder: /opt/stack/diskimage-builder
# Comma-separated list, in the format of a string, of drivers that are enabled.
enabled_drivers: "agent_ipmitool,pxe_amt,agent_ilo,agent_ucs"
# DHCP pool for requests.
# DHCP pool for requests -- ignored if inventory_dhcp is set to True
# since IP allocation will be static.
dhcp_pool_start: 192.168.1.200
dhcp_pool_end: 192.168.1.250
# Default network interface that bifrost will be attached to.
@ -64,3 +65,7 @@ cors_allowed_origin: "http://localhost:8000"
# the setting should be set to false. This setting should
# not need to be modified by the user.
enable_cors_credential_support: false
# Set this to true to configure dnsmasq to respond to requests from the
# hosts in your dynamic inventory.
inventory_dhcp: False

View File

@ -159,6 +159,12 @@
service: name=ironic-api state=restarted
- name: "Create and populate /tftpboot"
include: create_tftpboot.yml
- name: "Setup Inventory Hosts Directory"
file: path=/etc/dnsmasq.d/bifrost.hosts.d state=directory owner=root group=root mode=0755
when: "{{inventory_dhcp|bool}}"
- name: "Setup Inventory DHCP Hosts Directory"
file: path=/etc/dnsmasq.d/bifrost.dhcp-hosts.d state=directory owner=root group=root mode=0755
when: "{{inventory_dhcp|bool}}"
- name: "Deploy dnsmasq configuration file"
template: src=dnsmasq.conf.j2 dest=/etc/dnsmasq.conf
when: "{{include_dhcp_server|bool}}"

View File

@ -125,6 +125,10 @@ bind-interfaces
# or if you want it to read another file, as well as /etc/hosts, use
# this.
#addn-hosts=/etc/banner_add_hosts
{% if inventory_dhcp %}
addn-hosts=/etc/dnsmasq.d/bifrost.hosts.d
dhcp-hostsfile=/etc/dnsmasq.d/bifrost.dhcp-hosts.d
{% endif %}
# Set this (and domain: see below) if you want to have a domain
# automatically added to simple names in a hosts-file.
@ -150,11 +154,13 @@ bind-interfaces
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
# service.
{% if not inventory_dhcp %}
{% if testing %}
dhcp-range=192.168.122.2,192.168.122.254,12h
{% else %}
dhcp-range={{dhcp_pool_start}},{{dhcp_pool_end}},12h
{% endif %}
{% endif %}
# This is an example of a DHCP range where the netmask is given. This
# is needed for networks we reach the dnsmasq DHCP server via a relay

View File

@ -0,0 +1,4 @@
# This file is managed by bifrost
{% for hostname, host in dynamic_inventory %}
{% host['ipv4_address'] %} {% hostname %}
{% endfor %}