Skip to content

Instantly share code, notes, and snippets.

@jbarber
Created August 3, 2016 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarber/52c94eb4f2e14881865531ab65bb7db4 to your computer and use it in GitHub Desktop.
Save jbarber/52c94eb4f2e14881865531ab65bb7db4 to your computer and use it in GitHub Desktop.
Example of adding/removing libvirt DHCP host entriy with ruby-libvirt
# Example of ruby-libvirt bindings to add a DHCP entry for a particular host
# This updates the dnsmasq config
# Requires ruby-libvirt 0.6.0
require 'libvirt'
conn = Libvirt::open()
network = conn.lookup_network_by_name('default')
xml = %q(<host mac='52:54:00:00:00:01' name='bob' ip='192.168.122.45'/>)
# Add the lease
network.update(
Libvirt::Network::UPDATE_COMMAND_ADD_LAST,
Libvirt::Network::SECTION_IP_DHCP_HOST,
-1,
xml,
Libvirt::Network::UPDATE_AFFECT_LIVE | Libvirt::Network::UPDATE_AFFECT_CONFIG
)
# Remove the lease
network.update(
Libvirt::Network::UPDATE_COMMAND_DELETE,
Libvirt::Network::SECTION_IP_DHCP_HOST,
-1,
xml,
Libvirt::Network::UPDATE_AFFECT_LIVE | Libvirt::Network::UPDATE_AFFECT_CONFIG
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment