Class: Bosh::Director::DeploymentPlan::InstancePlan
- Defined in:
- lib/bosh/director/deployment_plan/instance_plan.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#desired_instance ⇒ Object
readonly
Returns the value of attribute desired_instance.
-
#existing_instance ⇒ Object
readonly
Returns the value of attribute existing_instance.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#network_plans ⇒ Object
Returns the value of attribute network_plans.
-
#recreate_deployment ⇒ Object
readonly
Returns the value of attribute recreate_deployment.
-
#skip_drain ⇒ Object
readonly
Returns the value of attribute skip_drain.
Instance Method Summary collapse
- #already_detached? ⇒ Boolean
-
#changed? ⇒ Boolean
Returns true if the any of the expected specifications differ from the ones provided by the VM.
-
#changes ⇒ Set<Symbol>
Returns a set of all of the specification differences.
- #configuration_changed? ⇒ Boolean
- #desired_az_name ⇒ Object
- #dns_changed? ⇒ Boolean
- #existing? ⇒ Boolean
- #find_existing_reservation_for_network(network) ⇒ Object
-
#initialize(attrs) ⇒ InstancePlan
constructor
A new instance of InstancePlan.
- #instance_model ⇒ Object
- #job_changed? ⇒ Boolean
- #mark_desired_network_plans_as_existing ⇒ Object
- #needs_disk? ⇒ Boolean
- #needs_recreate? ⇒ Boolean
- #needs_restart? ⇒ Boolean
- #needs_shutting_down? ⇒ Boolean
- #network_address(network_name) ⇒ Object
- #network_addresses ⇒ Object
- #network_plan_for_network(network) ⇒ Object
- #network_settings ⇒ Object
- #network_settings_hash ⇒ Object
- #networks_changed? ⇒ Boolean
- #new? ⇒ Boolean
- #obsolete? ⇒ Boolean
- #packages_changed? ⇒ Boolean
- #persist_current_spec ⇒ Object
- #persistent_disk_changed? ⇒ Boolean
- #release_all_network_plans ⇒ Object
- #release_obsolete_network_plans ⇒ Object
- #should_be_ignored? ⇒ Boolean
- #spec ⇒ Object
- #state_changed? ⇒ Boolean
- #templates ⇒ Object
Constructor Details
#initialize(attrs) ⇒ InstancePlan
Returns a new instance of InstancePlan.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 5 def initialize(attrs) @existing_instance = attrs.fetch(:existing_instance) @desired_instance = attrs.fetch(:desired_instance) @instance = attrs.fetch(:instance) @network_plans = attrs.fetch(:network_plans, []) @skip_drain = attrs.fetch(:skip_drain, false) @recreate_deployment = attrs.fetch(:recreate_deployment, false) @logger = attrs.fetch(:logger, Config.logger) @dns_manager = DnsManagerProvider.create end |
Instance Attribute Details
#desired_instance ⇒ Object (readonly)
Returns the value of attribute desired_instance.
16 17 18 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 16 def desired_instance @desired_instance end |
#existing_instance ⇒ Object (readonly)
Returns the value of attribute existing_instance.
16 17 18 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 16 def existing_instance @existing_instance end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
16 17 18 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 16 def instance @instance end |
#network_plans ⇒ Object
Returns the value of attribute network_plans.
18 19 20 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 18 def network_plans @network_plans end |
#recreate_deployment ⇒ Object (readonly)
Returns the value of attribute recreate_deployment.
16 17 18 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 16 def recreate_deployment @recreate_deployment end |
#skip_drain ⇒ Object (readonly)
Returns the value of attribute skip_drain.
16 17 18 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 16 def skip_drain @skip_drain end |
Instance Method Details
#already_detached? ⇒ Boolean
252 253 254 255 256 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 252 def already_detached? return false if new? @existing_instance.state == 'detached' end |
#changed? ⇒ Boolean
Returns true if the any of the expected specifications differ from the ones provided by the VM
23 24 25 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 23 def changed? !changes.empty? end |
#changes ⇒ Set<Symbol>
Returns a set of all of the specification differences
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 29 def changes return @changes if @changes @changes = Set.new @changes << :dirty if @instance.dirty? @changes << :restart if needs_restart? @changes << :recreate if needs_recreate? @changes << :cloud_properties if instance.cloud_properties_changed? @changes << :stemcell if stemcell_changed? @changes << :env if env_changed? @changes << :network if networks_changed? @changes << :packages if packages_changed? @changes << :persistent_disk if persistent_disk_changed? @changes << :configuration if configuration_changed? @changes << :job if job_changed? @changes << :state if state_changed? @changes << :dns if dns_changed? @changes << :trusted_certs if instance.trusted_certs_changed? @changes end |
#configuration_changed? ⇒ Boolean
140 141 142 143 144 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 140 def configuration_changed? changed = instance.configuration_hash != instance_model.spec_p('configuration_hash') log_changes(__method__, instance_model.spec_p('configuration_hash'), instance.configuration_hash, instance) if changed changed end |
#desired_az_name ⇒ Object
213 214 215 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 213 def desired_az_name @desired_instance.az ? @desired_instance.az.name : nil end |
#dns_changed? ⇒ Boolean
130 131 132 133 134 135 136 137 138 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 130 def dns_changed? return false unless @dns_manager.dns_enabled? network_settings.dns_record_info.any? do |name, ip| not_found = @dns_manager.find_dns_record(name, ip).nil? @logger.debug("#{__method__} The requested dns record with name '#{name}' and ip '#{ip}' was not found in the db.") if not_found not_found end end |
#existing? ⇒ Boolean
166 167 168 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 166 def existing? !new? && !obsolete? end |
#find_existing_reservation_for_network(network) ⇒ Object
209 210 211 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 209 def find_existing_reservation_for_network(network) @instance.existing_network_reservations.find_for_network(network) end |
#instance_model ⇒ Object
67 68 69 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 67 def instance_model new? ? instance.model : existing_instance end |
#job_changed? ⇒ Boolean
231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 231 def job_changed? job = @desired_instance.job return true if @instance.current_job_spec.nil? # The agent job spec could be in legacy form. job_spec cannot be, # though, because we got it from the spec function in job.rb which # automatically makes it non-legacy. converted_current = InstanceGroup.convert_from_legacy_spec(@instance.current_job_spec) changed = job.spec != converted_current log_changes(__method__, converted_current, job.spec, @instance) if changed changed end |
#mark_desired_network_plans_as_existing ⇒ Object
146 147 148 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 146 def mark_desired_network_plans_as_existing network_plans.select(&:desired?).each { |network_plan| network_plan.existing = true } end |
#needs_disk? ⇒ Boolean
258 259 260 261 262 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 258 def needs_disk? job = @desired_instance.job job && job.persistent_disk_type && job.persistent_disk_type.disk_size > 0 end |
#needs_recreate? ⇒ Boolean
79 80 81 82 83 84 85 86 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 79 def needs_recreate? if @recreate_deployment @logger.debug("#{__method__} job deployment is configured with \"recreate\" state") true else @instance.virtual_state == 'recreate' end end |
#needs_restart? ⇒ Boolean
75 76 77 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 75 def needs_restart? @instance.virtual_state == 'restart' end |
#needs_shutting_down? ⇒ Boolean
200 201 202 203 204 205 206 207 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 200 def needs_shutting_down? return true if obsolete? instance.cloud_properties_changed? || stemcell_changed? || env_changed? || needs_recreate? end |
#network_address(network_name) ⇒ Object
192 193 194 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 192 def network_address(network_name) network_settings.network_address(network_name) end |
#network_addresses ⇒ Object
196 197 198 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 196 def network_addresses network_settings.network_addresses end |
#network_plan_for_network(network) ⇒ Object
217 218 219 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 217 def network_plan_for_network(network) @network_plans.find { |plan| plan.reservation.network == network } end |
#network_settings ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 170 def network_settings desired_reservations = network_plans .reject(&:obsolete?) .map { |network_plan| network_plan.reservation } DeploymentPlan::NetworkSettings.new( @instance.job_name, @instance.model.deployment.name, @desired_instance.job.default_network, desired_reservations, @instance.current_networks, @instance.availability_zone, @instance.index, @instance.uuid, @dns_manager ) end |
#network_settings_hash ⇒ Object
188 189 190 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 188 def network_settings_hash network_settings.to_hash end |
#networks_changed? ⇒ Boolean
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 88 def networks_changed? desired_network_plans = network_plans.select(&:desired?) obsolete_network_plans = network_plans.select(&:obsolete?) old_network_settings = new? ? {} : @existing_instance.spec_p('networks') new_network_settings = network_settings.to_hash changed = false if obsolete_network_plans.any? @logger.debug("#{__method__} obsolete reservations: [#{obsolete_network_plans.map(&:reservation).map(&:to_s).join(", ")}]") changed = true end if desired_network_plans.any? @logger.debug("#{__method__} desired reservations: [#{desired_network_plans.map(&:reservation).map(&:to_s).join(", ")}]") changed = true end if network_settings_changed?(old_network_settings, new_network_settings) @logger.debug("#{__method__} network settings changed FROM: #{old_network_settings} TO: #{new_network_settings} on instance #{@existing_instance}") changed = true end changed end |
#new? ⇒ Boolean
162 163 164 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 162 def new? existing_instance.nil? end |
#obsolete? ⇒ Boolean
158 159 160 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 158 def obsolete? desired_instance.nil? end |
#packages_changed? ⇒ Boolean
244 245 246 247 248 249 250 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 244 def packages_changed? job = @desired_instance.job changed = job.package_spec != @instance.current_packages log_changes(__method__, @instance.current_packages, job.package_spec, @instance) if changed changed end |
#persist_current_spec ⇒ Object
264 265 266 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 264 def persist_current_spec instance_model.update(spec: spec.full_spec) end |
#persistent_disk_changed? ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 50 def persistent_disk_changed? if @existing_instance && obsolete? return !@existing_instance.persistent_disk.nil? end job = @desired_instance.job new_disk_size = job.persistent_disk_type ? job.persistent_disk_type.disk_size : 0 new_disk_cloud_properties = job.persistent_disk_type ? job.persistent_disk_type.cloud_properties : {} changed = new_disk_size != disk_size log_changes(__method__, "disk size: #{disk_size}", "disk size: #{new_disk_size}", @existing_instance) if changed return true if changed changed = new_disk_size != 0 && new_disk_cloud_properties != disk_cloud_properties log_changes(__method__, disk_cloud_properties, new_disk_cloud_properties, @existing_instance) if changed changed end |
#release_all_network_plans ⇒ Object
154 155 156 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 154 def release_all_network_plans network_plans.clear end |
#release_obsolete_network_plans ⇒ Object
150 151 152 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 150 def release_obsolete_network_plans network_plans.delete_if(&:obsolete?) end |
#should_be_ignored? ⇒ Boolean
71 72 73 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 71 def should_be_ignored? !instance_model.nil? && instance_model.ignore end |
#spec ⇒ Object
221 222 223 224 225 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 221 def spec return InstanceSpec.create_empty if obsolete? InstanceSpec.create_from_instance_plan(self) end |
#state_changed? ⇒ Boolean
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 114 def state_changed? if instance.state == 'detached' && existing_instance.state != instance.state @logger.debug("Instance '#{instance}' needs to be detached") return true end if instance.state == 'stopped' && instance.current_job_state == 'running' || instance.state == 'started' && instance.current_job_state != 'running' @logger.debug("Instance state is '#{instance.state}' and agent reports '#{instance.current_job_state}'") return true end false end |
#templates ⇒ Object
227 228 229 |
# File 'lib/bosh/director/deployment_plan/instance_plan.rb', line 227 def templates @desired_instance.job.templates end |