Module: ForemanFogProxmox::ComputeResourcesVmsController::Overrides

Defined in:
app/controllers/concerns/foreman_fog_proxmox/compute_resources_vms_controller.rb

Instance Method Summary collapse

Instance Method Details

#associateObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/concerns/foreman_fog_proxmox/compute_resources_vms_controller.rb', line 27

def associate
  if Host.for_vm_uuid(@compute_resource, @vm).any?
    process_error(:error_msg => _("VM already associated with a host"),
      :redirect => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id],
        :id => proxmox_vm_id(@compute_resource, @vm)))
    return
  end
  host = @compute_resource.associated_host(@vm) if @compute_resource.respond_to?(:associated_host)
  if host.present?
    host.associate!(@compute_resource, @vm)
    process_success(:success_msg => _("VM associated to host %s") % host.name,
      :success_redirect => host_path(host))
  else
    process_error(:error_msg => _("No host found to associate this VM with"),
      :redirect => compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id],
        :id => proxmox_vm_id(@compute_resource, @vm)))
  end
end

#consoleObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/concerns/foreman_fog_proxmox/compute_resources_vms_controller.rb', line 46

def console
  @console = @compute_resource.console proxmox_vm_id(@compute_resource, @vm)
  render case @console[:type]
         when 'spice'
           'hosts/console/spice'
         when 'vnc'
           'hosts/console/vnc'
         when 'vmrc'
           'hosts/console/vmrc'
         else
           'hosts/console/log'
         end
rescue StandardError => e
  process_error :redirect => compute_resource_vm_path(@compute_resource, proxmox_vm_id(@compute_resource, @vm)),
    :error_msg => (_("Failed to set console: %s") % e), :object => @vm
end