Skip to content

Commit

Permalink
merging jedi4ever veewee/master
Browse files Browse the repository at this point in the history
  • Loading branch information
hh committed Oct 29, 2012
2 parents 61945d4 + 546abda commit 88d83ed
Show file tree
Hide file tree
Showing 474 changed files with 9,524 additions and 2,684 deletions.
5 changes: 2 additions & 3 deletions .rvmrc
@@ -1,6 +1,5 @@
rvm use ruby-1.9.2
rvm gemset create veewee
rvm gemset use veewee
rvm use ruby-1.9.2@veewee --create

alias veewee="bundle exec veewee"
alias vagrant="bundle exec vagrant"
alias irb="bundle exec irb"
6 changes: 6 additions & 0 deletions Gemfile
@@ -1,6 +1,12 @@
#if RUBY_VERSION =~ /1.9/
#Encoding.default_external = Encoding::UTF_8
#Encoding.default_internal = Encoding::UTF_8
#end

source "http://rubygems.org"

#gem "veewee", :path => "."
#gem "fission", :path => '/Users/patrick/dev/fission'

group :test do
gem "rake"
Expand Down
202 changes: 22 additions & 180 deletions README.md
@@ -1,195 +1,37 @@
# This is a branch that allows windows VM's to be used via winrm and not relying on ssh.
**VeeWee:** the tool to easily build vagrant base boxes or kvm,virtualbox and fusion images

-------
Vagrant is a great tool to test new things or changes in a virtual machine(Virtualbox) using either chef or puppet.
The first step is to download an existing 'base box'. I believe this scares a lot of people as they don't know who or how this box was build. Therefore lots of people end up first building their own base box to use with vagrant.

Besides building Vagrant boxes, veewee can also be used for:

- veewee vbox define windows-7-enterprise-amd64-winrm windows-7-enterprise-amd64-winrm
- veewee vbox build windows-7-enterprise-amd64-winrm
- veewee vbox winrm windows-7-enterprise-amd64-winrm 'hostname'
- veewee vbox copy windows-7-enterprise-amd64-winrm sourcefile.txt destfileinVM.txt
- veewee vbox copy windows-7-enterprise-amd64-winrm sourcefile.txt destfileinVM.txt
- vagrant basebox export windows-7-enterprise-amd64-winrm
- vagrant box add 'windows-7-enterprise-amd64-winrm' 'windows-7-enterprise-amd64-winrm.box'
- vagrant init windows-7-enterprise-amd64-winrm
- create vmware (fusion), kvm virtual machines
- interact with with those vms (up, destroy, halt, ssh)
- export them : OVA for fusion, IMG for KVM and ovf for virtualbox

```
$ veewee vbox define windows-7-enterprise-amd64-winrm windows-7-enterprise-amd64-winrm
Before you start read through:

The basebox 'windows-7-enterprise-amd64-winrm' has been succesfully created from the template 'windows-7-enterprise-amd64-winrm'
You can now edit the definition files stored in definitions/windows-7-enterprise-amd64-winrm or build the box with:
veewee vbox build 'windows-7-enterprise-amd64-winrm'
```
- the [requirements](https://github.com/jedi4ever/veewee/tree/master/doc/requirements.md)
- the [installation](https://github.com/jedi4ever/veewee/tree/master/doc/installation.md) procedure

```
$ veewee vbox build windows-7-enterprise-amd64-winrm --force
Downloading vbox guest additions iso v 4.1.12 - http://download.virtualbox.org/virtualbox/4.1.12/VBoxGuestAdditions_4.1.12.iso
Checking if isofile VBoxGuestAdditions_4.1.12.iso already exists.
Full path: /home/hh/chef/veewee/iso/VBoxGuestAdditions_4.1.12.iso
Depending on how you want to use veewee, read through one of the following guides: (**work in progres**)

The isofile VBoxGuestAdditions_4.1.12.iso already exists.
Building Box windows-7-enterprise-amd64-winrm with Definition windows-7-enterprise-amd64-winrm:
- postinstall_include : []
- postinstall_exclude : []
- force : true
- [guide for vagrant](https://github.com/jedi4ever/veewee/tree/master/doc/vagrant.md)

The isofile 7600.16385.090713-1255_x64fre_enterprise_en-us_EVAL_Eval_Enterprise-GRMCENXEVAL_EN_DVD.iso already exists.
VBoxManage unregistervm 'windows-7-enterprise-amd64-winrm' --delete
Deleting vm windows-7-enterprise-amd64-winrm
Creating vm windows-7-enterprise-amd64-winrm : 512M - 1 CPU - Windows7_64
Creating new harddrive of size 20280
Mounting cdrom: /home/hh/chef/veewee/iso/7600.16385.090713-1255_x64fre_enterprise_en-us_EVAL_Eval_Enterprise-GRMCENXEVAL_EN_DVD.iso
Mounting guest additions: /home/hh/chef/veewee/iso/VBoxGuestAdditions_4.1.12.iso
Attaching disk: /home/hh/VirtualBox VMs/windows-7-enterprise-amd64-winrm/windows-7-enterprise-amd64-winrm.vdi
Using winrm because winrm_user and winrm_password are both set
Received port hint - 5985
Found port 5985 available
Received port hint - 5985
Found port 5985 available
Waiting 0 seconds for the machine to boot
- [guide for Virtualbox](https://github.com/jedi4ever/veewee/tree/master/doc/vbox.md)
- [guide for Vmware fusion](https://github.com/jedi4ever/veewee/tree/master/doc/fusion.md)
- [guide for KVM](https://github.com/jedi4ever/veewee/tree/master/doc/kvm.md)

Done typing.
You can also look at the more detailed pages on each subject in the [documentation directory](https://github.com/jedi4ever/veewee/tree/master/doc)

Skipping webserver as no kickstartfile was specified
Received port hint - 7000
Found port 7000 available
Waiting for winrm login on 127.0.0.1 with user vagrant to windows on port => 5986 to work, timeout=10000 sec
........................
Executing winrm command: cmd.exe /C dir %TEMP%\\wget.vbs > %TEMP%\null
File Not Found
Creating wget.vbs
Executing winrm command: cmd.exe /C echo "Rendering '%TEMP%\\wget.vbs' chunk 1" && >> %TEMP%\\wget.vbs (echo.url = WScript.Arguments.Named^("url"^)) && >> %TEMP%\\wget.vbs (echo.path = WScript.Arguments.Named^("path"^)) && >> %TEMP%\\wget.vbs (echo.Set objXMLHTTP = CreateObject^("MSXML2.ServerXMLHTTP"^)) && >> %TEMP%\\wget.vbs (echo.Set wshShell = CreateObject^( "WScript.Shell" ^)) && >> %TEMP%\\wget.vbs (echo.Set objUserVariables = wshShell.Environment^("USER"^)) && >> %TEMP%\\wget.vbs (echo.) && >> %TEMP%\\wget.vbs (echo.'http proxy is optional) && >> %TEMP%\\wget.vbs (echo.'attempt to read from HTTP_PROXY env var first) && >> %TEMP%\\wget.vbs (echo.On Error Resume Next) && >> %TEMP%\\wget.vbs (echo.) && >> %TEMP%\\wget.vbs (echo.If NOT ^(objUserVariables^("HTTP_PROXY"^) = ""^) Then) && >> %TEMP%\\wget.vbs (echo.objXMLHTTP.setProxy 2, objUserVariables^("HTTP_PROXY"^)) && >> %TEMP%\\wget.vbs (echo.) && >> %TEMP%\\wget.vbs (echo.'fall back to named arg) && >> %TEMP%\\wget.vbs (echo.ElseIf NOT ^(WScript.Arguments.Named^("proxy"^) = ""^) Then) && >> %TEMP%\\wget.vbs (echo.objXMLHTTP.setProxy 2, WScript.Arguments.Named^("proxy"^)) && >> %TEMP%\\wget.vbs (echo.End If) && >> %TEMP%\\wget.vbs (echo.) && >> %TEMP%\\wget.vbs (echo.On Error Goto 0) && >> %TEMP%\\wget.vbs (echo.) && >> %TEMP%\\wget.vbs (echo.objXMLHTTP.open "GET", url, false) && >> %TEMP%\\wget.vbs (echo.objXMLHTTP.send^(^)) && >> %TEMP%\\wget.vbs (echo.If objXMLHTTP.Status = 200 Then) && >> %TEMP%\\wget.vbs (echo.Set objADOStream = CreateObject^("ADODB.Stream"^)) && >> %TEMP%\\wget.vbs (echo.objADOStream.Open) && >> %TEMP%\\wget.vbs (echo.objADOStream.Type = 1) && >> %TEMP%\\wget.vbs (echo.objADOStream.Write objXMLHTTP.ResponseBody) && >> %TEMP%\\wget.vbs (echo.objADOStream.Position = 0) && >> %TEMP%\\wget.vbs (echo.Set objFSO = Createobject^("Scripting.FileSystemObject"^)) && >> %TEMP%\\wget.vbs (echo.If objFSO.Fileexists^(path^) Then objFSO.DeleteFile path) && >> %TEMP%\\wget.vbs (echo.Set objFSO = Nothing) && >> %TEMP%\\wget.vbs (echo.objADOStream.SaveToFile path) && >> %TEMP%\\wget.vbs (echo.objADOStream.Close)
"Rendering 'C:\Users\vagrant\AppData\Local\Temp\\wget.vbs' chunk 1"
Executing winrm command: cmd.exe /C echo "Rendering '%TEMP%\\wget.vbs' chunk 2" && >> %TEMP%\\wget.vbs (echo.Set objADOStream = Nothing) && >> %TEMP%\\wget.vbs (echo.End if) && >> %TEMP%\\wget.vbs (echo.Set objXMLHTTP = Nothing)
"Rendering 'C:\Users\vagrant\AppData\Local\Temp\\wget.vbs' chunk 2"
Spinning up a wait_for_http_request on http://10.0.2.2:7000//tmp/.veewee_version20121022-9183-15gv13c
Going to try and copy /tmp/.veewee_version20121022-9183-15gv13c to ".veewee_version"
Executing winrm command: cmd.exe /C cscript %TEMP%\wget.vbs /url:http://10.0.2.2:7000/tmp/.veewee_version20121022-9183-15gv13c /path:.veewee_version
Serving file /tmp/.veewee_version20121022-9183-15gv13c
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
People have reported good experiences, why don't you give it a try?

Received port hint - 7000
Found port 7001 available
Changing wincp port from 7000 to 7001
Executing winrm command: cmd.exe /C dir %TEMP%\\wget.vbs > %TEMP%\null
Spinning up a wait_for_http_request on http://10.0.2.2:7001//tmp/.vbox_version20121022-9183-1guel7e
Going to try and copy /tmp/.vbox_version20121022-9183-1guel7e to ".vbox_version"
Executing winrm command: cmd.exe /C cscript %TEMP%\wget.vbs /url:http://10.0.2.2:7001/tmp/.vbox_version20121022-9183-1guel7e /path:.vbox_version
Serving file /tmp/.vbox_version20121022-9183-1guel7e
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
## If you have a setup working, share your 'definition' with me. That would be fun!

Received port hint - 7001
Found port 7002 available
Changing wincp port from 7001 to 7002
Executing winrm command: cmd.exe /C dir %TEMP%\\wget.vbs > %TEMP%\null
Spinning up a wait_for_http_request on http://10.0.2.2:7002//home/hh/chef/veewee/definitions/windows-7-enterprise-amd64-winrm/install-chef.bat
Going to try and copy /home/hh/chef/veewee/definitions/windows-7-enterprise-amd64-winrm/install-chef.bat to "install-chef.bat"
Executing winrm command: cmd.exe /C cscript %TEMP%\wget.vbs /url:http://10.0.2.2:7002/home/hh/chef/veewee/definitions/windows-7-enterprise-amd64-winrm/install-chef.bat /path:install-chef.bat
Serving file /home/hh/chef/veewee/definitions/windows-7-enterprise-amd64-winrm/install-chef.bat
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
IDEAS:

Executing winrm command: install-chef.bat
- Now you integrate this with your CI build to create a daily basebox

C:\Users\vagrant>cmd /C cscript C:\Users\vagrant\AppData\Local\Temp\wget.vbs /url:http://www.opscode.com/chef/install.msi /path:C:\Users\vagrant\AppData\Local\Temp\chef-client.msi
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
[whren - 2012/04/12]

C:\Users\vagrant>cmd /C msiexec /qn /i C:\Users\vagrant\AppData\Local\Temp\chef-client.msi
The box windows-7-enterprise-amd64-winrm was build succesfully!
You can now login to the box with:
knife winrm -m 127.0.0.1 -P 5986 -x vagrant -P vagrant COMMAND
```

```
$ veewee vbox winrm windows-7-enterprise-amd64-winrm hostname
Executing winrm command: hostname
vagrant-win7ent
```

```
$ veewee vbox winrm windows-7-enterprise-amd64-winrm 'dir %TEMP%'
Executing winrm command: dir %TEMP%
Volume in drive C is Windows 7 Enterprise
Volume Serial Number is 58F7-01E9
Directory of C:\Users\vagrant\AppData\Local\Temp
10/22/2012 11:26 PM <DIR> .
10/22/2012 11:26 PM <DIR> ..
10/22/2012 11:26 PM 63,636,395 chef-client.msi
10/22/2012 11:25 PM 0 FXSAPIDebugLogFile.txt
10/22/2012 11:24 PM <DIR> Low
10/22/2012 11:25 PM 283 null
10/22/2012 11:24 PM 49,208 vagrant.bmp
10/22/2012 11:24 PM 1,105 wget.vbs
10/22/2012 11:25 PM 843 wmsetup.log
10/22/2012 11:25 PM <DIR> WPDNSE
6 File(s) 63,687,834 bytes
4 Dir(s) 1,431,273,472 bytes free
```

```
$ veewee vbox winrm windows-7-enterprise-amd64-winrm 'dir'
Executing winrm command: dir
Volume in drive C is Windows 7 Enterprise
Volume Serial Number is 58F7-01E9
Directory of C:\Users\vagrant
10/22/2012 11:25 PM <DIR> .
10/22/2012 11:25 PM <DIR> ..
10/22/2012 11:25 PM 7 .vbox_version
10/22/2012 11:24 PM 13 .veewee_version
10/22/2012 11:25 PM <DIR> Contacts
10/22/2012 11:25 PM <DIR> Desktop
10/22/2012 11:25 PM <DIR> Documents
10/22/2012 11:25 PM <DIR> Downloads
10/22/2012 11:25 PM <DIR> Favorites
10/22/2012 11:25 PM 150 install-chef.bat
10/22/2012 11:25 PM <DIR> Links
10/22/2012 11:25 PM <DIR> Music
10/22/2012 11:25 PM <DIR> Pictures
10/22/2012 11:25 PM <DIR> Saved Games
10/22/2012 11:25 PM <DIR> Searches
10/22/2012 11:25 PM <DIR> Videos
3 File(s) 170 bytes
13 Dir(s) 1,431,273,472 bytes free
```

```
$ vagrant basebox export windows-7-enterprise-amd64-winrm --force
[vagrant] Vagrant requires the box to be shutdown, before it can export
[vagrant] Sudo also needs to work for user
[vagrant] Performing a clean shutdown now.
[vagrant] Waiting for winrm login on 127.0.0.1 with user vagrant to windows on port => 5986 to work, timeout=10000 sec
[vagrant] .[vagrant]
[vagrant] Executing winrm command: shutdown /s /t 10 /c "Vagrant Shutdown" /f /d p:4:1
[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant] .[vagrant]
[vagrant] Machine windows-7-enterprise-amd64-winrm is powered off cleanly
[vagrant] Excuting vagrant voodoo:
[vagrant] vagrant package --base 'windows-7-enterprise-amd64-winrm' --output 'windows-7-enterprise-amd64-winrm.box'
[vagrant]
[vagrant] To import it into vagrant type:
[vagrant] vagrant box add 'windows-7-enterprise-amd64-winrm' 'windows-7-enterprise-amd64-winrm.box'
[vagrant]
[vagrant] To use it:
[vagrant] vagrant init 'windows-7-enterprise-amd64-winrm'
[vagrant] vagrant up
[vagrant] vagrant ssh
```

Now you could make windows-7-enterprise-amd64-winrm.box via an internal url and use in a Vagrantfile or

```
$ vagrant box add 'windows-7-enterprise-amd64-winrm' 'windows-7-enterprise-amd64-winrm.box
[vagrant] Downloading with Vagrant::Downloaders::File...
[vagrant] Copying box to temporary location...
[vagrant] Extracting box...
[vagrant] Verifying box...
[vagrant] Cleaning up downloaded box...
```

Obviously we have a bit of work to do to get vagrant working with winrm, but at least now we can contruct windows base boxes from scratch.
See [use of pre_postinstall_file in defition.rb](https://github.com/whren/veewee/wiki/Use-of-pre_postinstall_file-in-definition.rb)
81 changes: 70 additions & 11 deletions Rakefile
Expand Up @@ -25,7 +25,7 @@ Rake::TestTask.new do |t|
end

desc 'Verify ISO'
task :iso, [:box_name] do |t,args|
task :iso, [:template_name] do |t,args|
require 'net/http'
#if args.to_hash.size!=1
#puts "needs one arguments: rake iso [\"yourname\"]"
Expand All @@ -42,24 +42,83 @@ task :iso, [:box_name] do |t,args|
response = nil
while found==false
uri=URI.parse(url)
Net::HTTP.start(uri.host,uri.port) {|http|
response = http.head(uri.path)
}
unless response['location'].nil?
#puts "Redirecting to "+response['location']
url=response['location']
else
found=true
if uri.is_a?(URI::HTTP)
Net::HTTP.start(uri.host,uri.port) {|http|
response = http.head(uri.path)
}
unless response['location'].nil?
#puts "Redirecting to "+response['location']
url=response['location']
else
length=response['content-length']
found=true
end
elsif uri.is_a?(URI::FTP)
require 'net/ftp'
ftp = Net::FTP.new(uri.host)
ftp.login
begin
length = ftp.size(uri.path)
found = true
rescue Net::FTPReplyError => e
reply = e.message
err_code = reply[0,3].to_i
unless err_code == 500 || err_code == 502
# other problem, raise
raise "Got ftp site but doesn't support size subcommand"
end
# fallback solution
end

end
end
length=response['content-length']
if length.to_i < 10000
puts definition.iso_src
p response['content-type']
puts "Incorrect length #{length.to_i}"
puts uri.host,uri.port, uri.path,response.code
end
rescue Exception => ex
puts "Error"+ex.to_s+definition.iso_src
end
end
end

desc 'Autobuilds all templates and runs validation.'
task :autotest, [:pattern] do |t,args|

# We overrule all timeouts for tcp and ssh
#ENV['VEEWEE_TIMEOUT']='600'

ve=Veewee::Environment.new()
ve.templates.each do |name,template|

# If pattern was given, only take the ones that match the pattern
unless args[:pattern].nil?
next unless name.match(args[:pattern])
end

begin
ve.definitions.define("auto",name, { 'force' => true})
vd=ve.definitions["auto"]
box=ve.providers["virtualbox"].get_box("auto")
puts "AUTO: Building #{name}"
box.build({"auto" => true,"force" => true, 'nogui' => true })
puts "AUTO: Validating #{name}"
box.validate_vagrant
puts "AUTO: Success #{name}"
box.destroy
rescue Exception => ex
puts "AUTO: Template #{name} failed - #{ex}"
if box.running?
begin
screenshot="screenshot-auto-#{name}.png"
puts "AUTO: Taking snapshot #{screenshot}"
box.screenshot(screenshot)
rescue Veewee::Error => ex
puts "AUTO: Error taking screenshot"
end
end
end

end
end
7 changes: 6 additions & 1 deletion bin/veewee
@@ -1,4 +1,9 @@
#!/usr/bin/env ruby
begin
require 'rubygems'
rescue LoadError
end

require 'veewee'

env = Veewee::Environment.new
Expand All @@ -18,5 +23,5 @@ begin
::Veewee::CLI.start(ARGV,:env => env)

rescue Veewee::Error => e
puts "#{e}"
env.ui.error "#{e}"
end
3 changes: 2 additions & 1 deletion 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
Expand All @@ -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
2 changes: 1 addition & 1 deletion doc/TODO
Expand Up @@ -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

0 comments on commit 88d83ed

Please sign in to comment.