Class: Sahara::Session::VMWare
- Inherits:
-
Object
- Object
- Sahara::Session::VMWare
- Defined in:
- lib/sahara/session/vmware.rb
Instance Method Summary collapse
- #commit ⇒ Object
-
#initialize(machine) ⇒ VMWare
constructor
A new instance of VMWare.
- #is_snapshot_mode_on? ⇒ Boolean
- #is_vm_created? ⇒ Boolean
- #list_snapshots ⇒ Object
- #off ⇒ Object
- #on ⇒ Object
- #rollback ⇒ Object
Constructor Details
#initialize(machine) ⇒ VMWare
Returns a new instance of VMWare.
5 6 7 8 9 10 11 12 13 |
# File 'lib/sahara/session/vmware.rb', line 5 def initialize(machine) @machine=machine @vmx_path=@machine.provider.driver.vmx_path @vmwarecmd=@machine.provider.driver.instance_variable_get(:@vmrun_path).to_s.gsub(" ", "\\ ") @sandboxname="sahara-sandbox" if @machine.provider.driver.class.to_s != "HashiCorp::VagrantVMwarefusion::Driver::Fusion" raise Sahara::Errors::ProviderNotSupported end end |
Instance Method Details
#commit ⇒ Object
33 34 35 36 |
# File 'lib/sahara/session/vmware.rb', line 33 def commit `#{@vmwarecmd} -T ws deleteSnapshot "#{@vmx_path}" "#{@sandboxname}"` `#{@vmwarecmd} -T ws snapshot "#{@vmx_path}" "#{@sandboxname}"` end |
#is_snapshot_mode_on? ⇒ Boolean
20 21 22 23 |
# File 'lib/sahara/session/vmware.rb', line 20 def is_snapshot_mode_on? snapshots=self.list_snapshots return snapshots.include?(@sandboxname) end |
#is_vm_created? ⇒ Boolean
52 53 54 |
# File 'lib/sahara/session/vmware.rb', line 52 def is_vm_created? return !@machine.id.nil? end |
#list_snapshots ⇒ Object
15 16 17 18 |
# File 'lib/sahara/session/vmware.rb', line 15 def list_snapshots output = `#{@vmwarecmd} listSnapshots "#{@vmx_path}"` output.rstrip.split(/\r?\n/).map {|line| line.chomp } end |
#off ⇒ Object
25 26 27 |
# File 'lib/sahara/session/vmware.rb', line 25 def off `#{@vmwarecmd} -T ws deleteSnapshot "#{@vmx_path}" "#{@sandboxname}"` end |
#on ⇒ Object
29 30 31 |
# File 'lib/sahara/session/vmware.rb', line 29 def on `#{@vmwarecmd} -T ws snapshot "#{@vmx_path}" "#{@sandboxname}"` end |
#rollback ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sahara/session/vmware.rb', line 38 def rollback `#{@vmwarecmd} -T ws revertToSnapshot "#{@vmx_path}" "#{@sandboxname}" ` sleep 2 gui_boot = @machine.provider_config.gui if gui_boot boot_mode = "gui" else boot_mode = "nogui" end # restore boot mode `#{@vmwarecmd} -T ws start "#{@vmx_path}" #{boot_mode} ` end |