Class: Bosh::Director::InstanceUpdater::NetworkUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/instance_updater/network_updater.rb

Defined Under Namespace

Classes: ConfigureNetworksStrategy, PrepareNetworkChangeStrategy

Instance Method Summary collapse

Constructor Details

#initialize(instance, vm_model, agent_client, vm_updater, cloud, logger) ⇒ NetworkUpdater

Returns a new instance of NetworkUpdater.



3
4
5
6
7
8
9
10
# File 'lib/bosh/director/instance_updater/network_updater.rb', line 3

def initialize(instance, vm_model, agent_client, vm_updater, cloud, logger)
  @instance = instance
  @vm_model = vm_model
  @agent_client = agent_client
  @vm_updater = vm_updater
  @cloud = cloud
  @logger = logger
end

Instance Method Details

#updateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bosh/director/instance_updater/network_updater.rb', line 12

def update
  unless @instance.networks_changed?
    @logger.info('Skipping network re-configuration')
    return [@vm_model, @agent_client]
  end

  network_settings = @instance.network_settings

  strategies = [
    ConfigureNetworksStrategy.new(@agent_client, network_settings, @logger),
    PrepareNetworkChangeStrategy.new(@agent_client, network_settings, @logger),
  ]

  @logger.info("Planning to reconfigure network with settings: #{network_settings}")
  selected_strategy = strategies.find { |s| s.before_configure_networks }

  @cloud.configure_networks(@vm_model.cid, network_settings)

  selected_strategy.after_configure_networks

  [@vm_model, @agent_client]

rescue Bosh::Clouds::NotSupported => e
  @logger.info("Failed reconfiguring existing VM: #{e.inspect}")

  # If configure_networks CPI method cannot reconfigure VM networking
  # (e.g. when the security groups change on AWS)
  # it raises Bosh::Clouds::NotSupported to indicate new VM is needed.
  @logger.info('Creating VM with new network configurations')
  @instance.recreate = true
  @vm_updater.update(nil)
end