Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'upstream/master' into remote-postinstal…

…l-basedir
  • Loading branch information...
commit 001c0e67c99b9d63c2dc77458650e87dc7999e0c 2 parents e3a011b + b047eaf
@konstan authored
Showing with 952 additions and 1,362 deletions.
  1. +1 −0  Gemfile
  2. +5 −0 bin/veewee
  3. +8 −1 doc/definition.md
  4. +3 −5 lib/fission.rb
  5. +0 −76 lib/fission/cli.rb
  6. +0 −15 lib/fission/command.rb
  7. +0 −68 lib/fission/command/clone.rb
  8. +0 −71 lib/fission/command/delete.rb
  9. +0 −52 lib/fission/command/snapshot_create.rb
  10. +0 −45 lib/fission/command/snapshot_list.rb
  11. +0 −54 lib/fission/command/snapshot_revert.rb
  12. +0 −69 lib/fission/command/start.rb
  13. +0 −31 lib/fission/command/status.rb
  14. +0 −49 lib/fission/command/stop.rb
  15. +0 −67 lib/fission/command/suspend.rb
  16. +52 −5 lib/fission/config.rb
  17. +0 −5 lib/fission/core_ext/class.rb
  18. +0 −7 lib/fission/core_ext/file.rb
  19. +0 −112 lib/fission/core_ext/object.rb
  20. +0 −9 lib/fission/error.rb
  21. +0 −17 lib/fission/fusion.rb
  22. +0 −74 lib/fission/leasesfile.rb
  23. +0 −39 lib/fission/metadata.rb
  24. +0 −16 lib/fission/response.rb
  25. +0 −22 lib/fission/ui.rb
  26. +0 −3  lib/fission/version.rb
  27. +0 −365 lib/fission/vm.rb
  28. +1 −1  lib/veewee/cli.rb
  29. +2 −2 lib/veewee/command.rb
  30. +1 −1  lib/veewee/command/base.rb
  31. +1 −1  lib/veewee/command/{vmfusion.rb → fusion.rb}
  32. +2 −1  lib/veewee/command/group_base.rb
  33. +1 −0  lib/veewee/command/kvm.rb
  34. +1 −1  lib/veewee/command/{virtualbox.rb → vbox.rb}
  35. +29 −10 lib/veewee/definitions.rb
  36. +8 −0 lib/veewee/environment.rb
  37. +2 −2 lib/veewee/provider/core/box/build.rb
  38. +2 −2 lib/veewee/provider/core/box/floppy.rb
  39. +1 −1  lib/veewee/provider/core/box/scp.rb
  40. +9 −4 lib/veewee/provider/core/helper/web.rb
  41. +3 −2 lib/veewee/provider/kvm/box/create.rb
  42. +3 −3 lib/veewee/provider/kvm/box/helper/console_type.rb
  43. +1 −1  lib/veewee/provider/kvm/box/helper/ip.rb
  44. +2 −2 lib/veewee/provider/kvm/box/helper/status.rb
  45. +1 −1  lib/veewee/provider/kvm/provider.rb
  46. +3 −11 lib/veewee/provider/vmfusion/box.rb
  47. +1 −1  lib/veewee/provider/vmfusion/box/create.rb
  48. +1 −1  lib/veewee/provider/vmfusion/box/destroy.rb
  49. +1 −1  lib/veewee/provider/vmfusion/box/export_ova.rb
  50. +16 −8 lib/veewee/provider/vmfusion/box/helper/buildinfo.rb
  51. +48 −3 lib/veewee/provider/vmfusion/box/helper/ip.rb
  52. +2 −2 lib/veewee/provider/vmfusion/box/helper/vnc.rb
  53. +15 −2 lib/veewee/provider/vmfusion/provider.rb
  54. +1 −2  lib/veewee/templates.rb
  55. +1 −1  lib/veewee/version.rb
  56. +1 −1  templates/CentOS-6.2-i386-minimal/definition.rb
  57. +1 −1  templates/CentOS-6.2-x86_64-minimal/definition.rb
  58. +1 −1  templates/CentOS-6.2-x86_64-netboot/definition.rb
  59. +14 −0 templates/CentOS-6.3-i386-minimal/base.sh
  60. +3 −0  templates/CentOS-6.3-i386-minimal/chef.sh
  61. +5 −0 templates/CentOS-6.3-i386-minimal/cleanup.sh
  62. +39 −0 templates/CentOS-6.3-i386-minimal/definition.rb
  63. +42 −0 templates/CentOS-6.3-i386-minimal/ks.cfg
  64. +12 −0 templates/CentOS-6.3-i386-minimal/puppet.sh
  65. +3 −0  templates/CentOS-6.3-i386-minimal/ruby.sh
  66. +17 −0 templates/CentOS-6.3-i386-minimal/vagrant.sh
  67. +8 −0 templates/CentOS-6.3-i386-minimal/virtualbox.sh
  68. +14 −0 templates/CentOS-6.3-x86_64-minimal/base.sh
  69. +3 −0  templates/CentOS-6.3-x86_64-minimal/chef.sh
  70. +5 −0 templates/CentOS-6.3-x86_64-minimal/cleanup.sh
  71. +39 −0 templates/CentOS-6.3-x86_64-minimal/definition.rb
  72. +42 −0 templates/CentOS-6.3-x86_64-minimal/ks.cfg
  73. +12 −0 templates/CentOS-6.3-x86_64-minimal/puppet.sh
  74. +3 −0  templates/CentOS-6.3-x86_64-minimal/ruby.sh
  75. +17 −0 templates/CentOS-6.3-x86_64-minimal/vagrant.sh
  76. +8 −0 templates/CentOS-6.3-x86_64-minimal/virtualbox.sh
  77. +29 −0 templates/Fedora-16-x86_64-netboot/definition.rb
  78. +70 −0 templates/Fedora-16-x86_64-netboot/ks.cfg
  79. +26 −0 templates/Fedora-16-x86_64-netboot/postinstall.sh
  80. +1 −1  templates/gentoo-latest-x86_64-experimental/definition.rb
  81. +1 −0  templates/scientificlinux-6.2-i386-netboot/base.sh
  82. +1 −0  templates/scientificlinux-6.2-i386-netboot/chef.sh
  83. +4 −0 templates/scientificlinux-6.2-i386-netboot/cleanup.sh
  84. +36 −0 templates/scientificlinux-6.2-i386-netboot/definition.rb
  85. +53 −0 templates/scientificlinux-6.2-i386-netboot/ks.cfg
  86. +30 −0 templates/scientificlinux-6.2-i386-netboot/postinstall.sh
  87. +1 −0  templates/scientificlinux-6.2-i386-netboot/puppet.sh
  88. +8 −0 templates/scientificlinux-6.2-i386-netboot/vagrant.sh
  89. +8 −0 templates/scientificlinux-6.2-i386-netboot/virtualbox.sh
  90. +1 −0  templates/scientificlinux-6.2-x86_64-netboot/base.sh
  91. +1 −0  templates/scientificlinux-6.2-x86_64-netboot/chef.sh
  92. +4 −0 templates/scientificlinux-6.2-x86_64-netboot/cleanup.sh
  93. +36 −0 templates/scientificlinux-6.2-x86_64-netboot/definition.rb
  94. +53 −0 templates/scientificlinux-6.2-x86_64-netboot/ks.cfg
  95. +30 −0 templates/scientificlinux-6.2-x86_64-netboot/postinstall.sh
  96. +1 −0  templates/scientificlinux-6.2-x86_64-netboot/puppet.sh
  97. +8 −0 templates/scientificlinux-6.2-x86_64-netboot/vagrant.sh
  98. +8 −0 templates/scientificlinux-6.2-x86_64-netboot/virtualbox.sh
  99. +9 −0 templates/ubuntu-10.04.4-server-amd64/postinstall.sh
  100. +1 −1  templates/ubuntu-12.04-server-amd64-packages/definition.rb
  101. +1 −1  templates/ubuntu-12.04-server-amd64/definition.rb
  102. +1 −1  templates/ubuntu-12.04-server-i386-packages/definition.rb
  103. +1 −1  templates/ubuntu-12.04-server-i386/definition.rb
  104. +8 −8 templates/windows-7-enterprise-amd64/Autounattend.xml
  105. +4 −2 veewee.gemspec
View
1  Gemfile
@@ -6,6 +6,7 @@
source "http://rubygems.org"
#gem "veewee", :path => "."
+#gem "fission", :path => '/Users/patrick/dev/fission'
group :test do
gem "rake"
View
5 bin/veewee
@@ -1,4 +1,9 @@
#!/usr/bin/env ruby
+begin
+ require 'rubygems'
+rescue LoadError
+end
+
require 'veewee'
env = Veewee::Environment.new
View
9 doc/definition.md
@@ -1,12 +1,16 @@
# Veewee definition
## Creating a definition
-A definition is create be 'cloning' a *template*.
+A definition is created by 'cloning' a *template*.
To create a definition you use the 'define' subcommand:
veewee vbox define 'myubuntu' 'ubuntu-10.10-server-amd64'
+If you want to use an external repo for the definition you can specify a git-url
+
+ veewee vbox define 'myubuntu' 'git://github.com/jedi4ever/myubuntu'
+
## Modifying a definition
Definitions are stored under a directory 'definitions' relative to the current directory.
@@ -48,6 +52,9 @@ The 'Veewee::Session.declare' is now deprecated and you should use 'Veewee::Defi
The default user of definitions is now 'veewee' and not 'vagrant'. This is because on other virtualizations like fusion and kvm, there is not relationship with the 'vagrant'. Users 'vagrant' are created by the 'vagrant.sh' script and not by the preseed or kickstart.
+_Using ERB in files_
+
+Add '.erb' to your files in a definition and they will get rendered (useful for generting kickstart,postinstall) (thx @mconigilaro)
## Listing existing definitions
View
8 lib/fission.rb
@@ -5,9 +5,10 @@
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
-require 'fission/error'
+#require 'fission/error'
require 'fission/cli'
require 'fission/command'
+require 'fission/command_helpers'
require 'fission/command/clone'
require 'fission/command/snapshot_create'
require 'fission/command/snapshot_list'
@@ -16,12 +17,12 @@
require 'fission/command/status'
require 'fission/command/stop'
require 'fission/command/suspend'
-require 'fission/command/delete'
require 'fission/config'
require 'fission/core_ext/class'
require 'fission/core_ext/file'
require 'fission/core_ext/object'
require 'fission/fusion'
+require 'fission/lease'
require 'fission/metadata'
require 'fission/response'
require 'fission/ui'
@@ -35,7 +36,4 @@ def config
@config ||= Fission::Config.new
end
- def ui
- @ui ||= Fission::UI.new
- end
end
View
76 lib/fission/cli.rb
@@ -1,76 +0,0 @@
-module Fission
- class CLI
- def self.execute(args=ARGV)
- optparse = OptionParser.new do |opts|
- opts.banner = "\nUsage: fission [options] COMMAND [arguments]"
-
- opts.on_head('-v', '--version', 'Output the version of fission') do
- Fission.ui.output Fission::VERSION
- exit(0)
- end
-
- opts.on_head('-h', '--help', 'Displays this message') do
- show_all_help(optparse)
- exit(0)
- end
-
- opts.define_tail do
- commands_banner
- end
-
- end
-
- begin
- optparse.order! args
- rescue OptionParser::InvalidOption => e
- Fission.ui.output e
- show_all_help(optparse)
- exit(1)
- end
-
- if commands.include?(args.first)
- @cmd = Fission::Command.const_get(args.first.capitalize).new args.drop 1
- elsif is_snapshot_command?(args)
- klass = args.take(2).map {|c| c.capitalize}.join('')
- @cmd = Fission::Command.const_get(klass).new args.drop 2
- else
- show_all_help(optparse)
- exit(1)
- end
-
- begin
- @cmd.execute
- rescue Error => e
- puts "Error: #{e}"
- end
- end
-
- def self.commands
- cmds = Dir.entries(File.join(File.dirname(__FILE__), 'command')).select do |file|
- !File.directory? file
- end
-
- cmds.map { |cmd| File.basename(cmd, '.rb').gsub '_', ' ' }
- end
-
- private
- def self.is_snapshot_command?(args)
- args.first == 'snapshot' && args.count > 1 && commands.include?(args.take(2).join(' '))
- end
-
- def self.commands_banner
- text = "\nCommands:\n"
- Fission::Command.descendants.each do |command_klass|
- text << (command_klass.send :help)
- end
-
- text
- end
-
- def self.show_all_help(options)
- Fission.ui.output options
- Fission.ui.output commands_banner
- end
-
- end
-end
View
15 lib/fission/command.rb
@@ -1,15 +0,0 @@
-module Fission
- class Command
- attr_reader :options, :args
-
- def initialize(args=[])
- @options = OpenStruct.new
- @args = args
- end
-
- def self.help
- self.new.option_parser.to_s
- end
-
- end
-end
View
68 lib/fission/command/clone.rb
@@ -1,68 +0,0 @@
-module Fission
- class Command
- class Clone < Command
-
- def initialize(args=[])
- super
- @options.start = false
- end
-
- def execute
- option_parser.parse! @args
-
- unless @args.count > 1
- Fission.ui.output self.class.help
- Fission.ui.output ""
- Fission.ui.output_and_exit "Incorrect arguments for clone command", 1
- end
-
- source_vm_name = @args.first
- target_vm_name = @args[1]
- source_vm=Fission::VM.new(source_vm_name)
- target_vm=Fission::VM.new(target_vm_name)
-
- unless source_vm.exists?
- Fission.ui.output_and_exit "Unable to find the source vm #{source_vm_name} (#{source_vm.path})", 1
- end
-
- if target_vm.exists?
- Fission::ui.output_and_exit "The target vm #{target_vm_name} already exists", 1
- end
-
- clone_task = Fission::VM.clone source_vm_name, target_vm_name
-
- if clone_task.successful?
- Fission.ui.output ''
- Fission.ui.output 'Clone complete!'
-
- if @options.start
- Fission.ui.output "Starting '#{target_vm_name}'"
-
- start_task = target_vm.start
-
- if start_task.successful?
- Fission.ui.output "VM '#{target_vm_name}' started"
- else
- Fission.ui.output_and_exit "There was an error starting the VM. The error was:\n#{start_task.output}", start_task.code
- end
- end
- else
- Fission.ui.output_and_exit "There was an error cloning the VM. The error was:\n#{clone_task.output}", clone_task.code
- end
- end
-
- def option_parser
- optparse = OptionParser.new do |opts|
- opts.banner = "\nclone usage: fission clone source_vm target_vm [options]"
-
- opts.on '--start', 'Start the VM after cloning' do
- @options.start = true
- end
- end
-
- optparse
- end
-
- end
- end
-end
View
71 lib/fission/command/delete.rb
@@ -1,71 +0,0 @@
-module Fission
- class Command
- class Delete < Command
-
- def initialize(args=[])
- super
- @options.force = false
- end
-
- def execute
- option_parser.parse! @args
-
- if @args.count < 1
- Fission.ui.output self.class.help
- Fission.ui.output ""
- Fission.ui.output_and_exit "Incorrect arguments for delete command", 1
- end
-
- target_vm_name = @args.first
- target_vm=Fission::VM.new(target_vm_name)
- unless target_vm.exists?
- Fission.ui.output_and_exit "Vm #{target_vm_name} does not exist at (#{target_vm.path})", 1
- end
-
- if target_vm.running?
- Fission.ui.output 'VM is currently running'
- if @options.force
- Fission.ui.output 'Going to stop it'
- Fission::Command::Stop.new([target_vm_name]).execute
- else
- Fission.ui.output_and_exit "Either stop/suspend the VM or use '--force' and try again.", 1
- end
- end
-
-
- if Fission::Fusion.running?
- Fission.ui.output 'It looks like the Fusion GUI is currently running'
-
- if @options.force
- Fission.ui.output 'The Fusion metadata for the VM may not be removed completely'
- else
- Fission.ui.output "Either exit the Fusion GUI or use '--force' and try again"
- Fission.ui.output_and_exit "NOTE: Forcing a VM deletion with the Fusion GUI running may not clean up all of the VM metadata", 1
- end
- end
-
- delete_task = Fission::VM.delete target_vm_name
-
- if delete_task.successful?
- Fission.ui.output ''
- Fission.ui.output "Deletion complete!"
- else
- Fission.ui.output_and_exit "There was an error deleting the VM. The error was:\n#{delete_task.output}", delete_task.code
- end
- end
-
- def option_parser
- optparse = OptionParser.new do |opts|
- opts.banner = "\ndelete usage: fission delete target_vm [--force]"
-
- opts.on '--force', "Stop the VM if it's running and then delete it" do
- @options.force = true
- end
- end
-
- optparse
- end
-
- end
- end
-end
View
52 lib/fission/command/snapshot_create.rb
@@ -1,52 +0,0 @@
-module Fission
- class Command
- class SnapshotCreate < Command
-
- def initialize(args=[])
- super
- end
-
- def execute
- unless @args.count == 2
- Fission.ui.output self.class.help
- Fission.ui.output ""
- Fission.ui.output_and_exit "Incorrect arguments for snapshot create command", 1
- end
-
- vm_name, snap_name = @args.take 2
-
- vm = Fission::VM.new vm_name
- unless vm.exists?
- Fission.ui.output_and_exit "Unable to find the VM #{vm_name} (#{Fission::VM.path(vm_name)})", 1
- end
-
- unless vm.running?
- Fission.ui.output "VM '#{vm_name}' is not running"
- Fission.ui.output_and_exit 'A snapshot cannot be created unless the VM is running', 1
- end
-
- if vm.snapshots.include? snap_name
- Fission.ui.output_and_exit "VM '#{vm_name}' already has a snapshot named '#{snap_name}'", 1
- end
-
- Fission.ui.output "Creating snapshot"
- task = vm.create_snapshot(snap_name)
-
- if task.successful?
- Fission.ui.output "Snapshot '#{snap_name}' created"
- else
- Fission.ui.output_and_exit "There was an error creating the snapshot. The error was:\n#{task.output}", task.code
- end
- end
-
- def option_parser
- optparse = OptionParser.new do |opts|
- opts.banner = "\nsnapshot create: fission snapshot create my_vm snapshot_1"
- end
-
- optparse
- end
-
- end
- end
-end
View
45 lib/fission/command/snapshot_list.rb
@@ -1,45 +0,0 @@
-module Fission
- class Command
- class SnapshotList < Command
-
- def initialize(args=[])
- super
- end
-
- def execute
- unless @args.count == 1
- Fission.ui.output self.class.help
- Fission.ui.output ""
- Fission.ui.output_and_exit "Incorrect arguments for snapshot list command", 1
- end
-
- vm_name = @args.first
-
- vm = Fission::VM.new vm_name
-
- unless vm.exists?
- Fission.ui.output_and_exit "Unable to find the VM #{vm_name} (#{vm.path})", 1
- end
-
- snaps=vm.snapshots
- unless snaps.empty?
- Fission.ui.output snaps.join("\n")
- else
- Fission.ui.output "No snapshots found for VM '#{vm_name}'"
- end
-
- # TODO
- Fission.ui.output_and_exit "There was an error listing the snapshots. The error was:\n#{task.output}", task.code
- end
-
- def option_parser
- optparse = OptionParser.new do |opts|
- opts.banner = "\nsnapshot list: fission snapshot list my_vm"
- end
-
- optparse
- end
-
- end
- end
-end
View
54 lib/fission/command/snapshot_revert.rb
@@ -1,54 +0,0 @@
-module Fission
- class Command
- class SnapshotRevert < Command
-
- def initialize(args=[])
- super
- end
-
- def execute
- unless @args.count == 2
- Fission.ui.output self.class.help
- Fission.ui.output ''
- Fission.ui.output_and_exit 'Incorrect arguments for snapshot revert command', 1
- end
-
- vm_name, snap_name = @args.take 2
- vm = Fission::VM.new vm_name
-
- unless vm.exists? vm_name
- Fission.ui.output_and_exit "Unable to find the VM #{vm_name} (#{Fission::VM.path(vm_name)})", 1
- end
-
- if Fission::Fusion.running?
- Fission.ui.output 'It looks like the Fusion GUI is currently running'
- Fission.ui.output_and_exit 'Please exit the Fusion GUI and try again', 1
- end
-
- snaps = vm.snapshots
-
- unless snaps.include? snap_name
- Fission.ui.output_and_exit "Unable to find the snapshot '#{snap_name}'", 1
- end
-
- Fission.ui.output "Reverting to snapshot '#{snap_name}'"
- task = vm.revert_to_snapshot snap_name
-
- if task.successful?
- Fission.ui.output "Reverted to snapshot '#{snap_name}'"
- else
- Fission.ui.output_and_exit "There was an error reverting to the snapshot. The error was:\n#{task.output}", task.code
- end
- end
-
- def option_parser
- optparse = OptionParser.new do |opts|
- opts.banner = "\nsnapshot revert: fission snapshot revert my_vm snapshot_1"
- end
-
- optparse
- end
-
- end
- end
-end
View
69 lib/fission/command/start.rb
@@ -1,69 +0,0 @@
-module Fission
- class Command
- class Start < Command
-
- def initialize(args=[])
- super
- @options.headless = false
- end
-
- def execute
- option_parser.parse! @args
-
- if @args.empty?
- Fission.ui.output self.class.help
- Fission.ui.output ""
- Fission.ui.output_and_exit "Incorrect arguments for start command", 1
- end
-
- vm_name = @args.first
-
- vm = Fission::VM.new(vm_name)
-
- unless vm.exists?
- Fission.ui.output_and_exit "Unable to find the VM #{vm_name} (#{Fission::VM.path(vm_name)})", 1
- end
-
- if vm.running?
- Fission.ui.output ''
- Fission.ui.output_and_exit "VM '#{vm_name}' is already running", 0
- end
-
- Fission.ui.output "Starting '#{vm_name}'"
- start_args = {}
-
- if @options.headless
-
- if Fission::Fusion.running?
- Fission.ui.output 'It looks like the Fusion GUI is currently running'
- Fission.ui.output 'A VM cannot be started in headless mode when the Fusion GUI is running'
- Fission.ui.output_and_exit "Exit the Fusion GUI and try again", 1
- else
- start_args[:headless] = true
- end
- end
-
- task = vm.start(start_args)
-
- if task.successful?
- Fission.ui.output "VM '#{vm_name}' started"
- else
- Fission.ui.output_and_exit "There was a problem starting the VM. The error was:\n#{task.output}", task.code
- end
- end
-
- def option_parser
- optparse = OptionParser.new do |opts|
- opts.banner = "\nstart usage: fission start vm [options]"
-
- opts.on '--headless', 'Start the VM in headless mode (i.e. no Fusion GUI console)' do
- @options.headless = true
- end
- end
-
- optparse
- end
-
- end
- end
-end
View
31 lib/fission/command/status.rb
@@ -1,31 +0,0 @@
-module Fission
- class Command
- class Status < Command
-
- def initialize(args=[])
- super
- end
-
- def execute
-
- all_vms=Fission::VM.all
- vm_with_longest_name = all_vms.max { |a,b| a.name.length <=> b.name.length }
- max_name_length=vm_with_longest_name.name.length
- all_vms.each do |vm|
- status = vm.state
- Fission.ui.output_printf "%-#{max_name_length}s %s\n", vm.name, "["+status+"]"
- end
-
- end
-
- def option_parser
- optparse = OptionParser.new do |opts|
- opts.banner = "\nstatus usage: fission status"
- end
-
- optparse
- end
-
- end
- end
-end
View
49 lib/fission/command/stop.rb
@@ -1,49 +0,0 @@
-module Fission
- class Command
- class Stop < Command
-
- def initialize(args=[])
- super
- end
-
- def execute
- unless @args.count == 1
- Fission.ui.output self.class.help
- Fission.ui.output ""
- Fission.ui.output_and_exit "Incorrect arguments for stop command", 1
- end
-
- vm_name = @args.first
- vm = Fission::VM.new vm_name
-
- unless vm.exists?
- Fission.ui.output_and_exit "VM #{vm_name} does not exist at (#{vm.path})", 1
- end
-
-
- unless vm.running?
- Fission.ui.output ''
- Fission.ui.output_and_exit "VM '#{vm_name}' is not running", 0
- end
-
- Fission.ui.output "Stopping '#{vm_name}'"
- task = vm.stop
-
- if task.successful?
- Fission.ui.output "VM '#{vm_name}' stopped"
- else
- Fission.ui.output_and_exit "There was an error stopping the VM. The error was:\n#{response.output}", response.code
- end
- end
-
- def option_parser
- optparse = OptionParser.new do |opts|
- opts.banner = "\nstop usage: fission stop vm"
- end
-
- optparse
- end
-
- end
- end
-end
View
67 lib/fission/command/suspend.rb
@@ -1,67 +0,0 @@
-module Fission
- class Command
- class Suspend < Command
-
- def initialize(args=[])
- super
- @options.all = false
- end
-
- def execute
- option_parser.parse! @args
-
- if @args.count != 1 && !@options.all
- Fission.ui.output self.class.help
- Fission.ui.output ""
- Fission.ui.output_and_exit "Incorrect arguments for suspend command", 1
- end
-
- vms_to_suspend.each do |vm|
- Fission.ui.output "Suspending '#{vm.name}'"
- task = vm.suspend
-
- if task.successful?
- Fission.ui.output "VM '#{vm.name}' suspended"
- else
- Fission.ui.output_and_exit "There was an error suspending the VM. The error was:\n#{task.output}", task.code
- end
- end
- end
-
- def vms_to_suspend
- if @options.all
- vms=Fission::VM.all_running
- else
- vm_name = @args.first
- vm=Fission::VM.new(vm_name)
-
- unless vm.exists?
- Fission.ui.output ''
- Fission.ui.output_and_exit "VM #{vm_name} does not exist (#{Fission::VM.path(vm_name)})", 1
- end
-
- unless vm.running?
- Fission.ui.output ''
- Fission.ui.output_and_exit "VM '#{vm_name}' is not running", 1
- end
-
- vms = [vm]
- end
- vms
- end
-
- def option_parser
- optparse = OptionParser.new do |opts|
- opts.banner = "\nsuspend usage: fission suspend [vm | --all]"
-
- opts.on '--all', 'Suspend all running VMs' do
- @options.all = true
- end
- end
-
- optparse
- end
-
- end
- end
-end
View
57 lib/fission/config.rb
@@ -1,24 +1,71 @@
module Fission
class Config
+
+ # Public: Gets/Sets the Hash of attributes.
attr_accessor :attributes
+ # Public: Path to the Fission conf file (default: ~/.fissionrc).
CONF_FILE = File.expand_path '~/.fissionrc'
+ # Public: Initializes a Config object. This also sets the default config
+ # attributes for 'vmrun_bin', 'vmrun_cmd', 'vm_dir', 'plist_file', and
+ # 'gui_bin'.
+ #
+ # Examples
+ #
+ # Fission::Config.new
+ #
+ # Returns a new Config instance.
def initialize
@attributes = {}
- load_from_file
- if @attributes['vm_dir'].blank?
- @attributes['vm_dir'] = File.expand_path('~/Documents/Virtual Machines.localized/')
+ @attributes['vm_dir'] = File.expand_path('~/Documents/Virtual Machines.localized/')
+ @attributes['lease_file'] = '/var/db/vmware/vmnet-dhcpd-vmnet8.leases'
+
+ fusion_version = :unknown
+
+ if File.exists?("/Library/Application Support/VMware Fusion/vmrun")
+ @attributes['vmrun_bin'] = '/Library/Application Support/VMware Fusion/vmrun'
+ end
+
+ if File.exists?("/Applications/VMware Fusion.app/Contents/Library/vmrun")
+ @attributes['vmrun_bin'] = "/Applications/VMware Fusion.app/Contents/Library/vmrun"
+ end
+
+ if fusion_version == :unknown
end
- @attributes['vmrun_bin'] = '/Library/Application Support/VMware Fusion/vmrun'
- @attributes['vmrun_cmd'] = "#{@attributes['vmrun_bin'].gsub(' ', '\ ')} -T fusion"
@attributes['plist_file'] = File.expand_path('~/Library/Preferences/com.vmware.fusion.plist')
@attributes['gui_bin'] = File.expand_path('/Applications/VMware Fusion.app/Contents/MacOS/vmware')
+
+ load_from_file
+
+ @attributes['vmrun_cmd'] = "#{@attributes['vmrun_bin'].gsub(' ', '\ ')} -T fusion"
+ end
+
+ # Public: Helper method to access config atributes. This is a shortcut for
+ # querying the config attributes.
+ #
+ # item - The config item to query.
+ #
+ # Examples
+ #
+ # Fission.config['vmrun_bin']
+ # # => '/foo/bar/vmrun'
+ #
+ # Returns the value of the specified config item.
+ def [](item)
+ @attributes[item]
end
private
+ # Internal: Loads config values from the Fission conf file into attributes.
+ #
+ # Examples
+ #
+ # load_from_file
+ #
+ # Returns nothing.
def load_from_file
if File.file?(CONF_FILE)
@attributes.merge!(YAML.load_file(CONF_FILE))
View
5 lib/fission/core_ext/class.rb
@@ -1,5 +0,0 @@
-class Class
- def descendants
- ObjectSpace.each_object(Class).select { |klass| klass < self }
- end
-end
View
7 lib/fission/core_ext/file.rb
@@ -1,7 +0,0 @@
-class File
- # from ptools
- def self.binary?(file)
- s = (File.read(file, File.stat(file).blksize) || "").split(//)
- ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
- end
-end
View
112 lib/fission/core_ext/object.rb
@@ -1,112 +0,0 @@
-# this is from active_support
-# github.com/rails/rails/activesupport
-#
-class Object
- # An object is blank if it's false, empty, or a whitespace string.
- # For example, "", " ", +nil+, [], and {} are blank.
- #
- # This simplifies:
- #
- # if !address.nil? && !address.empty?
- #
- # ...to:
- #
- # if !address.blank?
- def blank?
- respond_to?(:empty?) ? empty? : !self
- end
-
- # An object is present if it's not <tt>blank?</tt>.
- def present?
- !blank?
- end
-
- # Returns object if it's <tt>present?</tt> otherwise returns +nil+.
- # <tt>object.presence</tt> is equivalent to <tt>object.present? ? object : nil</tt>.
- #
- # This is handy for any representation of objects where blank is the same
- # as not present at all. For example, this simplifies a common check for
- # HTTP POST/query parameters:
- #
- # state = params[:state] if params[:state].present?
- # country = params[:country] if params[:country].present?
- # region = state || country || 'US'
- #
- # ...becomes:
- #
- # region = params[:state].presence || params[:country].presence || 'US'
- def presence
- self if present?
- end
-end
-
-class NilClass
- # +nil+ is blank:
- #
- # nil.blank? # => true
- #
- def blank?
- true
- end
-end
-
-class FalseClass
- # +false+ is blank:
- #
- # false.blank? # => true
- #
- def blank?
- true
- end
-end
-
-class TrueClass
- # +true+ is not blank:
- #
- # true.blank? # => false
- #
- def blank?
- false
- end
-end
-
-class Array
- # An array is blank if it's empty:
- #
- # [].blank? # => true
- # [1,2,3].blank? # => false
- #
- alias_method :blank?, :empty?
-end
-
-class Hash
- # A hash is blank if it's empty:
- #
- # {}.blank? # => true
- # {:key => 'value'}.blank? # => false
- #
- alias_method :blank?, :empty?
-end
-
-class String
- # A string is blank if it's empty or contains whitespaces only:
- #
- # "".blank? # => true
- # " ".blank? # => true
- # " something here ".blank? # => false
- #
- def blank?
- self !~ /\S/
- end
-end
-
-class Numeric #:nodoc:
- # No number is blank:
- #
- # 1.blank? # => false
- # 0.blank? # => false
- #
- def blank?
- false
- end
-end
View
9 lib/fission/error.rb
@@ -1,9 +0,0 @@
-module Fission
- class Error < StandardError
- attr_reader :orginal
- def initialize(msg, original=$!)
- super(msg)
- @original = original; end
- end
-end
-
View
17 lib/fission/fusion.rb
@@ -1,17 +0,0 @@
-module Fission
- class Fusion
-
- def self.running?
- command = "ps -ef | grep -v grep | grep -c "
- command << "#{Fission.config.attributes['gui_bin'].gsub(' ', '\ ')} 2>&1"
- output = `#{command}`
-
- response = Fission::Response.new :code => 0
-
- output.strip.to_i > 0 ? response.data = true : response.data = false
-
- response
- end
-
- end
-end
View
74 lib/fission/leasesfile.rb
@@ -1,74 +0,0 @@
-require 'date'
-
-class Lease
- attr_accessor :name,:mac,:start,:end,:ip
-
- def initialize(name)
- @name=name
- @ip=name
- end
-
- def expired?
- @end < DateTime.now
- end
-end
-
-class LeasesFile
-
- attr_reader :leases
-
- def initialize(filename)
- @filename=filename
- @leases=Array.new
- load
- end
-
- def load
- @leases=Array.new
- File.open(@filename,"r") do |leasefile|
- lease=nil
- while (line = leasefile.gets)
-
- line=line.lstrip.gsub(';','')
- case line
- when /^lease/
- @leases << lease unless lease.nil?
- name=line.split(' ')[1]
- lease=Lease.new(name)
- when /^hardware/
- lease.mac=line.split(" ")[2]
- when /^starts/
- lease.start=DateTime.parse(line.split(" ")[2..3].join(" "))
- when /^ends/
- lease.end=DateTime.parse(line.split(" ")[2..3].join(" "))
- end
-
- end
- @leases << lease unless lease.nil?
- end
- return @leases
- end
-
- def all_leases
- return @leases
- end
-
- def current_leases
- hash_list=Hash.new
- @leases.each do |lease|
- hash_list[lease.name]=lease
- end
- collapsed_list=Array.new
- hash_list.each do |key,value|
- collapsed_list << value
- end
- return collapsed_list
- end
-
- def find_lease_by_mac(mac)
- matches=current_leases.select{|l| l.mac==mac}
- return nil if matches.nil?
- return matches[0]
- end
-
-end
View
39 lib/fission/metadata.rb
@@ -1,39 +0,0 @@
-module Fission
- class Metadata
-
- require 'cfpropertylist'
-
- attr_accessor :content
-
- def self.delete_vm_info(vm_path)
- metadata = new
- metadata.load
- metadata.delete_vm_restart_document(vm_path)
- metadata.delete_vm_favorite_entry(vm_path)
- metadata.save
- end
-
- def load
- raw_data = CFPropertyList::List.new :file => Fission.config.attributes['plist_file']
- @content = CFPropertyList.native_types raw_data.value
- end
-
- def save
- new_content = CFPropertyList::List.new
- new_content.value = CFPropertyList.guess @content
- new_content.save Fission.config.attributes['plist_file'],
- CFPropertyList::List::FORMAT_BINARY
- end
-
- def delete_vm_restart_document(vm_path)
- if @content.has_key?('PLRestartDocumentPaths')
- @content['PLRestartDocumentPaths'].delete_if { |p| p == vm_path }
- end
- end
-
- def delete_vm_favorite_entry(vm_path)
- @content['VMFavoritesListDefaults2'].delete_if { |vm| vm['path'] == vm_path }
- end
-
- end
-end
View
16 lib/fission/response.rb
@@ -1,16 +0,0 @@
-module Fission
- class Response
- attr_accessor :code, :output, :data
-
- def initialize(args={})
- @code = args.fetch :code, 1
- @output = args.fetch :output, ''
- @data = args.fetch :data, nil
- end
-
- def successful?
- @code == 0
- end
-
- end
-end
View
22 lib/fission/ui.rb
@@ -1,22 +0,0 @@
-module Fission
- class UI
- attr_reader :stdout
-
- def initialize(stdout=$stdout)
- @stdout = stdout
- end
-
- def output(s)
- @stdout.puts s
- end
-
- def output_printf(string, key, value)
- @stdout.send :printf, string, key, value
- end
-
- def output_and_exit(s, exit_code)
- output s
- exit exit_code
- end
- end
-end
View
3  lib/fission/version.rb
@@ -1,3 +0,0 @@
-module Fission
- VERSION = "0.4.0a"
-end
View
365 lib/fission/vm.rb
@@ -1,365 +0,0 @@
-require 'fission/leasesfile'
-require 'shellwords'
-require 'fission/error'
-
-module Fission
- class VM
- attr_reader :name
-
- def initialize(name)
- @name = name
- end
-
- #####################################################
- # Path Helpers
- #####################################################
- # Returns the topdir of the vm
- def path
- File.join Fission.config.attributes['vm_dir'], "#{@name}.vmwarevm"
- end
-
- # Returns a string to the path of the config file
- # There is no guarantee it exists
- def vmx_path
- return File.join(path, "#{@name}.vmx")
- end
-
-
- ####################################################################
- # State information
- ####################################################################
- def running?
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
-
- command = "#{vmrun_cmd} list"
- output = `#{command}`
-
- response = Fission::Response.new :code => $?.exitstatus
-
- if response.successful?
- vms = output.split("\n").select do |vm|
- vm.include?('.vmx') && File.exists?(vm) && File.extname(vm) == '.vmx'
- end
- return vms.include?(self.vmx_path)
- else
- raise Fission::Error,"Error listing the state of vm #{@name}:\n#{output}"
- end
- end
-
- def suspended?
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
-
- suspend_filename=File.join(File.dirname(vmx_path), File.basename(vmx_path,".vmx")+".vmem")
- return File.exists?(suspend_filename)
- end
-
- # Checks to see if a vm exists
- def exists?
- File.exists? vmx_path
- end
-
- # Returns the state of a vm
- def state
- return "not created" unless self.exists?
-
- return "suspend" if self.suspended?
-
- return "running" if self.running?
-
- return "not running"
- end
-
- ####################################################################
- # VM information
- ####################################################################
-
- # Returns an Array of snapshot names
- def snapshots
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
-
- command = "#{vmrun_cmd} listSnapshots #{vmx_path.shellescape} 2>&1"
- output = `#{command}`
-
- raise "There was an error listing the snapshots of #{@name} :\n #{output}" unless $?.exitstatus==0
-
- snaps_unfiltered = output.split("\n").select { |s| !s.include? 'Total snapshots:' }
- snaps=snaps_unfiltered.map { |s| s.strip }
- return snaps
- end
-
- # Retrieve the first mac address for a vm
- # This will only retrieve the first auto generate mac address
- def mac_address
- raise ::Fission::Error,"VM #{@name} does not exist" unless self.exists?
-
- line=File.new(vmx_path).grep(/^ethernet0.generatedAddress =/)
- if line.nil?
- #Fission.ui.output "Hmm, the vmx file #{vmx_path} does not contain a generated mac address "
- return nil
- end
- address=line.first.split("=")[1].strip.split(/\"/)[1]
- return address
- end
-
- # Retrieve the ip address for a vm.
- # This will only look for dynamically assigned ip address via vmware dhcp
- def ip_address
- raise ::Fission::Error,"VM #{@name} does not exist" unless self.exists?
-
- unless mac_address.nil?
- lease=LeasesFile.new("/var/db/vmware/vmnet-dhcpd-vmnet8.leases").find_lease_by_mac(mac_address)
- if lease.nil?
- return nil
- else
- return lease.ip
- end
- else
- # No mac address was found for this machine so we can't calculate the ip-address
- return nil
- end
- end
-
- ####################################################################
- # VMS information
- ####################################################################
-
- # Returns an array of vm objects
- def self.all
- vm_dirs = Dir[File.join Fission.config.attributes['vm_dir'], '*.vmwarevm'].select do |d|
- File.directory? d
- end
-
- vm_names=vm_dirs.map { |d| File.basename d, '.vmwarevm' }
- vms=[]
- vm_names.each do |vmname|
- vm=Fission::VM.new vmname
- vms << vm
- end
-
- return vms
- end
-
- # Returns an array of vms that are running
- def self.all_running
- running_vms=self.all.select do |vm|
- vm.state=="running"
- end
- return running_vms
- end
-
- # Returns an existing vm
- def self.get(name)
- return Fission::VM.new(name)
- end
-
- #####################################################
- # VM Class Actions
- #####################################################
- def self.clone(source_vm, target_vm)
- raise Fission::Error,"VM #{source_vm} does not exist" unless Fission::VM.new(source_vm).exists?
- raise Fission::Error,"VM #{target_vm} already exists" if Fission::VM.new(target_vm).exists?
-
- FileUtils.cp_r Fission::VM.new(source_vm).path, Fission::VM.new(target_vm).path
-
- rename_vm_files source_vm, target_vm
- update_config source_vm, target_vm
-
- response = Response.new :code => 0
- end
-
- def self.delete(vm_name)
- raise Fission::Error,"VM #{vm_name} does not exist" unless Fission::VM.new(vm_name).exists?
-
- vm=Fission::VM.new(vm_name)
- FileUtils.rm_rf vm.path
- Fission::Metadata.delete_vm_info(vm.path)
-
- Response.new :code => 0
- end
-
-
- #####################################################
- # VM Instance Actions
- #####################################################
- def create_snapshot(name)
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
-
- command = "#{vmrun_cmd} snapshot #{vmx_path.shellescape} \"#{name}\" 2>&1"
- output = `#{command}`
-
- response = Fission::Response.new :code => $?.exitstatus
- response.output = output unless response.successful?
-
- response
- end
-
- def start(args={})
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
- raise Fission::Error,"VM #{@name} is already started" if self.running?
-
-
- command = "#{vmrun_cmd} start #{vmx_path.shellescape}"
-
- if !args[:headless].blank? && args[:headless]
- command << " nogui 2>&1"
- else
- command << " gui 2>&1"
- end
-
- output = `#{command}`
-
- response = Fission::Response.new :code => $?.exitstatus
- response.output = output unless response.successful?
-
- response
- end
-
- def stop
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
- raise Fission::Error,"VM #{@name} is not running" unless self.running?
-
- command = "#{vmrun_cmd} stop #{vmx_path.shellescape} 2>&1"
- output = `#{command}`
-
- response = Fission::Response.new :code => $?.exitstatus
- response.output = output unless response.successful?
-
- response
- end
-
- def halt
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
- raise Fission::Error,"VM #{@name} is not running" unless self.running?
-
- command = "#{vmrun_cmd} stop #{vmx_path.shellescape} hard 2>&1"
- output = `#{command}`
-
- response = Fission::Response.new :code => $?.exitstatus
- response.output = output unless response.successful?
-
- response
- end
-
- def resume
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
- raise Fission::Error,"VM #{@name} is already running" if self.running?
- if self.suspended?
- self.start
- end
- end
-
- def suspend
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
- raise Fission::Error,"VM #{@name} is not running" unless self.running?
-
- command = "#{vmrun_cmd} suspend #{vmx_path.shellescape} hard 2>&1"
- output = `#{command}`
-
- response = Fission::Response.new :code => $?.exitstatus
- response.output = output unless response.successful?
- response
- end
-
- # Action to revert to a snapshot
- # Returns a response object
- def revert_to_snapshot(name)
- raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
-
- command = "#{vmrun_cmd} revertToSnapshot #{vmx_path.shellescape} \"#{name}\" 2>&1"
- output = `#{command}`
-
- response = Fission::Response.new :code => $?.exitstatus
- response.output = output unless response.successful?
-
- response
- end
-
- #####################################################
- # Helpers
- #####################################################
- private
- def self.rename_vm_files(from, to)
- to_vm=Fission::VM.new(to)
-
- files_to_rename(from, to).each do |filename|
- text_to_replace = File.basename(filename, File.extname(filename))
-
- if File.extname(filename) == '.vmdk'
- if filename.match /\-s\d+\.vmdk/
- text_to_replace = filename.partition(/\-s\d+.vmdk/).first
- end
- end
-
- unless File.exists?(File.join(to_vm.path, filename.gsub(text_to_replace, to)))
- FileUtils.mv File.join(to_vm.path, filename),
- File.join(to_vm.path, filename.gsub(text_to_replace, to))
- end
- end
- end
-
- def self.files_to_rename(from, to)
- files_which_match_source_vm = []
- other_files = []
-
- from_vm=Fission::VM.new(from)
-
- Dir.entries(from_vm.path).each do |f|
- unless f == '.' || f == '..'
- f.include?(from) ? files_which_match_source_vm << f : other_files << f
- end
- end
-
- files_which_match_source_vm + other_files
- end
-
- def self.vm_file_extensions
- ['.nvram', '.vmdk', '.vmem', '.vmsd', '.vmss', '.vmx', '.vmxf']
- end
-
- # This is done after a clone has been done
- # All files are already at the to location
- # The content of the text files will be substituted with strings from => to
- def self.update_config(from, to)
- to_vm=Fission::VM.new(to)
-
- ['.vmx', '.vmxf', '.vmdk'].each do |ext|
- file = File.join to_vm.path, "#{to}#{ext}"
-
- unless File.binary?(file)
- text = (File.read file).gsub from, to
- # 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
-
- # Rewrite vmx file to avoid messages
- new_vmx_file=File.open(File.join(to_vm.vmx_path),'r')
-
- content=new_vmx_file.read
-
- # Filter out other values
- content=content.gsub(/^tools.remindInstall.*\n/, "")
- content=content.gsub(/^uuid.action.*\n/,"").strip
-
- # Remove generate mac addresses
- content=content.gsub(/^ethernet.+generatedAddress.*\n/,"").strip
-
- # Add the correct values
- content=content+"\ntools.remindInstall = \"FALSE\"\n"
- content=content+"uuid.action = \"create\"\n"
-
- # Now rewrite the vmx file
- # 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
-
- def vmrun_cmd
- return Fission.config.attributes['vmrun_cmd']
- end
-
- end
-end
View
2  lib/veewee/cli.rb
@@ -52,4 +52,4 @@ def self.register(klass, name, usage, description, opts=nil)
end
end
end
-end #Veewee
+end #Veewee
View
4 lib/veewee/command.rb
@@ -10,6 +10,6 @@ module Command
# The built-in commands must always be loaded
require 'veewee/command/version'
require 'veewee/command/kvm'
-require 'veewee/command/virtualbox'
-require 'veewee/command/vmfusion'
+require 'veewee/command/vbox'
+require 'veewee/command/fusion'
require 'veewee/command/parallels'
View
2  lib/veewee/command/base.rb
@@ -103,4 +103,4 @@ def self.extract_name_from_usage(usage)
end
end
end
-end
+end
View
2  lib/veewee/command/vmfusion.rb → lib/veewee/command/fusion.rb
@@ -1,6 +1,6 @@
module Veewee
module Command
- class Vmfusion< Veewee::Command::GroupBase
+ class Fusion< Veewee::Command::GroupBase
register "fusion", "Subcommand for Vmware fusion"
desc "build [BOX_NAME]", "Build box"
View
3  lib/veewee/command/group_base.rb
@@ -100,7 +100,8 @@ def initialize(*args)
# Override the basename to include the subcommand name.
def self.basename
- "#{super} #{@_name}"
+ "#{super}"
+ #"#{super} #{@_name}"
end
end
end
View
1  lib/veewee/command/kvm.rb
@@ -10,6 +10,7 @@ class Kvm< Veewee::Command::GroupBase
method_option :auto,:type => :boolean , :default => false, :aliases => "-a", :desc => "auto answers"
method_option :postinstall_include, :type => :array, :default => [], :aliases => "-i", :desc => "ruby regexp of postinstall filenames to additionally include"
method_option :postinstall_exclude, :type => :array, :default => [], :aliases => "-e", :desc => "ruby regexp of postinstall filenames to exclude"
+ method_option :use_emulation, :type => :boolean , :default => false, :desc => "Use QEMU emulation"
def build(box_name)
venv=Veewee::Environment.new(options)
venv.ui=env.ui
View
2  lib/veewee/command/virtualbox.rb → lib/veewee/command/vbox.rb
@@ -1,6 +1,6 @@
module Veewee
module Command
- class Virtualbox< Veewee::Command::GroupBase
+ class Vbox< Veewee::Command::GroupBase
register "vbox", "Subcommand for VirtualBox"
desc "build [BOX_NAME]", "Build box"
View
39 lib/veewee/definitions.rb
@@ -1,3 +1,4 @@
+require 'grit'
require 'veewee/definition'
require 'veewee/templates'
require 'veewee/template'
@@ -39,7 +40,7 @@ def each(&block)
end
if definitions.length==0
- env.logger.debug("[Definition] no definitions found")
+ env.logger.debug("[Definition] no definitions found")
end
definitions.each(&block)
@@ -61,9 +62,15 @@ def define(definition_name,template_name,options = {})
env.logger.debug("Forceflag : #{options['force']}")
+ git_template=false
+ # Check if the template is a git repo
+ if template_name.start_with?("git://")
+ git_template=true
+ end
+
# Check if template exists
template=env.templates[template_name]
- if template.nil?
+ if template.nil? and ! git_template
env.logger.fatal("Template '#{template_name}' does not exist")
raise Veewee::TemplateError, "Template '#{template_name}' does not exist"
else
@@ -83,19 +90,31 @@ def define(definition_name,template_name,options = {})
end
end
- env.logger.debug("Creating definition #{definition_name} in directory '#{env.definition_dir}' ")
+ env.logger.info("Creating definition #{definition_name} in directory '#{env.definition_dir}' ")
dst_dir="#{File.join(env.definition_dir,definition_name)}"
FileUtils.mkdir(dst_dir)
env.logger.debug("Definition Directory '#{File.join(env.definition_dir,definition_name)}' succesfuly created")
# Start copying/cloning the directory of the template to the definition directory
- begin
- env.logger.debug("Starting copy '#{template.path}' to '#{dst_dir}'")
- FileUtils.cp_r(template.path+"/.",dst_dir)
- env.logger.debug("Copy '#{template.path}' to '#{dst_dir}' succesfull")
- rescue Exception => ex
- env.logger.fatal("Copy '#{template.path}' to #{dst_dir}' failed: #{ex}")
- raise Veewee::Error , "Copy '#{template.path}' to #{dst_dir}' failed: #{ex}"
+ if (git_template)
+ begin
+ env.logger.info("Starting git clone #{template_name} #{dst_dir}")
+ g = Grit::Git.new(dst_dir)
+ g.clone({ :timeout => false }, template_name, dst_dir)
+ rescue Exception => ex
+ err = "git clone #{template_name} #{dst_dir} failed: #{ex}"
+ env.logger.fatal(err)
+ raise Veewee::DefinitionError, err
+ end
+ else
+ begin
+ env.logger.debug("Starting copy '#{template.path}' to '#{dst_dir}'")
+ FileUtils.cp_r(template.path+"/.",dst_dir)
+ env.logger.debug("Copy '#{template.path}' to '#{dst_dir}' succesfull")
+ rescue Exception => ex
+ env.logger.fatal("Copy '#{template.path}' to #{dst_dir}' failed: #{ex}")
+ raise Veewee::Error , "Copy '#{template.path}' to #{dst_dir}' failed: #{ex}"
+ end
end
definition=env.definitions[definition_name]
View
8 lib/veewee/environment.rb
@@ -69,6 +69,14 @@ def initialize(options={})
}
options = defaults.merge(options)
+ veeweefile_config = defaults.keys.inject({}) do |memo,obj|
+ if config.env.methods.include?(obj) && !config.env.send(obj).nil?
+ memo.merge({ obj => config.env.send(obj) })
+ else
+ memo
+ end
+ end
+ options = options.merge(veeweefile_config)
# We need to set this variable before the first call to the logger object
if options.has_key?("debug")
View
4 lib/veewee/provider/core/box/build.rb
@@ -70,7 +70,7 @@ def build(options={})
# This needs to be done after the kickstart:
# As the dhcp request will likely occur just before the kickstart fetch
until !self.ip_address.nil?
- env.logger.info "wait for Ip addres"
+ env.logger.info "wait for Ip address"
sleep 2
end
@@ -119,7 +119,7 @@ def filter_postinstall_files(options)
unless options["postinstall_exclude"].nil?
options["postinstall_exclude"].each do |p|
env.logger.info "Exclude pattern #{p}"
- new_definition.postinstall_files.collect! { |f| f.match(p) ? f.gsub(/^/,"_"): f}
+ new_definition.postinstall_files.reject! { |f| f.match(p) }
end
end
View
4 lib/veewee/provider/core/box/floppy.rb
@@ -2,7 +2,7 @@ module Veewee
module Provider
module Core
module BoxCommand
- def create_floppy(filename)
+ def create_floppy(floppy_filename)
# Todo Check for java
# Todo check output of commands
@@ -15,7 +15,7 @@ def create_floppy(filename)
FileUtils.cp("#{full_filename}","#{temp_dir}")
end
javacode_dir=File.expand_path(File.join(__FILE__,'..','..','..','..','..','java'))
- floppy_file=File.join(definition.path,filename)
+ floppy_file=File.join(definition.path,floppy_filename)
if File.exists?(floppy_file)
env.logger.info "Removing previous floppy file"
FileUtils.rm(floppy_file)
View
2  lib/veewee/provider/core/box/scp.rb
@@ -10,7 +10,7 @@ def scp(localfile,remotefile,options={})
new_options=ssh_options.merge(options)
self.when_ssh_login_works(self.ip_address,new_options) do
begin
- env.logger.info "About to transfer #{localfile} to #{remotefile} to the box #{name} - #{self.ip_address} - #{new_options}"
+ env.logger.info "About to transfer #{localfile} to #{remotefile} to the box #{name} - #{self.ip_address} - #{new_options.inspect}"
self.ssh_transfer_file(self.ip_address,localfile,remotefile,new_options)
rescue RuntimeError => ex
ui.error("Error transfering file #{localfile} failed, possible not enough permissions to write? #{ex}",:prefix => false)
View
13 lib/veewee/provider/core/helper/web.rb
@@ -21,10 +21,15 @@ def initialize(server,localfile,ui)
def do_GET(request,response)
response['Content-Type']='text/plain'
response.status = 200
- ui.info "Serving file #{@localfile}"
- displayfile=File.open(@localfile,'r')
- content=displayfile.read()
- response.body=content
+ content = File.open(@localfile, "r").read
+ response.body = case File.extname(@localfile)
+ when ".erb"
+ ui.info "Rendering and serving file #{@localfile}"
+ ERB.new(content).result(binding)
+ else
+ ui.info "Serving file #{@localfile}"
+ content
+ end
#If we shut too fast it might not get the complete file
sleep 2
@server.shutdown
View
5 lib/veewee/provider/kvm/box/create.rb
@@ -21,7 +21,8 @@ def create_server(options)
:memory_size => definition.memory_size.to_i*1024,
:cpus => definition.cpu_count.to_i,
:volume_capacity => "#{definition.disk_size}M",
- :network_interface_type => "nat",
+ :domain_type => options['use_emulation'] ? 'qemu': 'kvm',
+ :network_interface_type => "network",
:iso_file => definition.iso_file,
:arch => definition.os_type_id.end_with?("_64") ? "x86_64" : "i686",
:iso_dir => env.config.veewee.iso_dir
@@ -63,7 +64,7 @@ def add_floppy
# Get the raw xml of the changed document
new_xml=domain_doc.to_xml
- # Undefine the existing domain
+ # Undefine the existing domain
s.undefine
# Re-define the domain
View
6 lib/veewee/provider/kvm/box/helper/console_type.rb
@@ -8,9 +8,9 @@ module Kvm
module BoxCommand
# Type on the console
def console_type(sequence,type_options={})
- vnc_port=@connection.servers.all(:name => name).first.vnc_port
- display_port=vnc_port.to_i - 5900
- ui.success "Sending keystrokes to VNC port :#{display_port} - TCP port: #{vnc_port}"
+ tcp_port=@connection.servers.all(:name => name).first.display[:port]
+ display_port=tcp_port.to_i - 5900
+ ui.success "Sending keystrokes to VNC port :#{display_port} - TCP port: #{tcp_port}"
vnc_type(sequence,"127.0.0.1",display_port)
end
View
2  lib/veewee/provider/kvm/box/helper/ip.rb
@@ -3,7 +3,7 @@ module Provider
module Kvm
module BoxCommand
def ip_address
- ip=@connection.servers.all(:name => "#{name}").first.addresses[:public]
+ ip=@connection.servers.all(:name => "#{name}").first.public_ip_address
return ip.first unless ip.nil?
return ip
end
View
4 lib/veewee/provider/kvm/box/helper/status.rb
@@ -15,11 +15,11 @@ def exists?
end
def exists_volume?
- !@connection.volumes.all(:name => "#{name}.img").nil?
+ @connection.list_volumes.find { |v| v[:name] == "#{name}.img" }
end
def exists_vm?
- !@connection.servers.all(:name => name).nil?
+ @connection.list_domains.find { |d| d[:name] == name }
end
end # End Module
View
2  lib/veewee/provider/kvm/provider.rb
@@ -42,7 +42,7 @@ def check_requirements
# http://www.libvirt.org/html/libvirt-libvirt.html#virGetVersion
# format major * 1,000,000 + minor * 1,000 + release
env.logger.info "Checking libvirt version"
- libvirt_version=conn.libversion
+ libvirt_version=conn.version
if libvirt_version < 8003
raise Veewee::Error,"You need at least libvirt version 0.8.3 or higher "
end
View
14 lib/veewee/provider/vmfusion/box.rb
@@ -33,23 +33,15 @@ class Box < Veewee::Provider::Core::Box
def initialize(name,env)
require 'fission'
-
super(name,env)
end
- def determine_vmrun_cmd
- return "#{fusion_path}/vmrun"
+ def vmrun_cmd
+ return ::Fission.config['vmrun_bin']
end
def vm_path
- home=ENV['HOME']
- dir="#{home}/Documents/Virtual Machines.localized/#{name}.vmwarevm"
- return dir
- end
-
- def fusion_path
- dir="/Library/Application Support/VMware Fusion/"
- return dir
+ return File.join(::Fission.config['vm_dir'], "#{name}.vmwarevm")
end
def vmx_file_path
View
2  lib/veewee/provider/vmfusion/box/create.rb
@@ -27,7 +27,7 @@ def create_disk
current_dir=FileUtils.pwd
FileUtils.chdir(vm_path)
env.ui.info "Creating disk"
- command="#{fusion_path.shellescape}/vmware-vdiskmanager -c -s #{definition.disk_size}M -a lsilogic -t #{disk_type} #{name}.vmdk"
+ command="#{File.dirname(vmrun_cmd).shellescape}/vmware-vdiskmanager -c -s #{definition.disk_size}M -a lsilogic -t #{disk_type} #{name}.vmdk"
shell_results=shell_exec("#{command}",{:mute => true})
FileUtils.chdir(current_dir)
end
View
2  lib/veewee/provider/vmfusion/box/destroy.rb
@@ -9,7 +9,7 @@ def destroy(options={})
end
raw.halt if raw.state=="running"
- ::Fission::VM.delete(name)
+ ::Fission::VM.new(name).delete
# remove it from memory
@raw=nil
end
View
2  lib/veewee/provider/vmfusion/box/export_ova.rb
@@ -41,7 +41,7 @@ def export_ova(options)
# before exporting the system needs to be shut down
# otherwise the debug log will show - The specified virtual disk needs repair
- shell_exec("#{fusion_path.shellescape}/ovftool/ovftool.bin #{debug} #{flags} #{vmx_file_path.shellescape} #{name}.ova")
+ shell_exec("#{File.dirname(vmrun_cmd).shellescape}/ovftool/ovftool.bin #{debug} #{flags} #{vmx_file_path.shellescape} #{name}.ova")
end
end
end
View
24 lib/veewee/provider/vmfusion/box/helper/buildinfo.rb
@@ -5,22 +5,30 @@ module BoxCommand
def build_info
info=super
- command="/Library/Application Support/VMware Fusion/vmrun"
- output=IO.popen("#{command.shellescape}").readlines
+ output=IO.popen("#{vmrun_cmd.shellescape}").readlines
info << {:filename => ".vmfusion_version",:content => output[1].split(/ /)[2..3].join.strip}
+ end
+
+
+ def guest_iso_directory
+ # use vmware fusion 3.x as default path
+ iso_images_dir="/Library/Application Support/VMware Fusion/isoimages"
+ # if path doesn't exist check for vmware fusion 4.x path
+ if( ! File.exists?(iso_images_dir) )
+ iso_images_dir="/Applications/VMware Fusion.app/Contents/Library/isoimages"
+ end
+ return iso_images_dir
end
# Determine the iso of the guest additions
def guest_iso_path
# So we begin by transferring the ISO file of the vmware tools
-
- iso_image="/Library/Application Support/VMware Fusion/isoimages/linux.iso"
- iso_image="/Library/Application Support/VMware Fusion/isoimages/darwin.iso" if definition.os_type_id=~/^Darwin/
- iso_image="/Library/Application Support/VMware Fusion/isoimages/freebsd.iso" if definition.os_type_id=~/^Free/
- iso_image="/Library/Application Support/VMware Fusion/isoimages/windows.iso" if definition.os_type_id=~/^Win/
+ iso_image=File.join(guest_iso_directory, "linux.iso")
+ iso_image=File.join(guest_iso_directory, "darwin.iso") if definition.os_type_id=~/^Darwin/
+ iso_image=File.join(guest_iso_directory, "freebsd.iso") if definition.os_type_id=~/^Free/
+ iso_image=File.join(guest_iso_directory, "windows.iso") if definition.os_type_id=~/^Win/
return iso_image
-
end
# Transfer information provide by the provider to the box
View
51 lib/veewee/provider/vmfusion/box/helper/ip.rb
@@ -3,14 +3,59 @@ module Provider
module Vmfusion
module BoxCommand
- # Get the IP address of the box
+ # Retrieve the first mac address for a vm
+ # This will only retrieve the first auto generate mac address
+ def mac_address
+ raise ::Fission::Error,"VM #{name} does not exist" unless self.exists?
+
+ line=File.new(vmx_file_path).grep(/^ethernet0.generatedAddress =/)
+ if line.nil?
+ #Fission.ui.output "Hmm, the vmx file #{vmx_path} does not contain a generated mac address "
+ return nil
+ end
+ address=line.first.split("=")[1].strip.split(/\"/)[1]
+ return address
+ end
+
+ # Retrieve the ip address for a vm.
+ # This will only look for dynamically assigned ip address via vmware dhcp
def ip_address
- return raw.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?
+
+ unless mac_address.nil?
+ lease = Fission::Lease.all.data.find { |l| l.mac_address=mac_address}
+ return lease.ip_address unless lease.nil?
+ return nil
+ else
+ # No mac address was found for this machine so we can't calculate the ip-address
+ return nil
+ end
end
# http://www.thirdbit.net/articles/2008/03/04/dhcp-on-vmware-fusion/
def host_ip_as_seen_by_guest
- File.open("/Library/Application Support/VMware Fusion/vmnet8/nat.conf").readlines.grep(/ip = /).first.split(" ")[2]
+
+ # if File.exists?("/Library/Application Support/VMware Fusion/vmnet8/nat.conf")
+ # file = "/Library/Application Support/VMware Fusion/vmnet8/nat.conf"
+ # end
+
+ # if File.exists?("/Library/Preferences/VMware Fusion/vmnet8/nat.conf")
+ # file = "/Library/Preferences/VMware Fusion/vmnet8/nat.conf"
+ # end
+ # File.open(file).readlines.grep(/ip = /).first.split(" ")[2]
+
+ # The above is not always correct
+ # There seems also an entry for vmnet8 in the dhcpd.conf
+ # /Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf
+ # host vmnet8 {
+ # fixed-address
+
+ # The above is fancy but doesn't always agree, we need to do is ifconfig vmnet8
+ # Ifconfig never lies
+ shell_results = shell_exec("ifconfig vmnet8", { :mute => true})
+ shell_results.stdout.split(/\n/).grep(/inet /)[0].strip.split(/ /)[1]
end
end
View
4 lib/veewee/provider/vmfusion/box/helper/vnc.rb
@@ -4,7 +4,7 @@ module Vmfusion
module BoxCommand
def vnc_port
- lines=File.readlines(raw.vmx_path)
+ lines=File.readlines(vmx_file_path)
matches=lines.grep(/^RemoteDisplay.vnc.port/)
if matches.length==0
raise Veewee::Error,"No VNC port found, maybe it is not enabled?"
@@ -42,7 +42,7 @@ def vnc_display_port
end
def vnc_enabled?
- lines=File.readlines(raw.vmx_path)
+ lines=File.readlines(vmx_file_path)
matches=lines.grep(/^RemoteDisplay.vnc.enabled/)
if matches.length==0
return false
View
17 lib/veewee/provider/vmfusion/provider.rb