Class: Dcmgr::Scheduler::HostNode::LeastUsage

Inherits:
Dcmgr::Scheduler::HostNodeScheduler show all
Includes:
Logger
Defined in:
lib/dcmgr/scheduler/host_node/least_usage.rb

Overview

Find host node which has the largest available capacity.

Instance Method Summary collapse

Methods included from Logger

create, default_logdev, included

Methods inherited from Dcmgr::Scheduler::HostNodeScheduler

#initialize

Constructor Details

This class inherits a constructor from Dcmgr::Scheduler::HostNodeScheduler

Instance Method Details

#schedule(instance) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dcmgr/scheduler/host_node/least_usage.rb', line 11

def schedule(instance)
  ds = Models::HostNode.online_nodes.filter(:arch=>instance.spec.arch,
                                            :hypervisor=>instance.spec.hypervisor)

  host_node = ds.all.find_all { |hn|
    hn.available_cpu_cores >= instance.cpu_cores && \
      hn.available_memory_size >= instance.memory_size
  }.sort_by { |hn|
    hn.available_memory_size
  }.reverse.first

  raise HostNodeSchedulingError if host_node.nil?
  instance.host_node = host_node
end