diff --git a/lib/fission.old/cli.rb b/lib/fission.old/cli.rb
new file mode 100644
index 00000000..fac1bd23
--- /dev/null
+++ b/lib/fission.old/cli.rb
@@ -0,0 +1,76 @@
+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
diff --git a/lib/fission.old/command.rb b/lib/fission.old/command.rb
new file mode 100644
index 00000000..76fec57a
--- /dev/null
+++ b/lib/fission.old/command.rb
@@ -0,0 +1,15 @@
+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
diff --git a/lib/fission.old/command/clone.rb b/lib/fission.old/command/clone.rb
new file mode 100644
index 00000000..d69c38f5
--- /dev/null
+++ b/lib/fission.old/command/clone.rb
@@ -0,0 +1,68 @@
+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
diff --git a/lib/fission.old/command/delete.rb b/lib/fission.old/command/delete.rb
new file mode 100644
index 00000000..d692b8a6
--- /dev/null
+++ b/lib/fission.old/command/delete.rb
@@ -0,0 +1,71 @@
+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
diff --git a/lib/fission.old/command/snapshot_create.rb b/lib/fission.old/command/snapshot_create.rb
new file mode 100644
index 00000000..2ec23f06
--- /dev/null
+++ b/lib/fission.old/command/snapshot_create.rb
@@ -0,0 +1,52 @@
+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
diff --git a/lib/fission.old/command/snapshot_list.rb b/lib/fission.old/command/snapshot_list.rb
new file mode 100644
index 00000000..3bc7244e
--- /dev/null
+++ b/lib/fission.old/command/snapshot_list.rb
@@ -0,0 +1,45 @@
+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
diff --git a/lib/fission.old/command/snapshot_revert.rb b/lib/fission.old/command/snapshot_revert.rb
new file mode 100644
index 00000000..31ded2be
--- /dev/null
+++ b/lib/fission.old/command/snapshot_revert.rb
@@ -0,0 +1,54 @@
+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
diff --git a/lib/fission.old/command/start.rb b/lib/fission.old/command/start.rb
new file mode 100644
index 00000000..c611d7b0
--- /dev/null
+++ b/lib/fission.old/command/start.rb
@@ -0,0 +1,69 @@
+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
diff --git a/lib/fission.old/command/status.rb b/lib/fission.old/command/status.rb
new file mode 100644
index 00000000..28565047
--- /dev/null
+++ b/lib/fission.old/command/status.rb
@@ -0,0 +1,31 @@
+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
diff --git a/lib/fission.old/command/stop.rb b/lib/fission.old/command/stop.rb
new file mode 100644
index 00000000..82c480df
--- /dev/null
+++ b/lib/fission.old/command/stop.rb
@@ -0,0 +1,49 @@
+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
diff --git a/lib/fission.old/command/suspend.rb b/lib/fission.old/command/suspend.rb
new file mode 100644
index 00000000..26062fed
--- /dev/null
+++ b/lib/fission.old/command/suspend.rb
@@ -0,0 +1,67 @@
+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
diff --git a/lib/fission.old/config.rb b/lib/fission.old/config.rb
new file mode 100644
index 00000000..45be495e
--- /dev/null
+++ b/lib/fission.old/config.rb
@@ -0,0 +1,34 @@
+module Fission
+ class Config
+ attr_accessor :attributes
+
+ CONF_FILE = File.expand_path '~/.fissionrc'
+
+ def initialize
+ @attributes = {}
+ load_from_file
+
+ if @attributes['vm_dir'].blank?
+ @attributes['vm_dir'] = File.expand_path('~/Documents/Virtual Machines.localized/')
+ end
+
+ if File.exists?('/Library/Application Support/VMware Fusion/vmrun')
+ @attributes['vmrun_bin'] = '/Library/Application Support/VMware Fusion/vmrun'
+ else
+ @attributes['vmrun_bin'] = '/Applications/VMware Fusion.app/Contents/Library/vmrun'
+ end
+
+ @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')
+ end
+
+ private
+ def load_from_file
+ if File.file?(CONF_FILE)
+ @attributes.merge!(YAML.load_file(CONF_FILE))
+ end
+ end
+
+ end
+end
diff --git a/lib/fission.old/core_ext/class.rb b/lib/fission.old/core_ext/class.rb
new file mode 100644
index 00000000..088143d6
--- /dev/null
+++ b/lib/fission.old/core_ext/class.rb
@@ -0,0 +1,5 @@
+class Class
+ def descendants
+ ObjectSpace.each_object(Class).select { |klass| klass < self }
+ end
+end
diff --git a/lib/fission.old/core_ext/file.rb b/lib/fission.old/core_ext/file.rb
new file mode 100644
index 00000000..3b2623f0
--- /dev/null
+++ b/lib/fission.old/core_ext/file.rb
@@ -0,0 +1,7 @@
+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
diff --git a/lib/fission.old/core_ext/object.rb b/lib/fission.old/core_ext/object.rb
new file mode 100644
index 00000000..321ff029
--- /dev/null
+++ b/lib/fission.old/core_ext/object.rb
@@ -0,0 +1,112 @@
+# 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 blank?.
+ def present?
+ !blank?
+ end
+
+ # Returns object if it's present? otherwise returns +nil+.
+ # object.presence is equivalent to object.present? ? object : nil.
+ #
+ # 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
diff --git a/lib/fission.old/error.rb b/lib/fission.old/error.rb
new file mode 100644
index 00000000..b9103535
--- /dev/null
+++ b/lib/fission.old/error.rb
@@ -0,0 +1,9 @@
+module Fission
+ class Error < StandardError
+ attr_reader :orginal
+ def initialize(msg, original=$!)
+ super(msg)
+ @original = original; end
+ end
+end
+
diff --git a/lib/fission.old/fusion.rb b/lib/fission.old/fusion.rb
new file mode 100644
index 00000000..c95178fd
--- /dev/null
+++ b/lib/fission.old/fusion.rb
@@ -0,0 +1,17 @@
+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
diff --git a/lib/fission.old/leasesfile.rb b/lib/fission.old/leasesfile.rb
new file mode 100644
index 00000000..961bbe6f
--- /dev/null
+++ b/lib/fission.old/leasesfile.rb
@@ -0,0 +1,74 @@
+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
diff --git a/lib/fission.old/metadata.rb b/lib/fission.old/metadata.rb
new file mode 100644
index 00000000..7a78d329
--- /dev/null
+++ b/lib/fission.old/metadata.rb
@@ -0,0 +1,39 @@
+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
diff --git a/lib/fission.old/response.rb b/lib/fission.old/response.rb
new file mode 100644
index 00000000..4e055bd5
--- /dev/null
+++ b/lib/fission.old/response.rb
@@ -0,0 +1,16 @@
+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
diff --git a/lib/fission.old/ui.rb b/lib/fission.old/ui.rb
new file mode 100644
index 00000000..1eeabccb
--- /dev/null
+++ b/lib/fission.old/ui.rb
@@ -0,0 +1,22 @@
+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
diff --git a/lib/fission.old/version.rb b/lib/fission.old/version.rb
new file mode 100644
index 00000000..a83f9d63
--- /dev/null
+++ b/lib/fission.old/version.rb
@@ -0,0 +1,3 @@
+module Fission
+ VERSION = "0.4.0a"
+end
diff --git a/lib/fission.old/vm.rb b/lib/fission.old/vm.rb
new file mode 100644
index 00000000..a93cabed
--- /dev/null
+++ b/lib/fission.old/vm.rb
@@ -0,0 +1,370 @@
+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
+ if File.exists?("/Library/Application Support/VMware Fusion/vmrun")
+ return("/Library/Application Support/VMware Fusion/vmrun").shellescape
+ end
+ if File.exists?("/Applications/VMware Fusion.app/Contents/Library/vmrun")
+ return("/Applications/VMware Fusion.app/Contents/Library/vmrun").shellescape
+ end
+ end
+
+ end
+end
diff --git a/lib/veewee/provider/core/box/build.rb b/lib/veewee/provider/core/box/build.rb
index fe37f6ef..5011d5de 100644
--- a/lib/veewee/provider/core/box/build.rb
+++ b/lib/veewee/provider/core/box/build.rb
@@ -301,7 +301,7 @@ def transfer_params(options)
# Iterate over params
params.each do |key,value|
- content += "#{key}='#{value}'\n"
+ content += "export #{key}='#{value}'\n"
end
begin
diff --git a/lib/veewee/provider/core/box/validate_tags.rb b/lib/veewee/provider/core/box/validate_tags.rb
index 50f330da..ed4d7404 100644
--- a/lib/veewee/provider/core/box/validate_tags.rb
+++ b/lib/veewee/provider/core/box/validate_tags.rb
@@ -15,47 +15,154 @@ def validate_tags(tags,options)
exit -1
end
- require 'cucumber'
+ if definition.winrm_user && definition.winrm_password # prefer winrm
+ checks = checks_windows
+ else
+ checks = checks_linux
+ end
- require 'cucumber/rspec/disable_option_parser'
- require 'cucumber/cli/main'
+ # Some reject here based on tags
+ checks.reject! { |c|
+ tagged = false
+ c[:tags].each do |t|
+ tagged = true if tags.include?(t)
+ end
+ ! tagged
+ }
- # Passing ssh options via ENV varialbles to cucumber
- # VEEWEE_SSH_USER, VEEWEE_SSH_PASSWORD ,VEEWEE_SSH_PORT
- cucumber_vars=ssh_options
- cucumber_vars.each do |key,value|
- ENV['VEEWEE_'+key.to_s.upcase]=cucumber_vars[key].to_s
- end
+ # Assume clean exitcode
+ exitcode = 0
- # Pass the name of the box
- ENV['VEEWEE_BOXNAME']=@name
- ENV['VEEWEE_PROVIDER']=@provider.name
+ # Loop over checks
+ checks.each do |check|
+ if check[:sudo]
+ result = check_output_sudorun(check[:command],check[:expected_string])
+ else
+ result = check_output_run(check[:command],check[:expected_string])
+ end
- if definition.winrm_user && definition.winrm_password # prefer winrm
- featurefile="veewee-windows.feature"
- else
- featurefile="veewee.feature"
+ if result[:match]
+ ui.success("#{check[:description]} - OK")
+ else
+ ui.error("#{check[:description]} - FAILED")
+ ui.error("Command: #{check[:command]}")
+ ui.error("Expected string #{check[:expected_string]}")
+ ui.error("Output: #{check[:output]}")
+ exitcode = -1
+ end
end
- feature_path=File.join(definition.env.validation_dir,featurefile)
+ exit -1 if exitcode < 0
+ end
+
+ def check_output_sudorun(command,expected_string)
+ result = { :command => command,
+ :expected_string => expected_string,
+ :output => nil
+ }
+
+ begin
+ self.exec("echo '#{command}' > /tmp/validation.sh && chmod a+x /tmp/validation.sh", :mute => true)
+ sshresult = self.exec(self.sudo("/tmp/validation.sh"),:mute => true)
+
+ result[:output] = sshresult.stdout
+ result[:match] = ! sshresult.stdout.match(/#{expected_string}/).nil?
+ rescue
+ result[:match] = false
+ end
+ return result
+ end
- features=Array.new
- features[0]=feature_path
- features << "--tags"
- features << tags.map {|t| "@#{t}"}.join(',')
+ def check_output_run(command,expected_string)
+ result = { :command => command,
+ :expected_string => expected_string,
+ :output => nil
+ }
begin
- # The dup is to keep ARGV intact, so that tools like ruby-debug can respawn.
- failure = Cucumber::Cli::Main.execute(features.dup)
- Kernel.exit(failure ? 1 : 0)
- rescue SystemExit => e
- Kernel.exit(e.status)
- rescue Exception => e
- ui.error("#{e.message} (#{e.class})")
- ui.error(e.backtrace.join("\n"))
- Kernel.exit(1)
+ sshresult = self.exec(command, {:exitcode => '*',:mute => true})
+ result[:output] = sshresult.stdout
+ result[:match] = ! sshresult.stdout.match(/#{expected_string}/).nil?
+ rescue
+ result[:match] = false
end
+ return result
+ end
+
+ def checks_linux
+ return [
+ { :description => 'Checking user',
+ :tags => [ 'virtualbox','kvm', 'parallels'],
+ :command => 'who am i',
+ :expected_string => definition.ssh_user,
+ :sudo => false
+ },
+ { :description => 'Checking sudo',
+ :tags => [ 'virtualbox','kvm', 'parallels'],
+ :command => 'whoami',
+ :expected_string => 'root',
+ :sudo => true
+ },
+ { :description => 'Checking ruby',
+ :tags => [ 'virtualbox','kvm', 'parallels','ruby'],
+ :command => '. /etc/profile ;ruby --version 2> /dev/null 1> /dev/null; echo $?',
+ :expected_string => "0",
+ :sudo => false
+ },
+ { :description => 'Checking gem',
+ :tags => [ 'virtualbox','kvm', 'parallels','gem'],
+ :command => '. /etc/profile ;gem --version 2> /dev/null 1> /dev/null; echo $?',
+ :expected_string => "0",
+ :sudo => false
+ },
+ { :description => 'Checking chef',
+ :tags => [ 'chef'],
+ :command => '. /etc/profile ;chef-client --version 2> /dev/null 1>/dev/null; echo $?',
+ :expected_string => "0",
+ :sudo => false
+ },
+ { :description => 'Checking puppet',
+ :tags => [ 'puppet'],
+ :command => '. /etc/profile ;puppet --version 2> /dev/null 1>/dev/null; echo $?',
+ :expected_string => "0",
+ :sudo => false
+ },
+ { :description => 'Checking shared folder',
+ :tags => [ 'vagrant'],
+ :command => 'mount|grep veewee-validation',
+ :expected_string => "0",
+ :sudo => false
+ }
+ ]
+ end
+ def checks_windows
+ return [
+ { :description => 'Checking user',
+ :tags => [ 'virtualbox','kvm','vmfusion'],
+ :command => 'whoami',
+ :expected_string => definition.ssh_user,
+ :sudo => false
+ },
+ { :description => 'Checking ruby',
+ :tags => [ 'virtualbox','kvm','vmfusion'],
+ :command => 'ruby --version > %TEMP%\devnull && echo %ERRORLEVEL%',
+ :expected_string => "0",
+ :sudo => false
+ },
+ { :description => 'Checking gem',
+ :tags => [ 'virtualbox','kvm','vmfusion'],
+ :command => 'gem --version > %TEMP%\devnull && echo %ERRORLEVEL%',
+ :expected_string => "0",
+ :sudo => false
+ },
+ { :description => 'Checking chef',
+ :tags => [ 'chef'],
+ :command => 'chef-client --version > %TEMP%\devnull && echo %ERRORLEVEL%',
+ :expected_string => "0",
+ :sudo => false
+ },
+ ]
end
end #Module
diff --git a/lib/veewee/provider/core/helper/ssh.rb b/lib/veewee/provider/core/helper/ssh.rb
index 7ea1ba67..314a6cd4 100644
--- a/lib/veewee/provider/core/helper/ssh.rb
+++ b/lib/veewee/provider/core/helper/ssh.rb
@@ -25,20 +25,24 @@ def when_ssh_login_works(ip="127.0.0.1", options = { } , &block)
defaults={ :port => '22', :timeout => 20000 }
options=defaults.merge(options)
+
timeout = options[:timeout]
timeout=ENV['VEEWEE_TIMEOUT'].to_i unless ENV['VEEWEE_TIMEOUT'].nil?
+ unless options[:mute]
ui.info "Waiting for ssh login on #{ip} with user #{options[:user]} to sshd on port => #{options[:port]} to work, timeout=#{timeout} sec"
+ end
+
begin
Timeout::timeout(timeout) do
connected=false
while !connected do
begin
- env.ui.info ".",{:new_line => false , :prefix => false}
+ env.ui.info ".",{:new_line => false , :prefix => false} unless options[:mute]
Net::SSH.start(ip, options[:user], { :port => options[:port] , :password => options[:password], :paranoid => false , :timeout => timeout }) do |ssh|
- ui.info "\n", {:prefix => false}
+ ui.info "\n", {:prefix => false} unless options[:mute]
block.call(ip);
return true
end
@@ -83,7 +87,9 @@ def ssh_execute(host,command, options = { :progress => "on"} )
stderr=""
status=-99999
- ui.info "Executing command: #{command}"
+ unless options[:mute]
+ ui.info "Executing command: #{command}"
+ end
Net::SSH.start(host, options[:user], { :port => options[:port], :password => options[:password], :paranoid => false }) do |ssh|
@@ -104,7 +110,7 @@ def ssh_execute(host,command, options = { :progress => "on"} )
ch.on_data do |c, data|
stdout+=data
- ui.info data
+ ui.info data unless options[:mute]
end
@@ -113,7 +119,7 @@ def ssh_execute(host,command, options = { :progress => "on"} )
ch.on_extended_data do |c, type, data|
stderr+=data
- ui.info data
+ ui.info data unless options[:mute]
end
@@ -123,14 +129,14 @@ def ssh_execute(host,command, options = { :progress => "on"} )
exit_code = data.read_long
status=exit_code
if exit_code > 0
- ui.info "ERROR: exit code #{exit_code}"
+ ui.info "ERROR: exit code #{exit_code}" unless options[:mute]
else
#ui.info "Successfully executed"
end
end
channel.on_request("exit-signal") do |ch, data|
- ui.info "SIGNAL: #{data.read_long}"
+ ui.info "SIGNAL: #{data.read_long}" unless options[:mute]
end
ch.on_close {
diff --git a/validation/features/steps/ssh_steps.old b/validation/features/steps/ssh_steps.old
deleted file mode 100644
index 19c3d443..00000000
--- a/validation/features/steps/ssh_steps.old
+++ /dev/null
@@ -1,170 +0,0 @@
-# http://stackoverflow.com/questions/216202/why-does-an-ssh-remote-command-get-fewer-environment-variables-then-when-run-manu
-
-Given /^I have no public keys set$/ do
- @auth_methods = %w(password)
-end
-
-Then /^I can ssh to "([^\"]*)" with the following credentials:$/ do |host, table|
- @auth_methods ||= %w(publickey password)
-
- credentials = table.hashes
- credentials.each do |creds|
- lambda {
- Net::SSH.start(host, creds["username"], :password => creds["password"], :auth_methods => @auth_methods)
- }.should_not raise_error(Net::SSH::AuthenticationFailed)
- end
-end
-
-Then /^I can ssh to the following hosts with these credentials:$/ do |table|
- @keys ||= []
- @auth_methods ||= %w(password)
- environment_details = table.hashes
-
- environment_details.each do |environment|
- # initialize a list of keys and auth methods for just this environment, as
- # environment can have environment-specific keys mixed with global keys
- environment_keys = Array.new(@keys)
- environment_auth_methods = Array.new(@auth_methods)
-
- # you can pass in a keyfile in the environment details, so we need to
- if environment["keyfile"]
- environment_keys << environment["keyfile"]
- environment_auth_methods << "publickey"
- end
-
- lambda {
- Net::SSH.start(environment["hostname"], environment["username"], :password => environment["password"],
- :auth_methods => environment_auth_methods,
- :keys => environment_keys)
- }.should_not raise_error(Net::SSH::AuthenticationFailed)
- end
-end
-
-Given /^I have the following public keys:$/ do |table|
- @keys = []
- public_key_paths = table.hashes
-
- public_key_paths.each do |key|
- File.exist?(key["keyfile"]).should be_true
- @keys << key["keyfile"]
- end
-
- @auth_methods ||= %w(password)
- @auth_methods << "publickey"
-end
-
-When /^I ssh to "([^\"]*)" with the following credentials:$/ do |hostname, table|
- @keys = []
- @auth_methods ||= %w(password)
- environment = table.hashes.first
- environment_keys = Array.new(@keys)
- environment_auth_methods = Array.new(@auth_methods)
- if environment["keyfile"]
- environment_keys << environment["keyfile"]
- environment_auth_methods << "publickey"
- end
- environment_port=ENV['VEEWEE_SSH_PORT'] || 7222
- if environment["port"]
- environment_port=environment["port"]
- end
-
-
- lambda {
- # This is the list of authorization methods to try. It defaults to “publickey”, “hostbased”, “password”, and “keyboard-interactive”. (These are also the only authorization methods that are supported.) If
- # http://net-ssh.rubyforge.org/ssh/v1/chapter-2.html
- key_auth_tried = false
- ssh_options = {:password => environment["password"], :auth_methods => environment_auth_methods, :port => environment_port, :keys => environment_keys}
- # ssh_options[:verbose] => :debug
- begin
- print "."
- @connection = Net::SSH.start(environment["hostname"], environment["username"], ssh_options)
- rescue Net::SSH::AuthenticationFailed
- ssh_options[:keys] = Array.new([File.join(File.dirname(__FILE__),'./../../vagrant')])
- ssh_options.delete(:password)
- ssh_options[:auth_methods] = ['publickey']
- if key_auth_tried
- raise
- else
- key_auth_tried = true
- retry
- end
- rescue Net::SSH::Disconnect, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNABORTED, Errno::ECONNRESET, Errno::ENETUNREACH
- sleep 5
- end
- }.should_not raise_error
-end
-
-#
-When /^I run "([^\"]*)"$/ do |command|
- @stdout=nil
- @stderr=nil
- @status=-9999
- channel = @connection.open_channel do |ch|
- ch.request_pty do |ch, success|
- if success
- # puts "pty successfully obtained"
- else
- # puts "could not obtain pty"
- end
- end
- ch.exec "#{command}" do |ch, success|
- raise "could not execute command" unless success
-
- # "on_data" is called when the process writes something to stdout
- ch.on_data do |c, data|
- if @stdout.nil?
- @stdout=data
- else
- @stdout+=data
- end
- end
-
- # "on_extended_data" is called when the process writes something to stderr
- ch.on_extended_data do |c, type, data|
- if @stderr.nil?
- @stderr=data
- else
- @stderr+=data
- end
- end
-
- #exit code
- #http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/a806b0f5dae4e1e2
- channel.on_request("exit-status") do |ch, data|
- exit_code = data.read_long
- @status=exit_code
- end
-
- channel.on_request("exit-signal") do |ch, data|
- puts "SIGNAL: #{data.read_long}"
- end
-
- ch.on_close {
- puts "done!"
- }
- end
- end
- channel.wait
- if !@stdout.nil?
- if @output.nil?
- @output=""
- end
- @output=@output+@stdout
- end
- if !@stderr.nil?
-
- if @output.nil?
- @output=""
- end
- @output=@output+@stderr
- end
- puts @output
-
- #@output = @connection.exec!(command)
-
-end
-
-Then /^I should see "([^\"]*)" in the output$/ do |string|
- @output.should =~ /#{string}/
-end
-
diff --git a/validation/features/steps/veewee_steps.rb b/validation/features/steps/veewee_steps.rb
deleted file mode 100644
index 7e1b05f9..00000000
--- a/validation/features/steps/veewee_steps.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# http://stackoverflow.com/questions/216202/why-does-an-ssh-remote-command-get-fewer-environment-variables-then-when-run-manu
-
-Given /^a veeweebox was build$/ do
- @environment=Veewee::Environment.new()
- @provider_name=ENV['VEEWEE_PROVIDER']
- @definition_name=ENV['VEEWEE_BOXNAME']
- @box_name=ENV['VEEWEE_BOXNAME']
- @box=@environment.providers[@provider_name].get_box(@box_name)
-end
-
-When /^I sudorun "([^\"]*)" over ssh$/ do |command|
- @box.exec("echo '#{command}' > /tmp/validation.sh && chmod a+x /tmp/validation.sh")
- @sshresult=@box.exec(@box.sudo("/tmp/validation.sh"))
-end
-
-When /^I run "([^\"]*)" over ssh$/ do |command|
- @sshresult=@box.exec(command, {:exitcode => '*'})
-end
-
-Then /^I should see the provided username in the output$/ do
- @sshresult.stdout.should =~ /#{ENV["VEEWEE_SSH_USER"]}/
-end
-
-Then /^I should see "([^\"]*)" in the output$/ do |string|
- @sshresult.stdout.should =~ /#{string}/
-end
-
diff --git a/validation/support/env.rb b/validation/support/env.rb
deleted file mode 100644
index 768c768a..00000000
--- a/validation/support/env.rb
+++ /dev/null
@@ -1 +0,0 @@
-require 'net/ssh'
diff --git a/validation/veewee-windows.feature b/validation/veewee-windows.feature
deleted file mode 100644
index c671983a..00000000
--- a/validation/veewee-windows.feature
+++ /dev/null
@@ -1,34 +0,0 @@
-Feature: veewee box validation
- As a valid veewee box
- I need to comply to a set of rules
- In order to make sure it works on Windows with Winrm
-
- @vmfusion @virtualbox @kvm
- Scenario: Valid definition
- Given a veeweebox was build
- And I run "whoami" over ssh
- Then I should see the provided username in the output
-
- @vmfusion @virtualbox @kvm
- Scenario: Checking ruby
- Given a veeweebox was build
- And I run "ruby --version > %TEMP%\devnull && echo %ERRORLEVEL%" over ssh
- Then I should see "0" in the output
-
- @vmfusion @virtualbox @kvm
- Scenario: Checking gem
- Given a veeweebox was build
- And I run "gem --version > %TEMP%\devnull && echo %ERRORLEVEL%" over ssh
- Then I should see "0" in the output
-
- @vmfusion @virtualbox @kvm
- Scenario: Checking chef
- Given a veeweebox was build
- And I run "chef-client --version > %TEMP%\devnull && echo %ERRORLEVEL%" over ssh
- Then I should see "0" in the output
-
- @vagrant
- Scenario: Checking shared folders
- Given a veeweebox was build
- And I run "net use|grep veewee-validation" over ssh
- Then I should see "veewee-validation" in the output
diff --git a/validation/veewee.feature b/validation/veewee.feature
deleted file mode 100644
index 9fdc2d83..00000000
--- a/validation/veewee.feature
+++ /dev/null
@@ -1,45 +0,0 @@
-Feature: veewee box validation
- As a valid veewee box
- I need to comply to a set of rules
-
- @vmfusion @virtualbox @kvm @parallels
- Scenario: Valid definition
- Given a veeweebox was build
- And I run "whoami" over ssh
- Then I should see the provided username in the output
-
- @vmfusion @virtualbox @kvm @parallels
- Scenario: Checking sudo
- Given a veeweebox was build
- And I sudorun "whoami" over ssh
- Then I should see "root" in the output
-
- @vmfusion @virtualbox @kvm @parallels
- Scenario: Checking ruby
- Given a veeweebox was build
- And I run ". /etc/profile ;ruby --version 2> /dev/null 1> /dev/null; echo $?" over ssh
- Then I should see "0" in the output
-
- @vmfusion @virtualbox @kvm @parallels
- Scenario: Checking gem
- Given a veeweebox was build
- And I run ". /etc/profile; gem --version 2> /dev/null 1> /dev/null ; echo $?" over ssh
- Then I should see "0" in the output
-
- @chef
- Scenario: Checking chef
- Given a veeweebox was build
- And I run ". /etc/profile ;chef-client --version 2> /dev/null 1>/dev/null; echo $?" over ssh
- Then I should see "0" in the output
-
- @puppet
- Scenario: Checking puppet
- Given a veeweebox was build
- And I run ". /etc/profile ; puppet --version 2> /dev/null 1>/dev/null; echo $?" over ssh
- Then I should see "0" in the output
-
- @vagrant
- Scenario: Checking shared folders
- Given a veeweebox was build
- And I run "mount|grep veewee-validation" over ssh
- Then I should see "veewee-validation" in the output
diff --git a/veewee.gemspec b/veewee.gemspec
index 9195b997..67346639 100644
--- a/veewee.gemspec
+++ b/veewee.gemspec
@@ -14,7 +14,6 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "veewee"
- s.add_dependency "vagrant", ">= 0.9"
# Currently locked to 2.2.0
# if specifying to >= 2.2.0 it would use 2.3 and bundler would go in a resolver loop
@@ -26,7 +25,7 @@ Gem::Specification.new do |s|
s.add_dependency "highline"
s.add_dependency "progressbar"
s.add_dependency "i18n"
- s.add_dependency "cucumber", ">=1.0.0"
+ #s.add_dependency "cucumber", ">=1.0.0"
s.add_dependency "ansi", "~> 1.3.0"
s.add_dependency "ruby-vnc", "~> 1.0.0"
s.add_dependency "fog", "~> 1.8"
@@ -39,7 +38,7 @@ Gem::Specification.new do |s|
# 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"
+ s.add_development_dependency "rspec", "~> 2.5"
s.add_development_dependency "bundler", ">= 1.0.0"
#s.add_development_dependency('ruby-libvirt','~>0.4.0')