vagrant-libvirt 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +16 -0
- data/README.md +108 -59
- data/lib/vagrant-libvirt/action/connect_libvirt.rb +8 -3
- data/lib/vagrant-libvirt/action/create_domain.rb +5 -3
- data/lib/vagrant-libvirt/action/read_ssh_info.rb +15 -44
- data/lib/vagrant-libvirt/action/wait_till_up.rb +2 -9
- data/lib/vagrant-libvirt/config.rb +14 -2
- data/lib/vagrant-libvirt/errors.rb +0 -4
- data/lib/vagrant-libvirt/version.rb +1 -1
- data/locales/en.yml +0 -4
- data/tools/prepare_redhat_for_box.sh +114 -0
- data/vagrant-libvirt.gemspec +1 -1
- metadata +5 -3
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# 0.0.3 (Apr 11, 2013)
|
2
|
+
|
3
|
+
* Cpu and memory settings for domains.
|
4
|
+
* IP is parsed from dnsmasq lease files only, no saving of IP address into
|
5
|
+
files anymore.
|
6
|
+
* Tool for preparation RedHat Linux distros for box image added.
|
7
|
+
|
8
|
+
# 0.0.2 (Apr 1, 2013)
|
9
|
+
|
10
|
+
* Halt, suspend, resume, ssh and provision commands added.
|
11
|
+
* IP address of VM is saved into $data_dir/ip file.
|
12
|
+
* Provider can be set via VAGRANT_DEFAULT_PROVIDER env variable.
|
13
|
+
|
14
|
+
# 0.0.1 (Mar 26, 2013)
|
15
|
+
|
16
|
+
* Initial release.
|
data/README.md
CHANGED
@@ -4,52 +4,49 @@ This is a [Vagrant](http://www.vagrantup.com) 1.1+ 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
|
-
|
7
|
+
**Note:** Actual version (0.0.3) is still a development one. Feedback is
|
8
|
+
welcome and can help a lot :-)
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
## Features (Version 0.0.2)
|
10
|
+
## Features (Version 0.0.3)
|
12
11
|
|
12
|
+
* Vagrant `up`, `destroy`, `suspend`, `resume`, `halt`, `ssh` and `provision` commands.
|
13
13
|
* Upload box image (qcow2 format) to Libvirt storage pool.
|
14
14
|
* Create volume as COW diff image for domains.
|
15
15
|
* Create and boot Libvirt domains.
|
16
16
|
* SSH into domains.
|
17
17
|
* Provision domains with any built-in Vagrant provisioner.
|
18
18
|
* Minimal synced folder support via `rsync`.
|
19
|
-
* Up, destroy, suspend, resume, halt, ssh, provision subcommands.
|
20
19
|
|
21
|
-
##
|
20
|
+
## Future work
|
21
|
+
|
22
|
+
* More boxes should be available.
|
23
|
+
* Take a look at [open issues](https://github.com/pradels/vagrant-libvirt/issues?state=open).
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Install using standard [Vagrant 1.1+](http://downloads.vagrantup.com) plugin installation methods. After
|
28
|
+
installing, `vagrant up` and specify the `libvirt` provider. An example is shown below.
|
26
29
|
|
27
30
|
```
|
28
31
|
$ vagrant plugin install vagrant-libvirt
|
29
|
-
...
|
30
|
-
$ vagrant up --provider=libvirt
|
31
|
-
...
|
32
32
|
```
|
33
33
|
|
34
|
-
|
35
|
-
box file for Vagrant.
|
36
|
-
|
37
|
-
### Problems with plugin installation
|
34
|
+
### Possible problems with plugin installation
|
38
35
|
|
39
|
-
In case of problems with building nokogiri gem, install
|
40
|
-
libraries libxslt and
|
36
|
+
In case of problems with building nokogiri and ruby-libvirt gem, install
|
37
|
+
missing development libraries for libxslt, libxml2 and libvirt.
|
41
38
|
|
42
39
|
In Ubuntu, Debian, ...
|
43
40
|
```
|
44
|
-
$ sudo apt-get install libxslt-dev libxml2-dev
|
41
|
+
$ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev
|
45
42
|
```
|
46
43
|
|
47
44
|
In RedHat, Centos, Fedora, ...
|
48
45
|
```
|
49
|
-
# yum install libxslt-devel libxml2-devel
|
46
|
+
# yum install libxslt-devel libxml2-devel libvirt-devel
|
50
47
|
```
|
51
48
|
|
52
|
-
##
|
49
|
+
## Vagrant Project Preparation
|
53
50
|
|
54
51
|
After installing the plugin (instructions above), the quickest way to get
|
55
52
|
started is to add Libvirt box and specify all the details manually within
|
@@ -58,13 +55,12 @@ want. This is just an example of Libvirt CentOS 6.4 box available:
|
|
58
55
|
|
59
56
|
```
|
60
57
|
$ vagrant box add centos64 http://kwok.cz/centos64.box
|
61
|
-
...
|
62
58
|
```
|
63
59
|
|
64
60
|
And then make a Vagrantfile that looks like the following, filling in
|
65
61
|
your information where necessary.
|
66
62
|
|
67
|
-
```
|
63
|
+
```ruby
|
68
64
|
Vagrant.configure("2") do |config|
|
69
65
|
config.vm.define :test_vm do |test_vm|
|
70
66
|
test_vm.vm.box = "centos64"
|
@@ -75,31 +71,13 @@ Vagrant.configure("2") do |config|
|
|
75
71
|
libvirt.host = "example.com"
|
76
72
|
libvirt.connect_via_ssh = true
|
77
73
|
libvirt.username = "root"
|
78
|
-
#libvirt.password = "secret"
|
79
74
|
libvirt.storage_pool_name = "default"
|
80
75
|
end
|
81
76
|
end
|
82
77
|
|
83
78
|
```
|
84
79
|
|
85
|
-
|
86
|
-
use Libvirt provider is to setup environment variable `export VAGRANT_DEFAULT_PROVIDER=libvirt`.
|
87
|
-
|
88
|
-
This will first upload box image to remote Libvirt storage pool as new volume.
|
89
|
-
Then create and start a CentOS 6.4 domain on example.com Libvirt host. In this
|
90
|
-
example configuration, connection to Libvirt is tunneled via SSH.
|
91
|
-
|
92
|
-
## Box Format
|
93
|
-
|
94
|
-
Every provider in Vagrant must introduce a custom box format. This
|
95
|
-
provider introduces `Libvirt` boxes. You can view an example box in
|
96
|
-
the [example_box/directory](https://github.com/pradels/vagrant-libvirt/tree/master/example_box). That directory also contains instructions on how to build a box.
|
97
|
-
|
98
|
-
The box format is qcow2 image file `box.img`, the required `metadata.json` file
|
99
|
-
along with a `Vagrantfile` that does default settings for the
|
100
|
-
provider-specific configuration for this provider.
|
101
|
-
|
102
|
-
## Configuration
|
80
|
+
### Libvirt Configuration Options
|
103
81
|
|
104
82
|
This provider exposes quite a few provider-specific configuration options:
|
105
83
|
|
@@ -111,6 +89,55 @@ This provider exposes quite a few provider-specific configuration options:
|
|
111
89
|
* `storage_pool_name` - Libvirt storage pool name, where box image and
|
112
90
|
instance snapshots will be stored.
|
113
91
|
|
92
|
+
### Domain Specific Options
|
93
|
+
|
94
|
+
* `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
|
95
|
+
* `cpus` - Number of virtual cpus. Defaults to 1 if not set.
|
96
|
+
|
97
|
+
Specific domain settings can be set for each domain separately in multi-VM
|
98
|
+
environment. Example below shows a part of Vagrantfile, where specific options
|
99
|
+
are set for dbserver domain.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
Vagrant.configure("2") do |config|
|
103
|
+
config.vm.define :dbserver do |dbserver|
|
104
|
+
dbserver.vm.box = "centos64"
|
105
|
+
dbserver.vm.provider :libvirt do |domain|
|
106
|
+
domain.memory = 2048
|
107
|
+
domain.cpus = 2
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
...
|
112
|
+
```
|
113
|
+
|
114
|
+
## Create Project - Vagrant up
|
115
|
+
|
116
|
+
In prepared project directory, run following command:
|
117
|
+
|
118
|
+
```
|
119
|
+
$ vagrant up --provider=libvirt
|
120
|
+
```
|
121
|
+
|
122
|
+
Vagrant needs to know that we want to use Libvirt and not default VirtualBox.
|
123
|
+
That's why there is `--provider=libvirt` option specified. Other way to tell
|
124
|
+
Vagrant to use Libvirt provider is to setup environment variable
|
125
|
+
`export VAGRANT_DEFAULT_PROVIDER=libvirt`.
|
126
|
+
|
127
|
+
### How Project Is Created
|
128
|
+
|
129
|
+
Vagrant goes through steps below when creating new project:
|
130
|
+
|
131
|
+
1. Connect to Libvirt localy or remotely via SSH.
|
132
|
+
2. Check if box image is available in Libvirt storage pool. If not, upload it to
|
133
|
+
remote Libvirt storage pool as new volume.
|
134
|
+
3. Create COW diff image of base box image for new Libvirt domain.
|
135
|
+
4. Create and start new domain on Libvirt host.
|
136
|
+
5. Check for DHCP lease from dnsmasq server.
|
137
|
+
6. Wait till SSH is available.
|
138
|
+
7. Sync folders via `rsync` and run Vagrant provisioner on new domain if
|
139
|
+
setup in Vagrantfile.
|
140
|
+
|
114
141
|
## Networks
|
115
142
|
|
116
143
|
Networking features in the form of `config.vm.network` are supported only
|
@@ -119,26 +146,24 @@ provider.
|
|
119
146
|
|
120
147
|
Example of network interface definition:
|
121
148
|
|
122
|
-
```
|
149
|
+
```ruby
|
123
150
|
config.vm.define :test_vm do |test_vm|
|
124
151
|
test_vm.vm.network :bridged, :bridge => "default", :adapter => 1
|
125
152
|
end
|
126
153
|
```
|
127
154
|
|
128
|
-
|
129
|
-
|
130
|
-
## Getting IP address
|
155
|
+
In example above, bridged network adapter connected to network `default` is
|
156
|
+
defined.
|
131
157
|
|
132
|
-
|
133
|
-
domain. Fog library uses SSH connection to remote libvirt host and by default
|
134
|
-
checks arpwatch entries there.
|
135
|
-
|
136
|
-
Vagrant Libvirt provider is using dnsmasq leases files to find out, which IPs
|
137
|
-
dhcp server offered. VMs IP address is then saved to `$data_dir/ip` file for
|
138
|
-
later use. Of course, VMs IP can be changed over time. That's why IP is
|
139
|
-
checked, if matches with VMs MAC address after each reading from this state
|
140
|
-
file. Mismatch error is shown if IP doesn't match.
|
158
|
+
## Obtaining Domain IP Address
|
141
159
|
|
160
|
+
Libvirt doesn't provide standard way how to find out an IP address of running
|
161
|
+
domain. But we know, what is MAC address of virtual machine. Libvirt is closely
|
162
|
+
connected with dnsmasq server, which acts also as a DHCP server. Dnsmasq server
|
163
|
+
makes lease information public in `/var/lib/libvirt/dnsmasq` directory, or in
|
164
|
+
`/var/lib/misc/dnsmasq.leases` file on some systems. This is the place, where
|
165
|
+
information like which MAC address has which IP address resides and it's parsed
|
166
|
+
by vagrant-libvirt plugin.
|
142
167
|
|
143
168
|
## Synced Folders
|
144
169
|
|
@@ -149,13 +174,25 @@ to the remote machine over SSH.
|
|
149
174
|
This is good enough for all built-in Vagrant provisioners (shell,
|
150
175
|
chef, and puppet) to work!
|
151
176
|
|
177
|
+
## Box Format
|
178
|
+
|
179
|
+
You can view an example box in the [example_box/directory](https://github.com/pradels/vagrant-libvirt/tree/master/example_box). That directory also contains instructions on how to build a box.
|
180
|
+
|
181
|
+
The box is a tarball containing:
|
182
|
+
|
183
|
+
* qcow2 image file named `box.img`.
|
184
|
+
* `metadata.json` file describing box image (provider, virtual_size, format).
|
185
|
+
* `Vagrantfile` that does default settings for the provider-specific configuration for this provider.
|
186
|
+
|
152
187
|
## Development
|
153
188
|
|
154
189
|
To work on the `vagrant-libvirt` plugin, clone this repository out, and use
|
155
190
|
[Bundler](http://gembundler.com) to get the dependencies:
|
156
191
|
|
157
192
|
```
|
158
|
-
$
|
193
|
+
$ git clone https://github.com/pradels/vagrant-libvirt.git
|
194
|
+
$ cd vagrant-libvirt
|
195
|
+
$ bundle install
|
159
196
|
```
|
160
197
|
|
161
198
|
Once you have the dependencies, verify the unit tests pass with `rake`:
|
@@ -167,12 +204,24 @@ $ bundle exec rake
|
|
167
204
|
If those pass, you're ready to start developing the plugin. You can test
|
168
205
|
the plugin without installing it into your Vagrant environment by just
|
169
206
|
creating a `Vagrantfile` in the top level of this directory (it is gitignored)
|
170
|
-
that uses it
|
207
|
+
that uses it. Don't forget to add following line at the beginning of your
|
208
|
+
`Vagrantfile` while in development mode:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
Vagrant.require_plugin "vagrant-libvirt"
|
212
|
+
```
|
213
|
+
|
214
|
+
Now you can use bundler to execute Vagrant:
|
171
215
|
|
172
216
|
```
|
173
217
|
$ bundle exec vagrant up --provider=libvirt
|
174
218
|
```
|
175
219
|
|
176
|
-
##
|
220
|
+
## Contributing
|
221
|
+
|
222
|
+
1. Fork it
|
223
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
224
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
225
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
226
|
+
5. Create new Pull Request
|
177
227
|
|
178
|
-
Take a look on [open issues](https://github.com/pradels/vagrant-libvirt/issues?state=open).
|
@@ -48,9 +48,14 @@ module VagrantPlugins
|
|
48
48
|
conn_attr[:libvirt_password] = config.password if config.password
|
49
49
|
|
50
50
|
# Setup command for retrieving IP address for newly created machine
|
51
|
-
# with some MAC address. Get it from dnsmasq leases table
|
52
|
-
|
53
|
-
|
51
|
+
# with some MAC address. Get it from dnsmasq leases table - either
|
52
|
+
# /var/lib/libvirt/dnsmasq/*.leases files, or
|
53
|
+
# /var/lib/misc/dnsmasq.leases if available.
|
54
|
+
ip_command = "LEASES='/var/lib/libvirt/dnsmasq/*.leases'; "
|
55
|
+
ip_command << "[ -f /var/lib/misc/dnsmasq.leases ] && "
|
56
|
+
ip_command << "LEASES='/var/lib/misc/dnsmasq.leases'; "
|
57
|
+
ip_command << "cat $LEASES | grep $mac | awk '{ print $3 }'"
|
58
|
+
conn_attr[:libvirt_ip_command] = ip_command
|
54
59
|
|
55
60
|
@logger.info("Connecting to Libvirt (#{uri}) ...")
|
56
61
|
begin
|
@@ -13,12 +13,14 @@ module VagrantPlugins
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def call(env)
|
16
|
+
# Get config.
|
17
|
+
config = env[:machine].provider_config
|
18
|
+
|
16
19
|
# Gather some info about domain
|
17
20
|
@name = env[:domain_name]
|
21
|
+
@cpus = config.cpus
|
22
|
+
@memory_size = config.memory*1024
|
18
23
|
|
19
|
-
@cpus = 1
|
20
|
-
@memory_size = 512*1024
|
21
|
-
|
22
24
|
# TODO get type from driver config option
|
23
25
|
@domain_type = 'kvm'
|
24
26
|
|
@@ -18,7 +18,7 @@ module VagrantPlugins
|
|
18
18
|
@app.call(env)
|
19
19
|
end
|
20
20
|
|
21
|
-
def read_ssh_info(libvirt,machine)
|
21
|
+
def read_ssh_info(libvirt, machine)
|
22
22
|
return nil if machine.id.nil?
|
23
23
|
|
24
24
|
# Find the machine
|
@@ -30,53 +30,24 @@ module VagrantPlugins
|
|
30
30
|
return nil
|
31
31
|
end
|
32
32
|
|
33
|
-
# IP address
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
# Check if stored IP address matches with MAC address of machine.
|
45
|
-
# Command is executed either localy, or on remote libvirt hypervisor,
|
46
|
-
# depends on establised fog libvirt connection.
|
47
|
-
ip_match = false
|
48
|
-
ip_command = "ping -c1 #{ip_address} > /dev/null && "
|
49
|
-
ip_command << "arp -an | grep $mac | sed '"
|
50
|
-
ip_command << 's/.*(\([0-9\.]*\)).*/\1/' + "'"
|
51
|
-
options_hash = { :ip_command => ip_command }
|
52
|
-
3.times do |x|
|
53
|
-
break if ip_match
|
54
|
-
domain.wait_for(1) {
|
55
|
-
begin
|
56
|
-
addresses(service, options_hash).each_pair do |type, ip|
|
57
|
-
if ip[0] != nil
|
58
|
-
ip_match = true
|
59
|
-
break
|
60
|
-
end
|
61
|
-
end
|
62
|
-
rescue Fog::Errors::Error
|
63
|
-
# Sometimes, if pinging happen too quickly after after IP
|
64
|
-
# assignment, machine is not responding yet. Give it a little
|
65
|
-
# time..
|
66
|
-
sleep 1
|
67
|
-
end
|
68
|
-
|
69
|
-
break if ip_match
|
70
|
-
}
|
71
|
-
end
|
72
|
-
raise Errors::IpAddressMismatchError if not ip_match
|
33
|
+
# Get IP address from dnsmasq lease file.
|
34
|
+
ip_address = nil
|
35
|
+
domain.wait_for(2) {
|
36
|
+
addresses.each_pair do |type, ip|
|
37
|
+
ip_address = ip[0] if ip[0] != nil
|
38
|
+
end
|
39
|
+
ip_address != nil
|
40
|
+
}
|
41
|
+
raise Errors::NoIpAddressError if not ip_address
|
73
42
|
|
74
43
|
# Return the info
|
75
44
|
# TODO: Some info should be configurable in Vagrantfile
|
76
45
|
return {
|
77
|
-
:host
|
78
|
-
:port
|
79
|
-
:username
|
46
|
+
:host => ip_address,
|
47
|
+
:port => 22,
|
48
|
+
:username => 'root',
|
49
|
+
:forward_agent => true,
|
50
|
+
:forward_x11 => true,
|
80
51
|
}
|
81
52
|
end
|
82
53
|
end
|
@@ -37,7 +37,7 @@ module VagrantPlugins
|
|
37
37
|
# Wait for domain to obtain an ip address
|
38
38
|
domain.wait_for(2) {
|
39
39
|
addresses.each_pair do |type, ip|
|
40
|
-
env[:ip_address] = ip[0]
|
40
|
+
env[:ip_address] = ip[0] if ip[0] != nil
|
41
41
|
end
|
42
42
|
env[:ip_address] != nil
|
43
43
|
}
|
@@ -46,14 +46,7 @@ module VagrantPlugins
|
|
46
46
|
terminate(env) if env[:interrupted]
|
47
47
|
@logger.info("Got IP address #{env[:ip_address]}")
|
48
48
|
@logger.info("Time for getting IP: #{env[:metrics]["instance_ip_time"]}")
|
49
|
-
|
50
|
-
# Save newly assigned IP address to machines data_dir
|
51
|
-
ip_file_path = env[:machine].data_dir + 'ip'
|
52
|
-
@logger.info("Saving IP address to #{ip_file_path} file.")
|
53
|
-
File.open(ip_file_path, 'w') do |file|
|
54
|
-
file.write(env[:ip_address])
|
55
|
-
end
|
56
|
-
|
49
|
+
|
57
50
|
# Machine has ip address assigned, now wait till we are able to
|
58
51
|
# connect via ssh.
|
59
52
|
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
|
@@ -22,6 +22,10 @@ module VagrantPlugins
|
|
22
22
|
# be stored.
|
23
23
|
attr_accessor :storage_pool_name
|
24
24
|
|
25
|
+
# Domain specific settings used while creating new domain.
|
26
|
+
attr_accessor :memory
|
27
|
+
attr_accessor :cpus
|
28
|
+
|
25
29
|
def initialize
|
26
30
|
@driver = UNSET_VALUE
|
27
31
|
@host = UNSET_VALUE
|
@@ -29,15 +33,23 @@ module VagrantPlugins
|
|
29
33
|
@username = UNSET_VALUE
|
30
34
|
@password = UNSET_VALUE
|
31
35
|
@storage_pool_name = UNSET_VALUE
|
36
|
+
|
37
|
+
# Domain specific settings.
|
38
|
+
@memory = UNSET_VALUE
|
39
|
+
@cpus = UNSET_VALUE
|
32
40
|
end
|
33
41
|
|
34
42
|
def finalize!
|
35
|
-
@driver
|
36
|
-
@host
|
43
|
+
@driver = 'qemu' if @driver == UNSET_VALUE
|
44
|
+
@host = nil if @host == UNSET_VALUE
|
37
45
|
@connect_via_ssh = false if @connect_via_ssh == UNSET_VALUE
|
38
46
|
@username = nil if @username == UNSET_VALUE
|
39
47
|
@password = nil if @password == UNSET_VALUE
|
40
48
|
@storage_pool_name = 'default' if @storage_pool_name == UNSET_VALUE
|
49
|
+
|
50
|
+
# Domain specific settings.
|
51
|
+
@memory = 512 if @memory == UNSET_VALUE
|
52
|
+
@cpus = 1 if @cpus == UNSET_VALUE
|
41
53
|
end
|
42
54
|
|
43
55
|
def validate(machine)
|
data/locales/en.yml
CHANGED
@@ -101,10 +101,6 @@ en:
|
|
101
101
|
Error while attaching new device to domain. %{error_message}
|
102
102
|
no_ip_address_error: |-
|
103
103
|
No IP address found.
|
104
|
-
ip_address_mismatch_error: |-
|
105
|
-
IP address mismatch. Possible reason is that domain IP address changed.
|
106
|
-
You can run `vagrant destroy` and then `vagrant up` to rebuild your
|
107
|
-
project.
|
108
104
|
|
109
105
|
states:
|
110
106
|
short_paused: |-
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/bin/bash +x
|
2
|
+
|
3
|
+
# This script should help to prepare RedHat and RedHat like OS (CentOS,
|
4
|
+
# Scientific Linux, ...) for Vagrant box usage.
|
5
|
+
|
6
|
+
# To create new box image, just install minimal base system in VM on top of not
|
7
|
+
# fully allocated qcow2 image. Then upload this script to the VM and run it.
|
8
|
+
# After script has finished, nothing else than halting machine should be done.
|
9
|
+
|
10
|
+
# For more info about creating custom box refer to
|
11
|
+
# https://github.com/pradels/vagrant-libvirt/tree/master/example_box
|
12
|
+
|
13
|
+
# We need a hostname.
|
14
|
+
if [ $# -ne 1 ]; then
|
15
|
+
echo "Usage: $0 <hostname>"
|
16
|
+
echo "Hostname should be in format vagrant-[os-name], e.g. vagrant-redhat63."
|
17
|
+
exit 1
|
18
|
+
fi
|
19
|
+
|
20
|
+
|
21
|
+
# On which version of RedHet are we running?
|
22
|
+
RHEL_MAJOR_VERSION=$(sed 's/.*release \([0-9]\)\..*/\1/' /etc/redhat-release)
|
23
|
+
if [ $? -ne 0 ]; then
|
24
|
+
echo "Is this a RedHat distro?"
|
25
|
+
exit 1
|
26
|
+
fi
|
27
|
+
echo "* Found RedHat ${RHEL_MAJOR_VERSION} version."
|
28
|
+
|
29
|
+
|
30
|
+
# Setup hostname vagrant-something.
|
31
|
+
FQDN="$1.vagrantup.com"
|
32
|
+
if grep '^HOSTNAME=' /etc/sysconfig/network > /dev/null; then
|
33
|
+
sed -i 's/HOSTNAME=\(.*\)/HOSTNAME='${FQDN}'/' /etc/sysconfig/network
|
34
|
+
else
|
35
|
+
echo "HOSTNAME=${FQDN}" >> /etc/sysconfig/network
|
36
|
+
fi
|
37
|
+
|
38
|
+
|
39
|
+
# Enable EPEL repository.
|
40
|
+
yum -y install wget
|
41
|
+
cd ~root
|
42
|
+
if [ $RHEL_MAJOR_VERSION -eq 5 ]; then
|
43
|
+
wget http://ftp.astral.ro/mirrors/fedora/pub/epel/5/i386/epel-release-5-4.noarch.rpm
|
44
|
+
EPEL_PKG="epel-release-5-4.noarch.rpm"
|
45
|
+
else
|
46
|
+
wget http://ftp.astral.ro/mirrors/fedora/pub/epel/6/i386/epel-release-6-8.noarch.rpm
|
47
|
+
EPEL_PKG="epel-release-6-8.noarch.rpm"
|
48
|
+
fi
|
49
|
+
rpm -i ~root/${EPEL_PKG}
|
50
|
+
rm -f ~root/${EPEL_PKG}
|
51
|
+
|
52
|
+
|
53
|
+
# Install some required software.
|
54
|
+
yum -y install openssh-server openssh-clients sudo \
|
55
|
+
ruby ruby-devel make gcc rubygems rsync
|
56
|
+
chkconfig sshd on
|
57
|
+
gem install puppet
|
58
|
+
gem install chef
|
59
|
+
|
60
|
+
|
61
|
+
# Users, groups, passwords and sudoers.
|
62
|
+
echo 'vagrant' | passwd --stdin root
|
63
|
+
grep 'vagrant' /etc/passwd > /dev/null
|
64
|
+
if [ $? -ne 0 ]; then
|
65
|
+
echo '* Creating user vagrant.'
|
66
|
+
useradd vagrant
|
67
|
+
echo 'vagrant' | passwd --stdin vagrant
|
68
|
+
fi
|
69
|
+
grep '^admin:' /etc/group > /dev/null || groupadd admin
|
70
|
+
usermod -G admin vagrant
|
71
|
+
|
72
|
+
echo 'Defaults env_keep += "SSH_AUTH_SOCK"' >> /etc/sudoers
|
73
|
+
echo '%admin ALL=NOPASSWD: ALL' >> /etc/sudoers
|
74
|
+
sed -i 's/Defaults\s*requiretty/Defaults !requiretty/' /etc/sudoers
|
75
|
+
|
76
|
+
|
77
|
+
# SSH setup
|
78
|
+
# Add Vagrant ssh key for root accout.
|
79
|
+
sed -i 's/.*UseDNS.*/UseDNS no/' /etc/ssh/sshd_config
|
80
|
+
|
81
|
+
[ -d ~root/.ssh ] || mkdir ~root/.ssh
|
82
|
+
chmod 700 ~root/.ssh
|
83
|
+
cat > ~root/.ssh/authorized_keys << EOF
|
84
|
+
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
|
85
|
+
EOF
|
86
|
+
chmod 600 ~root/.ssh/authorized_keys
|
87
|
+
|
88
|
+
|
89
|
+
# Disable firewall and switch SELinux to permissive mode.
|
90
|
+
chkconfig iptables off
|
91
|
+
chkconfig ip6tables off
|
92
|
+
sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/sysconfig/selinux
|
93
|
+
|
94
|
+
|
95
|
+
# Networking setup..
|
96
|
+
# Don't fix ethX names to hw address.
|
97
|
+
rm -f /etc/udev/rules.d/*persistent-net.rules
|
98
|
+
rm -f /etc/udev/rules.d/*-net.rules
|
99
|
+
rm -fr /var/lib/dhclient/*
|
100
|
+
|
101
|
+
# Interface eth0 should get IP address via dhcp.
|
102
|
+
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
|
103
|
+
DEVICE="eth0"
|
104
|
+
BOOTPROTO="dhcp"
|
105
|
+
ONBOOT="yes"
|
106
|
+
NM_CONTROLLED="no"
|
107
|
+
EOF
|
108
|
+
|
109
|
+
|
110
|
+
# Do some cleanup..
|
111
|
+
rm -f ~root/.bash_history
|
112
|
+
rm -r "$(gem env gemdir)"/doc/*
|
113
|
+
yum clean all
|
114
|
+
|
data/vagrant-libvirt.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["ls@elostech.cz"]
|
7
7
|
gem.description = %q{Vagrant provider for libvirt.}
|
8
8
|
gem.summary = %q{Vagrant provider for libvirt.}
|
9
|
-
gem.homepage = "
|
9
|
+
gem.homepage = "https://github.com/pradels/vagrant-libvirt"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
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.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -67,6 +67,7 @@ extensions: []
|
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
69
|
- .gitignore
|
70
|
+
- CHANGELOG.md
|
70
71
|
- Gemfile
|
71
72
|
- LICENSE
|
72
73
|
- README.md
|
@@ -115,8 +116,9 @@ files:
|
|
115
116
|
- lib/vagrant-libvirt/util/timer.rb
|
116
117
|
- lib/vagrant-libvirt/version.rb
|
117
118
|
- locales/en.yml
|
119
|
+
- tools/prepare_redhat_for_box.sh
|
118
120
|
- vagrant-libvirt.gemspec
|
119
|
-
homepage:
|
121
|
+
homepage: https://github.com/pradels/vagrant-libvirt
|
120
122
|
licenses: []
|
121
123
|
post_install_message:
|
122
124
|
rdoc_options: []
|