Class: Bosh::Director::DeploymentPlan::Vm
- Defined in:
- lib/bosh/director/deployment_plan/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 ⇒ Object
-
#model ⇒ Models::Vm
Associated DB model.
-
#network_reservation ⇒ NetworkReservation
VM network reservation.
-
#resource_pool ⇒ DeploymentPlan::ResourcePool
readonly
Associated resource pool.
Instance Method Summary collapse
-
#changed? ⇒ Boolean
Returns true if the any of the expected specifications differ from the ones provided by the VM.
-
#clean_vm ⇒ Object
TODO: rename ‘clean’.
-
#has_network_reservation? ⇒ Boolean
Does this VM have a network reservation?.
-
#initialize(resource_pool) ⇒ Vm
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) ⇒ Vm
Creates a new idle VM reference for the specific resource pool
36 37 38 39 40 41 42 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 36 def initialize(resource_pool) @resource_pool = resource_pool @current_state = nil @bound_instance = nil @network_reservation = nil @model = nil end |
Instance Attribute Details
#bound_instance ⇒ DeploymentPlan::Instance?
Returns Instance that reserved this VM.
24 25 26 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 24 def bound_instance @bound_instance end |
#current_state ⇒ Object
26 27 28 29 30 31 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 26 def current_state if @current_state @current_state.delete('release') end @current_state end |
#model ⇒ Models::Vm
Returns Associated DB model.
18 19 20 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 18 def model @model end |
#network_reservation ⇒ NetworkReservation
Returns VM network reservation.
15 16 17 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 15 def network_reservation @network_reservation end |
#resource_pool ⇒ DeploymentPlan::ResourcePool (readonly)
Returns Associated resource pool.
12 13 14 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 12 def resource_pool @resource_pool end |
Instance Method Details
#changed? ⇒ Boolean
Returns true if the any of the expected specifications differ from the ones provided by the VM
109 110 111 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 109 def changed? resource_pool_changed? || networks_changed? end |
#clean_vm ⇒ Object
TODO: rename ‘clean’
114 115 116 117 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 114 def clean_vm self.model = nil self.current_state = nil end |
#has_network_reservation? ⇒ Boolean
Returns Does this VM have a network reservation?.
46 47 48 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 46 def has_network_reservation? !@network_reservation.nil? end |
#network_settings ⇒ Hash
Returns BOSH network settings used for Agent apply call.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 69 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
91 92 93 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 91 def networks_changed? network_settings != @current_state['networks'] end |
#release_reservation ⇒ void
This method returns an undefined value.
Releases current network reservation (if any)
60 61 62 63 64 65 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 60 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
98 99 100 101 102 103 104 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 98 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 @model && @model.env != resource_pool.env false end |
#use_reservation(reservation) ⇒ Object
Uses provided network reservation
53 54 55 |
# File 'lib/bosh/director/deployment_plan/vm.rb', line 53 def use_reservation(reservation) @network_reservation = reservation end |