vagrant-libvirt 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5475753167fabd89226aeb3801ae1122a07b0e9
4
- data.tar.gz: 4e9db984dfcd0100c10a5e04d7a9b738a64d33ec
3
+ metadata.gz: 38f679c4994924e362840cb557548fd54cb12fa9
4
+ data.tar.gz: a6f1ffd51906f47c366fb72b0cf87b8ffbd145b2
5
5
  SHA512:
6
- metadata.gz: bdc9f497e2e357be510406e75e44e6638cdbd4e07830a96821c51cc698ceb21849f2216adfe829bbdc9a96396e46e0507b789b0741f8e996ea3319dbace2a418
7
- data.tar.gz: 872af8fbd4e578d78a20f030a04ddf1a9aa60844f0bf6c87603b28b19c2850c5763266a47ec148d106731c15b69a08ddfd46d6a5996b5fe513a212b018e9b58e
6
+ metadata.gz: 1cdcb6b6d8d55a4dc5e025cc7c83452d64d1f964013ade0537acfbea3c27c314133a52ff58d842ec74832056f230d4ea259757482101a1f2613162199aeaccde
7
+ data.tar.gz: de6039104f84243740a0437c278f0d6b4b283293ff6efb0a15e6109cd58f4fa0d6ebdd2111bece79e88b87fc85b9d4d5501cbdbefcd8832bda8c539e375767b1
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Vagrant Libvirt Provider
2
2
 
3
- This is a [Vagrant](http://www.vagrantup.com) 1.4.3+ plugin that adds an
3
+ This is a [Vagrant](http://www.vagrantup.com) plugin that adds an
4
4
  [Libvirt](http://libvirt.org) provider to Vagrant, allowing Vagrant to
5
5
  control and provision machines via Libvirt toolkit.
6
6
 
7
- **Note:** Actual version (0.0.15) is still a development one. Feedback is
7
+ **Note:** Actual version is still a development one. Feedback is
8
8
  welcome and can help a lot :-)
9
9
 
10
10
  ## Features
@@ -25,13 +25,15 @@ welcome and can help a lot :-)
25
25
 
26
26
  ## Future work
27
27
 
28
- * More boxes should be available.
29
28
  * Take a look at [open issues](https://github.com/pradels/vagrant-libvirt/issues?state=open).
30
29
 
31
30
  ## Installation
32
31
 
33
- Install using standard [Vagrant 1.4.3+](http://downloads.vagrantup.com) plugin installation methods. After
34
- installing, `vagrant up` and specify the `libvirt` provider. An example is shown below.
32
+ First, you should have libvirt installed if you plan to run VMs on your local system. For instructions, refer to your linux distribution's documentation,
33
+
34
+ Next, you must have [Vagrant installed](http://docs.vagrantup.com/v2/installation/index.html). Vagrant-libvirt supports Vagrant 1.5 and 1.6.
35
+
36
+ Now you're ready to install vagrant-libvirt using standard [Vagrant plugin](http://docs.vagrantup.com/v2/plugins/usage.html) installation methods.
35
37
 
36
38
  ```
37
39
  $ vagrant plugin install vagrant-libvirt
@@ -54,6 +56,8 @@ In RedHat, Centos, Fedora, ...
54
56
 
55
57
  ## Vagrant Project Preparation
56
58
 
59
+ ### Add Box
60
+
57
61
  After installing the plugin (instructions above), the quickest way to get
58
62
  started is to add Libvirt box and specify all the details manually within
59
63
  a `config.vm.provider` block. So first, add Libvirt box using any name you
@@ -63,42 +67,53 @@ want. This is just an example of Libvirt CentOS 6.4 box available:
63
67
  $ vagrant box add centos64 http://kwok.cz/centos64.box
64
68
  ```
65
69
 
70
+ ### Create Vagrantfile
71
+
66
72
  And then make a Vagrantfile that looks like the following, filling in your
67
73
  information where necessary. In example below, VM named test_vm is created from
68
- centos64 box and setup with 10.20.30.40 IP address.
74
+ centos64 box.
69
75
 
70
76
  ```ruby
71
77
  Vagrant.configure("2") do |config|
72
-
73
- # If you are still using old centos box, you have to setup root username for
74
- # ssh access. Read more in section 'SSH Access To VM'.
75
- config.ssh.username = "root"
76
-
77
78
  config.vm.define :test_vm do |test_vm|
78
79
  test_vm.vm.box = "centos64"
79
- test_vm.vm.network :private_network, :ip => '10.20.30.40'
80
- end
81
-
82
- config.vm.provider :libvirt do |libvirt|
83
- libvirt.driver = "kvm"
84
- libvirt.host = "localhost"
85
- libvirt.connect_via_ssh = true
86
- libvirt.username = "root"
87
- libvirt.storage_pool_name = "default"
88
-
89
- # include as many of these addition disks as you want to
90
- libvirt.storage :file,
91
- #:path => '', # automatically chosen if unspecified!
92
- #:device => 'vdb', # automatically chosen if unspecified!
93
- #:size => '10G', # defaults to 10G if unspecified!
94
- :type => 'qcow2' # defaults to 'qcow2' if unspecified!
95
80
  end
96
81
  end
97
82
  ```
98
83
 
99
- ### Libvirt Configuration Options
84
+ ### Start VM
85
+
86
+ In prepared project directory, run following command:
87
+
88
+ ```
89
+ $ vagrant up --provider=libvirt
90
+ ```
91
+
92
+ Vagrant needs to know that we want to use Libvirt and not default VirtualBox.
93
+ That's why there is `--provider=libvirt` option specified. Other way to tell
94
+ Vagrant to use Libvirt provider is to setup environment variable
95
+ `export VAGRANT_DEFAULT_PROVIDER=libvirt`.
96
+
97
+ ### How Project Is Created
100
98
 
101
- This provider exposes quite a few provider-specific configuration options:
99
+ Vagrant goes through steps below when creating new project:
100
+
101
+ 1. Connect to Libvirt localy or remotely via SSH.
102
+ 2. Check if box image is available in Libvirt storage pool. If not, upload it to
103
+ remote Libvirt storage pool as new volume.
104
+ 3. Create COW diff image of base box image for new Libvirt domain.
105
+ 4. Create and start new domain on Libvirt host.
106
+ 5. Check for DHCP lease from dnsmasq server.
107
+ 6. Wait till SSH is available.
108
+ 7. Sync folders and run Vagrant provisioner on new domain if
109
+ setup in Vagrantfile.
110
+
111
+
112
+ ### Libvirt Configuration
113
+
114
+ ### Provider Options
115
+
116
+ Although it should work without any configuration for most people, this provider exposes quite a few provider-specific configuration options. The following options allow you to configure how vagrant-libvirt connects to libvirt, and are used to generate the [libvirt connection URI](http://libvirt.org/uri.html):
102
117
 
103
118
  * `driver` - A hypervisor name to access. For now only kvm and qemu are supported.
104
119
  * `host` - The name of the server, where libvirtd is running.
@@ -107,8 +122,22 @@ This provider exposes quite a few provider-specific configuration options:
107
122
  * `password` - Password to access Libvirt.
108
123
  * `id_ssh_key_file` - The id ssh key file name to access Libvirt (eg: id_dsa or id_rsa or ... in the user .ssh directory)
109
124
  * `socket` - Path to the libvirt unix socket (eg: /var/run/libvirt/libvirt-sock)
125
+ * `uri` - For advanced usage. Directly specifies what libvirt connection URI vagrant-libvirt should use. Overrides all other connection configuration options.
126
+
127
+ Connection-independent options:
128
+
110
129
  * `storage_pool_name` - Libvirt storage pool name, where box image and instance snapshots will be stored.
111
130
 
131
+ Here is an example of how to set these options.
132
+
133
+ ```ruby
134
+ Vagrant.configure("2") do |config|
135
+ config.vm.provider :libvirt do |libvirt|
136
+ libvirt.host = "example.com"
137
+ end
138
+ end
139
+ ```
140
+
112
141
  ### Domain Specific Options
113
142
 
114
143
  * `disk_bus` - The type of disk device to emulate. Defaults to virtio if not set. Possible values are documented in libvirt's [description for _target_](http://libvirt.org/formatdomain.html#elementsDisks).
@@ -141,33 +170,6 @@ Vagrant.configure("2") do |config|
141
170
  # ...
142
171
  ```
143
172
 
144
- ## Create Project - Vagrant up
145
-
146
- In prepared project directory, run following command:
147
-
148
- ```
149
- $ vagrant up --provider=libvirt
150
- ```
151
-
152
- Vagrant needs to know that we want to use Libvirt and not default VirtualBox.
153
- That's why there is `--provider=libvirt` option specified. Other way to tell
154
- Vagrant to use Libvirt provider is to setup environment variable
155
- `export VAGRANT_DEFAULT_PROVIDER=libvirt`.
156
-
157
- ### How Project Is Created
158
-
159
- Vagrant goes through steps below when creating new project:
160
-
161
- 1. Connect to Libvirt localy or remotely via SSH.
162
- 2. Check if box image is available in Libvirt storage pool. If not, upload it to
163
- remote Libvirt storage pool as new volume.
164
- 3. Create COW diff image of base box image for new Libvirt domain.
165
- 4. Create and start new domain on Libvirt host.
166
- 5. Check for DHCP lease from dnsmasq server.
167
- 6. Wait till SSH is available.
168
- 7. Sync folders and run Vagrant provisioner on new domain if
169
- setup in Vagrantfile.
170
-
171
173
  ## Networks
172
174
 
173
175
  Networking features in the form of `config.vm.network` support private networks
@@ -262,6 +264,26 @@ a DHCP server. dnsmasq writes lease information in the `/var/lib/libvirt/dnsmasq
262
264
  directory. Vagrant-libvirt looks for the MAC address in this file and extracts
263
265
  the corresponding IP address.
264
266
 
267
+ ## Additional Disks
268
+
269
+ You can create and attach additional disks to a VM via `libvirt.storage :file`. It has a number of options:
270
+
271
+ * `path` - Location of the disk image. If unspecified, a path is automtically chosen in the same storage pool as the VMs primary disk.
272
+ * `device` - Name of the device node the disk image will have in the VM, e.g. *vdb*. If unspecified, the next available device is chosen.
273
+ * `size` - Size of the disk image. If unspecified, defaults to 10G.
274
+ * `type` - Type of disk image to create. Defaults to *qcow2*.
275
+
276
+ The following example creates two additional disks.
277
+
278
+ ```ruby
279
+ Vagrant.configure("2") do |config|
280
+ config.vm.provider :libvirt do |libvirt|
281
+ libvirt.storage :file, :size => '20G'
282
+ libvirt.storage :file, :size => '40G', :type => 'raw'
283
+ end
284
+ end
285
+ ```
286
+
265
287
  ## SSH Access To VM
266
288
 
267
289
  There are some configuration options for ssh access to VM via `config.ssh.*` in
@@ -11,7 +11,6 @@ module VagrantPlugins
11
11
  end
12
12
 
13
13
  def call(env)
14
-
15
14
  # If already connected to libvirt, just use it and don't connect
16
15
  # again.
17
16
  if ProviderLibvirt.libvirt_connection
@@ -21,49 +20,7 @@ module VagrantPlugins
21
20
 
22
21
  # Get config options for libvirt provider.
23
22
  config = env[:machine].provider_config
24
-
25
- # Setup connection uri.
26
- uri = config.driver.dup
27
- virt_path = case uri
28
- when 'qemu', 'openvz', 'uml', 'phyp', 'parallels', 'kvm'
29
- '/system'
30
- when 'xen', 'esx'
31
- '/'
32
- when 'vbox', 'vmwarews', 'hyperv'
33
- '/session'
34
- else
35
- raise "Require specify driver #{uri}"
36
- end
37
- if uri == 'kvm'
38
- uri = 'qemu' # use qemu uri for kvm domain type
39
- end
40
-
41
- if config.connect_via_ssh
42
- uri << '+ssh://'
43
- if config.username
44
- uri << config.username + '@'
45
- end
46
-
47
- if config.host
48
- uri << config.host
49
- else
50
- uri << 'localhost'
51
- end
52
- else
53
- uri << '://'
54
- uri << config.host if config.host
55
- end
56
-
57
- uri << virt_path
58
- uri << '?no_verify=1'
59
-
60
- if config.id_ssh_key_file
61
- # set ssh key for access to libvirt host
62
- home_dir = `echo ${HOME}`.chomp
63
- uri << "\&keyfile=#{home_dir}/.ssh/"+config.id_ssh_key_file
64
- end
65
- # set path to libvirt socket
66
- uri << "\&socket="+config.socket if config.socket
23
+ uri = config.uri
67
24
 
68
25
  conn_attr = {}
69
26
  conn_attr[:provider] = 'libvirt'
@@ -31,7 +31,7 @@ module VagrantPlugins
31
31
  # Get config options
32
32
  config = env[:machine].provider_config
33
33
  box_image_file = env[:machine].box.directory.join('box.img').to_s
34
- env[:box_volume_name] = env[:machine].box.name.to_s.dup
34
+ env[:box_volume_name] = env[:machine].box.name.to_s.dup.gsub("/", "-VAGRANTSLASH-")
35
35
  env[:box_volume_name] << '_vagrant_box_image.img'
36
36
 
37
37
  # Don't continue if image already exists in storage pool.
@@ -12,6 +12,10 @@ end
12
12
  module VagrantPlugins
13
13
  module ProviderLibvirt
14
14
  class Config < Vagrant.plugin('2', :config)
15
+ # manually specify URI
16
+ # will supercede most other options if provided
17
+ attr_accessor :uri
18
+
15
19
  # A hypervisor name to access via Libvirt.
16
20
  attr_accessor :driver
17
21
 
@@ -19,8 +23,7 @@ module VagrantPlugins
19
23
  attr_accessor :host
20
24
 
21
25
  # If use ssh tunnel to connect to Libvirt.
22
- attr_accessor :connect_via_ssh
23
-
26
+ attr_accessor :connect_via_ssh
24
27
  # Path towards the libvirt socket
25
28
  attr_accessor :socket
26
29
 
@@ -59,6 +62,7 @@ module VagrantPlugins
59
62
  attr_accessor :disks
60
63
 
61
64
  def initialize
65
+ @uri = UNSET_VALUE
62
66
  @driver = UNSET_VALUE
63
67
  @host = UNSET_VALUE
64
68
  @connect_via_ssh = UNSET_VALUE
@@ -122,6 +126,54 @@ module VagrantPlugins
122
126
  end
123
127
  end
124
128
 
129
+ # code to generate URI from a config moved out of the connect action
130
+ def _generate_uri
131
+ # builds the libvirt connection URI from the given driver config
132
+ # Setup connection uri.
133
+ uri = @driver.dup
134
+ virt_path = case uri
135
+ when 'qemu', 'openvz', 'uml', 'phyp', 'parallels', 'kvm'
136
+ '/system'
137
+ when '@en', 'esx'
138
+ '/'
139
+ when 'vbox', 'vmwarews', 'hyperv'
140
+ '/session'
141
+ else
142
+ raise "Require specify driver #{uri}"
143
+ end
144
+ if uri == 'kvm'
145
+ uri = 'qemu' # use qemu uri for kvm domain type
146
+ end
147
+
148
+ if @connect_via_ssh
149
+ uri << '+ssh://'
150
+ if @username
151
+ uri << @username + '@'
152
+ end
153
+
154
+ if @host
155
+ uri << @host
156
+ else
157
+ uri << 'localhost'
158
+ end
159
+ else
160
+ uri << '://'
161
+ uri << @host if @host
162
+ end
163
+
164
+ uri << virt_path
165
+ uri << '?no_verify=1'
166
+
167
+ if @id_ssh_key_file
168
+ # set ssh key for access to libvirt host
169
+ home_dir = `echo ${HOME}`.chomp
170
+ uri << "\&keyfile=#{home_dir}/.ssh/"+@id_ssh_key_file
171
+ end
172
+ # set path to libvirt socket
173
+ uri << "\&socket="+@socket if @socket
174
+ return uri
175
+ end
176
+
125
177
  def finalize!
126
178
  @driver = 'kvm' if @driver == UNSET_VALUE
127
179
  @host = nil if @host == UNSET_VALUE
@@ -133,6 +185,9 @@ module VagrantPlugins
133
185
  @management_network_name = 'vagrant-libvirt' if @management_network_name == UNSET_VALUE
134
186
  @management_network_address = '192.168.121.0/24' if @management_network_address == UNSET_VALUE
135
187
 
188
+ # generate a URI if none is supplied
189
+ @uri = _generate_uri() if @uri == UNSET_VALUE
190
+
136
191
  # Domain specific settings.
137
192
  @memory = 512 if @memory == UNSET_VALUE
138
193
  @cpus = 1 if @cpus == UNSET_VALUE
@@ -6,8 +6,8 @@
6
6
  <source dev='<%= @device %>' mode='<%= @mode %>'/>
7
7
  <% else %>
8
8
  <source bridge='<%=@device%>'/>
9
- <model type='<%=@model_type%>'/>
10
9
  <% end %>
10
+ <model type='<%=@model_type%>'/>
11
11
  </interface>
12
12
 
13
13
 
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ProviderLibvirt
3
- VERSION = '0.0.16'
3
+ VERSION = '0.0.17'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-libvirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Stanek
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-05-11 00:00:00.000000000 Z
13
+ date: 2014-06-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fog