Class: Bosh::Director::DeploymentPlan::IdleVm
- Defined in:
- lib/bosh/director/deployment_plan/idle_vm.rb
Overview
Represents a resource pool VM.
It represents a VM until it’s officially bound to an instance. It can be reserved for an instance to minimize the number of CPI operations (network & storage) required for the VM to match the instance requirements.
Instance Attribute Summary collapse
-
#bound_instance ⇒ DeploymentPlan::Instance?
Instance that reserved this VM.
-
#current_state ⇒ Hash
Current state as provided by the BOSH Agent.
-
#network_reservation ⇒ NetworkReservation
VM network reservation.
-
#resource_pool ⇒ DeploymentPlan::ResourcePool
readonly
Associated resource pool.
-
#vm ⇒ Models::Vm
Associated model.
Instance Method Summary collapse
-
#changed? ⇒ Boolean
Returns true if the any of the expected specifications differ from the ones provided by the VM.
-
#has_network_reservation? ⇒ Boolean
Does this VM have a network reservation?.
-
#initialize(resource_pool) ⇒ IdleVm
constructor
Creates a new idle VM reference for the specific resource pool.
-
#network_settings ⇒ Hash
BOSH network settings used for Agent apply call.
-
#networks_changed? ⇒ Boolean
Returns true if the expected network configuration differs from the one provided by the VM.
-
#release_reservation ⇒ void
Releases current network reservation (if any).
-
#resource_pool_changed? ⇒ Boolean
Returns true if the expected resource pool specification differs from the one provided by the VM.
-
#use_reservation(reservation) ⇒ Object
Uses provided network reservation.
Constructor Details
#initialize(resource_pool) ⇒ IdleVm
Creates a new idle VM reference for the specific resource pool
31 32 33 34 35 36 37 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 31 def initialize(resource_pool) @resource_pool = resource_pool @current_state = nil @bound_instance = nil @network_reservation = nil @vm = nil end |
Instance Attribute Details
#bound_instance ⇒ DeploymentPlan::Instance?
Returns Instance that reserved this VM.
26 27 28 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 26 def bound_instance @bound_instance end |
#current_state ⇒ Hash
Returns Current state as provided by the BOSH Agent.
23 24 25 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 23 def current_state @current_state end |
#network_reservation ⇒ NetworkReservation
Returns VM network reservation.
17 18 19 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 17 def network_reservation @network_reservation end |
#resource_pool ⇒ DeploymentPlan::ResourcePool (readonly)
Returns Associated resource pool.
14 15 16 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 14 def resource_pool @resource_pool end |
#vm ⇒ Models::Vm
Returns Associated model.
20 21 22 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 20 def vm @vm end |
Instance Method Details
#changed? ⇒ Boolean
Returns true if the any of the expected specifications differ from the ones provided by the VM
104 105 106 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 104 def changed? resource_pool_changed? || networks_changed? end |
#has_network_reservation? ⇒ Boolean
Returns Does this VM have a network reservation?.
41 42 43 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 41 def has_network_reservation? !@network_reservation.nil? end |
#network_settings ⇒ Hash
Returns BOSH network settings used for Agent apply call.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 64 def network_settings # use the instance network settings if bound, otherwise use the one # provided by the resource pool if @bound_instance @bound_instance.network_settings else unless @network_reservation raise NetworkReservationMissing, "Missing network reservation for resource pool VM" end network_settings = {} network = @resource_pool.network network_settings[network.name] = network.network_settings( @network_reservation) network_settings end end |
#networks_changed? ⇒ Boolean
Returns true if the expected network configuration differs from the one provided by the VM
86 87 88 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 86 def networks_changed? network_settings != @current_state["networks"] end |
#release_reservation ⇒ void
This method returns an undefined value.
Releases current network reservation (if any)
55 56 57 58 59 60 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 55 def release_reservation if has_network_reservation? @resource_pool.network.release(@network_reservation) @network_reservation = nil end end |
#resource_pool_changed? ⇒ Boolean
Returns true if the expected resource pool specification differs from the one provided by the VM
93 94 95 96 97 98 99 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 93 def resource_pool_changed? return true if resource_pool.spec != @current_state["resource_pool"] return true if resource_pool.deployment_plan.recreate return true if @vm && @vm.env != resource_pool.env false end |
#use_reservation(reservation) ⇒ Object
Uses provided network reservation
48 49 50 |
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 48 def use_reservation(reservation) @network_reservation = reservation end |