Libvirt and bhyve
Craig Rodrigues
rodrigc@FreeBSD.org
Bay Area FreeBSD Users Group
July 10, 2014
libvirt
What is libvirt?
● Open source project: http://libvirt.org
● Toolkit to interact with hypervisors: KVM, Xen,
LXC, OpenVZ, Usermode Linux, VirtualBox,
VMWare ESX, Hyper-V, Parallels, Bhyve
● C library, with bindings for other languages:
Python, Ruby, Java, C#, Ocaml, Perl, PHP
●
Used by many 3rd
party applications
Libvirt architecture
Source:
http://www.tuxradar.com/content/howto-linux-and-wind
libvirt and bhyve
Libvirt and bhyve:
Thanks to Roman
● Roman Bogorodskiy <novel@freebsd.org> has
added bhyve support to libvirt
● Roman has pushed the code upstream to
libvirt.org
Installing the code
● Need to build from ports, patches committed on July
9, 2014
● Update ports tree:
portsnap fetch; portsnap update
● Make sure you have libvirt 1.2.6 or higher
● Build it:
cd /usr/ports/devel/libvirt; make; make install
● In future, pkg install devel/libvirt
Running the code
● Customize /usr/local/etc/libvirtd.conf
● Start the demon: libvirtd
● Edit a config file in XML format with the bhyve
VM info
● Run commands via virsh to start the VM
● See step-by-step instructions:
http://people.freebsd.org/~rodrigc/libvirt/libvirt-bhyve
py-libvirt
py-libvirt
● Python bindings for libvirt
● Available in ports: /usr/ports/devel/py-libvirt
py-libvirt sample code
import libvirt
import sys
# Note we need to specify the URL here
conn = libvirt.openReadOnly("bhyve:///system")
if conn == None:
print 'Failed to open connection to the hypervisor'
sys.exit(1)
try:
print("All domains: ",conn.listAllDomains())
print("Defined domains: ", conn.listDefinedDomains())
dom0 = conn.lookupByName("bhyve")
except:
print 'Failed to find the main domain'
sys.exit(1)
print("Domain 0: id %d running" % (dom0.ID()))
print(dom0.info())
virt-manager
What is virt-manager?
● GUI application for interacting with libvirt
● Written in Python, with GTK bindings for GUI
● Available in ports:
/usr/ports/deskutils/virt-manager
● Patch to port for bhyve required:
http://people.freebsd.org/~rodrigc/libvirt/virt-manage
virt-manager screenshot
Jenkins and libvirt
Jenkins libvirt plugin
● Libvirt slaves plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Libvirt+S
● Allows VM's to be created on demand in
response to build jobs, and shut down after job
is complete
● See step-by-step instructions:
http://people.freebsd.org/~rodrigc/libvirt/libvirt-bhyve
Thanks!
● Roman Bogorodskiy <novel@freebsd.org>,
wrote the code, pushed it upstream
● Jason Helfman <jgh@freebsd.org>, maintains
the libvirt port
I need help
● Need more people to try this stuff out
● Report bugs to
freebsd-virtualization@freebsd.org
(see http://lists.freebsd.org )
● Supply code, patches, and documentation
● Implement more of the libvirt API for bhyve, and
send patches to Roman

Libvirt and bhyve under FreeBSD

  • 1.
    Libvirt and bhyve CraigRodrigues rodrigc@FreeBSD.org Bay Area FreeBSD Users Group July 10, 2014
  • 2.
  • 3.
    What is libvirt? ●Open source project: http://libvirt.org ● Toolkit to interact with hypervisors: KVM, Xen, LXC, OpenVZ, Usermode Linux, VirtualBox, VMWare ESX, Hyper-V, Parallels, Bhyve ● C library, with bindings for other languages: Python, Ruby, Java, C#, Ocaml, Perl, PHP ● Used by many 3rd party applications
  • 4.
  • 5.
  • 6.
    Libvirt and bhyve: Thanksto Roman ● Roman Bogorodskiy <novel@freebsd.org> has added bhyve support to libvirt ● Roman has pushed the code upstream to libvirt.org
  • 7.
    Installing the code ●Need to build from ports, patches committed on July 9, 2014 ● Update ports tree: portsnap fetch; portsnap update ● Make sure you have libvirt 1.2.6 or higher ● Build it: cd /usr/ports/devel/libvirt; make; make install ● In future, pkg install devel/libvirt
  • 8.
    Running the code ●Customize /usr/local/etc/libvirtd.conf ● Start the demon: libvirtd ● Edit a config file in XML format with the bhyve VM info ● Run commands via virsh to start the VM ● See step-by-step instructions: http://people.freebsd.org/~rodrigc/libvirt/libvirt-bhyve
  • 9.
  • 10.
    py-libvirt ● Python bindingsfor libvirt ● Available in ports: /usr/ports/devel/py-libvirt
  • 11.
    py-libvirt sample code importlibvirt import sys # Note we need to specify the URL here conn = libvirt.openReadOnly("bhyve:///system") if conn == None: print 'Failed to open connection to the hypervisor' sys.exit(1) try: print("All domains: ",conn.listAllDomains()) print("Defined domains: ", conn.listDefinedDomains()) dom0 = conn.lookupByName("bhyve") except: print 'Failed to find the main domain' sys.exit(1) print("Domain 0: id %d running" % (dom0.ID())) print(dom0.info())
  • 12.
  • 13.
    What is virt-manager? ●GUI application for interacting with libvirt ● Written in Python, with GTK bindings for GUI ● Available in ports: /usr/ports/deskutils/virt-manager ● Patch to port for bhyve required: http://people.freebsd.org/~rodrigc/libvirt/virt-manage
  • 14.
  • 15.
  • 16.
    Jenkins libvirt plugin ●Libvirt slaves plugin: https://wiki.jenkins-ci.org/display/JENKINS/Libvirt+S ● Allows VM's to be created on demand in response to build jobs, and shut down after job is complete ● See step-by-step instructions: http://people.freebsd.org/~rodrigc/libvirt/libvirt-bhyve
  • 17.
    Thanks! ● Roman Bogorodskiy<novel@freebsd.org>, wrote the code, pushed it upstream ● Jason Helfman <jgh@freebsd.org>, maintains the libvirt port
  • 18.
    I need help ●Need more people to try this stuff out ● Report bugs to freebsd-virtualization@freebsd.org (see http://lists.freebsd.org ) ● Supply code, patches, and documentation ● Implement more of the libvirt API for bhyve, and send patches to Roman