Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Windows 7 x64 POC

I have made a fork from the master and successfully define/build/export/add/init/up a box on windows 7 x64.
What I've done so far - https://github.com/whren/veewee.git :

- Replacing simple quotes by double quotes as mentioned by ikka as VirtualBox does not support simple quote on windows
- Fixed the get_vbox_home for windows has the 'Default machine path' from VBoxManage would include a drive letter, then a ':', so the split didn't correctly work in this case (ie "Default machine folder:          C:\Users\[myUserName]\VirtualBox VMs" was resolved to "C" instead of "C:\Users\[myUserName]\VirtualBox VMs").
- Forced opening of files for writing and Tempfile in binary mode to prevent windows CR+LF line end style (see http://www.ruby-forum.com/topic/60697#58748 and http://www.ruby-forum.com/topic/127453#568546)
- Fixed a defect, not windows related, for the nogui option not working
- Include equivalent of pull request 252 (ui confirm switch to success as confirm does not exists in vagrant ui) - see #252
- Changed CRPropertyList dependency version as libxml-ruby dependency has been removed in version 2.1.1 allowing to build veewee on windows x64 - see ckruse/CFPropertyList#14
- Added an optional pre_postinstall_file in definition, allowing a script to be executed before each postinstall script. The purpose is, for ie, to export proxy env (http_proxy, https_proxy) for working behing a proxy, but not to add such modifications in the future box (modifying /etc/profile for ie). Thanks to this I can build a box behind a proxy, and later, choose to wheter set a fixed proxy by provisioning in the vm.

Signed-off-by: Whren <whren@free.fr>
  • Loading branch information...
commit 915f519682ecb32942bb72565891e08436ec2ff1 1 parent 67f3e78
@whren whren authored
View
3  doc/README-changes.txt
@@ -1,5 +1,6 @@
Changelog
now has include-postinstall, exclude-postinstall
+ now has pre_postinstall_file allowing pre postinstall execution (ie to export http_proxy, https_proxy)
ostypes are now synchronized accross kvm
require libvirt 0.8+ version
user veewee instead of vagrant
@@ -13,7 +14,7 @@ Todo:
validate vms - + features selection
check libvirt version
windows test
- validation of checks (also - inclide/exclude)
+ validation of checks (also - include/exclude)
check execs with exit code
multinetwork card
dkms for kernel installs
View
2  doc/TODO
@@ -54,7 +54,7 @@ Todo:
validate vms - + features selection
check libvirt version
windows test
- validation of checks (also - inclide/exclude)
+ validation of checks (also - include/exclude)
check execs with exit code
multinetwork card
dkms for kernel installs
View
8 lib/fission/vm.rb
@@ -327,7 +327,9 @@ def self.update_config(from, to)
unless File.binary?(file)
text = (File.read file).gsub from, to
- File.open(file, 'w'){ |f| f.print text }
+ # Force binary mode to prevent windows from putting CR-LF end line style
+ # http://www.ruby-forum.com/topic/60697#58748
+ File.open(file, 'wb'){ |f| f.print text }
end
end
@@ -349,7 +351,9 @@ def self.update_config(from, to)
content=content+"uuid.action = \"create\"\n"
# Now rewrite the vmx file
- File.open(new_vmx_file,'w'){ |f| f.print content}
+ # Force binary mode to prevent windows from putting CR-LF end line style
+ # http://www.ruby-forum.com/topic/60697#58748
+ File.open(new_vmx_file,'wb'){ |f| f.print content}
end
View
3  lib/veewee/definition.rb
@@ -24,6 +24,8 @@ class Definition
attr_accessor :sudo_cmd
attr_accessor :shutdown_cmd
+ attr_accessor :pre_postinstall_file
+
attr_accessor :postinstall_files, :postinstall_timeout
attr_accessor :floppy_files
@@ -58,6 +60,7 @@ def initialize(name,path,env)
@floppy_files = nil
# Default there are no post install files
+ @pre_postinstall_file = nil
@postinstall_files=[]; @postinstall_timeout = 10000;
@iso_file=""
View
28 lib/veewee/provider/core/box/build.rb
@@ -38,7 +38,7 @@ def build(options={})
self.create(options)
# Check the GUI mode required
- env.logger.info "Provider asks the box to start: GUI enabled? #{!options[:nogui]}"
+ env.logger.info "Provider asks the box to start: GUI enabled? #{!options['nogui']}"
self.up(options)
# Waiting for it to boot
@@ -77,7 +77,7 @@ def build(options={})
self.transfer_buildinfo(options)
self.handle_postinstall(options)
- env.ui.confirm "The box #{name} was build succesfully!"
+ env.ui.success "The box #{name} was build succesfully!"
env.ui.info "You can now login to the box with:"
env.ui.info ssh_command_string
@@ -190,13 +190,32 @@ def handle_kickstart(options)
# This function handles all the post-install scripts
# It requires a box(to login to) and a definition(listing the postinstall files)
def handle_postinstall(options)
+ is_pre_postinstall_file = !definition.pre_postinstall_file.nil? && !definition.pre_postinstall_file.length != 0
+ transfered = false
definition.postinstall_files.each do |postinstall_file|
# Filenames of postinstall_files are relative to their definition
filename=File.join(definition.path,postinstall_file)
unless File.basename(postinstall_file)=~/^_/
self.scp(filename,File.basename(filename))
self.exec("chmod +x \"#{File.basename(filename)}\"")
- self.exec(sudo("./"+File.basename(filename)))
+ if is_pre_postinstall_file
+ # Filename of pre_postinstall_file are relative to their definition
+ pre_filename=File.join(definition.path, definition.pre_postinstall_file)
+ # Upload the pre postinstall script if not already transfered
+ if !transfered
+ self.scp(pre_filename,File.basename(pre_filename))
+ transfered = true
+ self.exec("chmod +x \"#{File.basename(pre_filename)}\"")
+ # Inject the call to the real script by executing the first argument (it will be the postinstall script file name to be executed)
+ self.exec("execute=\"# We must execute the script passed as the first argument\\n\\$1\" && printf \"%b\\n\" \"$execute\" >> #{File.basename(pre_filename)}")
+ end
+ command = "./" + File.basename(pre_filename)
+ command = sudo(command) + " ./"+File.basename(filename)
+ else
+ command = "./"+File.basename(filename)
+ command = sudo(command)
+ end
+ self.exec(command)
else
env.logger.info "Skipping postinstallfile #{postinstall_file}"
end
@@ -210,6 +229,9 @@ def transfer_buildinfo(options)
build_info.each do |info|
begin
infofile=Tempfile.open("#{info[:filename]}")
+ # Force binary mode to prevent windows from putting CR-LF end line style
+ # http://www.ruby-forum.com/topic/127453#568546
+ infofile.binmode
infofile.puts "#{info[:content]}"
infofile.rewind
infofile.close
View
2  lib/veewee/provider/kvm/box/helper/console_type.rb
@@ -10,7 +10,7 @@ module BoxCommand
def console_type(sequence,type_options={})
vnc_port=@connection.servers.all(:name => name).first.vnc_port
display_port=vnc_port.to_i - 5900
- env.ui.confirm "Sending keystrokes to VNC port :#{display_port} - TCP port: #{vnc_port}"
+ env.ui.success "Sending keystrokes to VNC port :#{display_port} - TCP port: #{vnc_port}"
vnc_type(sequence,"127.0.0.1",display_port)
end
View
6 lib/veewee/provider/virtualbox/box/destroy.rb
@@ -19,7 +19,7 @@ def destroy(option={})
sleep 2
end
- command="#{@vboxcmd} unregistervm '#{name}' --delete"
+ command="#{@vboxcmd} unregistervm \"#{name}\" --delete"
env.ui.info command
env.ui.info "Deleting vm #{name}"
@@ -39,9 +39,9 @@ def destroy(option={})
if location.match(/#{pattern}/)
if File.exists?(location)
- command="#{@vboxcmd} closemedium disk '#{location}' --delete"
+ command="#{@vboxcmd} closemedium disk \"#{location}\" --delete"
else
- command="#{@vboxcmd} closemedium disk '#{location}'"
+ command="#{@vboxcmd} closemedium disk \"#{location}\""
end
env.ui.info "Deleting disk #{location}"
View
2  lib/veewee/provider/virtualbox/box/helper/console_type.rb
@@ -44,7 +44,7 @@ def send_virtualbox_sequence(sequence)
end
def send_keycode(keycode)
- command= "#{@vboxcmd} controlvm '#{name}' keyboardputscancode #{keycode}"
+ command= "#{@vboxcmd} controlvm \"#{name}\" keyboardputscancode #{keycode}"
env.logger.info "#{command}"
sshresult=shell_exec("#{command}",{:mute => true})
unless sshresult.stdout.index("E_ACCESSDENIED").nil?
View
49 lib/veewee/provider/virtualbox/box/helper/create.rb
@@ -4,21 +4,21 @@ module Virtualbox
module BoxCommand
def add_ide_controller
- #unless => "${vboxcmd} showvminfo '${vname}' | grep 'IDE Controller' "
- command ="#{@vboxcmd} storagectl '#{name}' --name 'IDE Controller' --add ide"
+ #unless => "${vboxcmd} showvminfo \"${vname}\" | grep \"IDE Controller\" "
+ command ="#{@vboxcmd} storagectl \"#{name}\" --name \"IDE Controller\" --add ide"
shell_exec("#{command}")
end
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"
+ #unless => "${vboxcmd} showvminfo \"${vname}\" | grep \"SATA Controller\" ";
+ command ="#{@vboxcmd} storagectl \"#{name}\" --name \"SATA Controller\" --add sata --hostiocache #{definition.hostiocache} --sataportcount 1"
shell_exec("#{command}")
end
def attach_serial_console
- command ="#{@vboxcmd} modifyvm '#{name}' --uart1 0x3F8 4"
+ command ="#{@vboxcmd} modifyvm \"#{name}\" --uart1 0x3F8 4"
shell_exec("#{command}")
- command ="#{@vboxcmd} modifyvm '#{name}' --uartmode1 file '#{File.join(FileUtils.pwd,name+"-serial-console"+'.log')}'"
+ command ="#{@vboxcmd} modifyvm \"#{name}\" --uartmode1 file \"#{File.join(FileUtils.pwd,name+"-serial-console"+".log")}\""
shell_exec("#{command}")
end
@@ -26,20 +26,27 @@ def add_ssh_nat_mapping
unless definition.nil?
#Map SSH Ports
- command="#{@vboxcmd} modifyvm '#{name}' --natpf1 'guestssh,tcp,,#{definition.ssh_host_port},,#{definition.ssh_guest_port}'"
+ command="#{@vboxcmd} modifyvm \"#{name}\" --natpf1 \"guestssh,tcp,,#{definition.ssh_host_port},,#{definition.ssh_guest_port}\""
shell_exec("#{command}")
end
end
def add_shared_folder
- command="#{@vboxcmd} sharedfolder add '#{name}' --name 'veewee-validation' --hostpath '#{File.expand_path(env.validation_dir)}' --automount"
+ command="#{@vboxcmd} sharedfolder add \"#{name}\" --name \"veewee-validation\" --hostpath \"#{File.expand_path(env.validation_dir)}\" --automount"
shell_exec("#{command}")
end
def get_vbox_home
command="#{@vboxcmd} list systemproperties"
shell_results=shell_exec("#{command}")
- location=shell_results.stdout.split(/\n/).grep(/Default machine/)[0].split(":")[1].strip
+ # Do not know how to correctly require Util::Platform, so we use a fqdn call
+ if Vagrant::Util::Platform.windows?
+ # On windows Default machine path would include a drive letter, then ':'.
+ # So here we tell to split no more than 2 elements to keep the full path
+ location=shell_results.stdout.split(/\n/).grep(/Default machine/)[0].split(":", 2)[1].strip
+ else
+ location=shell_results.stdout.split(/\n/).grep(/Default machine/)[0].split(":")[1].strip
+ end
return location
end
@@ -55,7 +62,7 @@ def suppress_messages
["GUI/UpdateCheckCount","60"]
]
extraData.each do |data|
- command="#{@vboxcmd} setextradata global '#{data[0]}' '#{data[1]}'"
+ command="#{@vboxcmd} setextradata global \"#{data[0]}\" \"#{data[1]}\""
shell_results=shell_exec("#{command}")
end
@@ -67,7 +74,7 @@ def create_disk
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}"
+ command ="#{@vboxcmd} createhd --filename \"#{File.join(place,name,name+"."+definition.disk_format.downcase)}\" --size \"#{definition.disk_size.to_i}\" --format #{definition.disk_format.downcase}"
shell_exec("#{command}")
end
@@ -80,8 +87,8 @@ def attach_disk
location="#{File.join(place,name,location)}"
env.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 'SATA Controller' --port 0 --device 0 --type hdd --medium '#{location}'"
+ #command => "${vboxcmd} storageattach \"${vname}\" --storagectl \"SATA Controller\" --port 0 --device 0 --type hdd --medium \"${vname}.vdi\"",
+ command ="#{@vboxcmd} storageattach \"#{name}\" --storagectl \"SATA Controller\" --port 0 --device 0 --type hdd --medium \"#{location}\""
shell_exec("#{command}")
end
@@ -90,14 +97,14 @@ def attach_disk
def attach_isofile
full_iso_file=File.join(env.config.veewee.iso_dir,definition.iso_file)
env.ui.info "Mounting cdrom: #{full_iso_file}"
- command ="#{@vboxcmd} storageattach '#{name}' --storagectl 'IDE Controller' --type dvddrive --port 0 --device 0 --medium '#{full_iso_file}'"
+ command ="#{@vboxcmd} storageattach \"#{name}\" --storagectl \"IDE Controller\" --type dvddrive --port 0 --device 0 --medium \"#{full_iso_file}\""
shell_exec("#{command}")
end
def attach_guest_additions
full_iso_file=File.join(env.config.veewee.iso_dir,"VBoxGuestAdditions_#{self.vbox_version}.iso")
env.ui.info "Mounting guest additions: #{full_iso_file}"
- command ="#{@vboxcmd} storageattach '#{name}' --storagectl 'IDE Controller' --type dvddrive --port 1 --device 0 --medium '#{full_iso_file}'"
+ command ="#{@vboxcmd} storageattach \"#{name}\" --storagectl \"IDE Controller\" --type dvddrive --port 1 --device 0 --medium \"#{full_iso_file}\""
shell_exec("#{command}")
end
@@ -106,7 +113,7 @@ def add_floppy_controller
# Create floppy controller
unless definition.floppy_files.nil?
- command="#{@vboxcmd} storagectl '#{name}' --name 'Floppy Controller' --add floppy"
+ command="#{@vboxcmd} storagectl \"#{name}\" --name \"Floppy Controller\" --add floppy"
shell_exec("#{command}")
end
end
@@ -117,7 +124,7 @@ def attach_floppy
# Attach floppy to machine (the vfd extension is crucial to detect msdos type floppy)
floppy_file=File.join(definition.path,"virtualfloppy.vfd")
- command="#{@vboxcmd} storageattach '#{name}' --storagectl 'Floppy Controller' --port 0 --device 0 --type fdd --medium '#{floppy_file}'"
+ command="#{@vboxcmd} storageattach \"#{name}\" --storagectl \"Floppy Controller\" --port 0 --device 0 --type fdd --medium \"#{floppy_file}\""
shell_exec("#{command}")
end
end
@@ -129,7 +136,7 @@ def vbox_os_type_id(veewee_type_id)
end
def create_vm
- command="#{@vboxcmd} createvm --name '#{name}' --ostype '#{vbox_os_type_id(definition.os_type_id)}' --register"
+ command="#{@vboxcmd} createvm --name \"#{name}\" --ostype \"#{vbox_os_type_id(definition.os_type_id)}\" --register"
#Exec and system stop the execution here
shell_exec("#{command}")
@@ -137,15 +144,15 @@ def create_vm
env.ui.info "Creating vm #{name} : #{definition.memory_size}M - #{definition.cpu_count} CPU - #{vbox_os_type_id(definition.os_type_id)}"
#setting cpu's
- command="#{@vboxcmd} modifyvm '#{name}' --cpus #{definition.cpu_count}"
+ command="#{@vboxcmd} modifyvm \"#{name}\" --cpus #{definition.cpu_count}"
shell_exec("#{command}")
#setting memory size
- command="#{@vboxcmd} modifyvm '#{name}' --memory #{definition.memory_size}"
+ command="#{@vboxcmd} modifyvm \"#{name}\" --memory #{definition.memory_size}"
shell_exec("#{command}")
#setting bootorder
- command="#{@vboxcmd} modifyvm '#{name}' --boot1 disk --boot2 dvd --boot3 none --boot4 none"
+ command="#{@vboxcmd} modifyvm \"#{name}\" --boot1 disk --boot2 dvd --boot3 none --boot4 none"
shell_exec("#{command}")
# Modify the vm to enable or disable hw virtualization extensions
View
4 lib/veewee/provider/virtualbox/box/helper/forwarding.rb
@@ -4,7 +4,7 @@ module Virtualbox
module BoxCommand
def forwarding(name)
- command="#{@vboxcmd} showvminfo --details --machinereadable '#{self.name}'"
+ command="#{@vboxcmd} showvminfo --details --machinereadable \"#{self.name}\""
shell_results=shell_exec("#{command}")
rules=shell_results.stdout.split(/\n/).grep(/^Forward/)
result=nil
@@ -28,7 +28,7 @@ def forwarding(name)
def delete_forwarding(name)
forward=self.forwarding(name)
- command="#{@vboxcmd} controlvm '#{self.name}' natpf#{forward[:nr]} delete #{name}"
+ command="#{@vboxcmd} controlvm \"#{self.name}\" natpf#{forward[:nr]} delete #{name}"
shell_results=shell_exec("#{command}")
end
View
2  lib/veewee/provider/virtualbox/box/poweroff.rb
@@ -8,7 +8,7 @@ def poweroff(options={})
if (self.exists? && self.running?)
env.ui.info "Shutting down vm #{name}"
#We force it here, maybe vm.shutdown is cleaner
- command="#{@vboxcmd} controlvm '#{name}' poweroff"
+ command="#{@vboxcmd} controlvm \"#{name}\" poweroff"
shell_exec("#{command}")
end
end
View
6 lib/veewee/provider/virtualbox/box/up.rb
@@ -4,7 +4,7 @@ module Virtualbox
module BoxCommand
def up(options={})
- gui_enabled=options[:nogui]==true ? false : true
+ gui_enabled=options['nogui']==true ? false : true
raise Veewee::Error,"Box is already running" if self.running?
@@ -29,9 +29,9 @@ def up(options={})
# Once assembled we start the machine
env.logger.info "Started the VM with GUI Enabled? #{gui_enabled}"
- command="#{@vboxcmd} startvm --type gui '#{name}'"
+ command="#{@vboxcmd} startvm --type gui \"#{name}\""
unless (gui_enabled)
- command="#{@vboxcmd} startvm --type headless '#{name}'"
+ command="#{@vboxcmd} startvm --type headless \"#{name}\""
end
shell_results=shell_exec("#{command}",{:mute => true})
end
View
6 lib/veewee/ui.rb
@@ -2,7 +2,7 @@ module Veewee
# Vagrant UIs handle communication with the outside world (typically
# through a shell). They must respond to the typically logger methods
- # of `warn`, `error`, `info`, and `confirm`.
+ # of `warn`, `error`, `info`, and `success`.
class UI
attr_accessor :env
@@ -10,7 +10,7 @@ def initialize(env)
@env = env
end
- [:warn, :error, :info, :confirm].each do |method|
+ [:warn, :error, :info, :success].each do |method|
define_method(method) do |message, *argv|
opts , *argv = argv
opts ||= {}
@@ -33,7 +33,7 @@ def initialize(env, shell)
@shell = shell
end
- [[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
+ [[:warn, :yellow], [:error, :red], [:info, nil], [:success, :green]].each do |method, color|
class_eval <<-CODE
def #{method}(message, opts=nil)
super(message)
View
5 veewee.gemspec
@@ -27,7 +27,10 @@ Gem::Specification.new do |s|
s.add_dependency "fog", "~> 1.1.2"
s.add_dependency "childprocess"
- s.add_dependency "CFPropertyList", "~> 2.0.17"
+ # Modified dependency version, as libxml-ruby dependency has been removed in version 2.1.1
+ # See : https://github.com/ckruse/CFPropertyList/issues/14
+ # See : https://github.com/jedi4ever/veewee/issues/6
+ s.add_dependency "CFPropertyList", ">= 2.1.1"
# s.add_dependency "libvirt"
s.add_dependency "rspec", "~> 2.5"
Please sign in to comment.
Something went wrong with that request. Please try again.