Method: Lab::Controllers::VmController#build_from_running

Defined in:
lib/lab/vm_controller.rb

#build_from_running(driver_type = nil, user = nil, host = nil, clear = false, pass = nil) ⇒ Object

Builds a vm lab from all running vms. Handy for connecting and saving out a config or just managing the currently running vms



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/lab/vm_controller.rb', line 173

def build_from_running(driver_type=nil, user=nil, host=nil, clear=false, pass=nil)

  if clear
    @vms = []
  end

  case driver_type.intern
    when :workstation
      vm_list = ::Lab::Controllers::WorkstationController::running_list
      vm_list.each do |item|
        # Name the VM
        index = @vms.count + 1
        # Add it to the vm list
        @vms << Vm.new({
          'vmid' => "vm_#{index}",
          'driver' => driver_type, 
          'location' => item
          })
      end
    when :remote_workstation
      vm_list = ::Lab::Controllers::RemoteWorkstationController::running_list(user, host)
      vm_list.each do |item|
        # Name the VM
        index = @vms.count + 1
        # Add it to the VM list
        @vms << Vm.new({
          'vmid' => "vm_#{index}",
          'driver' => driver_type, 
          'location' => item, 
          'user' => user,
          'host' => host 
          })
      end
    when :virtualbox
      vm_list = ::Lab::Controllers::VirtualBoxController::running_list
      vm_list.each do |item|
        # Add it to the vm list
        @vms << Vm.new( {  
          'vmid' => "#{item}",
          'driver' => driver_type,
          'location' => nil 
          })
      end
    when :fog
      raise "Unsupported"
    when :dynagen
      raise "Unsupported"
    when :remote_esxi
      vm_list = ::Lab::Controllers::RemoteEsxiController::running_list(user,host)
      vm_list.each do |item|
        @vms << Vm.new( {  
          'vmid' => "#{item[:id]}",
          'name' => "#{item[:name]}",
          'driver' => driver_type, 
          'user' => user,
          'host' => host 
          })
      end
    when :vsphere
      vm_list = ::Lab::Controllers::VsphereController::running_list(user,host,pass)
      vm_list.each do |item|
        @vms << Vm.new( {  
          'vmid' => "#{item[:id]}",
          'name' => "#{item[:name]}",
          'driver' => driver_type, 
          'user' => user,
          'host' => host,
          'pass' => pass
          })
      end
    else
      raise TypeError, "Unsupported VM Type"
    end

end