Class: Bosh::Director::DeploymentPlan::ResourcePool
- Includes:
- ValidationHelper
- Defined in:
- lib/bosh/director/deployment_plan/resource_pool.rb
Instance Attribute Summary collapse
-
#active_vm_count ⇒ Integer
readonly
Number of active resource pool VMs.
-
#allocated_vms ⇒ Array<DeploymentPlan::IdleVm] List of allocated idle VMs
readonly
Array<DeploymentPlan::IdleVm] List of allocated idle VMs.
-
#cloud_properties ⇒ Hash
readonly
Cloud properties.
-
#deployment_plan ⇒ DeploymentPlan
readonly
Deployment plan.
-
#env ⇒ Hash
readonly
Resource pool environment.
-
#idle_vms ⇒ Array<DeploymentPlan::IdleVm>
readonly
List of idle VMs.
-
#name ⇒ String
readonly
Resource pool name.
-
#network ⇒ DeploymentPlan::Network
readonly
Network spec.
-
#size ⇒ Integer
readonly
Expected resource pool size (in VMs).
-
#stemcell ⇒ DeploymentPlan::Stemcell
readonly
Stemcell spec.
Instance Method Summary collapse
-
#add_idle_vm ⇒ Object
Adds a new VM to a list of managed idle VMs.
- #allocate_vm ⇒ Object
- #deallocate_vm(idle_vm_cid) ⇒ Object
-
#initialize(deployment_plan, spec) ⇒ ResourcePool
constructor
A new instance of ResourcePool.
-
#mark_active_vm ⇒ void
“Active” VM is a VM that is currently running a job.
-
#missing_vm_count ⇒ Integer
Returns a number of VMs that need to be created in order to bring this resource pool to a desired size.
-
#process_idle_vms ⇒ void
Creates IdleVm objects for any missing resource pool VMs and reserves dynamic networks for all idle VMs.
-
#reserve_capacity(n) ⇒ void
Checks if there is enough capacity to run extra N VMs, raise error if not enough capacity.
-
#reserve_dynamic_network ⇒ NetworkReservation
Tries to obtain one dynamic reservation in its own network.
- #reserve_errand_capacity(n) ⇒ Object
-
#spec ⇒ Hash
Returns resource pools spec as Hash (usually for agent to serialize).
Methods included from ValidationHelper
Constructor Details
#initialize(deployment_plan, spec) ⇒ ResourcePool
Returns a new instance of ResourcePool.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 40 def initialize(deployment_plan, spec) @deployment_plan = deployment_plan @name = safe_property(spec, "name", :class => String) @size = safe_property(spec, "size", :class => Integer) @cloud_properties = safe_property(spec, "cloud_properties", :class => Hash) stemcell_spec = safe_property(spec, "stemcell", :class => Hash) @stemcell = Stemcell.new(self, stemcell_spec) network_name = safe_property(spec, "network", :class => String) @network = @deployment_plan.network(network_name) if @network.nil? raise ResourcePoolUnknownNetwork, "Resource pool `#{@name}' references " + "an unknown network `#{network_name}'" end @env = safe_property(spec, "env", :class => Hash, :default => {}) @idle_vms = [] @allocated_vms = [] @active_vm_count = 0 @required_capacity = 0 @errand_capacity = 0 end |
Instance Attribute Details
#active_vm_count ⇒ Integer (readonly)
Returns Number of active resource pool VMs.
36 37 38 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 36 def active_vm_count @active_vm_count end |
#allocated_vms ⇒ Array<DeploymentPlan::IdleVm] List of allocated idle VMs (readonly)
Returns Array<DeploymentPlan::IdleVm] List of allocated idle VMs.
33 34 35 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 33 def allocated_vms @allocated_vms end |
#cloud_properties ⇒ Hash (readonly)
Returns Cloud properties.
24 25 26 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 24 def cloud_properties @cloud_properties end |
#deployment_plan ⇒ DeploymentPlan (readonly)
Returns Deployment plan.
15 16 17 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 15 def deployment_plan @deployment_plan end |
#env ⇒ Hash (readonly)
Returns Resource pool environment.
27 28 29 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 27 def env @env end |
#idle_vms ⇒ Array<DeploymentPlan::IdleVm> (readonly)
Returns List of idle VMs.
30 31 32 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 30 def idle_vms @idle_vms end |
#name ⇒ String (readonly)
Returns Resource pool name.
9 10 11 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 9 def name @name end |
#network ⇒ DeploymentPlan::Network (readonly)
Returns Network spec.
21 22 23 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 21 def network @network end |
#size ⇒ Integer (readonly)
Returns Expected resource pool size (in VMs).
12 13 14 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 12 def size @size end |
#stemcell ⇒ DeploymentPlan::Stemcell (readonly)
Returns Stemcell spec.
18 19 20 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 18 def stemcell @stemcell end |
Instance Method Details
#add_idle_vm ⇒ Object
Adds a new VM to a list of managed idle VMs
112 113 114 115 116 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 112 def add_idle_vm idle_vm = IdleVm.new(self) @idle_vms << idle_vm idle_vm end |
#allocate_vm ⇒ Object
118 119 120 121 122 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 118 def allocate_vm allocated_vm = @idle_vms.pop @allocated_vms << allocated_vm allocated_vm end |
#deallocate_vm(idle_vm_cid) ⇒ Object
124 125 126 127 128 129 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 124 def deallocate_vm(idle_vm_cid) deallocated_vm = @allocated_vms.find { |idle_vm| idle_vm.vm.cid == idle_vm_cid } @allocated_vms.delete(deallocated_vm) @idle_vms << deallocated_vm deallocated_vm end |
#mark_active_vm ⇒ void
This method returns an undefined value.
“Active” VM is a VM that is currently running a job
133 134 135 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 133 def mark_active_vm @active_vm_count += 1 end |
#missing_vm_count ⇒ Integer
Returns a number of VMs that need to be created in order to bring this resource pool to a desired size
107 108 109 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 107 def missing_vm_count @size - @active_vm_count - @idle_vms.size end |
#process_idle_vms ⇒ void
This method returns an undefined value.
Creates IdleVm objects for any missing resource pool VMs and reserves dynamic networks for all idle VMs.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 83 def process_idle_vms # First, see if we need any data structures to balance the pool size missing_vm_count.times { add_idle_vm } # Second, see if some of idle VMs still need network reservations idle_vms.each do |idle_vm| unless idle_vm.has_network_reservation? idle_vm.use_reservation(reserve_dynamic_network) end end end |
#reserve_capacity(n) ⇒ void
This method returns an undefined value.
Checks if there is enough capacity to run extra N VMs, raise error if not enough capacity
141 142 143 144 145 146 147 148 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 141 def reserve_capacity(n) @required_capacity += n if @required_capacity > @size raise ResourcePoolNotEnoughCapacity, "Resource pool `#{@name}' is not big enough: " + "#{@required_capacity} VMs needed, capacity is #{@size}" end end |
#reserve_dynamic_network ⇒ NetworkReservation
Tries to obtain one dynamic reservation in its own network
98 99 100 101 102 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 98 def reserve_dynamic_network reservation = NetworkReservation.new_dynamic @network.reserve!(reservation, "Resource pool `#{@name}'") reservation end |
#reserve_errand_capacity(n) ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 150 def reserve_errand_capacity(n) needed = n - @errand_capacity if needed > 0 reserve_capacity(needed) @errand_capacity = n end end |
#spec ⇒ Hash
Returns resource pools spec as Hash (usually for agent to serialize)
72 73 74 75 76 77 78 |
# File 'lib/bosh/director/deployment_plan/resource_pool.rb', line 72 def spec { "name" => @name, "cloud_properties" => @cloud_properties, "stemcell" => @stemcell.spec } end |