Class: Dcmgr::Models::PhysicalHost

Inherits:
Base
  • Object
show all
Defined in:
lib/dcmgr/models/physical_host.rb

Instance Attribute Summary

Attributes included from UUIDMethods::ClassMethods

#prefix_uuid

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UUIDMethods::ClassMethods

#[], #set_prefix_uuid, #trim_uuid

Methods included from UUIDMethods

#generate_uuid, #save, #setup_uuid, #to_s, #uuid

Class Method Details

.assign(instance) ⇒ Object



18
19
20
# File 'lib/dcmgr/models/physical_host.rb', line 18

def self.assign(instance)
  Dcmgr::scheduler.assign_to_instance(enable_hosts, instance)
end

.enable_hostsObject



14
15
16
# File 'lib/dcmgr/models/physical_host.rb', line 14

def self.enable_hosts
  filter(~:id => TagMapping.filter(:target_type=>TagMapping::TYPE_PHYSICAL_HOST).select(:target_id)).order_by(:id).all
end

Instance Method Details

#after_createObject



26
27
28
29
30
31
# File 'lib/dcmgr/models/physical_host.rb', line 26

def after_create
  super
  TagMapping.create(:tag_id=>Tag.system_tag(:STANDBY_INSTANCE).id,
                    :target_type=>TagMapping::TYPE_PHYSICAL_HOST,
                    :target_id=>self.id)
end

#before_createObject



22
23
24
# File 'lib/dcmgr/models/physical_host.rb', line 22

def before_create
  super
end

#create_location_tag(name, account) ⇒ Object



37
38
39
40
41
# File 'lib/dcmgr/models/physical_host.rb', line 37

def create_location_tag(name, )
  TagMapping.create(:tag_id=>Tag.create(:name=>name, :account=>).id,
                    :target_type=>TagMapping::TYPE_PHYSICAL_HOST_LOCATION,
                    :target_id=>self.id)
end

#instancesObject



33
34
35
# File 'lib/dcmgr/models/physical_host.rb', line 33

def instances
  self.hv_agents.map{|hva| hva.instances}.flatten
end

#setup_spaceObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dcmgr/models/physical_host.rb', line 48

def setup_space
  
  need_cpu_mhz = instances.inject(0) {|v, ins| v + ins.need_cpu_mhz}
  space_cpu_mhz = cpu_mhz - need_cpu_mhz
  # 10 % down
  @space_cpu_mhz = space_cpu_mhz * 0.9
  
  need_memory = instances.inject(0) {|v, ins| v + ins.need_memory}
  space_memory = memory - need_memory
  # 10 % down
  @space_memory = space_memory * 0.9
end

#space_cpu_mhzObject



43
44
45
46
# File 'lib/dcmgr/models/physical_host.rb', line 43

def space_cpu_mhz
  setup_space unless @space_cpu_mhz
  @space_cpu_mhz
end

#space_memoryObject



61
62
63
64
# File 'lib/dcmgr/models/physical_host.rb', line 61

def space_memory
  setup_space unless @space_memory
  @space_memory
end