Class: Dcmgr::Models::HostPool
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]
- SUPPORTED_HYPERVISOR =
[HYPERVISOR_KVM]
Constants inherited
from BaseNew
BaseNew::LOCK_TABLES_KEY
Instance Method Summary
collapse
#account
Methods inherited from BaseNew
Proxy, dataset, default_row_lock_mode=, install_data, install_data_hooks, lock!, unlock!, #with_timestamps?
Instance Method Details
#after_initialize ⇒ Object
35
36
37
|
# File 'lib/dcmgr/models/host_pool.rb', line 35
def after_initialize
super
end
|
#check_capacity(spec) ⇒ Object
Returns true/false if the host pool has enough capacity to run the spec.
107
108
109
110
111
112
113
|
# File 'lib/dcmgr/models/host_pool.rb', line 107
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.cpu_cores } + spec.cpu_cores) &&
(self.offering_memory_size >= inst_on_hp.inject(0) {|t, i| t += i.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.
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/dcmgr/models/host_pool.rb', line 78
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.cpu_cores = spec.cpu_cores
i.memory_size = spec.memory_size
i.quota_weight = spec.quota_weight
i.host_pool = self
i.save
vnic = i.add_nic(network)
IpLease.lease(vnic, network)
nat_network = Network.find(:id => vnic[:nat_network_id])
IpLease.lease(vnic,nat_network) unless nat_network.nil?
i
end
|
#depend_resources? ⇒ boolean
Check if the resources exist depending on the HostPool.
68
69
70
|
# File 'lib/dcmgr/models/host_pool.rb', line 68
def depend_resources?
!self.instances_dataset.runnings.empty?
end
|
#status ⇒ Object
101
102
103
|
# File 'lib/dcmgr/models/host_pool.rb', line 101
def status
node.nil? ? :offline : node.state
end
|
#to_api_document ⇒ Object
115
116
117
118
119
|
# File 'lib/dcmgr/models/host_pool.rb', line 115
def to_api_document
h = to_hash
h.delete(:node_id)
h
end
|
#to_hash ⇒ Object
62
63
64
|
# File 'lib/dcmgr/models/host_pool.rb', line 62
def to_hash
super.merge(:status=>self.status)
end
|
#validate ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/dcmgr/models/host_pool.rb', line 39
def validate
super
unless self.node_id =~ /^hva[-.]/
errors.add(:node_id, "is invalid ID: #{self.node_id}")
end
if (h = self.class.filter(:node_id=>self.node_id).first) && h.id != self.id
errors.add(:node_id, " #{self.node_id} is already been associated to #{h.canonical_uuid} ")
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
|