forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
operations.rb
60 lines (46 loc) · 1.94 KB
/
operations.rb
1
2
3
4
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module Vm::Operations
extend ActiveSupport::Concern
include Guest
include Power
include Lifecycle
included do
supports :html5_console do
consup = %w[vnc webmks spice].any? { |type| send(:console_supported?, type) }
_("The web-based HTML5 Console is not supported") unless consup
end
supports :vmrc_console do
_("VMRC Console not supported") unless console_supported?('VMRC')
end
supports :native_console do
_("VM NATIVE Console not supported") unless console_supported?('NATIVE')
end
supports :launch_html5_console do
_("The web-based HTML5 Console is not available because the VM is not powered on") unless power_state == 'on'
end
supports :launch_vmrc_console do
validate_remote_console_vmrc_support
rescue => err
_('VM VMRC Console error: %{error}') % {:error => err}
end
supports :launch_native_console do
validate_native_console_support
rescue => err
_('VM NATIVE Console error: %{error}') % {:error => err}
end
supports :collect_running_processes do
reason = N_('VM Process collection is only available for Windows VMs.') unless ['windows'].include?(platform)
reason ||= N_('VM Process collection is only available for Runnable VMs.') unless runnable?
reason ||= N_('VM Process collection is only available while the VM is powered on.') unless state == "on"
reason ||= N_('VM Process collection requires credentials set at the Zone level.') if my_zone.nil? || my_zone_obj.auth_user_pwd(:windows_domain).nil?
reason ||= N_('VM Process collection requires an IP address for the VM.') if ipaddresses.blank?
reason
end
end
def ipv4_address
return public_address unless public_address.nil?
ipaddresses.find { |ip| IPAddr.new(ip).ipv4? && !ip.starts_with?('192') }
end
def public_address
ipaddresses.find { |ip| !Addrinfo.tcp(ip, 80).ipv4_private? && IPAddr.new(ip).ipv4? }
end
end