Module: Crew::Context::Fusion

Includes:
SSH
Defined in:
lib/crew/context/fusion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SSH

#cd, #current_dir, #reconnect!, #save_data, #save_file, #sh_raw, #sh_with_code

Instance Attribute Details

#snapshot_nameObject

Returns the value of attribute snapshot_name.



6
7
8
# File 'lib/crew/context/fusion.rb', line 6

def snapshot_name
  @snapshot_name
end

Instance Method Details

#prepare_snapshot(name, force = false, &initializer) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/crew/context/fusion.rb', line 19

def prepare_snapshot(name, force = false, &initializer)
  path = vm_path
  fusion_context = self
  @home.run_in_context(Local, "Preparing snapshot `#{name}'") do
    vmrun_snapshots_delete(path, name) if force
    unless vmrun_snapshots(path).include?(name)
      vmrun_snapshots_revert(path, "snapshot")
      @home.run_in_context(fusion_context, "Setting up", &initializer) if initializer
      vmrun_snapshots_create(path, name)
    end
  end
end

#reset!(name) ⇒ Object



12
13
14
15
16
17
# File 'lib/crew/context/fusion.rb', line 12

def reset!(name)
  path = vm_path
  @home.run_in_context(Local, "Restoring to `#{name}'") do
    vmrun_snapshots_revert(path, name)
  end
end

#start_shellObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/crew/context/fusion.rb', line 32

def start_shell
  path = vm_path
  reset!(@snapshot_name) if @snapshot_name
  @home.run_in_context(Local, "Starting VM") do
    vmrun_start path
  end
  opts[:host] = @home.run_in_context(Local, "Connecting to VM") do
    poll("Getting ip address") { vmrun_getguestipaddress(path) }
  end
  run_callbacks(:before)
end

#stop_shellObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/crew/context/fusion.rb', line 44

def stop_shell
  if @_shell
    @_shell.close
    @_shell = nil
  end
  @current_dir = nil
  run_callbacks(:after)
  path = vm_path
  #at_exit do
  #  @home.run_in_context(Local, "Suspending VM") do
  #    vmrun_suspend path
  #  end
  #end
end

#vm_pathObject



8
9
10
# File 'lib/crew/context/fusion.rb', line 8

def vm_path
  opts.fetch(:path)
end