Module: ComputeResourcesVmsHelper

Included in:
HostsHelper
Defined in:
app/helpers/compute_resources_vms_helper.rb

Instance Method Summary collapse

Instance Method Details

#libvirt_networks(compute) ⇒ Object


45
46
47
48
49
50
51
52
# File 'app/helpers/compute_resources_vms_helper.rb', line 45

def libvirt_networks(compute)
  networks   = compute.networks
  interfaces = compute.interfaces
  select     = []
  select << [_('Physical (Bridge)'), :bridge]
  select << [_('Virtual (NAT)'), :network] if networks.any?
  select
end

#prop(method, title = nil) ⇒ Object

little helper to help show VM properties


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/compute_resources_vms_helper.rb', line 4

def prop method, title = nil
   :tr do
    result =  :td do
      title || method.to_s.humanize
    end
    result +=  :td do
      value = @vm.send(method) rescue nil
      case value
      when Array
        value.map{|v| v.try(:name) || v.try(:to_s) || v}.to_sentence
      when Fog::Time, Time
        _("%s ago") % time_ago_in_words(value)
      when nil
          _("N/A")
      else
        value.to_s
      end
    end
    result
  end
end

#spice_data_attributes(console) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/compute_resources_vms_helper.rb', line 31

def spice_data_attributes(console)
  options = {
    :port     => console[:proxy_port],
    :password => console[:password]
  }
  options.merge!(
    :address     => console[:address],
    :secure_port => console[:secure_port],
    :ca_cert     => URI.escape(console[:ca_cert]),
    :title       => _("%s - Press Shift-F12 to release the cursor.") % console[:name]
  ) if supports_spice_xpi?
  options
end

#supports_spice_xpi?Boolean


26
27
28
29
# File 'app/helpers/compute_resources_vms_helper.rb', line 26

def supports_spice_xpi?
  user_agent = request.env['HTTP_USER_AGENT']
  user_agent =~ /linux/i && user_agent =~ /firefox/i
end