Class: Dcmgr::Models::HostPool
- Inherits:
-
AccountResource
- Object
- Sequel::Model
- BaseNew
- AccountResource
- Dcmgr::Models::HostPool
- Defined in:
- lib/dcmgr/models/host_pool.rb
Constant Summary collapse
- HYPERVISOR_XEN_34 =
:'xen-3.4'
- HYPERVISOR_XEN_40 =
:'xen-4.0'
- HYPERVISOR_KVM =
:'kvm'
- ARCH_X86 =
:x86.to_s
- ARCH_X86_64 =
:x86_64.to_s
- SUPPORTED_ARCH =
[ARCH_X86, ARCH_X86_64]
Constants inherited from BaseNew
Instance Method Summary collapse
- #after_initialize ⇒ Object
-
#check_capacity(spec) ⇒ Object
Returns true/false if the host pool has enough capacity to run the spec.
-
#create_instance(account, image, spec, network, &blk) ⇒ Models::Instance
Factory method for Instance model to run on this HostPool.
-
#depend_resources? ⇒ boolean
Check if the resources exist depending on the HostPool.
- #status ⇒ Object
- #to_hash ⇒ Object
- #validate ⇒ Object
Methods inherited from AccountResource
Methods inherited from BaseNew
Proxy, dataset, install_data, install_data_hooks, lock!, unlock!
Instance Method Details
#after_initialize ⇒ Object
32 33 34 |
# File 'lib/dcmgr/models/host_pool.rb', line 32 def after_initialize super end |
#check_capacity(spec) ⇒ Object
Returns true/false if the host pool has enough capacity to run the spec.
92 93 94 95 96 97 98 |
# File 'lib/dcmgr/models/host_pool.rb', line 92 def check_capacity(spec) raise TypeError unless spec.is_a?(InstanceSpec) inst_on_hp = self.instances_dataset.lives.all (self.offering_cpu_cores > inst_on_hp.inject(0) {|t, i| t += i.spec.cpu_cores } + spec.cpu_cores) && (self.offering_memory_size > inst_on_hp.inject(0) {|t, i| t += i.spec.memory_size } + spec.memory_size) end |
#create_instance(account, image, spec, network, &blk) ⇒ Models::Instance
Factory method for Instance model to run on this HostPool.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/dcmgr/models/host_pool.rb', line 70 def create_instance(account, image, spec, network, &blk) raise ArgumentError unless image.is_a?(Image) raise ArgumentError unless spec.is_a?(InstanceSpec) raise ArgumentError unless network.is_a?(Network) i = Instance.new &blk i.account_id = account.canonical_uuid i.image = image i.instance_spec = spec i.host_pool = self i.save vnic = i.add_nic(network) IpLease.lease(vnic, network) i end |
#depend_resources? ⇒ boolean
Check if the resources exist depending on the HostPool.
60 61 62 |
# File 'lib/dcmgr/models/host_pool.rb', line 60 def depend_resources? !self.instances_dataset.runnings.empty? end |
#status ⇒ Object
86 87 88 |
# File 'lib/dcmgr/models/host_pool.rb', line 86 def status node.nil? ? :offline : node.state end |
#to_hash ⇒ Object
54 55 56 |
# File 'lib/dcmgr/models/host_pool.rb', line 54 def to_hash super.merge(:status=>self.status) end |
#validate ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dcmgr/models/host_pool.rb', line 36 def validate super unless self.node_id =~ /^hva-/ errors.add(:node_id, "hva node has to be associated: #{self.node_id}") end unless SUPPORTED_ARCH.member?(self.arch) errors.add(:arch, "unknown architecture type: #{self.arch}") end unless self.offering_cpu_cores > 0 errors.add(:offering_cpu_cores, "it must have digit more than zero") end unless self.offering_memory_size > 0 errors.add(:offering_memory_size, "it must have digit more than zero") end end |