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

Instance Method Summary collapse

Instance Attribute Details

#disk_sizeObject



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_idObject



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_dataObject



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_filterObject



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_idObject



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_idObject



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_roleObject



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

#disksObject



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

#displayObject



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

#hostObject



103
104
105
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 103

def host
  onevm_object['HISTORY_RECORDS/HISTORY[last()]/HOSTNAME']
end

#interfacesObject



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

Returns:

  • (Boolean)


117
118
119
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 117

def poweroff?
  (status == 8)
end

#rebootObject



28
29
30
31
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 28

def reboot
  onevm_object.reboot
  true
end

#resetObject



33
34
35
36
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 33

def reset
  onevm_object.reboot(true)
  true
end

#sched_messageObject



107
108
109
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 107

def sched_message
  onevm_object['USER_TEMPLATE/SCHED_MESSAGE']
end

#sched_requirementsObject



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_sObject



121
122
123
# File 'app/models/concerns/fog_extensions/opennebula/server.rb', line 121

def to_s
  name
end

#vm_descriptionObject



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