Class: ForemanProxmox::VirtualmachinesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/foreman_proxmox/virtualmachines_controller.rb

Instance Method Summary collapse

Instance Method Details

#create_vmObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/foreman_proxmox/virtualmachines_controller.rb', line 5

def create_vm
  host = Host.find(params[:id])
  $LOG= Logger.new("/tmp/proxmox_debug.log")
  
  if Virtualmachine.where("host_id = '#{host.id}'").first == nil then
    new_vm = Virtualmachine.new
    
    $LOG.error("creating vm")
    
    if host.params['vmid'] == nil then
      $LOG.error("searching vmid")
      new_vm.get_free_vmid
    else
      new_vm.vmid = host.params['vmid']
    end
    
    $LOG.error(new_vm.vmid)
    new_vm.sockets = host.params['sockets']
    new_vm.cores = host.params['cores']
    new_vm.memory = host.params['memory']
    new_vm.size = host.params['size']
    new_vm.mac = host.mac
    new_vm.host_id = host.id
  
    if new_vm.save then
      flash[:notice] = "VM saved in DB"
    else
      flash[:error] = _('Fail')
    end
  end
  
  new_vm = Virtualmachine.where("host_id = '#{host.id}'").first
  
  new_vm.create_harddisk
  new_vm.create_virtualmachine
  new_vm.start
  
  redirect_to :back
end

#delete_vmObject



63
64
65
66
67
# File 'app/controllers/foreman_proxmox/virtualmachines_controller.rb', line 63

def delete_vm
  vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
  vm.delete_virtualmachine
  redirect_to :back
end

#reboot_vmObject



57
58
59
60
61
# File 'app/controllers/foreman_proxmox/virtualmachines_controller.rb', line 57

def reboot_vm
  vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
  vm.reboot
  redirect_to :back
end

#showObject



71
72
73
# File 'app/controllers/foreman_proxmox/virtualmachines_controller.rb', line 71

def show
  @vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
end

#start_vmObject



45
46
47
48
49
# File 'app/controllers/foreman_proxmox/virtualmachines_controller.rb', line 45

def start_vm
  vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
  vm.start
  redirect_to :back
end

#stop_vmObject



51
52
53
54
55
# File 'app/controllers/foreman_proxmox/virtualmachines_controller.rb', line 51

def stop_vm
  vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
  vm.stop
  redirect_to :back
end