sahara 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,3 +7,5 @@ Vagrantfile
7
7
  Gemfile.lock
8
8
  .bundle/
9
9
  vendor/
10
+ .idea/
11
+ *.iml
@@ -24,6 +24,7 @@ module Sahara
24
24
  next
25
25
  end
26
26
  if ses.is_snapshot_mode_on? then
27
+ puts "[#{machine.name}] Committing the virtual machine..."
27
28
  ses.commit
28
29
  else
29
30
  puts "[#{machine.name}] Not sandbox mode now"
@@ -24,6 +24,7 @@ module Sahara
24
24
  next
25
25
  end
26
26
  if ses.is_snapshot_mode_on? then
27
+ puts "[#{machine.name}] Stopping sandbox mode..."
27
28
  ses.off
28
29
  else
29
30
  puts "[#{machine.name}] Not sandbox mode now"
@@ -24,6 +24,7 @@ module Sahara
24
24
  next
25
25
  end
26
26
  if !ses.is_snapshot_mode_on? then
27
+ puts "[#{machine.name}] Starting sandbox mode..."
27
28
  ses.on
28
29
  else
29
30
  puts "[#{machine.name}] Already sandbox mode"
@@ -25,10 +25,10 @@ module Sahara
25
25
  end
26
26
  if !ses.is_snapshot_mode_on? then
27
27
  puts "[#{machine.name}] Not sandbox mode now"
28
- next
28
+ else
29
+ puts "[#{machine.name}] Rolling back the virtual machine..."
30
+ ses.rollback
29
31
  end
30
- ses.rollback
31
-
32
32
  end
33
33
  end
34
34
  end
@@ -55,7 +55,7 @@ module Sahara
55
55
  # Prints the help out for this command
56
56
  def help
57
57
  opts = OptionParser.new do |o|
58
- o.banner = "Usage: vagrant plugin <command> [<args>]"
58
+ o.banner = "Usage: vagrant sandbox <command> [<args>]"
59
59
  o.separator ""
60
60
  o.separator "Available subcommands:"
61
61
 
@@ -69,7 +69,7 @@ module Sahara
69
69
  end
70
70
 
71
71
  o.separator ""
72
- o.separator "For help on any individual command run `vagrant plugin COMMAND -h`"
72
+ o.separator "For help on any individual command run `vagrant sandbox <command> -h`"
73
73
  end
74
74
 
75
75
  @env.ui.info(opts.help, :prefix => false)
@@ -29,5 +29,9 @@ module Sahara
29
29
  error_key("snapshot_reversion_error")
30
30
  end
31
31
 
32
+ class HostOsNotSupported < Sahara::Errors::Error
33
+ error_key("host_os_not_supported")
34
+ end
35
+
32
36
  end
33
37
  end
@@ -11,6 +11,12 @@ module Sahara
11
11
  when :libvirt
12
12
  require_relative "libvirt"
13
13
  Libvirt.new(machine)
14
+ when :parallels
15
+ require_relative "parallels"
16
+ Parallels.new(machine)
17
+ when :vmware_fusion
18
+ require_relative "vmware"
19
+ VMWare.new(machine)
14
20
  else
15
21
  raise Sahara::Errors::ProviderNotSupported
16
22
  end
@@ -8,7 +8,7 @@ module Sahara
8
8
  @machine=machine
9
9
  @sandboxname="sahara-sandbox"
10
10
  @connection=connect_to_libvirt
11
- @domain = @connection.client.lookup_domain_by_uuid(@machine.id)
11
+ @domain=get_domain
12
12
  end
13
13
 
14
14
  # based on VagrantPlugins::ProviderLibvirt::Action::ConnectLibvirt
@@ -18,6 +18,10 @@ module Sahara
18
18
 
19
19
  # Setup connection uri.
20
20
  uri = config.driver
21
+ if uri == "kvm"
22
+ uri = "qemu"
23
+ end
24
+
21
25
  if config.connect_via_ssh
22
26
  uri << '+ssh://'
23
27
  if config.username
@@ -53,6 +57,14 @@ module Sahara
53
57
  end
54
58
  end
55
59
 
60
+ def get_domain
61
+ if is_vm_created?
62
+ return @connection.client.lookup_domain_by_uuid(@machine.id)
63
+ else
64
+ return nil
65
+ end
66
+ end
67
+
56
68
  def get_snapshot_if_exists
57
69
  # if we can get snapshot description without exception it exists
58
70
  begin
@@ -0,0 +1,70 @@
1
+ module Sahara
2
+ module Session
3
+ class Parallels
4
+
5
+ def initialize(machine)
6
+ @machine=machine
7
+ @instance_id = @machine.id
8
+ @prlctl="prlctl"
9
+ @sandboxname="sahara-sandbox"
10
+ @snapshots=list_snapshots
11
+ end
12
+
13
+ def list_snapshots
14
+ snapshotlist = Hash.new
15
+ output = `#{@prlctl} snapshot-list "#{@instance_id}" --tree`
16
+ snapshot_ids=output.scan(/\{([\w-]*)?\}/).flatten
17
+ snapshot_ids.each do |id|
18
+ res = `#{@prlctl} snapshot-list "#{@instance_id}" -i "#{id}"`
19
+ if res =~ (/^Name:\s(.*)$/)
20
+ snapshotlist[$1] = id
21
+ end
22
+ end
23
+ snapshotlist
24
+ end
25
+
26
+ def get_snapshot_id
27
+ # if we can get snapshot description without exception it exists
28
+ begin
29
+ snapshot_id = @snapshots.fetch(@sandboxname)
30
+ rescue
31
+ raise Sahara::Errors::SnapshotMissing
32
+ end
33
+ return snapshot_id
34
+ end
35
+
36
+ def is_snapshot_mode_on?
37
+ begin
38
+ snapshot_id = get_snapshot_id
39
+ rescue Sahara::Errors::SnapshotMissing
40
+ return false
41
+ end
42
+ return true
43
+ end
44
+
45
+ def off
46
+ snapshot_id = get_snapshot_id
47
+ `#{@prlctl} snapshot-delete "#{@instance_id}" --id "#{snapshot_id}" `
48
+ end
49
+
50
+ def on
51
+ `#{@prlctl} snapshot "#{@instance_id}" --name "#{@sandboxname}"`
52
+ end
53
+
54
+ def commit
55
+ off
56
+ on
57
+ end
58
+
59
+ def rollback
60
+ snapshot_id = get_snapshot_id
61
+ `#{@prlctl} snapshot-switch "#{@instance_id}" --id "#{snapshot_id}" `
62
+ end
63
+
64
+ def is_vm_created?
65
+ return !@machine.id.nil?
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -11,10 +11,11 @@ module Sahara
11
11
 
12
12
  def determine_vboxcmd
13
13
  if windows?
14
- # On Windows, we use the VBOX_INSTALL_PATH environmental
15
- if ENV.has_key?("VBOX_INSTALL_PATH")
14
+ # On Windows, we use the VBOX_INSTALL_PATH and VBOX_MSI_INSTALL_PATH environmental
15
+ if ENV.has_key?("VBOX_INSTALL_PATH") || ENV.has_key?("VBOX_MSI_INSTALL_PATH")
16
16
  # The path usually ends with a \ but we make sure here
17
- path = File.join(ENV["VBOX_INSTALL_PATH"], "VBoxManage.exe")
17
+ path = ENV["VBOX_INSTALL_PATH"] || ENV["VBOX_MSI_INSTALL_PATH"]
18
+ path = File.join(path, "VBoxManage.exe")
18
19
  return "\"#{path}\""
19
20
  end
20
21
  else
@@ -0,0 +1,58 @@
1
+ module Sahara
2
+ module Session
3
+ class VMWare
4
+
5
+ def initialize(machine)
6
+ @machine=machine
7
+ @vmx_path=@machine.provider.driver.vmx_path
8
+ @vmwarecmd=@machine.provider.driver.instance_variable_get(:@vmrun_path).to_s.gsub(" ", "\\ ")
9
+ @sandboxname="sahara-sandbox"
10
+ if @machine.provider.driver.class.to_s != "HashiCorp::VagrantVMwarefusion::Driver::Fusion"
11
+ raise Sahara::Errors::ProviderNotSupported
12
+ end
13
+ end
14
+
15
+ def list_snapshots
16
+ output = `#{@vmwarecmd} listSnapshots "#{@vmx_path}"`
17
+ output.rstrip.split(/\r?\n/).map {|line| line.chomp }
18
+ end
19
+
20
+ def is_snapshot_mode_on?
21
+ snapshots=self.list_snapshots
22
+ return snapshots.include?(@sandboxname)
23
+ end
24
+
25
+ def off
26
+ `#{@vmwarecmd} -T ws deleteSnapshot "#{@vmx_path}" "#{@sandboxname}"`
27
+ end
28
+
29
+ def on
30
+ `#{@vmwarecmd} -T ws snapshot "#{@vmx_path}" "#{@sandboxname}"`
31
+ end
32
+
33
+ def commit
34
+ `#{@vmwarecmd} -T ws deleteSnapshot "#{@vmx_path}" "#{@sandboxname}"`
35
+ `#{@vmwarecmd} -T ws snapshot "#{@vmx_path}" "#{@sandboxname}"`
36
+ end
37
+
38
+ def rollback
39
+ `#{@vmwarecmd} -T ws revertToSnapshot "#{@vmx_path}" "#{@sandboxname}" `
40
+ sleep 2
41
+
42
+ gui_boot = @machine.provider_config.gui
43
+ if gui_boot
44
+ boot_mode = "gui"
45
+ else
46
+ boot_mode = "nogui"
47
+ end
48
+ # restore boot mode
49
+ `#{@vmwarecmd} -T ws start "#{@vmx_path}" #{boot_mode} `
50
+ end
51
+
52
+ def is_vm_created?
53
+ return !@machine.id.nil?
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module Sahara
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.17"
3
3
  end
@@ -15,7 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "sahara"
16
16
 
17
17
  s.add_dependency "popen4", "~> 0.1.2"
18
- s.add_dependency "thor", "> 0.14"
19
18
 
20
19
  s.add_development_dependency "bundler", ">= 1.0.0"
21
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sahara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-21 00:00:00.000000000 Z
12
+ date: 2014-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: popen4
@@ -27,22 +27,6 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.1.2
30
- - !ruby/object:Gem::Dependency
31
- name: thor
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>'
36
- - !ruby/object:Gem::Version
37
- version: '0.14'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>'
44
- - !ruby/object:Gem::Version
45
- version: '0.14'
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: bundler
48
32
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +64,9 @@ files:
80
64
  - lib/sahara/errors.rb
81
65
  - lib/sahara/session/factory.rb
82
66
  - lib/sahara/session/libvirt.rb
67
+ - lib/sahara/session/parallels.rb
83
68
  - lib/sahara/session/virtualbox.rb
69
+ - lib/sahara/session/vmware.rb
84
70
  - lib/sahara/version.rb
85
71
  - locales/en.yml
86
72
  - sahara.gemspec
@@ -98,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
84
  version: '0'
99
85
  segments:
100
86
  - 0
101
- hash: -2734223008788270957
87
+ hash: 55792310888730998
102
88
  required_rubygems_version: !ruby/object:Gem::Requirement
103
89
  none: false
104
90
  requirements: