Module: ProxmoxComputeResourcesVmsHelper

Defined in:
app/helpers/proxmox_compute_resources_vms_helper.rb

Overview

You should have received a copy of the GNU General Public License along with ForemanFogProxmox. If not, see <www.gnu.org/licenses/>.

Instance Method Summary collapse

Instance Method Details

#proxmox_vm_id(compute_resource, vm) ⇒ Object



21
22
23
24
25
# File 'app/helpers/proxmox_compute_resources_vms_helper.rb', line 21

def proxmox_vm_id(compute_resource, vm)
  id = vm.identity
  id = vm.unique_cluster_identity(compute_resource) if compute_resource.instance_of?(ForemanFogProxmox::Proxmox)
  id
end

#vm_associate_action(vm) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/proxmox_compute_resources_vms_helper.rb', line 43

def vm_associate_action(vm)
  display_link_if_authorized(
    _('Associate VM'),
    hash_for_associate_compute_resource_vm_path(
      :compute_resource_id => @compute_resource,
      :id => proxmox_vm_id(@compute_resource, vm)
    ).merge(
      :auth_object => @compute_resource,
      :permission => 'edit_compute_resources'
    ),
    :title => _('Associate VM to a Foreman host'),
    :method => :put,
    :class => 'btn btn-default'
  )
end

#vm_console_action(vm) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/helpers/proxmox_compute_resources_vms_helper.rb', line 85

def vm_console_action(vm)
  return unless vm.ready?

  link_to_if_authorized(
    _('Console'),
    hash_for_console_compute_resource_vm_path.merge(
      :auth_object => @compute_resource,
      :id => proxmox_vm_id(@compute_resource, vm)
    ),
    {
      :id => 'console-button',
      :class => 'btn btn-info',
    }
  )
end

#vm_delete_action(vm, authorizer = nil) ⇒ Object



101
102
103
104
105
106
107
# File 'app/helpers/proxmox_compute_resources_vms_helper.rb', line 101

def vm_delete_action(vm, authorizer = nil)
  display_delete_if_authorized(
    hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => proxmox_vm_id(@compute_resource, vm)).merge(
      :auth_object => @compute_resource, :authorizer => authorizer
    ), :class => 'btn btn-danger'
  )
end

#vm_host_action(vm) ⇒ Object



27
28
29
30
31
32
# File 'app/helpers/proxmox_compute_resources_vms_helper.rb', line 27

def vm_host_action(vm)
  host = Host.for_vm_uuid(@compute_resource, vm).first
  return unless host

  display_link_if_authorized(_("Host"), hash_for_host_path(:id => host), :class => 'btn btn-default')
end

#vm_import_action(vm, html_options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/proxmox_compute_resources_vms_helper.rb', line 59

def vm_import_action(vm, html_options = {})
  @_linked_hosts_cache ||= Host.where(:compute_resource_id => @compute_resource.id).pluck(:uuid)
  return if @_linked_hosts_cache.include?(proxmox_vm_id(@compute_resource, vm).to_s)

  import_managed_link = display_link_if_authorized(
    _('Import as managed Host'),
    hash_for_import_compute_resource_vm_path(
      :compute_resource_id => @compute_resource,
      :id => proxmox_vm_id(@compute_resource, vm),
      :type => 'managed'
    ),
    html_options
  )
  import_unmanaged_link = display_link_if_authorized(
    _('Import as unmanaged Host'),
    hash_for_import_compute_resource_vm_path(
      :compute_resource_id => @compute_resource,
      :id => proxmox_vm_id(@compute_resource, vm),
      :type => 'unmanaged'
    ),
    html_options
  )

  import_managed_link + import_unmanaged_link
end

#vm_power_action(vm, authorizer = nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'app/helpers/proxmox_compute_resources_vms_helper.rb', line 34

def vm_power_action(vm, authorizer = nil)
  opts = hash_for_power_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => proxmox_vm_id(@compute_resource, vm)).merge(
    :auth_object => @compute_resource, :permission => 'power_compute_resources_vms', :authorizer => authorizer
  )
  html = power_action_html(vm)

  display_link_if_authorized "Power #{action_string(vm)}", opts, html.merge(:method => :put)
end