lib/dcmgr/models/host_pool.rb in wakame-vdc-agents-10.12.0 vs lib/dcmgr/models/host_pool.rb in wakame-vdc-agents-11.06.0
- old
+ new
@@ -1,20 +1,23 @@
# -*- coding: utf-8 -*-
+require 'isono'
+
module Dcmgr::Models
class HostPool < AccountResource
taggable 'hp'
with_timestamps
- HYPERVISOR_XEN_34=:'xen-3.4'
- HYPERVISOR_XEN_40=:'xen-4.0'
- HYPERVISOR_KVM=:'kvm'
+ 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]
inheritable_schema do
String :node_id, :size=>80, :null=>true
String :arch, :size=>10, :null=>false # :x86, :x86_64
@@ -33,13 +36,18 @@
super
end
def validate
super
- unless self.node_id =~ /^hva-/
- errors.add(:node_id, "hva node has to be associated: #{self.node_id}")
+ # for compatibility: hva.xxx or hva-xxxx
+ 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
@@ -73,15 +81,22 @@
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)
+
+ #Lease the nat ip in case there is an outside network mapped
+ nat_network = Network.find(:id => vnic[:nat_network_id])
+ IpLease.lease(vnic,nat_network) unless nat_network.nil?
i
end
def status
node.nil? ? :offline : node.state
@@ -91,12 +106,17 @@
# @param [InstanceSpec] spec
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)
+ (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
+ def to_api_document
+ h = to_hash
+ h.delete(:node_id)
+ h
+ end
end
end