boxgrinder-xenserver-platform-plugin 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/LICENSE.txt +20 -0
- data/README.md +35 -0
- data/Rakefile +23 -0
- data/lib/src/fstab_32bit +5 -0
- data/lib/src/fstab_64bit +5 -0
- data/lib/src/ifcfg-eth0 +7 -0
- data/lib/src/menu.lst +6 -0
- data/lib/src/rc_local +26 -0
- data/lib/xenserver-platform-plugin.rb +244 -0
- metadata +68 -0
data/.document
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Sergio Rubio
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+

|
2
|
+
|
3
|
+
#Boxgrinder XenServer Platform Plugin
|
4
|
+
|
5
|
+
Build XenServer/XCP compatible images with Boxgrinder.
|
6
|
+
|
7
|
+
#Requirements
|
8
|
+
|
9
|
+
* Boxgrinder (http://boxgrinder.org)
|
10
|
+
|
11
|
+
Previous Boxgrinder knowledge assumed.
|
12
|
+
|
13
|
+
#Installation
|
14
|
+
|
15
|
+
gem install boxgrinder-xenserver-platform-plugin
|
16
|
+
|
17
|
+
#Usage
|
18
|
+
|
19
|
+
Building Ubuntu appliances:
|
20
|
+
|
21
|
+
boxgrinder-build -lboxgrinder-ubuntu-plugin,xenserver-platform-plugin -p xenserver oneiric.appl
|
22
|
+
|
23
|
+
Building Fedora/CentOS appliances:
|
24
|
+
|
25
|
+
boxgrinder-build -lxenserver-platform-plugin -p xenserver fedora.appl
|
26
|
+
|
27
|
+
Note that to build Ubuntu appliances, you need to run Boxgrinder in Ubuntu. Building Ubuntu appliances from Fedora won't work. Building Fedora appliances from Ubuntu won't work either.
|
28
|
+
|
29
|
+
Get some tested appliance definitions for XenServer from https://github.com/bvox/boxgrinder-appliances/tree/master/bvox
|
30
|
+
|
31
|
+
# Copyright
|
32
|
+
|
33
|
+
Copyright (c) 2012 BVox S.L. See LICENSE.txt for
|
34
|
+
further details.
|
35
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
9
|
+
gem.version = '0.1'
|
10
|
+
gem.name = "boxgrinder-xenserver-platform-plugin"
|
11
|
+
gem.homepage = "http://github.com/bvox/boxgrinder-xenserver-platform-plugin"
|
12
|
+
gem.license = "MIT"
|
13
|
+
gem.summary = %Q{Boxgrinder XenServer platform plugin}
|
14
|
+
gem.description = %Q{Boxgrinder XenServer platform plugin}
|
15
|
+
gem.email = "rubiojr@bvox.net"
|
16
|
+
gem.authors = ["Sergio Rubio"]
|
17
|
+
gem.add_dependency('boxgrinder-build')
|
18
|
+
# dependencies defined in Gemfile
|
19
|
+
end
|
20
|
+
Jeweler::RubygemsDotOrgTasks.new
|
21
|
+
|
22
|
+
task :default => :build
|
23
|
+
|
data/lib/src/fstab_32bit
ADDED
data/lib/src/fstab_64bit
ADDED
data/lib/src/ifcfg-eth0
ADDED
data/lib/src/menu.lst
ADDED
data/lib/src/rc_local
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
key=`curl http://169.254.169.254/2009-04-04/meta-data/public-keys/0/openssh-key 2>/dev/null`
|
2
|
+
|
3
|
+
if [ $? -eq 0 ] ; then
|
4
|
+
for home in `find /home/* -maxdepth 0 -type d 2>/dev/null | tr '\n' ' '`; do
|
5
|
+
user=`echo $home | awk -F '/' '{ print $3 }'`
|
6
|
+
|
7
|
+
if [ ! -d $home/.ssh ] ; then
|
8
|
+
mkdir -p $home/.ssh
|
9
|
+
chmod 700 $home/.ssh
|
10
|
+
chown $user $home/.ssh
|
11
|
+
fi
|
12
|
+
|
13
|
+
actual_key=`echo $key | awk '{ print $2 }'`
|
14
|
+
|
15
|
+
if [ -f $home/.ssh/authorized_keys ]; then
|
16
|
+
if [ "`grep $actual_key $home/.ssh/authorized_keys | wc -l`" -gt 0 ]; then
|
17
|
+
continue
|
18
|
+
fi
|
19
|
+
fi
|
20
|
+
|
21
|
+
echo $key >> $home/.ssh/authorized_keys
|
22
|
+
chmod 600 $home/.ssh/authorized_keys
|
23
|
+
chown $user $home/.ssh/authorized_keys
|
24
|
+
done
|
25
|
+
fi
|
26
|
+
|
@@ -0,0 +1,244 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2010 Red Hat, Inc.
|
3
|
+
# Copyright 2012 BVox S.L
|
4
|
+
#
|
5
|
+
# Original EC2 platform plugin from Boxgrinder tweaked to generate VHD images
|
6
|
+
# XenServer compatible. Needs VirtualBox installed (VBoxManage in particular)
|
7
|
+
#
|
8
|
+
# This is free software; you can redistribute it and/or modify it
|
9
|
+
# under the terms of the GNU Lesser General Public License as
|
10
|
+
# published by the Free Software Foundation; either version 3 of
|
11
|
+
# the License, or (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This software is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
# Lesser General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Lesser General Public
|
19
|
+
# License along with this software; if not, write to the Free
|
20
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
21
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
22
|
+
|
23
|
+
require 'boxgrinder-build/plugins/base-plugin'
|
24
|
+
require 'boxgrinder-build/helpers/linux-helper'
|
25
|
+
require 'tempfile'
|
26
|
+
require 'fileutils'
|
27
|
+
|
28
|
+
module BoxGrinder
|
29
|
+
class XenServerPlugin < BasePlugin
|
30
|
+
plugin :type => :platform, :name => :xenserver, :full_name => "XenServer Platform Plugin", :require_root => true
|
31
|
+
|
32
|
+
def after_init
|
33
|
+
if %w{fedora rhel centos}.include? @appliance_config.os.name
|
34
|
+
register_deliverable(:disk => "#{@appliance_config.name}.raw")
|
35
|
+
end
|
36
|
+
register_deliverable(:vhd => "#{@appliance_config.name}.vhd")
|
37
|
+
|
38
|
+
register_supported_os('fedora', ['13', '14', '15', '16'])
|
39
|
+
register_supported_os('centos', ['5', '6'])
|
40
|
+
register_supported_os('sl', ['5', '6'])
|
41
|
+
register_supported_os('rhel', ['5', '6'])
|
42
|
+
register_supported_os('ubuntu', ['lucid', 'oneiric', 'precise', 'maveric'])
|
43
|
+
if `which VBoxManage`.empty?
|
44
|
+
@log.error "VBoxManage binary not found in your path, aborting."
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def execute
|
50
|
+
if %w{fedora rhel centos}.include? @appliance_config.os.name
|
51
|
+
execute_rpmdistro
|
52
|
+
else
|
53
|
+
execute_ubuntu
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def execute_ubuntu
|
58
|
+
convert_to_vhd
|
59
|
+
end
|
60
|
+
|
61
|
+
def convert_to_vhd
|
62
|
+
@log.info "Converting to VMDK Sparse using qemu-img..."
|
63
|
+
if @appliance_config.os.name == 'ubuntu'
|
64
|
+
@exec_helper.execute "qemu-img convert -O vmdk '#{@previous_deliverables.disk}' '#{@deliverables.vhd}.vmdk'"
|
65
|
+
@log.info "Converting to VHD using VBoxManage..."
|
66
|
+
@exec_helper.execute "VBoxManage clonehd --format VHD '#{@deliverables.vhd}.vmdk' '#{@deliverables.vhd}'"
|
67
|
+
FileUtils.rm_f "#{@deliverables.vhd}.vmdk"
|
68
|
+
else
|
69
|
+
@exec_helper.execute "qemu-img convert -O vmdk '#{@deliverables.disk}' '#{@deliverables.disk}.vmdk'"
|
70
|
+
@log.info "Converting to VHD using VBoxManage..."
|
71
|
+
@exec_helper.execute "VBoxManage clonehd --format VHD '#{@deliverables.disk}.vmdk' '#{@deliverables.vhd}'"
|
72
|
+
FileUtils.rm_f "#{@deliverables.disk}.vmdk"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def execute_rpmdistro
|
77
|
+
@linux_helper = LinuxHelper.new(:log => @log)
|
78
|
+
|
79
|
+
@log.info "Converting #{@appliance_config.name} appliance image to XenServer format..."
|
80
|
+
|
81
|
+
@image_helper.create_disk(@deliverables.disk, 10) # 10 GB destination disk
|
82
|
+
|
83
|
+
@image_helper.customize([@previous_deliverables.disk, @deliverables.disk], :automount => false) do |guestfs, guestfs_helper|
|
84
|
+
@image_helper.sync_filesystem(guestfs, guestfs_helper)
|
85
|
+
|
86
|
+
@log.debug "Uploading '/etc/resolv.conf'..."
|
87
|
+
guestfs.upload("/etc/resolv.conf", "/etc/resolv.conf")
|
88
|
+
@log.debug "'/etc/resolv.conf' uploaded."
|
89
|
+
|
90
|
+
if (@appliance_config.os.name == 'rhel' or @appliance_config.os.name == 'centos') and @appliance_config.os.version == '5'
|
91
|
+
# Remove normal kernel
|
92
|
+
guestfs.sh("yum -y remove kernel")
|
93
|
+
# because we need to install kernel-xen package
|
94
|
+
guestfs_helper.sh("yum -y install kernel-xen", :arch => @appliance_config.hardware.arch)
|
95
|
+
# and add require modules
|
96
|
+
@linux_helper.recreate_kernel_image(guestfs, ['xenblk', 'xennet'])
|
97
|
+
end
|
98
|
+
|
99
|
+
create_devices(guestfs)
|
100
|
+
|
101
|
+
upload_fstab(guestfs)
|
102
|
+
enable_networking(guestfs)
|
103
|
+
upload_rc_local(guestfs)
|
104
|
+
#change_configuration(guestfs_helper)
|
105
|
+
install_menu_lst(guestfs)
|
106
|
+
|
107
|
+
enable_nosegneg_flag(guestfs) if @appliance_config.os.name == 'fedora'
|
108
|
+
|
109
|
+
execute_post(guestfs_helper)
|
110
|
+
end
|
111
|
+
|
112
|
+
convert_to_vhd
|
113
|
+
|
114
|
+
@log.info "Image converted to XenServer format."
|
115
|
+
end
|
116
|
+
|
117
|
+
def execute_post(guestfs_helper)
|
118
|
+
unless @appliance_config.post['xenserver'].nil?
|
119
|
+
@appliance_config.post['xenserver'].each do |cmd|
|
120
|
+
@log.debug "Executing xenserver post command #{cmd}"
|
121
|
+
guestfs_helper.sh(cmd, :arch => @appliance_config.hardware.arch)
|
122
|
+
end
|
123
|
+
@log.debug "Post xenserver commands from appliance definition file executed."
|
124
|
+
else
|
125
|
+
@log.debug "No xenserver commands specified, skipping."
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def create_devices(guestfs)
|
130
|
+
return if guestfs.exists('/sbin/MAKEDEV') == 0
|
131
|
+
|
132
|
+
@log.debug "Creating required devices..."
|
133
|
+
guestfs.sh("/sbin/MAKEDEV -d /dev -x console")
|
134
|
+
guestfs.sh("/sbin/MAKEDEV -d /dev -x null")
|
135
|
+
guestfs.sh("/sbin/MAKEDEV -d /dev -x zero")
|
136
|
+
@log.debug "Devices created."
|
137
|
+
end
|
138
|
+
|
139
|
+
def disk_device_prefix
|
140
|
+
disk = 'xv'
|
141
|
+
disk = 's' if (@appliance_config.os.name == 'rhel' or @appliance_config.os.name == 'centos') and @appliance_config.os.version == '5'
|
142
|
+
|
143
|
+
disk
|
144
|
+
end
|
145
|
+
|
146
|
+
def upload_fstab(guestfs)
|
147
|
+
@log.debug "Uploading '/etc/fstab' file..."
|
148
|
+
|
149
|
+
fstab_file = @appliance_config.is64bit? ? "#{File.dirname(__FILE__)}/src/fstab_64bit" : "#{File.dirname(__FILE__)}/src/fstab_32bit"
|
150
|
+
|
151
|
+
fstab_data = File.open(fstab_file).read
|
152
|
+
fstab_data.gsub!(/#DISK_DEVICE_PREFIX#/, disk_device_prefix)
|
153
|
+
fstab_data.gsub!(/#FILESYSTEM_TYPE#/, @appliance_config.hardware.partitions['/']['type'])
|
154
|
+
|
155
|
+
fstab = Tempfile.new('fstab')
|
156
|
+
fstab << fstab_data
|
157
|
+
fstab.flush
|
158
|
+
|
159
|
+
guestfs.upload(fstab.path, "/etc/fstab")
|
160
|
+
|
161
|
+
fstab.close
|
162
|
+
|
163
|
+
@log.debug "'/etc/fstab' file uploaded."
|
164
|
+
end
|
165
|
+
|
166
|
+
def install_menu_lst(guestfs)
|
167
|
+
@log.debug "Uploading '/boot/grub/menu.lst' file..."
|
168
|
+
menu_lst_data = File.open("#{File.dirname(__FILE__)}/src/menu.lst").read
|
169
|
+
|
170
|
+
menu_lst_data.gsub!(/#TITLE#/, @appliance_config.name)
|
171
|
+
menu_lst_data.gsub!(/#KERNEL_VERSION#/, @linux_helper.kernel_version(guestfs))
|
172
|
+
menu_lst_data.gsub!(/#KERNEL_IMAGE_NAME#/, @linux_helper.kernel_image_name(guestfs))
|
173
|
+
|
174
|
+
menu_lst = Tempfile.new('menu_lst')
|
175
|
+
menu_lst << menu_lst_data
|
176
|
+
menu_lst.flush
|
177
|
+
|
178
|
+
guestfs.upload(menu_lst.path, "/boot/grub/menu.lst")
|
179
|
+
|
180
|
+
menu_lst.close
|
181
|
+
@log.debug "'/boot/grub/menu.lst' file uploaded."
|
182
|
+
end
|
183
|
+
|
184
|
+
# This fixes issues with Fedora 14 on EC2: https://bugzilla.redhat.com/show_bug.cgi?id=651861#c39
|
185
|
+
def enable_nosegneg_flag(guestfs)
|
186
|
+
@log.debug "Enabling nosegneg flag..."
|
187
|
+
guestfs.sh("echo \"hwcap 1 nosegneg\" > /etc/ld.so.conf.d/libc6-xen.conf")
|
188
|
+
guestfs.sh("/sbin/ldconfig")
|
189
|
+
@log.debug "Nosegneg enabled."
|
190
|
+
end
|
191
|
+
|
192
|
+
# enable networking on default runlevels
|
193
|
+
def enable_networking(guestfs)
|
194
|
+
@log.debug "Enabling networking..."
|
195
|
+
guestfs.sh("/sbin/chkconfig network on")
|
196
|
+
guestfs.upload("#{File.dirname(__FILE__)}/src/ifcfg-eth0", "/etc/sysconfig/network-scripts/ifcfg-eth0")
|
197
|
+
@log.debug "Networking enabled."
|
198
|
+
end
|
199
|
+
|
200
|
+
def upload_rc_local(guestfs)
|
201
|
+
@log.debug "Uploading '/etc/rc.d/rc.local' file..."
|
202
|
+
rc_local = Tempfile.new('rc_local')
|
203
|
+
|
204
|
+
if guestfs.exists("/etc/rc.d/rc.local") == 1
|
205
|
+
# We're appending
|
206
|
+
rc_local << guestfs.read_file("/etc/rc.d/rc.local")
|
207
|
+
else
|
208
|
+
# We're creating new file
|
209
|
+
rc_local << "#!/bin/bash\n\n"
|
210
|
+
end
|
211
|
+
|
212
|
+
rc_local << File.read("#{File.dirname(__FILE__)}/src/rc_local")
|
213
|
+
rc_local.flush
|
214
|
+
|
215
|
+
guestfs.upload(rc_local.path, "/etc/rc.d/rc.local")
|
216
|
+
|
217
|
+
rc_local.close
|
218
|
+
|
219
|
+
# Fedora 16 doesn't have /etc/rc.local file and we need to
|
220
|
+
# enable rc.local compatibility with systemd
|
221
|
+
# We need to make sure that network is available when executing rc.local
|
222
|
+
if (@appliance_config.os.name == 'fedora' and @appliance_config.os.version >= '16')
|
223
|
+
guestfs.cp("/lib/systemd/system/rc-local.service", "/etc/systemd/system/")
|
224
|
+
guestfs.sh("sed -i '/^ConditionFileIsExecutable/a After=network.target' /etc/systemd/system/rc-local.service")
|
225
|
+
guestfs.sh("systemctl enable rc-local.service")
|
226
|
+
guestfs.ln_sf("/etc/rc.d/rc.local", "/etc/rc.local")
|
227
|
+
guestfs.chmod(0755, "/etc/rc.d/rc.local")
|
228
|
+
end
|
229
|
+
|
230
|
+
@log.debug "'/etc/rc.d/rc.local' file uploaded."
|
231
|
+
end
|
232
|
+
|
233
|
+
def change_configuration(guestfs_helper)
|
234
|
+
guestfs_helper.augeas do
|
235
|
+
# disable password authentication
|
236
|
+
set("/etc/ssh/sshd_config", "PasswordAuthentication", "no")
|
237
|
+
|
238
|
+
# disable root login
|
239
|
+
set("/etc/ssh/sshd_config", "PermitRootLogin", "without-password")
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boxgrinder-xenserver-platform-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sergio Rubio
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: boxgrinder-build
|
16
|
+
requirement: &9149360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *9149360
|
25
|
+
description: Boxgrinder XenServer platform plugin
|
26
|
+
email: rubiojr@bvox.net
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files:
|
30
|
+
- LICENSE.txt
|
31
|
+
- README.md
|
32
|
+
files:
|
33
|
+
- .document
|
34
|
+
- LICENSE.txt
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/src/fstab_32bit
|
38
|
+
- lib/src/fstab_64bit
|
39
|
+
- lib/src/ifcfg-eth0
|
40
|
+
- lib/src/menu.lst
|
41
|
+
- lib/src/rc_local
|
42
|
+
- lib/xenserver-platform-plugin.rb
|
43
|
+
homepage: http://github.com/bvox/boxgrinder-xenserver-platform-plugin
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.17
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Boxgrinder XenServer platform plugin
|
68
|
+
test_files: []
|