Permalink
Browse files

Handle paths correctly when copying from windows box to host via webr…

…ick web server

Use the correct command line commands for vm when modifying a running and a stopped virtual machine
Add talifun templates for Ubuntu, Windows Server 2008 R2 and Windows Server 2012
  • Loading branch information...
taliesins committed Feb 25, 2013
1 parent d17e788 commit d76dac4ab6a86636959d370dc7f99764faf27a2e
Showing with 1,190 additions and 21 deletions.
  1. +9 −5 lib/veewee/provider/core/box/wincp.rb
  2. +7 −8 lib/veewee/provider/core/helper/web.rb
  3. +6 −0 lib/veewee/provider/virtualbox/box/export_vagrant.rb
  4. +11 −3 lib/veewee/provider/virtualbox/box/helper/create.rb
  5. +5 −1 lib/veewee/provider/virtualbox/box/helper/forwarding.rb
  6. +4 −4 lib/veewee/provider/virtualbox/box/up.rb
  7. +20 −0 templates/talifun-ubuntu-12.10-server-amd64/base.sh
  8. +49 −0 templates/talifun-ubuntu-12.10-server-amd64/chef.sh
  9. +25 −0 templates/talifun-ubuntu-12.10-server-amd64/cleanup.sh
  10. +44 −0 templates/talifun-ubuntu-12.10-server-amd64/definition.rb
  11. +87 −0 templates/talifun-ubuntu-12.10-server-amd64/preseed.cfg
  12. +17 −0 templates/talifun-ubuntu-12.10-server-amd64/puppet.sh
  13. +7 −0 templates/talifun-ubuntu-12.10-server-amd64/ruby.sh
  14. +27 −0 templates/talifun-ubuntu-12.10-server-amd64/vagrant.sh
  15. +15 −0 templates/talifun-ubuntu-12.10-server-amd64/virtualbox.sh
  16. +11 −0 templates/talifun-ubuntu-12.10-server-amd64/zerodisk.sh
  17. +217 −0 templates/talifun-windows-2008R2-serverstandard-amd64/Autounattend.xml
  18. +87 −0 templates/talifun-windows-2008R2-serverstandard-amd64/README.md
  19. +35 −0 templates/talifun-windows-2008R2-serverstandard-amd64/definition.rb
  20. +2 −0 templates/talifun-windows-2008R2-serverstandard-amd64/install-chef.bat
  21. +2 −0 templates/talifun-windows-2008R2-serverstandard-amd64/install-vbox.bat
  22. BIN templates/talifun-windows-2008R2-serverstandard-amd64/oracle-cert.cer
  23. +74 −0 templates/talifun-windows-2008R2-serverstandard-amd64/postinstall.sh
  24. +231 −0 templates/talifun-windows-2012-serverstandard-amd64/Autounattend.xml
  25. +87 −0 templates/talifun-windows-2012-serverstandard-amd64/README.md
  26. +33 −0 templates/talifun-windows-2012-serverstandard-amd64/definition.rb
  27. +2 −0 templates/talifun-windows-2012-serverstandard-amd64/install-chef.bat
  28. +2 −0 templates/talifun-windows-2012-serverstandard-amd64/install-vbox.bat
  29. BIN templates/talifun-windows-2012-serverstandard-amd64/oracle-cert.cer
  30. +74 −0 templates/talifun-windows-2012-serverstandard-amd64/postinstall.sh
@@ -23,18 +23,22 @@ def wincp(localfile,remotefile,options={})
definition.kickstart_port=guessed_port.to_s
end
env.ui.warn "Spinning up a wait_for_http_request on http://#{host_ip_as_seen_by_guest}:#{definition.kickstart_port}#{localfile}"
webthread=allow_for_http_request(localfile,{
#localfile = 'c:\\windows\\temp\\hello.txt'
#localfile = '/windows/temp/hello.txt'
localuri = localfile.gsub('\\', '/').sub(/([a-zA-Z]):/, '\1')
localuri = localuri.start_with?('/') ? localuri : '/' + localuri
env.ui.warn "Spinning up a wait_for_http_request on http://#{host_ip_as_seen_by_guest}:#{definition.kickstart_port}#{localuri}"
webthread=allow_for_http_request(localfile, localuri, {
:port => definition.kickstart_port,
:host => definition.kickstart_ip,
:timeout => definition.kickstart_timeout,
:web_dir => '/'
:timeout => definition.kickstart_timeout
})
begin
self.when_winrm_login_works(self.ip_address,winrm_options.merge(options)) do
env.ui.info "Going to try and copy #{localfile} to #{remotefile.inspect}"
self.exec("cmd.exe /C cscript %TEMP%\\wget.vbs /url:http://#{host_ip_as_seen_by_guest}:#{definition.kickstart_port}#{localfile} /path:#{remotefile}")
self.exec("cmd.exe /C cscript %TEMP%\\wget.vbs /url:http://#{host_ip_as_seen_by_guest}:#{definition.kickstart_port}#{localuri} /path:#{remotefile}")
# while true do
# sleep 0.1 # used to debug
# end
@@ -46,28 +46,27 @@ def wait_for_http_request(filename,options) # original blocking
s.start
end
def allow_for_http_request(filename,options) # start in new thread
s = server_for_http_request(filename,options.merge({:threaded => true}))
def allow_for_http_request(filename, fileuri, options) # start in new thread
s = server_for_http_request(filename,fileuri,options.merge({:threaded => true}))
Thread.new { s.start }
end
def server_for_http_request(filename,options={:timeout => 10, :web_dir => "", :port => 7125, :threaded => false})
def server_for_http_request(filename, fileuri, options={:timeout => 10, :web_dir => "", :port => 7125, :threaded => false})
# Calculate the OS equivalent of /dev/null , on windows this is NUL:
# http://www.ruby-forum.com/topic/115472
fn = test(?e, '/dev/null') ? '/dev/null' : 'NUL:'
webrick_logger=WEBrick::Log.new(fn, WEBrick::Log::INFO)
web_dir=options[:web_dir]
filename=filename
s= ::WEBrick::HTTPServer.new(
:Port => options[:port],
:Logger => webrick_logger,
:AccessLog => webrick_logger
)
mount_filename = filename.start_with?('/') ? filename : "/#{filename}"
env.logger.debug("mounting file #{mount_filename}")
s.mount("#{mount_filename}", Veewee::Provider::Core::Helper::Servlet::FileServlet,File.join(web_dir,filename),ui,options[:threaded])
env.logger.debug("mounting #{filename} for file #{fileuri}")
s.mount("#{fileuri}", Veewee::Provider::Core::Helper::Servlet::FileServlet,filename,ui,options[:threaded])
trap("INT"){
s.shutdown
ui.info "Stopping webserver"
@@ -139,6 +139,12 @@ def export_vagrant(options)
#we need to restore it in order to be able to login again
#self.add_ssh_nat_mapping
if definition.winrm_user && definition.winrm_password
self.add_winrm_nat_mapping
else
self.add_ssh_nat_mapping
end
ui.info "To import it into vagrant type:"
ui.info "vagrant box add '#{name}' '#{box_path}'"
ui.info ""
@@ -26,8 +26,12 @@ def add_ssh_nat_mapping
unless definition.nil?
unless definition.skip_nat_mapping == true
#Map SSH Ports
#Map SSH Ports
if self.running?
command="#{@vboxcmd} controlvm \"#{name}\" natpf#{self.natinterface} \"guestssh,tcp,,#{definition.ssh_host_port},,#{definition.ssh_guest_port}\""
else
command="#{@vboxcmd} modifyvm \"#{name}\" --natpf#{self.natinterface} \"guestssh,tcp,,#{definition.ssh_host_port},,#{definition.ssh_guest_port}\""
end
shell_exec("#{command}")
end
end
@@ -38,8 +42,12 @@ def add_winrm_nat_mapping
unless definition.nil?
#Map SSH Ports
unless definition.skip_nat_mapping == true
command="#{@vboxcmd} modifyvm \"#{name}\" --natpf1 'guestwinrm,tcp,,#{definition.winrm_host_port},,#{definition.winrm_guest_port}'"
shell_exec("#{command}")
if self.running?
command="#{@vboxcmd} controlvm \"#{name}\" natpf#{self.natinterface} \"guestwinrm,tcp,,#{definition.winrm_host_port},,#{definition.winrm_guest_port}\""
else
command="#{@vboxcmd} modifyvm \"#{name}\" --natpf#{self.natinterface} \"guestwinrm,tcp,,#{definition.winrm_host_port},,#{definition.winrm_guest_port}\""
end
shell_exec("#{command}")
end
end
end
@@ -28,7 +28,11 @@ def forwarding(name)
def delete_forwarding(name)
forward=self.forwarding(name)
command="#{@vboxcmd} controlvm \"#{self.name}\" natpf#{self.natinterface} delete #{name}"
if self.running?
command="#{@vboxcmd} controlvm \"#{self.name}\" natpf#{self.natinterface} delete \"#{name}\""
else
command="#{@vboxcmd} modifyvm \"#{self.name}\" --natpf#{self.natinterface} delete \"#{name}\""
end
shell_results=shell_exec("#{command}")
end
@@ -20,10 +20,10 @@ def up(options={})
definition.winrm_host_port=guessed_port.to_s
unless forward.nil?
if guessed_port!=forward[:guest_port]
if guessed_port!=forward[:host_port]
# Remove the existing one
self.delete_forwarding("guestwinrm")
env.ui.warn "Changing winrm port on UP from #{forward[:guest_port]} to #{guessed_port}"
env.ui.warn "Changing winrm port on UP from #{forward[:host_port]} to #{guessed_port}"
self.add_winrm_nat_mapping
end
else
@@ -38,10 +38,10 @@ def up(options={})
definition.ssh_host_port=guessed_port.to_s
unless forward.nil?
if guessed_port!=forward[:guest_port]
if guessed_port!=forward[:host_port]
# Remove the existing one
self.delete_forwarding("guestssh")
env.ui.warn "Changing ssh port from #{forward[:guest_port]} to #{guessed_port}"
env.ui.warn "Changing ssh port from #{forward[:host_port]} to #{guessed_port}"
self.add_ssh_nat_mapping
end
else
@@ -0,0 +1,20 @@
if [ -f .veewee_params ]
then
. .veewee_params
fi
# Apt-install various things necessary for Ruby, guest additions,
# etc., and remove optional things to trim down the machine.
# Compress apt indexes
cat <<EOF > /etc/apt/apt.conf.d/02compress-indexes
Acquire::GzipIndexes "true";
Acquire::CompressionTypes::Order:: "gz";
EOF
apt-get -y update
apt-get -y upgrade
apt-get -y install linux-headers-$(uname -r) build-essential
apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev
apt-get -y install vim
apt-get -y install acpid
@@ -0,0 +1,49 @@
if [ -f .veewee_params ]
then
. .veewee_params
fi
# Default to Gem install
if [ -z "$CHEF_INSTALLMETHOD" ]; then
export CHEF_INSTALLMETHOD="gems"
fi
# Installing chef
case $CHEF_INSTALLMETHOD in
"gems")
# Using gems
if [ -z "$CHEF_VERSION" ]; then
# Default to latest
gem install chef --no-ri --no-rdoc
else
gem install chef --no-ri --no-rdoc --version $CHEF_VERSION
fi
;;
"omnibus")
# Using omnibus
if [ -z "$CHEF_VERSION" ]; then
# Default to latest
wget -O - http://opscode.com/chef/install.sh | sudo bash -s
else
wget -O - http://opscode.com/chef/install.sh | sudo bash -s -- -v $CHEF_VERSION
fi
;;
"package")
# Using packages
apt-get install -y debconf-utils
echo "chef chef/chef_server_url string $CHEF_SERVER_URL" | debconf-set-selections
if [ -z "$CHEF_VERSION" ]; then
# Default to latest
apt-get install -y chef
else
apt-get install -y chef=$CHEF_VERSION
fi
;;
*)
echo "Unsupported method for installing chef"
exit -1
;;
esac
@@ -0,0 +1,25 @@
# Remove items used for building, since they aren't needed anymore
echo "removing unnessary packages"
apt-get -y remove linux-headers-$(uname -r) build-essential
apt-get -y autoremove
# Removing leftover leases and persistent rules
echo "cleaning up dhcp leases"
rm /var/lib/dhcp/*
echo "cleaning apt cache"
apt-get clean
echo "cleaning gem cache"
rm /var/lib/gems/1.9.1/cache/*
# Make sure Udev doesn't block our network
# http://6.ptmc.org/?p=164
echo "cleaning up udev rules"
rm /etc/udev/rules.d/70-persistent-net.rules
mkdir /etc/udev/rules.d/70-persistent-net.rules
rm -rf /dev/.udev/
rm /lib/udev/rules.d/75-persistent-net-generator.rules
echo "Adding a 2 sec delay to the interface up, to make the dhclient happy"
echo "pre-up sleep 2" >> /etc/network/interfaces
@@ -0,0 +1,44 @@
Veewee::Session.declare({
:cpu_count => '1',
:memory_size=> '368',
:disk_size => '10140',
:disk_format => 'VDI',
:hostiocache => 'off',
:os_type_id => 'Ubuntu_64',
:iso_file => "ubuntu-12.10-server-amd64.iso",
:iso_src => "http://releases.ubuntu.com/12.10/ubuntu-12.10-server-amd64.iso",
:iso_md5 => '4bd3270bde86d7e4e017e3847a4af485',
:iso_download_timeout => "1000",
:boot_wait => "4",
:boot_cmd_sequence => [
'<Esc><Esc><Enter>',
'/install/vmlinuz noapic preseed/url=http://%IP%:%PORT%/preseed.cfg ',
'debian-installer=en_US auto locale=en_US kbd-chooser/method=us ',
'hostname=%NAME% ',
'fb=false debconf/frontend=noninteractive ',
'keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=us keyboard-configuration/variant=us console-setup/ask_detect=false ',
'initrd=/install/initrd.gz -- <Enter>'
],
:kickstart_port => "7122",
:kickstart_timeout => "10000",
:kickstart_file => "preseed.cfg",
:ssh_login_timeout => "10000",
:ssh_user => "vagrant",
:ssh_password => "vagrant",
:ssh_key => "",
:ssh_host_port => "7222",
:ssh_guest_port => "22",
:sudo_cmd => "echo '%p'|sudo -S bash '%f'",
:shutdown_cmd => "shutdown -P now",
:postinstall_files => [
"base.sh",
"vagrant.sh",
"virtualbox.sh",
"ruby.sh",
"puppet.sh",
"chef.sh",
"cleanup.sh",
"zerodisk.sh",
],
:postinstall_timeout => "10000"
})
@@ -0,0 +1,87 @@
## Options to set on the command line
d-i debian-installer/locale string en_US.utf8
d-i console-setup/ask_detect boolean false
d-i console-setup/layout string us
#d-i netcfg/get_hostname string dummy
d-i netcfg/get_hostname string talifun-ubuntu-quantal
d-i netcfg/get_domain string talifun.com
# Continue without a default route
# Not working , specify a dummy in the DHCP
#d-i netcfg/no_default_route boolean
d-i time/zone string UTC
d-i clock-setup/utc-auto boolean true
d-i clock-setup/utc boolean true
d-i kbd-chooser/method select American English
d-i netcfg/wireless_wep string
d-i base-installer/kernel/override-image string linux-server
#d-i base-installer/kernel/override-image string linux-image-2.6.32-21-generic
# Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
d-i debconf debconf/frontend select Noninteractive
d-i pkgsel/install-language-support boolean false
tasksel tasksel/first multiselect standard, ubuntu-server
#d-i partman-auto/method string regular
d-i partman-auto/method string lvm
#d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
#http://ubuntu-virginia.ubuntuforums.org/showthread.php?p=9626883
#Message: "write the changes to disk and configure lvm preseed"
#http://serverfault.com/questions/189328/ubuntu-kickstart-installation-using-lvm-waits-for-input
#preseed partman-lvm/confirm_nooverwrite boolean true
# Write the changes to disks and configure LVM?
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto-lvm/guided_size string max
## Default user, we can get away with a recipe to change this
d-i passwd/user-fullname string vagrant
d-i passwd/username string vagrant
d-i passwd/user-password password vagrant
d-i passwd/user-password-again password vagrant
d-i user-setup/encrypt-home boolean false
d-i user-setup/allow-password-weak boolean true
## minimum is puppet and ssh and ntp
# Individual additional packages to install
d-i pkgsel/include string openssh-server ntp
# Whether to upgrade packages after debootstrap.
# Allowed values: none, safe-upgrade, full-upgrade
d-i pkgsel/upgrade select full-upgrade
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i finish-install/reboot_in_progress note
#For the update
d-i pkgsel/update-policy select none
# debconf-get-selections --install
#Use mirror
#d-i apt-setup/use_mirror boolean true
#d-i mirror/country string manual
#choose-mirror-bin mirror/protocol string http
#choose-mirror-bin mirror/http/hostname string 192.168.4.150
#choose-mirror-bin mirror/http/directory string /ubuntu
#choose-mirror-bin mirror/suite select maverick
#d-i debian-installer/allow_unauthenticated string true
choose-mirror-bin mirror/http/proxy string
@@ -0,0 +1,17 @@
if [ -f .veewee_params ]
then
. .veewee_params
fi
# Add puppet user and group
adduser --system --group --home /var/lib/puppet puppet
# Installing Puppet
gem install puppet --no-ri --no-rdoc
if [ -z "$PUPPET_VERSION" ]; then
# Default to latest
gem install puppet --no-ri --no-rdoc
else
gem install puppet --no-ri --no-rdoc --version $PUPPET_VERSION
fi
Oops, something went wrong.

0 comments on commit d76dac4

Please sign in to comment.