Class: Bosh::Director::DeploymentPlan::ManualNetwork

Inherits:
NetworkWithSubnets show all
Extended by:
ValidationHelper
Includes:
IpUtil
Defined in:
lib/bosh/director/deployment_plan/manual_network.rb

Overview

Represents a explicitly configured network.

Constant Summary

Constants inherited from Network

Network::VALID_DEFAULTS

Instance Attribute Summary collapse

Attributes inherited from Network

#canonical_name, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ValidationHelper

safe_property

Methods included from IpUtil

#each_ip, #format_ip, #ip_to_i, #ip_to_netaddr

Methods inherited from NetworkWithSubnets

#availability_zones, #has_azs?, #supports_azs?

Methods inherited from Network

#has_azs?, #supports_azs?, #validate_reference_from_job!

Constructor Details

#initialize(name, subnets, logger) ⇒ ManualNetwork

Returns a new instance of ManualNetwork.



30
31
32
33
# File 'lib/bosh/director/deployment_plan/manual_network.rb', line 30

def initialize(name, subnets, logger)
  super(name, TaggedLogger.new(logger, 'network-configuration'))
  @subnets = subnets
end

Instance Attribute Details

#subnetsObject (readonly)

Returns the value of attribute subnets.



9
10
11
# File 'lib/bosh/director/deployment_plan/manual_network.rb', line 9

def subnets
  @subnets
end

Class Method Details

.parse(network_spec, availability_zones, global_network_resolver, logger) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bosh/director/deployment_plan/manual_network.rb', line 11

def self.parse(network_spec, availability_zones, global_network_resolver, logger)
  name = safe_property(network_spec, "name", :class => String)

  reserved_ranges = global_network_resolver.reserved_ranges
  subnet_specs = safe_property(network_spec, 'subnets', :class => Array)
  subnets = []
  subnet_specs.each do |subnet_spec|
    new_subnet = ManualNetworkSubnet.parse(name, subnet_spec, availability_zones, reserved_ranges)
    subnets.each do |subnet|
      if subnet.overlaps?(new_subnet)
        raise NetworkOverlappingSubnets, "Network '#{name}' has overlapping subnets"
      end
    end
    subnets << new_subnet
  end
  validate_all_subnets_use_azs(subnets, name)
  new(name, subnets, logger)
end

Instance Method Details

#find_az_names_for_ip(ip) ⇒ Object



73
74
75
76
77
78
# File 'lib/bosh/director/deployment_plan/manual_network.rb', line 73

def find_az_names_for_ip(ip)
  subnet = find_subnet_containing(ip)
  if subnet
    return subnet.availability_zone_names
  end
end

#find_subnet_containing(ip) { ... } ⇒ Object

Parameters:

  • ip (Integer, NetAddr::CIDR, String)

Yields:

  • the subnet that contains the IP.



86
87
88
# File 'lib/bosh/director/deployment_plan/manual_network.rb', line 86

def find_subnet_containing(ip)
  @subnets.find { |subnet| subnet.range.contains?(ip) }
end

#ip_type(cidr_ip) ⇒ Object



68
69
70
71
# File 'lib/bosh/director/deployment_plan/manual_network.rb', line 68

def ip_type(cidr_ip)
  static_ips = @subnets.map { |subnet| subnet.static_ips.to_a }.flatten
  static_ips.include?(cidr_ip.to_i) ? :static : :dynamic
end

#manual?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/bosh/director/deployment_plan/manual_network.rb', line 80

def manual?
  true
end

#network_settings(reservation, default_properties = VALID_DEFAULTS, availability_zone = nil) ⇒ Hash

Returns the network settings for the specific reservation.

Parameters:

Returns:

  • (Hash)

    network settings that will be passed to the BOSH Agent



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bosh/director/deployment_plan/manual_network.rb', line 41

def network_settings(reservation, default_properties = VALID_DEFAULTS, availability_zone = nil)
  unless reservation.ip
    raise NetworkReservationIpMissing,
          "Can't generate network settings without an IP"
  end

  ip = ip_to_netaddr(reservation.ip)
  subnet = find_subnet_containing(reservation.ip)
  unless subnet
    raise NetworkReservationInvalidIp, "Provided IP '#{ip}' does not belong to any subnet"
  end

  config = {
    "ip" => ip.ip,
    "netmask" => subnet.netmask,
    "cloud_properties" => subnet.cloud_properties
  }

  if default_properties
    config["default"] = default_properties.sort
  end

  config["dns"] = subnet.dns if subnet.dns
  config["gateway"] = subnet.gateway.ip if subnet.gateway
  config
end