From 5dea377677c89663b4402f2693b6dfb2e9df23c2 Mon Sep 17 00:00:00 2001 From: pradels Date: Fri, 10 May 2013 00:01:00 +0200 Subject: [PATCH 1/4] Use network 'default' if nothing more is specified in `config.vm.network`. --- lib/vagrant-libvirt/action/create_networks.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 64b82ce..f35cebf 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -44,7 +44,7 @@ module VagrantPlugins # (:libvirt__network_name => ...). @options = scoped_hash_override(options, :libvirt) @options = { - :netmask => '255.255.255.0', + :netmask => '255.255.255.0', }.merge(@options) # Prepare a hash describing network for this specific interface. @@ -64,6 +64,13 @@ module VagrantPlugins handle_ip_option(env) elsif @options[:network_name] handle_network_name_option + else + # TODO Should be smarter than just using fixed 'default' string. + @interface_network = lookup_network_by_name('default') + if not @interface_network + raise Errors::NetworkNotAvailableError, + :network_name => 'default' + end end autostart_network if not @interface_network[:autostart] @@ -212,6 +219,7 @@ module VagrantPlugins # First is address of network, second is gateway. Start the range two # addresses after network address. + # TODO Detect if this IP is not set on the interface. start_address = net.to_range.begin.succ.succ # Stop address must not be broadcast. From 711b103ed4e10388dba55f8a617841b1d53dd3b4 Mon Sep 17 00:00:00 2001 From: pradels Date: Fri, 10 May 2013 14:50:15 +0200 Subject: [PATCH 2/4] Setting hostname with `config.vm.hostname`. --- lib/vagrant-libvirt/action.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 259a28f..665dc53 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -24,6 +24,7 @@ module VagrantPlugins b2.use TimedProvision b2.use CreateNetworks b2.use CreateNetworkInterfaces + b2.use SetHostname b2.use StartDomain b2.use WaitTillUp b2.use SyncFolders From cee5bbecb40f7683712c6007d58c7479b62b068b Mon Sep 17 00:00:00 2001 From: pradels Date: Fri, 10 May 2013 14:56:53 +0200 Subject: [PATCH 3/4] VMs IP is no longer stored in machines data_dir. Cleanup is no longer needed. --- lib/vagrant-libvirt/action.rb | 8 +------ .../action/cleanup_data_dir.rb | 22 ------------------- 2 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 lib/vagrant-libvirt/action/cleanup_data_dir.rb diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 665dc53..6aff1bc 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -81,10 +81,8 @@ module VagrantPlugins b2.use Call, IsRunning do |env2, b3| next if !env2[:result] - # VM is running, halt it.. Cleanup running instance data. Now - # only IP address is stored. + # VM is running, halt it. b3.use HaltDomain - b3.use CleanupDataDir end end end @@ -104,9 +102,6 @@ module VagrantPlugins b2.use ConnectLibvirt b2.use DestroyDomain b2.use DestroyNetworks - - # Cleanup running instance data. Now only IP address is stored. - b2.use CleanupDataDir end end end @@ -273,7 +268,6 @@ module VagrantPlugins autoload :HaltDomain, action_root.join("halt_domain") autoload :SuspendDomain, action_root.join("suspend_domain") autoload :ResumeDomain, action_root.join("resume_domain") - autoload :CleanupDataDir, action_root.join("cleanup_data_dir") autoload :ReadState, action_root.join("read_state") autoload :ReadSSHInfo, action_root.join("read_ssh_info") autoload :TimedProvision, action_root.join("timed_provision") diff --git a/lib/vagrant-libvirt/action/cleanup_data_dir.rb b/lib/vagrant-libvirt/action/cleanup_data_dir.rb deleted file mode 100644 index 57b8749..0000000 --- a/lib/vagrant-libvirt/action/cleanup_data_dir.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'log4r' - -module VagrantPlugins - module Libvirt - module Action - class CleanupDataDir - def initialize(app, env) - @logger = Log4r::Logger.new("vagrant_libvirt::action::cleanup_data_dir") - @app = app - end - - def call(env) - # Remove file holding IP address - ip_file_path = env[:machine].data_dir + 'ip' - File.delete(ip_file_path) if File.exists?(ip_file_path) - - @app.call(env) - end - end - end - end -end From 29daa532c6066a2eda722ff3649cda8ee62aec41 Mon Sep 17 00:00:00 2001 From: pradels Date: Fri, 10 May 2013 15:11:13 +0200 Subject: [PATCH 4/4] v0.0.5 --- CHANGELOG.md | 9 +++++ README.md | 68 +++++++++++++++++++++++++++------- lib/vagrant-libvirt/version.rb | 2 +- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b312efe..1b32848 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 0.0.5 (May 10, 2013) + +* Private networks support. +* Creating new private networks if ip is specified and network is not + available. +* Removing previously created networks, if there are no active connections. +* Guest interfaces configuration. +* Setting guest hostname (via `config.vm.hostname`). + # 0.0.4 (May 5, 2013) * Bug fix in number of parameters for provisioner. diff --git a/README.md b/README.md index 35dca08..e75f3f0 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,19 @@ This is a [Vagrant](http://www.vagrantup.com) 1.1+ plugin that adds an [Libvirt](http://libvirt.org) provider to Vagrant, allowing Vagrant to control and provision machines via Libvirt toolkit. -**Note:** Actual version (0.0.4) is still a development one. Feedback is +**Note:** Actual version (0.0.5) is still a development one. Feedback is welcome and can help a lot :-) -## Features (Version 0.0.4) +## Features (Version 0.0.5) +* Controll local or remote Libvirt hypervisors. * Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh` and `provision` commands. * Upload box image (qcow2 format) to Libvirt storage pool. * Create volume as COW diff image for domains. +* Create private networks. * Create and boot Libvirt domains. * SSH into domains. +* Setup hostname and network interfaces. * Provision domains with any built-in Vagrant provisioner. * Minimal synced folder support via `rsync`. @@ -31,7 +34,7 @@ installing, `vagrant up` and specify the `libvirt` provider. An example is shown $ vagrant plugin install vagrant-libvirt ``` -### Possible problems with plugin installation +### Possible problems with plugin installation on Linux In case of problems with building nokogiri and ruby-libvirt gem, install missing development libraries for libxslt, libxml2 and libvirt. @@ -57,26 +60,27 @@ want. This is just an example of Libvirt CentOS 6.4 box available: $ vagrant box add centos64 http://kwok.cz/centos64.box ``` -And then make a Vagrantfile that looks like the following, filling in -your information where necessary. +And then make a Vagrantfile that looks like the following, filling in your +information where necessary. In example below, VM named test_vm is created from +centos64 box and setup with 10.20.30.40 IP address. ```ruby Vagrant.configure("2") do |config| config.vm.define :test_vm do |test_vm| test_vm.vm.box = "centos64" + test_vm.vm.network :private_network, :ip => '10.20.30.40' end config.vm.provider :libvirt do |libvirt| libvirt.driver = "qemu" - libvirt.host = "example.com" + libvirt.host = "localhost" libvirt.connect_via_ssh = true libvirt.username = "root" libvirt.storage_pool_name = "default" - libvirt.nested = true end end - ``` + ### Libvirt Configuration Options This provider exposes quite a few provider-specific configuration options: @@ -93,7 +97,7 @@ This provider exposes quite a few provider-specific configuration options: * `memory` - Amount of memory in MBytes. Defaults to 512 if not set. * `cpus` - Number of virtual cpus. Defaults to 1 if not set. -* `nested` - [Enable nested virtualization.Default: false] (https://github.com/torvalds/linux/blob/master/Documentation/virtual/kvm/nested-vmx.txt) +* `nested` - [Enable nested virtualization](https://github.com/torvalds/linux/blob/master/Documentation/virtual/kvm/nested-vmx.txt). Default is false. Specific domain settings can be set for each domain separately in multi-VM environment. Example below shows a part of Vagrantfile, where specific options @@ -109,7 +113,7 @@ Vagrant.configure("2") do |config| end end - ... + # ... ``` ## Create Project - Vagrant up @@ -141,9 +145,47 @@ Vagrant goes through steps below when creating new project: ## Networks -Networking features in the form of `config.vm.network` are not supported right -now. Support for private network is planned to be added in next release of -provider. +Networking features in the form of `config.vm.network` support private networks +concept. No public network or port forwarding are supported in current version +of provider. + +An examples of network interface definitions: + +```ruby + config.vm.define :test_vm1 do |test_vm1| + test_vm1.vm.network :private_network, :ip => '10.20.30.40' + end +``` + +In example below, one network interface is configured for VM test_vm1. After +you run `vagrant up`, VM will be accessible on IP address 10.20.30.40. So if +you install a web server via provisioner, you will be able to access your +testing server on http://10.20.30.40 URL. But beware that this address is +private to libvirt host only. It's not visible outside of the hypervisor box. + +If network 10.20.30.0/24 doesn't exist, provider will create it. By default +created networks are NATed to outside world, so your VM will be able to connect +to the internet (if hypervisor can). And by default, DHCP is offering addresses +on newly created networks. + +### Private Network Options + +There is a way to pass specific options for libvirt provider when using +`config.vm.network` to configure new network interface. Each parameter name +starts with 'libvirt__' string. Here is a list of those options: + +* `:libvirt__network_name` - Name of libvirt network to connect to. By default, + network 'default' is used. +* `:libvirt__netmask` - Used only together with `:ip` option. Default is + '255.255.255.0'. +* `:libvirt__nat_interface` - Name of interface, where should network be + NATed. Used only when creating new network. By default, all physical + interfaces are used. +* `:libvirt__isolated` - If network should be isolated - without NAT to outside. + Used only when creating new network. Default is set to false. +* `:libvirt__dhcp_enabled` - If DHCP will offer addresses, or not. Used only + when creating new network. Default is true. +* `:libvirt__adapter` - Number specifiyng sequence number of interface. ## Obtaining Domain IP Address diff --git a/lib/vagrant-libvirt/version.rb b/lib/vagrant-libvirt/version.rb index a0b7666..e159d41 100644 --- a/lib/vagrant-libvirt/version.rb +++ b/lib/vagrant-libvirt/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module Libvirt - VERSION = "0.0.4" + VERSION = "0.0.5" end end