Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/jedi4ever/veewee
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Mar 28, 2013
2 parents 6f3b3b3 + 01d4afa commit dfaaf59
Show file tree
Hide file tree
Showing 129 changed files with 3,126 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pkg/*
virtualfloppy.vfd
*.swp
AutoPartition.app
.rbenv-gemsets
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ desc 'Default: run tests'
task :default => :test

require 'rake/testtask'
Bundler::GemHelper.install_tasks

desc 'Tests not requiring an real box'
Rake::TestTask.new do |t|
Expand Down
2 changes: 1 addition & 1 deletion doc/vagrant.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A typical workflow with Vagrant would be:

$ vagrant basebox define 'mybuntubox' 'ubuntu-10.12-amd64'
$ vagrant basebox define 'mybuntubox' 'ubuntu-12.10-server-amd64'
$ vagrant basebox build 'mybuntubox'
$ vagrant basebox export 'mybuntubox'

Expand Down
13 changes: 7 additions & 6 deletions lib/veewee/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Definition
attr_writer :cpu_count, :memory_size

attr_accessor :video_memory_size, :iso_file
attr_accessor :disk_size, :disk_format, :disk_variant
attr_accessor :disk_size, :disk_format, :disk_variant, :disk_count

attr_accessor :os_type_id

Expand Down Expand Up @@ -48,6 +48,8 @@ class Definition
attr_accessor :skip_iso_transfer
attr_accessor :skip_nat_mapping

attr_accessor :force_ssh_port

def ui
return @_ui if defined?(@_ui)
@_ui = @env.ui.dup
Expand Down Expand Up @@ -83,7 +85,7 @@ def initialize(name, path, env)
@postinstall_files = [] ; @postinstall_timeout = 10000 ;

@iso_file = ""
@disk_size = '10240' ; @disk_format = 'VDI' ; @disk_variant = 'Standard'
@disk_size = '10240' ; @disk_format = 'VDI' ; @disk_variant = 'Standard' ; @disk_count = 1
@use_sata = true

# :hostiocache => 'off' ,
Expand All @@ -106,6 +108,9 @@ def initialize(name, path, env)
@skip_iso_transfer = false

@skip_nat_mapping = false

@force_ssh_port = false

@params = {}
end

Expand Down Expand Up @@ -225,9 +230,5 @@ def ostype_valid?
end
end

def method_missing(m, *args, &block)
env.logger.info "There's no attribute #{m} defined for definition #{@name}-- ignoring it"
end

end #End Class
end #End Module
28 changes: 18 additions & 10 deletions lib/veewee/provider/core/helper/tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,39 @@ def is_tcp_port_open?(ip, port)

# This tries to guess a local free tcp port
def guess_free_port(min_port,max_port)
ui.info "Received port hint - #{min_port}"

if definition.force_ssh_port
return min_port
end
ui.info "Finding unused TCP port in range: #{min_port} - #{max_port}"

guessed_port=nil

for port in (min_port..max_port)
(min_port..max_port).each do |port|
unless is_tcp_port_open?(get_local_ip, port)
guessed_port=port
break
end
end

if guessed_port.nil?
ui.error "No free port available: tried #{min_port}..#{max_port}"
raise Veewee::Error, "No free port available: tried #{min_port}..#{max_port}"
else
ui.info "Found port #{guessed_port} available"
message = "No free TCP port available in range: #{min_port} - #{max_port}"
ui.error message
raise Veewee::Error, message
end

ui.info "Selected TCP port #{guessed_port}"
return guessed_port
end

def guess_free_ssh_port(min_port, max_port)
if definition.force_ssh_port
ui.warn "SSH port auto-configuration is disabled in the definition (force_ssh_port=true)."
if is_tcp_port_open?(get_local_ip, min_port)
ui.warn "TCP port #{min_port} is in use. You may execute the postinstall scripts on a different machine than intended!"
end
return min_port
else
return guess_free_port(min_port, max_port)
end
end

def execute_when_tcp_available(ip="127.0.0.1", options = { } , &block)

defaults={ :port => 22, :timeout => 2 , :pollrate => 5}
Expand Down
2 changes: 1 addition & 1 deletion lib/veewee/provider/core/helper/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def wait_for_http_request(filename,options) # original blocking
end

def allow_for_http_request(filename,options) # start in new thread
s = server_for_http_request(filename,options.merge({:threaded => true}))
s = server_for_http_request(filename,options.merge({:threaded => false}))
Thread.new { s.start }
end

Expand Down
3 changes: 3 additions & 0 deletions lib/veewee/provider/core/helper/winrm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def winrm_up?(ip,options)
rescue HTTPClient::ReceiveTimeoutError,HTTPClient::ConnectTimeoutError
@winrm_up = false
end
@winrm_up
end


Expand Down Expand Up @@ -62,6 +63,8 @@ def when_winrm_login_works(ip="127.0.0.1", options = {}, &block)
@connected = true
return true
rescue Exception => e
@winrm_up = false
next if e.message =~ /401/ # 2012 gives 401 errors
puts e.inspect
puts e.message
puts e.backtrace.inspect
Expand Down
2 changes: 1 addition & 1 deletion lib/veewee/provider/virtualbox/box/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def create(options={})
end
self.add_winrm_nat_mapping
else
guessed_port=guess_free_port(definition.ssh_host_port.to_i,definition.ssh_host_port.to_i+40).to_s
guessed_port=guess_free_ssh_port(definition.ssh_host_port.to_i,definition.ssh_host_port.to_i+40).to_s
if guessed_port.to_s!=definition.ssh_host_port
env.ui.warn "Changing ssh port from #{definition.ssh_host_port} to #{guessed_port}"
definition.ssh_host_port=guessed_port.to_s
Expand Down
36 changes: 19 additions & 17 deletions lib/veewee/provider/virtualbox/box/helper/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def add_ide_controller
shell_exec("#{command}")
end

def add_sata_controller
def add_sata_controller
#unless => "${vboxcmd} showvminfo \"${vname}\" | grep \"SATA Controller\" ";
command ="#{@vboxcmd} storagectl \"#{name}\" --name \"SATA Controller\" --add sata --hostiocache #{definition.hostiocache} --sataportcount 1"
command ="#{@vboxcmd} storagectl \"#{name}\" --name \"SATA Controller\" --add sata --hostiocache #{definition.hostiocache} --sataportcount #{definition.disk_count}"
shell_exec("#{command}")
end

Expand Down Expand Up @@ -79,25 +79,27 @@ def suppress_messages


def create_disk
ui.info "Creating new harddrive of size #{definition.disk_size.to_i}, format #{definition.disk_format}, variant #{definition.disk_variant} "


place=get_vbox_home
command ="#{@vboxcmd} createhd --filename \"#{File.join(place,name,name+"."+definition.disk_format.downcase)}\" --size \"#{definition.disk_size.to_i}\" --format #{definition.disk_format.downcase} --variant #{definition.disk_variant.downcase}"
shell_exec("#{command}")

place=get_vbox_home
1.upto(definition.disk_count.to_i) do |f|
ui.info "Creating new harddrive of size #{definition.disk_size.to_i}, format #{definition.disk_format}, variant #{definition.disk_variant} "
command ="#{@vboxcmd} createhd --filename \"#{File.join(place,name,name+"#{f}."+definition.disk_format.downcase)}\" --size \"#{definition.disk_size.to_i}\" --format #{definition.disk_format.downcase} --variant #{definition.disk_variant.downcase}"
shell_exec("#{command}")
end
end

def attach_disk_common(storagectl, device_number)
place=get_vbox_home
location=name+"."+definition.disk_format.downcase

location="#{File.join(place,name,location)}"
ui.info "Attaching disk: #{location}"

#command => "${vboxcmd} storageattach \"${vname}\" --storagectl \"SATA Controller\" --port 0 --device 0 --type hdd --medium \"${vname}.vdi\"",
command ="#{@vboxcmd} storageattach \"#{name}\" --storagectl \"#{storagectl}\" --port 0 --device #{device_number} --type hdd --medium \"#{location}\""
shell_exec("#{command}")

1.upto(definition.disk_count.to_i) do |f|
location=name+"#{f}."+definition.disk_format.downcase

location="#{File.join(place,name,location)}"
ui.info "Attaching disk: #{location}"

#command => "${vboxcmd} storageattach \"${vname}\" --storagectl \"SATA Controller\" --port 0 --device 0 --type hdd --medium \"${vname}.vdi\"",
command ="#{@vboxcmd} storageattach \"#{name}\" --storagectl \"#{storagectl}\" --port #{f-1} --device #{device_number} --type hdd --medium \"#{location}\""
shell_exec("#{command}")
end
end

def attach_disk_ide(device_number=0)
Expand Down
4 changes: 2 additions & 2 deletions lib/veewee/provider/virtualbox/box/up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module BoxCommand
def up(options={})

unless self.exists?
raise Veewee::Error, "Error:: You tried to up a non-existing box '#{name}'"
raise Veewee::Error, "Error:: You tried to up a non-existing box '#{name}'. Please run 'veewee vbox build #{name}' first."
end

gui_enabled=options['nogui']==true ? false : true
Expand Down Expand Up @@ -34,7 +34,7 @@ def up(options={})

# Before we start,correct the ssh port if needed
forward=self.forwarding("guestssh")
guessed_port=guess_free_port(definition.ssh_host_port.to_i,definition.ssh_host_port.to_i+40).to_s
guessed_port=guess_free_ssh_port(definition.ssh_host_port.to_i,definition.ssh_host_port.to_i+40).to_s
definition.ssh_host_port=guessed_port.to_s

unless forward.nil?
Expand Down
7 changes: 6 additions & 1 deletion lib/veewee/provider/vmfusion/box/helper/ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ def ip_address
# Does not work for now as the vmx path is not escape correctly by fission 0.4.0
#return raw.network_info.data.first['ip_address']
raise ::Fission::Error,"VM #{name} does not exist" unless self.exists?


# Use alternate method to retrieve the IP address using vmrun readVariable

ip_address = shell_exec("#{vmrun_cmd.shellescape} readVariable \"#{vmx_file_path}\" guestVar ip", { :mute => true}).stdout.strip
return ip_address unless ip_address.empty?

unless mac_address.nil?
lease = Fission::Lease.find_by_mac_address(mac_address).data
return lease.ip_address unless lease.nil?
Expand Down
2 changes: 1 addition & 1 deletion lib/veewee/provider/vmfusion/box/template.vmx.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ide1:0.present = "TRUE"
ide1:0.fileName = "<%= iso_file %>"
ide1:0.deviceType = "cdrom-image"
<% end %>
virtualHW.version = <%= virtualhw_version %>
virtualHW.version = "<%= virtualhw_version %>"
numvcpus = "<%= cpu_count %>"
scsi0.present = "TRUE"
scsi0.virtualDev = "<%= controller_type %>"
Expand Down
4 changes: 2 additions & 2 deletions templates/CentOS-5.8-x86_64-netboot/ks.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kickstart file automatically generated by anaconda.

install
url --url=http://mirrors.arsc.edu/centos/5.8/os/x86_64/
url --url=http://vault.centos.org/5.8/os/x86_64
lang en_US.UTF-8
langsupport --default=en_US.UTF-8 en_US.UTF-8
keyboard us
Expand Down Expand Up @@ -44,4 +44,4 @@ kernel-headers
/usr/sbin/groupadd vagrant
/usr/sbin/useradd vagrant -g vagrant -G wheel
echo "vagrant"|passwd --stdin vagrant
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
14 changes: 14 additions & 0 deletions templates/CentOS-6.4-i386-minimal/base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Base install

sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers

cat > /etc/yum.repos.d/epel.repo << EOM
[epel]
name=epel
baseurl=http://download.fedoraproject.org/pub/epel/6/\$basearch
enabled=1
gpgcheck=0
EOM

yum -y install gcc make gcc-c++ kernel-devel-`uname -r` zlib-devel openssl-devel readline-devel sqlite-devel perl wget dkms nfs-utils

2 changes: 2 additions & 0 deletions templates/CentOS-6.4-i386-minimal/chef.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Install Chef
curl -L https://www.opscode.com/chef/install.sh | bash
5 changes: 5 additions & 0 deletions templates/CentOS-6.4-i386-minimal/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
yum -y erase gtk2 libX11 hicolor-icon-theme avahi freetype bitstream-vera-fonts
yum -y clean all
rm -rf /etc/yum.repos.d/{puppetlabs,epel}.repo
rm -rf VBoxGuestAdditions_*.iso

37 changes: 37 additions & 0 deletions templates/CentOS-6.4-i386-minimal/definition.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Veewee::Session.declare({
:cpu_count => '1',
:memory_size=> '480',
:disk_size => '10140',
:disk_format => 'VDI',
:hostiocache => 'off',
:os_type_id => 'RedHat',
:iso_file => "CentOS-6.4-i386-minimal.iso",
:iso_src => "http://yum.singlehop.com/CentOS/6.4/isos/i386/CentOS-6.4-i386-minimal.iso",
:iso_md5 => "6b5c727fa76fcce7c9ab6213ad3df75a",
:iso_download_timeout => 1000,
:boot_wait => "10",
:boot_cmd_sequence => [
'<Tab> text ks=http://%IP%:%PORT%/ks.cfg<Enter>'
],
:kickstart_port => "7122",
:kickstart_timeout => 10000,
:kickstart_file => "ks.cfg",
:ssh_login_timeout => "10000",
:ssh_user => "veewee",
:ssh_password => "veewee",
:ssh_key => "",
:ssh_host_port => "7222",
:ssh_guest_port => "22",
:sudo_cmd => "echo '%p'|sudo -S sh '%f'",
:shutdown_cmd => "/sbin/halt -h -p",
:postinstall_files => [
"base.sh",
"chef.sh",
"puppet.sh",
"vagrant.sh",
"virtualbox.sh",
"cleanup.sh",
"zerodisk.sh"
],
:postinstall_timeout => 10000
})
36 changes: 36 additions & 0 deletions templates/CentOS-6.4-i386-minimal/ks.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
install
cdrom
lang en_US.UTF-8
keyboard us
network --bootproto=dhcp
rootpw --iscrypted $1$damlkd,f$UC/u5pUts5QiU3ow.CSso/
firewall --enabled --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone UTC
bootloader --location=mbr

text
skipx
zerombr

clearpart --all --initlabel
autopart

auth --useshadow --enablemd5
firstboot --disabled
reboot

%packages --nobase
@core
%end

%post
/usr/bin/yum -y install sudo
/usr/sbin/groupadd veewee
/usr/sbin/useradd veewee -g veewee -G wheel
echo "veewee"|passwd --stdin veewee
echo "veewee ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/veewee
chmod 0440 /etc/sudoers.d/veewee
%end

12 changes: 12 additions & 0 deletions templates/CentOS-6.4-i386-minimal/puppet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Install Puppet

cat > /etc/yum.repos.d/puppetlabs.repo << EOM
[puppetlabs]
name=puppetlabs
baseurl=http://yum.puppetlabs.com/el/6/products/\$basearch
enabled=1
gpgcheck=0
EOM

yum -y install puppet facter

18 changes: 18 additions & 0 deletions templates/CentOS-6.4-i386-minimal/vagrant.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Vagrant specific
date > /etc/vagrant_box_build_time

# Add vagrant user
/usr/sbin/groupadd vagrant
/usr/sbin/useradd vagrant -g vagrant -G wheel
echo "vagrant"|passwd --stdin vagrant
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
chmod 0440 /etc/sudoers.d/vagrant

# Installing vagrant keys
mkdir -pm 700 /home/vagrant/.ssh
wget --no-check-certificate 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' -O /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh

# Customize the message of the day
echo 'Welcome to your Vagrant-built virtual machine.' > /etc/motd
Loading

0 comments on commit dfaaf59

Please sign in to comment.