Skip to content
Browse files

Remove unnecessary virtualbox dependency

  • Loading branch information...
1 parent a31d823 commit 5d7ddef0331474922938e9fad659a01d5d8f5558 @matschaffer committed
Showing with 0 additions and 92 deletions.
  1. +0 −4 Gemfile.lock
  2. +0 −1 knife-solo.gemspec
  3. +0 −87 virtualbox_ext.rb
View
4 Gemfile.lock
@@ -47,7 +47,6 @@ GEM
fancy_irb (0.6.5)
unicode-display_width (>= 0.1.1)
wirb (>= 0.2.4)
- ffi (1.0.9)
fog (1.0.0)
builder
excon (~> 0.7.3)
@@ -144,8 +143,6 @@ GEM
polyglot (>= 0.3.1)
unicode-display_width (0.1.1)
uuidtools (2.1.2)
- virtualbox (0.8.6)
- ffi (~> 1.0)
wirb (0.3.0)
yajl-ruby (1.1.0)
zucker (11)
@@ -164,4 +161,3 @@ DEPENDENCIES
pry
rake
ruby-debug
- virtualbox
View
1 knife-solo.gemspec
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rake'
s.add_development_dependency 'mocha'
- s.add_development_dependency 'virtualbox'
s.add_dependency 'chef', '~> 0.10.0'
s.add_dependency 'net-ssh', '~> 2.1.3'
View
87 virtualbox_ext.rb
@@ -1,87 +0,0 @@
-require 'virtualbox'
-
-class VirtualBox::VM
- def find_first_interface(type)
- network_adapters.detect { |a| a.attachment_type == type }
- end
-
- def find_usable_interface
- host_only = find_first_interface(:host_only)
- return host_only.slot if host_only
-
- bridged = find_first_interface(:bridged)
- return bridged.slot if bridged
-
- raise "VM does not have any Host-only or bridged interfaces"
- end
-
- def get_ip_address
- slot = find_usable_interface
- interface.get_guest_property_value("/VirtualBox/GuestInfo/Net/#{slot}/V4/IP")
- end
-
- def ip_address
- sleep 1 while get_ip_address.empty?
- get_ip_address
- end
-end
-
-module VirtualBox
- extend Rake::DSL
-
- def self.define_rake_tasks(options)
- run_mode = options[:run_mode] || :gui
- image = options[:image]
- hosts = options[:hosts]
-
- namespace :virtualbox do
- desc 'Imports virtualbox images for each host'
- task :import do
- hosts.each do |type, host|
- next if host[:vm] = VirtualBox::VM.find(host[:name])
- host[:vm] = VirtualBox::VM.import(image) do |progress|
- print "Importing #{host[:name]}: #{progress.percent}%\r"
- end
- puts "Importing #{host[:name]}: 100%"
- host[:vm].name = host[:name]
- host[:vm].network_adapters.each { |a| a.mac_address = nil }
- host[:vm].save
- end
- end
-
- desc 'Starts the virtualbox hosts'
- task :start => :import do
- hosts.each do |type, host|
- host[:vm].start(run_mode)
- end
- end
-
- desc 'Show IP addresses for the virtualbox hosts'
- task :info => :start do
- hosts.each do |type, host|
- puts "#{type.capitalize}: #{host[:vm].ip_address}"
- end
- end
-
- desc 'Stops the virtualbox hosts'
- task :stop do
- hosts.each do |type, host|
- host[:vm] = VirtualBox::VM.find(host[:name])
- host[:vm].shutdown if host[:vm].running?
- end
- end
-
- desc 'Destroys the virtualbox hosts'
- task :destroy => :stop do
- hosts.each do |type, host|
- while host[:vm].running?
- sleep 1
- host[:vm].reload
- end
- sleep 1 # One more sleep incase it's not _really_ stopped
- host[:vm].destroy(:destroy_medium => true)
- end
- end
- end
- end
-end

0 comments on commit 5d7ddef

Please sign in to comment.
Something went wrong with that request. Please try again.