Module: Cuken::Api::Vagrant::VM

Included in:
VVM
Defined in:
lib/cuken/api/vagrant/v_m.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/cuken/api/vagrant/v_m.rb', line 21

def name
  @name
end

#pathObject



51
52
53
# File 'lib/cuken/api/vagrant/v_m.rb', line 51

def path
  @path ||= Pathname.pwd
end

#vagrant_vmObject (readonly)

Returns the value of attribute vagrant_vm.



23
24
25
# File 'lib/cuken/api/vagrant/v_m.rb', line 23

def vagrant_vm
  @vagrant_vm
end

#vmObject (readonly)

Returns the value of attribute vm.



23
24
25
# File 'lib/cuken/api/vagrant/v_m.rb', line 23

def vm
  @vm
end

Instance Method Details

#configurationObject



78
79
80
# File 'lib/cuken/api/vagrant/v_m.rb', line 78

def configuration
  @configuration ||= instance_variable_get :@config
end

#destroy(vm_name = name) ⇒ Object



94
95
96
# File 'lib/cuken/api/vagrant/v_m.rb', line 94

def destroy(vm_name = name)
  run_vagrant_cli(__method__.to_s, vm_name)
end

#environmentObject



60
61
62
# File 'lib/cuken/api/vagrant/v_m.rb', line 60

def environment
    @environment = ::Vagrant::Environment.new(:cwd => path).reload_config!
end

#get_vm(box_name) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cuken/api/vagrant/v_m.rb', line 64

def get_vm(box_name)
  unless environment.multivm?
    @vm[:primary] = environment.primary_vm
  else
    if box_name
      @vm[box_name.to_sym] = environment.vms[box_name.to_sym]
    else
      tmpvm = environment.vms.first
      @vm[tmpvm[0]] = tmpvm[1]
    end
  end
  environment.vm = @vm
end

#halt(vm_name = name) ⇒ Object



98
99
100
# File 'lib/cuken/api/vagrant/v_m.rb', line 98

def halt(vm_name = name)
  run_vagrant_cli(__method__.to_s, vm_name)
end

#initialize(name) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/cuken/api/vagrant/v_m.rb', line 25

def initialize(name)
  e = environment
  @vagrant_vm = ::Vagrant::VM.new(:env => e, :name => name)
  @vm = {}
  @name = name
  environment.vm = {}
  get_vm(name)
  @vagrant_vm
end

#provision(vm_name = name) ⇒ Object



102
103
104
# File 'lib/cuken/api/vagrant/v_m.rb', line 102

def provision(vm_name = name)
  run_vagrant_cli(__method__.to_s, vm_name)
end

#reload(vm_name = name) ⇒ Object



118
119
120
# File 'lib/cuken/api/vagrant/v_m.rb', line 118

def reload(vm_name = name)
  run_vagrant_cli(__method__.to_s, vm_name)
end

#resume(vm_name = name) ⇒ Object



114
115
116
# File 'lib/cuken/api/vagrant/v_m.rb', line 114

def resume(vm_name = name)
  run_vagrant_cli(__method__.to_s, vm_name)
end

#run_vagrant_cli(cmd, vm_name) ⇒ Object



86
87
88
# File 'lib/cuken/api/vagrant/v_m.rb', line 86

def run_vagrant_cli(cmd, vm_name)
  ::Vagrant::CLI.start([cmd, vm_name], :env => environment)
end

#state(name) ⇒ Object



82
83
84
# File 'lib/cuken/api/vagrant/v_m.rb', line 82

def state(name)
  vms[name.to_sym].vm ? vms[name.to_sym].vm.state : nil
end

#status(vm_name = name) ⇒ Object



106
107
108
# File 'lib/cuken/api/vagrant/v_m.rb', line 106

def status(vm_name = name)
  run_vagrant_cli(__method__.to_s, vm_name)
end

#suspend(vm_name = name) ⇒ Object



110
111
112
# File 'lib/cuken/api/vagrant/v_m.rb', line 110

def suspend(vm_name = name)
  run_vagrant_cli(__method__.to_s, vm_name)
end

#up(vm_name = name) ⇒ Object



90
91
92
# File 'lib/cuken/api/vagrant/v_m.rb', line 90

def up(vm_name = name)
  run_vagrant_cli(__method__.to_s, vm_name)
end

#uuidObject

def name

  @name ||= 'cuken'
end


47
48
49
# File 'lib/cuken/api/vagrant/v_m.rb', line 47

def uuid
  @vm.uuid
end

#vagrantfileObject



55
56
57
58
# File 'lib/cuken/api/vagrant/v_m.rb', line 55

def vagrantfile
  vf = path + 'Vagrantfile'
  vf.exist? ? vf : nil
end

#vm_configObject



35
36
37
# File 'lib/cuken/api/vagrant/v_m.rb', line 35

def vm_config
  @vm_config ||= environment.instance_variable_get(:@config).instance_variable_get(:@vm)
end

#vmsObject



39
40
41
# File 'lib/cuken/api/vagrant/v_m.rb', line 39

def vms
  @vms = environment.vms
end