Created
August 3, 2016 00:55
-
-
Save jbarber/52c94eb4f2e14881865531ab65bb7db4 to your computer and use it in GitHub Desktop.
Example of adding/removing libvirt DHCP host entriy with ruby-libvirt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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