Module: FogExtensions::OpenNebula::Server
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- app/models/concerns/fog_extensions/opennebula/server.rb
Instance Attribute Summary collapse
- #disk_size ⇒ Object
- #image_id ⇒ Object
- #scheduler_hint_data ⇒ Object
- #scheduler_hint_filter ⇒ Object
- #template_id ⇒ Object
- #vmgroup_id ⇒ Object
- #vmgroup_role ⇒ Object
Instance Method Summary collapse
- #disks ⇒ Object
- #display ⇒ Object
- #host ⇒ Object
- #interfaces ⇒ Object
- #poweroff? ⇒ Boolean
- #reboot ⇒ Object
- #reset ⇒ Object
- #sched_message ⇒ Object
- #sched_requirements ⇒ Object
- #select_nic(fog_nics, nic) ⇒ Object
- #to_s ⇒ Object
- #vm_description ⇒ Object
Instance Attribute Details
#disk_size ⇒ Object
89 90 91 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 89 def disk_size disks.try(:first).try(:size) || @disk_size end |
#image_id ⇒ Object
85 86 87 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 85 def image_id disks.try(:first).try(:image_id) || @image_id end |
#scheduler_hint_data ⇒ Object
70 71 72 73 74 75 76 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 70 def scheduler_hint_data if sched_requirements scheduler_hint_filter == 'Raw' ? sched_requirements : sched_requirements[/\d+/] else @scheduler_hint_data end end |
#scheduler_hint_filter ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 55 def scheduler_hint_filter if sched_requirements case sched_requirements when /^CLUSTER_ID = \d+$/ 'Cluster' when /^ID = \d+$/ 'Host' else 'Raw' end else @scheduler_hint_filter end end |
#template_id ⇒ Object
38 39 40 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 38 def template_id onevm_object.present? ? onevm_object['TEMPLATE/TEMPLATE_ID'] : @template_id end |
#vmgroup_id ⇒ Object
42 43 44 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 42 def vmgroup_id onevm_object.present? ? onevm_object['TEMPLATE/VMGROUP/VMGROUP_ID'] : @vmgroup_id end |
#vmgroup_role ⇒ Object
46 47 48 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 46 def vmgroup_role onevm_object.present? ? onevm_object['TEMPLATE/VMGROUP/ROLE'] : @vmgroup_role end |
Instance Method Details
#disks ⇒ Object
78 79 80 81 82 83 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 78 def disks return if onevm_object.nil? [onevm_object.to_hash['VM']['TEMPLATE']['DISK']].flatten.compact.map do |disk| OpenStruct.new(disk.transform_keys(&:downcase)) end end |
#display ⇒ Object
111 112 113 114 115 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 111 def display graphics = onevm_object.to_hash['VM']['TEMPLATE']['GRAPHICS'] graphics['TYPE'].downcase! graphics.transform_keys(&:downcase).symbolize_keys end |
#host ⇒ Object
103 104 105 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 103 def host onevm_object['HISTORY_RECORDS/HISTORY[last()]/HOSTNAME'] end |
#interfaces ⇒ Object
93 94 95 96 97 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 93 def interfaces [onevm_object.to_hash['VM']['TEMPLATE']['NIC']].flatten.compact.map do |nic| OpenStruct.new(nic.transform_keys(&:downcase)) end end |
#poweroff? ⇒ Boolean
117 118 119 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 117 def poweroff? (status == 8) end |
#reboot ⇒ Object
28 29 30 31 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 28 def reboot onevm_object.reboot true end |
#reset ⇒ Object
33 34 35 36 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 33 def reset onevm_object.reboot(true) true end |
#sched_message ⇒ Object
107 108 109 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 107 def onevm_object['USER_TEMPLATE/SCHED_MESSAGE'] end |
#sched_requirements ⇒ Object
50 51 52 53 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 50 def sched_requirements return unless onevm_object onevm_object['USER_TEMPLATE/SCHED_REQUIREMENTS'] end |
#select_nic(fog_nics, nic) ⇒ Object
99 100 101 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 99 def select_nic(fog_nics, nic) fog_nics.detect { |fn| fn.network_id == nic.compute_attributes['vnet'] } end |
#to_s ⇒ Object
121 122 123 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 121 def to_s name end |
#vm_description ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 125 def vm_description _('%{cpu} CPU, %{vcpu} VCPU, %{memory} memory and %{disk} disk') % { :cpu => cpu, :vcpu => vcpu, :memory => number_to_human_size(memory.to_i.megabytes), :disk => number_to_human_size(disk_size.to_i.megabytes) } end |