vagrant-libvirt: Cannot install on OS X because of ruby-libvirt

Installing ruby-libvirt on OS X does not work because of

https://bugzilla.redhat.com/show_bug.cgi?id=1161338

domain.c:5439:29: error: use of undeclared identifier 'VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK'
                    INT2NUM(VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK));
                            ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:1167:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:241:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
domain.c:5443:29: error: use of undeclared identifier 'VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT'
                    INT2NUM(VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT));
                            ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:1167:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:241:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
domain.c:5447:29: error: use of undeclared identifier 'VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT'
                    INT2NUM(VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT));
                            ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:1167:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:241:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
domain.c:5451:29: error: use of undeclared identifier 'VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT'
                    INT2NUM(VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT));
                            ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:1167:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:241:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
                                            ^
domain.c:5455:29: error: use of undeclared identifier 'VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP'
                    INT2NUM(VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP));
                            ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:1167:35: note: expanded from macro 'INT2NUM'
# define INT2NUM(v) INT2FIX((int)(v))
                                  ^
/opt/vagrant/embedded/include/ruby-2.0.0/ruby/ruby.h:241:45: note: expanded from macro 'INT2FIX'
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 1
  • Comments: 44 (3 by maintainers)

Most upvoted comments

This actually works. vagrant on macOS, libvirt on Ubuntu 17.04

macOS Sierra 10.12.6 Vagrant 2.0.0

  1. Install Homebrew

  2. Install necessary Homebrew recipes.

    brew install libiconv gcc libvirt
    
  3. Find the version of ruby used by your version of vagrant. Mine was 2.3.4

    /opt/vagrant/embedded/bin/ruby --version
    
  4. Install the vagrant plugin.

    CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/include/libvirt with-libvirt-lib=/usr/local/lib' \
    GEM_HOME=~/.vagrant.d/gems/2.3.4 \
    GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems \
    PATH=/opt/vagrant/embedded/bin:$PATH \
    vagrant plugin install vagrant-libvirt
    

Remote Host: Ubuntu 17.04 (zesty) @ 192.168.15.127 libvirt-daemon 2.5.0-3ubuntu5.5

This Vagrantfile will start a debian/jessie64 box on the host at 192.168.15.127. TCP:4242 on your local machine will be forwarded to the box.

Example Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "debian/jessie64"
  config.vm.provider :libvirt do |libvirt|
    libvirt.host = "192.168.15.127"
    libvirt.connect_via_ssh = true
  end
  config.vm.network "forwarded_port", guest: 4242, host: 4242, host_ip: "127.0.0.1"
  config.vm.synced_folder ".", "/vagrant", disabled: true
end

Travis and Azure DevOps both provide free builders for MacOS, quite useful for testing and assuring that the plugin is at least builable and instalable.

I can confirm that adding the mentioned environment variables allows me to install the plugin, which means that the build code needs to be updated to avoid the need for them.

vagrant version                                                                                                                                                                                                               Installed Version: 2.2.4
Latest Version: 2.2.4

CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/include/libvirt with-libvirt-lib=/usr/local/lib' GEM_HOME=~/.vagrant.d/gems/2.4.4 GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems PATH=/opt/vagrant/embedded/bin:$PATH vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Building native extensions.  This could take a while...
Fetching: fog-libvirt-0.6.0.gem (100%)
Fetching: vagrant-libvirt-0.0.45.gem (100%)
Installed the plugin 'vagrant-libvirt (0.0.45)'!

PS. If any maintainer needs access to a macos shell, please ping me on private and I will create an account for you on my box.

Few things said in this thread are a little confusing

  • should CONFIGURE_ARGS have flags with double-dash or without?
    • turns out both styles work (with-libvirt-lib= is same as --with-libvirt-lib=)
  • is with-ldflags=-L/opt/vagrant/embedded/lib actually needed?
    • turns out it is not needed (at least with vagrant 2.2.7 and ruby-libvirt 0.7.1)
  • some folks mentioned NOKOGIRI_USE_SYSTEM_LIBRARIES=true
    • this didn’t make any difference (at least with vagrant 2.2.7 and nokogiri 1.10.9)
  • it’s not clear if libiconv is actually needed or not

However, key details that are more critical are these:

  • above everyone seem so use with-libvirt-include=${prefix}/include/libvirt
    • that doesn’t work because the C code has #include <libvirt/libvirt.h>, so this will have to be with-libvirt-include=${prefix}/include (note: it’s not the subdirectory)

Here is what worked for me:

brew cask install vagrant && brew install libvirt
env CONFIGURE_ARGS="with-libvirt-lib=$(brew --prefix libvirt)/lib with-libvirt-include=$(brew --prefix libvirt)/include" vagrant plugin install vagrant-libvirt
``` $ brew cask install vagrant && brew install libvirt Updating Homebrew... ==> Auto-updated Homebrew! Updated 2 taps (homebrew/core and homebrew/cask). ==> Updated Formulae curl-openssl ==> Updated Casks microsoft-office

==> Downloading https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.dmg Already downloaded: /Users/ilya/Library/Caches/Homebrew/downloads/accec21e850b3dbacc4d406adebaecc0265de9b285c3e8431fcb7443f311d4d2–vagrant_2.2.7_x86_64.dmg ==> Verifying SHA-256 checksum for Cask ‘vagrant’. ==> Installing Cask vagrant ==> Running installer for vagrant; your password may be necessary. ==> Package installers may write to any location; options such as --appdir are ignored. installer: Package name is Vagrant installer: Installing at base path / installer: The install was successful. 🍺 vagrant was successfully installed! ==> Downloading https://libvirt.org/sources/libvirt-6.1.0.tar.xz Already downloaded: /Users/ilya/Library/Caches/Homebrew/downloads/42ed86b94110afc9b83a2cea9a114b765a8428faddac809ba6a1d260d8a09e1c–libvirt-6.1.0.tar.xz ==> …/configure --prefix=/Users/ilya/Library/Local/Homebrew/Cellar/libvirt/6.1.0 --localstatedir=/Users/ilya/Library/Local/Homebrew/var --mandir=/Users/ilya/Library/Local/Homebrew/Cel ==> make ==> make install ==> Caveats To have launchd start libvirt now and restart at login: brew services start libvirt Or, if you don’t want/need a background service you can just run: libvirtd ==> Summary 🍺 /Users/ilya/Library/Local/Homebrew/Cellar/libvirt/6.1.0: 532 files, 36.5MB, built in 2 minutes 7 seconds $ libvirt_prefix=“$(brew --prefix libvirt)” $ env CONFIGURE_ARGS=“with-libvirt-lib=${libvirt_prefix}/lib with-libvirt-include=${libvirt_prefix}/include” vagrant plugin install vagrant-libvirt
Installing the ‘vagrant-libvirt’ plugin. This can take a few minutes… Fetching: formatador-0.2.5.gem (100%) Fetching: excon-0.72.0.gem (100%) Fetching: fog-core-1.43.0.gem (100%) Fetching: mini_portile2-2.4.0.gem (100%) Fetching: nokogiri-1.10.9.gem (100%) Building native extensions. This could take a while… Fetching: fog-json-1.2.0.gem (100%) Fetching: fog-xml-0.1.3.gem (100%) Fetching: ruby-libvirt-0.7.1.gem (100%) Building native extensions. This could take a while… Fetching: fog-libvirt-0.7.0.gem (100%) Fetching: vagrant-libvirt-0.0.45.gem (100%) Installed the plugin ‘vagrant-libvirt (0.0.45)’! $

</details>

For those finding this thread… the tail continues by installing virt-manager using this repo: https://github.com/jeffreywildman/homebrew-virt-manager/

Once that’s done with brew you should start the daemon with virt-manager -c qemu+ssh://@/system?socket=/var/run/libvirt/libvirt-sock.

Maybe troubleshoot: brew install py2cairo.

Good luck!

ccosby’s steps worked for me, i think i am past the ruby error however i get:

Error while connecting to libvirt: Error making a connection to libvirt URI qemu+ssh://192.168.15.127/system?no_verify=1&keyfile=/Users/myuser/.ssh/id_rsa&socket=/var/run/libvirt/libvirt-sock: Call to virConnectOpen failed: internal error: received hangup event on socket

As a easier workaround:

CFLAGS="-DHAVE_VIRDOMAINQEMUMONITORCOMMAND" vagrant plugin install vagrant-libvirt

Howevr I didn’t manage to start a VM on OSX anyway

I got it working with the following:

brew install ruby ruby-build rbenv libiconv gcc
export NOKOGIRI_USE_SYSTEM_LIBRARIES=true
vagrant plugin install vagrant-libvirt

Turns out there is a brew package available, for those who use homebrew.

brew install libvirt

I managed to work around this issue on my Linux by following this guide: https://wiki.archlinux.org/index.php/Vagrant#vagrant-libvirt

I hope someone with knowledge of how plugins installation works could patch the code to enable these parameters for MacOS by default. We had at least 3 people confirming the fix and none saying that it would not work.

@ssbarnea I think someone with a Mac to test and verify the exact steps required, I don’t use Mac’s myself, not sure if any of the other maintainers have access to one

Did you port the patches manually to your ruby-libvirt 0.6.0 source tree? The repository from @kontrafiktion is ruby-libvirt 0.5.2, so to install 0.6.0 you need to port the following changes manually: https://github.com/kontrafiktion/ruby-libvirt/compare/bug-1161338 and https://github.com/kontrafiktion/ruby-libvirt/commit/3f768dc492353a143b45c08180fcd690885c2b09 (OSX specific).

You should also make sure that you are installing the local gem and not installing from source the remote one. Instead of

/opt/vagrant/embedded/bin/gem install -i ~/.vagrant.d/gems/ ruby-libvirt

you should try:

/opt/vagrant/embedded/bin/gem install -i ~/.vagrant.d/gems/ --local pkg/ruby-libvirt-0.6.0.gem

(after you did /opt/vagrant/embedded/bin/rake package of course).

I am running ruby-libvirt 0.6.0 on OS X El Capitan (10.11.3) without an issue.

// Added missing patch.

On High Sierra - 10.13.6

$ vagrant version
Installed Version: 2.1.5
Latest Version: 2.1.5

You're running an up-to-date version of Vagrant!

Fails though:

$ vagrant up
Bringing machine 'default' up with 'libvirt' provider...
Error while connecting to libvirt: Error making a connection to libvirt URI qemu+ssh://192.168.15.127/system?no_verify=1&keyfile=/Users/smingolelli/.ssh/id_rsa&socket=/var/run/libvirt/libvirt-sock:
Call to virConnectOpen failed: internal error: received hangup event on socket

Plugin was built like so:

$ CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/include/libvirt with-libvirt-lib=/usr/local/lib' GEM_HOME=~/.vagrant.d/gems/2.4.4 GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems PATH=/opt/vagrant/embedded/bin:$PATH vagrant plugin install vagrant-libvirt

@mcandre

I can confirm that it doesn’t work on High Sierra + Vagrant 2.0.1 with the same error that you posted. Still works on High Sierra 10.13.1 + Vagrant 2.0.0. I’ll investigate more and see what I find.

Look through https://github.com/hashicorp/vagrant/blob/master/CHANGELOG.md and see if there’s anything you absolutely need from there. If not, 2.0.0 is still available for download.

Same issue with vagrant-libvirt on Mac OSX El Capitan 10.11.6

$ git branch

  • (HEAD detached at origin/bug-1161338)

/opt/vagrant/embedded/include/ruby-2.2.0/ruby/backward/st.h:2:2: warning: use “ruby/st.h” instead of bare “st.h” [-W#warnings] #warning use “ruby/st.h” instead of bare “st.h”

here is the full log --> http://pastebin.ca/3760772

Please retest this against current master which updates fog-libvirt and ruby-libvirt.

You can git clone the repo and do a gem build vagrant-libvirt.gemspec which generates a .gem that can be installed with vagrant plugin install /path/to/gem

Sigh