Class: Bosh::Director::DeploymentPlan::NetworkSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/deployment_plan/network_settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(job_name, deployment_name, default_network, desired_reservations, current_networks, availability_zone, instance_index, instance_id, dns_manager) ⇒ NetworkSettings

Returns a new instance of NetworkSettings.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/bosh/director/deployment_plan/network_settings.rb', line 3

def initialize(job_name, deployment_name, default_network, desired_reservations, current_networks, availability_zone, instance_index, instance_id, dns_manager)
  @job_name = job_name
  @desired_reservations = desired_reservations
  @default_network = default_network
  @deployment_name = deployment_name
  @availability_zone = availability_zone
  @instance_index = instance_index
  @instance_id = instance_id
  @dns_manager = dns_manager
  @current_networks = current_networks
end

Instance Method Details

#dns_record_infoObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/bosh/director/deployment_plan/network_settings.rb', line 38

def dns_record_info
  dns_record_info = {}
  to_hash.each do |network_name, network|
    index_dns_name =  @dns_manager.dns_record_name(@instance_index, @job_name, network_name, @deployment_name)
    dns_record_info[index_dns_name] = network['ip']
    id_dns_name =  @dns_manager.dns_record_name(@instance_id, @job_name, network_name, @deployment_name)
    dns_record_info[id_dns_name] = network['ip']
  end
  dns_record_info
end

#network_address(preferred_network_name = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bosh/director/deployment_plan/network_settings.rb', line 49

def network_address(preferred_network_name = nil)
  network_name = preferred_network_name || @default_network['gateway']
  network_hash = to_hash

  if network_hash[network_name]['type'] == 'dynamic'
    address = @dns_manager.dns_record_name(@instance_id, @job_name, network_name, @deployment_name)
  else
    address = network_hash[network_name]['ip']
  end

  address
end

#network_addressesObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bosh/director/deployment_plan/network_settings.rb', line 62

def network_addresses
  network_addresses = {}

  to_hash.each do |network_name, network|
    if network['type'] == 'dynamic'
      address = @dns_manager.dns_record_name(@instance_id, @job_name, network_name, @deployment_name)
    else
      address = network['ip']
    end

    network_addresses[network_name] = address
  end

  network_addresses
end

#to_hashObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bosh/director/deployment_plan/network_settings.rb', line 15

def to_hash
  default_properties = {}
  @default_network.each do |key, value|
    (default_properties[value] ||= []) << key
  end

  network_settings = {}
  @desired_reservations.each do |reservation|
    network_name = reservation.network.name
    network_settings[network_name] = reservation.network.network_settings(reservation, default_properties[network_name], @availability_zone)
    # Somewhat of a hack: for dynamic networks we might know IP address, Netmask & Gateway
    # if they're featured in agent state, in that case we put them into network spec to satisfy
    # ConfigurationHasher in both agent and director.
    if @current_networks.is_a?(Hash) && @current_networks[network_name].is_a?(Hash) && network_settings[network_name]['type'] == 'dynamic'
      %w(ip netmask gateway).each do |key|
        network_settings[network_name][key] = @current_networks[network_name][key] unless @current_networks[network_name][key].nil?
      end
    end
  end

  network_settings
end