Skip to content
This repository
Browse code

working vmfusion 0.4 support, 1 monkey patch but now relying on plain…

… fission 0.4.0
  • Loading branch information...
commit ac7964c530ff0d59d166c238655cf3e8182b98a3 1 parent 88a79f5
Patrick Debois authored August 05, 2012

Showing 36 changed files with 140 additions and 1,307 deletions. Show diff stats Hide diff stats

  1. 2  Gemfile
  2. 4  doc/definition.md
  3. 8  lib/fission.rb
  4. 76  lib/fission/cli.rb
  5. 15  lib/fission/command.rb
  6. 68  lib/fission/command/clone.rb
  7. 71  lib/fission/command/delete.rb
  8. 52  lib/fission/command/snapshot_create.rb
  9. 45  lib/fission/command/snapshot_list.rb
  10. 54  lib/fission/command/snapshot_revert.rb
  11. 69  lib/fission/command/start.rb
  12. 31  lib/fission/command/status.rb
  13. 49  lib/fission/command/stop.rb
  14. 67  lib/fission/command/suspend.rb
  15. 57  lib/fission/config.rb
  16. 5  lib/fission/core_ext/class.rb
  17. 7  lib/fission/core_ext/file.rb
  18. 112  lib/fission/core_ext/object.rb
  19. 9  lib/fission/error.rb
  20. 17  lib/fission/fusion.rb
  21. 74  lib/fission/leasesfile.rb
  22. 39  lib/fission/metadata.rb
  23. 16  lib/fission/response.rb
  24. 22  lib/fission/ui.rb
  25. 3  lib/fission/version.rb
  26. 365  lib/fission/vm.rb
  27. 7  lib/veewee/definitions.rb
  28. 14  lib/veewee/provider/vmfusion/box.rb
  29. 2  lib/veewee/provider/vmfusion/box/create.rb
  30. 2  lib/veewee/provider/vmfusion/box/destroy.rb
  31. 2  lib/veewee/provider/vmfusion/box/export_ova.rb
  32. 24  lib/veewee/provider/vmfusion/box/helper/buildinfo.rb
  33. 51  lib/veewee/provider/vmfusion/box/helper/ip.rb
  34. 4  lib/veewee/provider/vmfusion/box/helper/vnc.rb
  35. 3  lib/veewee/provider/vmfusion/provider.rb
  36. 1  veewee.gemspec
2  Gemfile
@@ -6,7 +6,7 @@
6 6
 source "http://rubygems.org"
7 7
 
8 8
 #gem "veewee", :path => "."
9  
-gem "fission", :path => '/Users/patrick/dev/fission'
  9
+#gem "fission", :path => '/Users/patrick/dev/fission'
10 10
 
11 11
 group :test do
12 12
   gem "rake"
4  doc/definition.md
Source Rendered
@@ -7,6 +7,10 @@ To create a definition you use the 'define' subcommand:
7 7
 
8 8
     veewee vbox define 'myubuntu' 'ubuntu-10.10-server-amd64'
9 9
 
  10
+If you want to use an external repo for the definition you can specify a git-url
  11
+
  12
+    veewee vbox define 'myubuntu' 'git://github.com/jedi4ever/myubuntu'
  13
+
10 14
 ## Modifying a definition
11 15
 Definitions are stored under a directory 'definitions' relative to the current directory.
12 16
 
8  lib/fission.rb
@@ -5,9 +5,10 @@
5 5
 
6 6
 $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
7 7
 
8  
-require 'fission/error'
  8
+#require 'fission/error'
9 9
 require 'fission/cli'
10 10
 require 'fission/command'
  11
+require 'fission/command_helpers'
11 12
 require 'fission/command/clone'
12 13
 require 'fission/command/snapshot_create'
13 14
 require 'fission/command/snapshot_list'
@@ -16,12 +17,12 @@
16 17
 require 'fission/command/status'
17 18
 require 'fission/command/stop'
18 19
 require 'fission/command/suspend'
19  
-require 'fission/command/delete'
20 20
 require 'fission/config'
21 21
 require 'fission/core_ext/class'
22 22
 require 'fission/core_ext/file'
23 23
 require 'fission/core_ext/object'
24 24
 require 'fission/fusion'
  25
+require 'fission/lease'
25 26
 require 'fission/metadata'
26 27
 require 'fission/response'
27 28
 require 'fission/ui'
@@ -35,7 +36,4 @@ def config
35 36
     @config ||= Fission::Config.new
36 37
   end
37 38
 
38  
-  def ui
39  
-    @ui ||= Fission::UI.new
40  
-  end
41 39
 end
76  lib/fission/cli.rb
... ...
@@ -1,76 +0,0 @@
1  
-module Fission
2  
-  class CLI
3  
-    def self.execute(args=ARGV)
4  
-      optparse = OptionParser.new do |opts|
5  
-        opts.banner = "\nUsage: fission [options] COMMAND [arguments]"
6  
-
7  
-        opts.on_head('-v', '--version', 'Output the version of fission') do
8  
-          Fission.ui.output Fission::VERSION
9  
-          exit(0)
10  
-        end
11  
-
12  
-        opts.on_head('-h', '--help', 'Displays this message') do
13  
-          show_all_help(optparse)
14  
-          exit(0)
15  
-        end
16  
-
17  
-        opts.define_tail do
18  
-          commands_banner
19  
-        end
20  
-
21  
-      end
22  
-
23  
-      begin
24  
-        optparse.order! args
25  
-      rescue OptionParser::InvalidOption => e
26  
-        Fission.ui.output e
27  
-        show_all_help(optparse)
28  
-        exit(1)
29  
-      end
30  
-
31  
-      if commands.include?(args.first)
32  
-        @cmd = Fission::Command.const_get(args.first.capitalize).new args.drop 1
33  
-      elsif is_snapshot_command?(args)
34  
-        klass = args.take(2).map {|c| c.capitalize}.join('')
35  
-        @cmd = Fission::Command.const_get(klass).new args.drop 2
36  
-      else
37  
-        show_all_help(optparse)
38  
-        exit(1)
39  
-      end
40  
-
41  
-      begin
42  
-        @cmd.execute
43  
-      rescue Error => e
44  
-         puts "Error: #{e}"
45  
-      end
46  
-    end
47  
-
48  
-    def self.commands
49  
-      cmds = Dir.entries(File.join(File.dirname(__FILE__), 'command')).select do |file|
50  
-        !File.directory? file
51  
-      end
52  
-
53  
-      cmds.map { |cmd| File.basename(cmd, '.rb').gsub '_', ' ' }
54  
-    end
55  
-
56  
-    private
57  
-    def self.is_snapshot_command?(args)
58  
-      args.first == 'snapshot' && args.count > 1 && commands.include?(args.take(2).join(' '))
59  
-    end
60  
-
61  
-    def self.commands_banner
62  
-      text = "\nCommands:\n"
63  
-      Fission::Command.descendants.each do |command_klass|
64  
-        text << (command_klass.send :help)
65  
-      end
66  
-
67  
-      text
68  
-    end
69  
-
70  
-    def self.show_all_help(options)
71  
-      Fission.ui.output options
72  
-      Fission.ui.output commands_banner
73  
-    end
74  
-
75  
-  end
76  
-end
15  lib/fission/command.rb
... ...
@@ -1,15 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    attr_reader :options, :args
4  
-
5  
-    def initialize(args=[])
6  
-      @options = OpenStruct.new
7  
-      @args = args
8  
-    end
9  
-
10  
-    def self.help
11  
-      self.new.option_parser.to_s
12  
-    end
13  
-
14  
-  end
15  
-end
68  lib/fission/command/clone.rb
... ...
@@ -1,68 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    class Clone < Command
4  
-
5  
-      def initialize(args=[])
6  
-        super
7  
-        @options.start = false
8  
-      end
9  
-
10  
-      def execute
11  
-        option_parser.parse! @args
12  
-
13  
-        unless @args.count > 1
14  
-          Fission.ui.output self.class.help
15  
-          Fission.ui.output ""
16  
-          Fission.ui.output_and_exit "Incorrect arguments for clone command", 1
17  
-        end
18  
-
19  
-        source_vm_name = @args.first
20  
-        target_vm_name = @args[1]
21  
-        source_vm=Fission::VM.new(source_vm_name)
22  
-        target_vm=Fission::VM.new(target_vm_name)
23  
-
24  
-        unless source_vm.exists?
25  
-            Fission.ui.output_and_exit "Unable to find the source vm #{source_vm_name} (#{source_vm.path})", 1
26  
-        end
27  
-
28  
-        if target_vm.exists?
29  
-            Fission::ui.output_and_exit "The target vm #{target_vm_name} already exists", 1
30  
-        end
31  
-
32  
-        clone_task = Fission::VM.clone source_vm_name, target_vm_name
33  
-
34  
-        if clone_task.successful?
35  
-          Fission.ui.output ''
36  
-          Fission.ui.output 'Clone complete!'
37  
-
38  
-          if @options.start
39  
-            Fission.ui.output "Starting '#{target_vm_name}'"
40  
-
41  
-            start_task = target_vm.start
42  
-
43  
-            if start_task.successful?
44  
-              Fission.ui.output "VM '#{target_vm_name}' started"
45  
-            else
46  
-              Fission.ui.output_and_exit "There was an error starting the VM.  The error was:\n#{start_task.output}", start_task.code
47  
-            end
48  
-          end
49  
-        else
50  
-          Fission.ui.output_and_exit "There was an error cloning the VM.  The error was:\n#{clone_task.output}", clone_task.code
51  
-        end
52  
-      end
53  
-
54  
-      def option_parser
55  
-        optparse = OptionParser.new do |opts|
56  
-          opts.banner = "\nclone usage: fission clone source_vm target_vm [options]"
57  
-
58  
-          opts.on '--start', 'Start the VM after cloning' do
59  
-            @options.start = true
60  
-          end
61  
-        end
62  
-
63  
-        optparse
64  
-      end
65  
-
66  
-    end
67  
-  end
68  
-end
71  lib/fission/command/delete.rb
... ...
@@ -1,71 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    class Delete < Command
4  
-
5  
-      def initialize(args=[])
6  
-        super
7  
-        @options.force = false
8  
-      end
9  
-
10  
-      def execute
11  
-        option_parser.parse! @args
12  
-
13  
-        if @args.count < 1
14  
-          Fission.ui.output self.class.help
15  
-          Fission.ui.output ""
16  
-          Fission.ui.output_and_exit "Incorrect arguments for delete command", 1
17  
-        end
18  
-
19  
-        target_vm_name = @args.first
20  
-        target_vm=Fission::VM.new(target_vm_name)
21  
-        unless target_vm.exists?
22  
-          Fission.ui.output_and_exit "Vm #{target_vm_name} does not exist at (#{target_vm.path})", 1
23  
-        end
24  
-
25  
-        if target_vm.running?
26  
-          Fission.ui.output 'VM is currently running'
27  
-          if @options.force
28  
-            Fission.ui.output 'Going to stop it'
29  
-            Fission::Command::Stop.new([target_vm_name]).execute
30  
-          else
31  
-            Fission.ui.output_and_exit "Either stop/suspend the VM or use '--force' and try again.", 1
32  
-          end
33  
-        end
34  
-
35  
-
36  
-        if Fission::Fusion.running?
37  
-          Fission.ui.output 'It looks like the Fusion GUI is currently running'
38  
-
39  
-          if @options.force
40  
-            Fission.ui.output 'The Fusion metadata for the VM may not be removed completely'
41  
-          else
42  
-            Fission.ui.output "Either exit the Fusion GUI or use '--force' and try again"
43  
-            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
44  
-          end
45  
-        end
46  
-
47  
-        delete_task = Fission::VM.delete target_vm_name
48  
-
49  
-        if delete_task.successful?
50  
-          Fission.ui.output ''
51  
-          Fission.ui.output "Deletion complete!"
52  
-        else
53  
-          Fission.ui.output_and_exit "There was an error deleting the VM.  The error was:\n#{delete_task.output}", delete_task.code
54  
-        end
55  
-      end
56  
-
57  
-      def option_parser
58  
-        optparse = OptionParser.new do |opts|
59  
-          opts.banner = "\ndelete usage: fission delete target_vm [--force]"
60  
-
61  
-          opts.on '--force', "Stop the VM if it's running and then delete it" do
62  
-            @options.force = true
63  
-          end
64  
-        end
65  
-
66  
-        optparse
67  
-      end
68  
-
69  
-    end
70  
-  end
71  
-end
52  lib/fission/command/snapshot_create.rb
... ...
@@ -1,52 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    class SnapshotCreate < Command
4  
-
5  
-      def initialize(args=[])
6  
-        super
7  
-      end
8  
-
9  
-      def execute
10  
-        unless @args.count == 2
11  
-          Fission.ui.output self.class.help
12  
-          Fission.ui.output ""
13  
-          Fission.ui.output_and_exit "Incorrect arguments for snapshot create command", 1
14  
-        end
15  
-
16  
-        vm_name, snap_name = @args.take 2
17  
-
18  
-        vm = Fission::VM.new vm_name
19  
-        unless vm.exists?
20  
-          Fission.ui.output_and_exit "Unable to find the VM #{vm_name} (#{Fission::VM.path(vm_name)})", 1 
21  
-        end
22  
-
23  
-        unless vm.running?
24  
-          Fission.ui.output "VM '#{vm_name}' is not running"
25  
-          Fission.ui.output_and_exit 'A snapshot cannot be created unless the VM is running', 1
26  
-        end
27  
-
28  
-        if vm.snapshots.include? snap_name
29  
-          Fission.ui.output_and_exit "VM '#{vm_name}' already has a snapshot named '#{snap_name}'", 1
30  
-        end
31  
-
32  
-        Fission.ui.output "Creating snapshot"
33  
-        task = vm.create_snapshot(snap_name)
34  
-
35  
-        if task.successful?
36  
-          Fission.ui.output "Snapshot '#{snap_name}' created"
37  
-        else
38  
-          Fission.ui.output_and_exit "There was an error creating the snapshot.  The error was:\n#{task.output}", task.code
39  
-        end
40  
-      end
41  
-
42  
-      def option_parser
43  
-        optparse = OptionParser.new do |opts|
44  
-          opts.banner = "\nsnapshot create: fission snapshot create my_vm snapshot_1"
45  
-        end
46  
-
47  
-        optparse
48  
-      end
49  
-
50  
-    end
51  
-  end
52  
-end
45  lib/fission/command/snapshot_list.rb
... ...
@@ -1,45 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    class SnapshotList < Command
4  
-
5  
-      def initialize(args=[])
6  
-        super
7  
-      end
8  
-
9  
-      def execute
10  
-        unless @args.count == 1
11  
-          Fission.ui.output self.class.help
12  
-          Fission.ui.output ""
13  
-          Fission.ui.output_and_exit "Incorrect arguments for snapshot list command", 1
14  
-        end
15  
-
16  
-        vm_name = @args.first
17  
-
18  
-        vm = Fission::VM.new vm_name
19  
-
20  
-        unless vm.exists? 
21  
-          Fission.ui.output_and_exit "Unable to find the VM #{vm_name} (#{vm.path})", 1 
22  
-        end
23  
-
24  
-        snaps=vm.snapshots
25  
-        unless snaps.empty?
26  
-            Fission.ui.output snaps.join("\n")
27  
-        else
28  
-          Fission.ui.output "No snapshots found for VM '#{vm_name}'"
29  
-        end
30  
-
31  
-        # TODO
32  
-        Fission.ui.output_and_exit "There was an error listing the snapshots.  The error was:\n#{task.output}", task.code
33  
-      end
34  
-
35  
-      def option_parser
36  
-        optparse = OptionParser.new do |opts|
37  
-          opts.banner = "\nsnapshot list: fission snapshot list my_vm"
38  
-        end
39  
-
40  
-        optparse
41  
-      end
42  
-
43  
-    end
44  
-  end
45  
-end
54  lib/fission/command/snapshot_revert.rb
... ...
@@ -1,54 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    class SnapshotRevert < Command
4  
-
5  
-      def initialize(args=[])
6  
-        super
7  
-      end
8  
-
9  
-      def execute
10  
-        unless @args.count == 2
11  
-          Fission.ui.output self.class.help
12  
-          Fission.ui.output ''
13  
-          Fission.ui.output_and_exit 'Incorrect arguments for snapshot revert command', 1
14  
-        end
15  
-
16  
-        vm_name, snap_name = @args.take 2
17  
-        vm = Fission::VM.new vm_name
18  
-
19  
-        unless vm.exists? vm_name
20  
-          Fission.ui.output_and_exit "Unable to find the VM #{vm_name} (#{Fission::VM.path(vm_name)})", 1 
21  
-        end
22  
-
23  
-        if Fission::Fusion.running?
24  
-          Fission.ui.output 'It looks like the Fusion GUI is currently running'
25  
-          Fission.ui.output_and_exit 'Please exit the Fusion GUI and try again', 1
26  
-        end
27  
-
28  
-        snaps = vm.snapshots
29  
-
30  
-        unless snaps.include? snap_name
31  
-          Fission.ui.output_and_exit "Unable to find the snapshot '#{snap_name}'", 1
32  
-        end
33  
-
34  
-        Fission.ui.output "Reverting to snapshot '#{snap_name}'"
35  
-        task = vm.revert_to_snapshot snap_name
36  
-
37  
-        if task.successful?
38  
-          Fission.ui.output "Reverted to snapshot '#{snap_name}'"
39  
-        else
40  
-          Fission.ui.output_and_exit "There was an error reverting to the snapshot.  The error was:\n#{task.output}", task.code
41  
-        end
42  
-      end
43  
-
44  
-      def option_parser
45  
-        optparse = OptionParser.new do |opts|
46  
-          opts.banner = "\nsnapshot revert: fission snapshot revert my_vm snapshot_1"
47  
-        end
48  
-
49  
-        optparse
50  
-      end
51  
-
52  
-    end
53  
-  end
54  
-end
69  lib/fission/command/start.rb
... ...
@@ -1,69 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    class Start < Command
4  
-
5  
-      def initialize(args=[])
6  
-        super
7  
-        @options.headless = false
8  
-      end
9  
-
10  
-      def execute
11  
-        option_parser.parse! @args
12  
-
13  
-        if @args.empty?
14  
-          Fission.ui.output self.class.help
15  
-          Fission.ui.output ""
16  
-          Fission.ui.output_and_exit "Incorrect arguments for start command", 1
17  
-        end
18  
-
19  
-        vm_name = @args.first
20  
-
21  
-        vm = Fission::VM.new(vm_name)
22  
-
23  
-        unless vm.exists?
24  
-          Fission.ui.output_and_exit "Unable to find the VM #{vm_name} (#{Fission::VM.path(vm_name)})", 1 
25  
-        end
26  
-
27  
-        if vm.running?
28  
-          Fission.ui.output ''
29  
-          Fission.ui.output_and_exit "VM '#{vm_name}' is already running", 0
30  
-        end
31  
-
32  
-        Fission.ui.output "Starting '#{vm_name}'"
33  
-        start_args = {}
34  
-
35  
-        if @options.headless
36  
-
37  
-          if Fission::Fusion.running?
38  
-            Fission.ui.output 'It looks like the Fusion GUI is currently running'
39  
-            Fission.ui.output 'A VM cannot be started in headless mode when the Fusion GUI is running'
40  
-            Fission.ui.output_and_exit "Exit the Fusion GUI and try again", 1
41  
-          else
42  
-            start_args[:headless] = true
43  
-          end
44  
-        end
45  
-
46  
-        task = vm.start(start_args)
47  
-
48  
-        if task.successful?
49  
-          Fission.ui.output "VM '#{vm_name}' started"
50  
-        else
51  
-          Fission.ui.output_and_exit "There was a problem starting the VM.  The error was:\n#{task.output}", task.code
52  
-        end
53  
-      end
54  
-
55  
-      def option_parser
56  
-        optparse = OptionParser.new do |opts|
57  
-          opts.banner = "\nstart usage: fission start vm [options]"
58  
-
59  
-          opts.on '--headless', 'Start the VM in headless mode (i.e. no Fusion GUI console)' do
60  
-            @options.headless = true
61  
-          end
62  
-        end
63  
-
64  
-        optparse
65  
-      end
66  
-
67  
-    end
68  
-  end
69  
-end
31  lib/fission/command/status.rb
... ...
@@ -1,31 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    class Status < Command
4  
-
5  
-      def initialize(args=[])
6  
-        super
7  
-      end
8  
-
9  
-      def execute
10  
-
11  
-        all_vms=Fission::VM.all
12  
-        vm_with_longest_name = all_vms.max { |a,b| a.name.length <=> b.name.length }
13  
-        max_name_length=vm_with_longest_name.name.length
14  
-        all_vms.each do |vm|
15  
-          status = vm.state
16  
-          Fission.ui.output_printf "%-#{max_name_length}s   %s\n", vm.name, "["+status+"]"
17  
-        end
18  
-
19  
-      end
20  
-
21  
-      def option_parser
22  
-        optparse = OptionParser.new do |opts|
23  
-          opts.banner = "\nstatus usage: fission status"
24  
-        end
25  
-
26  
-        optparse
27  
-      end
28  
-
29  
-    end
30  
-  end
31  
-end
49  lib/fission/command/stop.rb
... ...
@@ -1,49 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    class Stop < Command
4  
-
5  
-      def initialize(args=[])
6  
-        super
7  
-      end
8  
-
9  
-      def execute
10  
-        unless @args.count == 1
11  
-          Fission.ui.output self.class.help
12  
-          Fission.ui.output ""
13  
-          Fission.ui.output_and_exit "Incorrect arguments for stop command", 1
14  
-        end
15  
-
16  
-        vm_name = @args.first
17  
-        vm = Fission::VM.new vm_name
18  
-
19  
-        unless vm.exists? 
20  
-          Fission.ui.output_and_exit "VM #{vm_name} does not exist at (#{vm.path})", 1
21  
-        end
22  
-
23  
-
24  
-        unless vm.running?
25  
-          Fission.ui.output ''
26  
-          Fission.ui.output_and_exit "VM '#{vm_name}' is not running", 0
27  
-        end
28  
-
29  
-        Fission.ui.output "Stopping '#{vm_name}'"
30  
-        task  = vm.stop
31  
-
32  
-        if task.successful?
33  
-          Fission.ui.output "VM '#{vm_name}' stopped"
34  
-        else
35  
-          Fission.ui.output_and_exit "There was an error stopping the VM.  The error was:\n#{response.output}", response.code
36  
-        end
37  
-      end
38  
-
39  
-      def option_parser
40  
-        optparse = OptionParser.new do |opts|
41  
-          opts.banner = "\nstop usage: fission stop vm"
42  
-        end
43  
-
44  
-        optparse
45  
-      end
46  
-
47  
-    end
48  
-  end
49  
-end
67  lib/fission/command/suspend.rb
... ...
@@ -1,67 +0,0 @@
1  
-module Fission
2  
-  class Command
3  
-    class Suspend < Command
4  
-
5  
-      def initialize(args=[])
6  
-        super
7  
-        @options.all = false
8  
-      end
9  
-
10  
-      def execute
11  
-        option_parser.parse! @args
12  
-
13  
-        if @args.count != 1 && !@options.all
14  
-          Fission.ui.output self.class.help
15  
-          Fission.ui.output ""
16  
-          Fission.ui.output_and_exit "Incorrect arguments for suspend command", 1
17  
-        end
18  
-
19  
-        vms_to_suspend.each do |vm|
20  
-          Fission.ui.output "Suspending '#{vm.name}'"
21  
-          task = vm.suspend
22  
-
23  
-          if task.successful?
24  
-            Fission.ui.output "VM '#{vm.name}' suspended"
25  
-          else
26  
-            Fission.ui.output_and_exit "There was an error suspending the VM.  The error was:\n#{task.output}", task.code
27  
-          end
28  
-        end
29  
-      end
30  
-
31  
-      def vms_to_suspend
32  
-        if @options.all
33  
-          vms=Fission::VM.all_running
34  
-        else
35  
-          vm_name = @args.first
36  
-          vm=Fission::VM.new(vm_name)
37  
-
38  
-          unless vm.exists?
39  
-            Fission.ui.output ''
40  
-            Fission.ui.output_and_exit "VM #{vm_name} does not exist (#{Fission::VM.path(vm_name)})", 1
41  
-          end
42  
-
43  
-          unless vm.running?
44  
-            Fission.ui.output ''
45  
-            Fission.ui.output_and_exit "VM '#{vm_name}' is not running", 1
46  
-          end
47  
-
48  
-          vms = [vm]
49  
-        end
50  
-        vms
51  
-      end
52  
-
53  
-      def option_parser
54  
-        optparse = OptionParser.new do |opts|
55  
-          opts.banner = "\nsuspend usage: fission suspend [vm | --all]"
56  
-
57  
-          opts.on '--all', 'Suspend all running VMs' do
58  
-            @options.all = true
59  
-          end
60  
-        end
61  
-
62  
-        optparse
63  
-      end
64  
-
65  
-    end
66  
-  end
67  
-end
57  lib/fission/config.rb
... ...
@@ -1,24 +1,71 @@
1 1
 module Fission
2 2
   class Config
  3
+
  4
+    # Public: Gets/Sets the Hash of attributes.
3 5
     attr_accessor :attributes
4 6
 
  7
+    # Public: Path to the Fission conf file (default: ~/.fissionrc).
5 8
     CONF_FILE = File.expand_path '~/.fissionrc'
6 9
 
  10
+    # Public: Initializes a Config object.  This also sets the default config
  11
+    # attributes for 'vmrun_bin', 'vmrun_cmd', 'vm_dir', 'plist_file', and
  12
+    # 'gui_bin'.
  13
+    #
  14
+    # Examples
  15
+    #
  16
+    #   Fission::Config.new
  17
+    #
  18
+    # Returns a new Config instance.
7 19
     def initialize
8 20
       @attributes = {}
9  
-      load_from_file
10 21
 
11  
-      if @attributes['vm_dir'].blank?
12  
-        @attributes['vm_dir'] = File.expand_path('~/Documents/Virtual Machines.localized/')
  22
+      @attributes['vm_dir'] = File.expand_path('~/Documents/Virtual Machines.localized/')
  23
+      @attributes['lease_file'] = '/var/db/vmware/vmnet-dhcpd-vmnet8.leases'
  24
+
  25
+      fusion_version = :unknown
  26
+
  27
+      if File.exists?("/Library/Application Support/VMware Fusion/vmrun")
  28
+        @attributes['vmrun_bin'] = '/Library/Application Support/VMware Fusion/vmrun'
  29
+      end
  30
+
  31
+      if File.exists?("/Applications/VMware Fusion.app/Contents/Library/vmrun")  
  32
+        @attributes['vmrun_bin'] = "/Applications/VMware Fusion.app/Contents/Library/vmrun"
  33
+      end
  34
+
  35
+      if fusion_version == :unknown
13 36
       end
14 37
 
15  
-      @attributes['vmrun_bin'] = '/Library/Application Support/VMware Fusion/vmrun'
16  
-      @attributes['vmrun_cmd'] = "#{@attributes['vmrun_bin'].gsub(' ', '\ ')} -T fusion"
17 38
       @attributes['plist_file'] = File.expand_path('~/Library/Preferences/com.vmware.fusion.plist')
18 39
       @attributes['gui_bin'] = File.expand_path('/Applications/VMware Fusion.app/Contents/MacOS/vmware')
  40
+
  41
+      load_from_file
  42
+
  43
+      @attributes['vmrun_cmd'] = "#{@attributes['vmrun_bin'].gsub(' ', '\ ')} -T fusion"
  44
+    end
  45
+
  46
+    # Public: Helper method to access config atributes.  This is a shortcut for
  47
+    # querying the config attributes.
  48
+    #
  49
+    # item - The config item to query.
  50
+    #
  51
+    # Examples
  52
+    #
  53
+    #   Fission.config['vmrun_bin']
  54
+    #   # => '/foo/bar/vmrun'
  55
+    #
  56
+    # Returns the value of the specified config item.
  57
+    def [](item)
  58
+      @attributes[item]
19 59
     end
20 60
 
21 61
     private
  62
+    # Internal: Loads config values from the Fission conf file into attributes.
  63
+    #
  64
+    # Examples
  65
+    #
  66
+    #   load_from_file
  67
+    #
  68
+    # Returns nothing.
22 69
     def load_from_file
23 70
       if File.file?(CONF_FILE)
24 71
         @attributes.merge!(YAML.load_file(CONF_FILE))
5  lib/fission/core_ext/class.rb
... ...
@@ -1,5 +0,0 @@
1  
-class Class
2  
-  def descendants
3  
-    ObjectSpace.each_object(Class).select { |klass| klass < self }
4  
-  end
5  
-end
7  lib/fission/core_ext/file.rb
... ...
@@ -1,7 +0,0 @@
1  
-class File
2  
-  # from ptools
3  
-  def self.binary?(file)
4  
-    s = (File.read(file, File.stat(file).blksize) || "").split(//)
5  
-    ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
6  
-  end
7  
-end
112  lib/fission/core_ext/object.rb
... ...
@@ -1,112 +0,0 @@
1  
-# this is from active_support
2  
-# github.com/rails/rails/activesupport
3  
-#
4  
-class Object
5  
-  # An object is blank if it's false, empty, or a whitespace string.
6  
-  # For example, "", "   ", +nil+, [], and {} are blank.
7  
-  #
8  
-  # This simplifies:
9  
-  #
10  
-  #   if !address.nil? && !address.empty?
11  
-  #
12  
-  # ...to:
13  
-  #
14  
-  #   if !address.blank?
15  
-  def blank?
16  
-    respond_to?(:empty?) ? empty? : !self
17  
-  end
18  
-
19  
-  # An object is present if it's not <tt>blank?</tt>.
20  
-  def present?
21  
-    !blank?
22  
-  end
23  
-
24  
-  # Returns object if it's <tt>present?</tt> otherwise returns +nil+.
25  
-  # <tt>object.presence</tt> is equivalent to <tt>object.present? ? object : nil</tt>.
26  
-  #
27  
-  # This is handy for any representation of objects where blank is the same
28  
-  # as not present at all.  For example, this simplifies a common check for
29  
-  # HTTP POST/query parameters:
30  
-  #
31  
-  #   state   = params[:state]   if params[:state].present?
32  
-  #   country = params[:country] if params[:country].present?
33  
-  #   region  = state || country || 'US'
34  
-  #
35  
-  # ...becomes:
36  
-  #
37  
-  #   region = params[:state].presence || params[:country].presence || 'US'
38  
-  def presence
39  
-    self if present?
40  
-  end
41  
-end
42  
-
43  
-class NilClass
44  
-  # +nil+ is blank:
45  
-  #
46  
-  #   nil.blank? # => true
47  
-  #
48  
-  def blank?
49  
-    true
50  
-  end
51  
-end
52  
-
53  
-class FalseClass
54  
-  # +false+ is blank:
55  
-  #
56  
-  #   false.blank? # => true
57  
-  #
58  
-  def blank?
59  
-    true
60  
-  end
61  
-end
62  
-
63  
-class TrueClass
64  
-  # +true+ is not blank:
65  
-  #
66  
-  #   true.blank? # => false
67  
-  #
68  
-  def blank?
69  
-    false
70  
-  end
71  
-end
72  
-
73  
-class Array
74  
-  # An array is blank if it's empty:
75  
-  #
76  
-  #   [].blank?      # => true
77  
-  #   [1,2,3].blank? # => false
78  
-  #
79  
-  alias_method :blank?, :empty?
80  
-end
81  
-
82  
-class Hash
83  
-  # A hash is blank if it's empty:
84  
-  #
85  
-  #   {}.blank?                # => true
86  
-  #   {:key => 'value'}.blank? # => false
87  
-  #
88  
-  alias_method :blank?, :empty?
89  
-end
90  
-
91  
-class String
92  
-  # A string is blank if it's empty or contains whitespaces only:
93  
-  #
94  
-  #   "".blank?                 # => true
95  
-  #   "   ".blank?              # => true
96  
-  #   " something here ".blank? # => false
97  
-  #
98  
-  def blank?
99  
-    self !~ /\S/
100  
-  end
101  
-end
102  
-
103  
-class Numeric #:nodoc:
104  
-  # No number is blank:
105  
-  #
106  
-  #   1.blank? # => false
107  
-  #   0.blank? # => false
108  
-  #
109  
-  def blank?
110  
-    false
111  
-  end
112  
-end
9  lib/fission/error.rb
... ...
@@ -1,9 +0,0 @@
1  
-module Fission
2  
-    class Error < StandardError
3  
-      attr_reader :orginal
4  
-      def initialize(msg, original=$!)
5  
-        super(msg)
6  
-        @original = original; end
7  
-    end
8  
-end
9  
-
17  lib/fission/fusion.rb
... ...
@@ -1,17 +0,0 @@
1  
-module Fission
2  
-  class Fusion
3  
-
4  
-    def self.running?
5  
-      command = "ps -ef | grep -v grep | grep -c "
6  
-      command << "#{Fission.config.attributes['gui_bin'].gsub(' ', '\ ')} 2>&1"
7  
-      output = `#{command}`
8  
-
9  
-      response = Fission::Response.new :code => 0
10  
-
11  
-      output.strip.to_i > 0 ? response.data = true : response.data = false
12  
-
13  
-      response
14  
-    end
15  
-
16  
-  end
17  
-end
74  lib/fission/leasesfile.rb
... ...
@@ -1,74 +0,0 @@
1  
-require 'date'
2  
-
3  
-class Lease
4  
-  attr_accessor :name,:mac,:start,:end,:ip
5  
-
6  
-  def initialize(name)
7  
-    @name=name
8  
-    @ip=name
9  
-  end
10  
-
11  
-  def expired?
12  
-    @end < DateTime.now
13  
-  end
14  
-end
15  
-
16  
-class LeasesFile
17  
-
18  
-  attr_reader :leases
19  
-
20  
-  def initialize(filename)
21  
-    @filename=filename
22  
-    @leases=Array.new
23  
-    load
24  
-  end
25  
-
26  
-  def load
27  
-    @leases=Array.new
28  
-    File.open(@filename,"r") do |leasefile|
29  
-      lease=nil
30  
-      while (line = leasefile.gets)
31  
-
32  
-        line=line.lstrip.gsub(';','')
33  
-        case line
34  
-        when /^lease/
35  
-          @leases << lease unless lease.nil?
36  
-          name=line.split(' ')[1]
37  
-          lease=Lease.new(name)
38  
-        when /^hardware/
39  
-          lease.mac=line.split(" ")[2]
40  
-        when /^starts/
41  
-          lease.start=DateTime.parse(line.split(" ")[2..3].join(" "))
42  
-        when /^ends/
43  
-          lease.end=DateTime.parse(line.split(" ")[2..3].join(" "))
44  
-        end
45  
-
46  
-      end
47  
-      @leases << lease unless lease.nil?
48  
-    end
49  
-    return @leases
50  
-  end
51  
-
52  
-  def all_leases
53  
-    return @leases
54  
-  end
55  
-
56  
-  def current_leases
57  
-    hash_list=Hash.new
58  
-    @leases.each do |lease|
59  
-      hash_list[lease.name]=lease
60  
-    end
61  
-    collapsed_list=Array.new
62  
-    hash_list.each do |key,value|
63  
-      collapsed_list << value
64  
-    end
65  
-    return collapsed_list
66  
-  end
67  
-
68  
-  def find_lease_by_mac(mac)
69  
-    matches=current_leases.select{|l| l.mac==mac}
70  
-    return nil if matches.nil?
71  
-    return matches[0]
72  
-  end
73  
-
74  
-end
39  lib/fission/metadata.rb
... ...
@@ -1,39 +0,0 @@
1  
-module Fission
2  
-  class Metadata
3  
-
4  
-    require 'cfpropertylist'
5  
-
6  
-    attr_accessor :content
7  
-
8  
-    def self.delete_vm_info(vm_path)
9  
-      metadata = new
10  
-      metadata.load
11  
-      metadata.delete_vm_restart_document(vm_path)
12  
-      metadata.delete_vm_favorite_entry(vm_path)
13  
-      metadata.save
14  
-    end
15  
-
16  
-    def load
17  
-      raw_data = CFPropertyList::List.new :file => Fission.config.attributes['plist_file']
18  
-      @content = CFPropertyList.native_types raw_data.value
19  
-    end
20  
-
21  
-    def save
22  
-      new_content = CFPropertyList::List.new
23  
-      new_content.value = CFPropertyList.guess @content
24  
-      new_content.save Fission.config.attributes['plist_file'],
25  
-        CFPropertyList::List::FORMAT_BINARY
26  
-    end
27  
-
28  
-    def delete_vm_restart_document(vm_path)
29  
-      if @content.has_key?('PLRestartDocumentPaths')
30  
-        @content['PLRestartDocumentPaths'].delete_if { |p| p == vm_path }
31  
-      end
32  
-    end
33  
-
34  
-    def delete_vm_favorite_entry(vm_path)
35  
-      @content['VMFavoritesListDefaults2'].delete_if { |vm| vm['path'] == vm_path }
36  
-    end
37  
-
38  
-  end
39  
-end
16  lib/fission/response.rb
... ...
@@ -1,16 +0,0 @@
1  
-module Fission
2  
-  class Response
3  
-    attr_accessor :code, :output, :data
4  
-
5  
-    def initialize(args={})
6  
-      @code = args.fetch :code, 1
7  
-      @output = args.fetch :output, ''
8  
-      @data = args.fetch :data, nil
9  
-    end
10  
-
11  
-    def successful?
12  
-      @code == 0
13  
-    end
14  
-
15  
-  end
16  
-end
22  lib/fission/ui.rb
... ...
@@ -1,22 +0,0 @@
1  
-module Fission
2  
-  class UI
3  
-    attr_reader :stdout
4  
-
5  
-    def initialize(stdout=$stdout)
6  
-      @stdout = stdout
7  
-    end
8  
-
9  
-    def output(s)
10  
-      @stdout.puts s
11  
-    end
12  
-
13  
-    def output_printf(string, key, value)
14  
-      @stdout.send :printf, string, key, value
15  
-    end
16  
-
17  
-    def output_and_exit(s, exit_code)
18  
-      output s
19  
-      exit exit_code
20  
-    end
21  
-  end
22  
-end
3  lib/fission/version.rb
... ...
@@ -1,3 +0,0 @@
1  
-module Fission
2  
-  VERSION = "0.4.0a"
3  
-end
365  lib/fission/vm.rb
... ...
@@ -1,365 +0,0 @@
1  
-require 'fission/leasesfile'
2  
-require 'shellwords'
3  
-require 'fission/error'
4  
-
5  
-module Fission
6  
-  class VM
7  
-    attr_reader :name
8  
-
9  
-    def initialize(name)
10  
-      @name = name
11  
-    end
12  
-
13  
-    #####################################################
14  
-    # Path Helpers
15  
-    #####################################################
16  
-    # Returns the topdir of the vm
17  
-    def path
18  
-      File.join Fission.config.attributes['vm_dir'], "#{@name}.vmwarevm"
19  
-    end
20  
-
21  
-    # Returns a string to the path of the config file
22  
-    # There is no guarantee it exists
23  
-    def vmx_path
24  
-      return File.join(path, "#{@name}.vmx")
25  
-    end
26  
-
27  
-
28  
-    ####################################################################
29  
-    # State information
30  
-    ####################################################################
31  
-    def running?
32  
-      raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
33  
-
34  
-      command = "#{vmrun_cmd} list"
35  
-      output = `#{command}`
36  
-
37  
-      response = Fission::Response.new :code => $?.exitstatus
38  
-
39  
-      if response.successful?
40  
-        vms = output.split("\n").select do |vm|
41  
-          vm.include?('.vmx') && File.exists?(vm) && File.extname(vm) == '.vmx'
42  
-        end
43  
-        return vms.include?(self.vmx_path)
44  
-      else
45  
-        raise Fission::Error,"Error listing the state of vm #{@name}:\n#{output}"
46  
-      end
47  
-    end
48  
-
49  
-    def suspended?
50  
-      raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
51  
-
52  
-      suspend_filename=File.join(File.dirname(vmx_path), File.basename(vmx_path,".vmx")+".vmem")
53  
-      return File.exists?(suspend_filename)
54  
-    end
55  
-
56  
-    # Checks to see if a vm exists
57  
-    def exists?
58  
-      File.exists? vmx_path
59  
-    end
60  
-
61  
-    # Returns the state of a vm
62  
-    def state
63  
-      return "not created" unless self.exists?
64  
-
65  
-      return "suspend" if self.suspended?
66  
-
67  
-      return "running" if self.running?
68  
-
69  
-      return "not running"
70  
-    end
71  
-
72  
-    ####################################################################
73  
-    # VM information
74  
-    ####################################################################
75  
-
76  
-    # Returns an Array of snapshot names
77  
-    def snapshots
78  
-      raise Fission::Error,"VM #{@name} does not exist" unless self.exists?
79  
-
80  
-      command = "#{vmrun_cmd} listSnapshots #{vmx_path.shellescape} 2>&1"
81