Class: Bosh::Director::DeploymentPlan::VipNetwork

Inherits:
Network show all
Includes:
IpUtil
Defined in:
lib/bosh/director/deployment_plan/vip_network.rb

Constant Summary

Constants inherited from Network

Network::VALID_DEFAULTS

Constants included from Bosh::Director::DnsHelper

Bosh::Director::DnsHelper::SOA, Bosh::Director::DnsHelper::TTL_4H, Bosh::Director::DnsHelper::TTL_5M

Instance Attribute Summary collapse

Attributes inherited from Network

#canonical_name, #deployment, #name

Instance Method Summary collapse

Methods included from IpUtil

#each_ip, #format_ip, #ip_to_i, #ip_to_netaddr, #process_range

Methods inherited from Network

#reserve!

Methods included from ValidationHelper

#invalid_type, #safe_property

Methods included from Bosh::Director::DnsHelper

#add_default_dns_server, #canonical, #default_dns_server, #delete_dns_records, #delete_empty_domain, #dns_domain_name, #dns_ns_record, #dns_servers, #flush_dns_cache, #invalid_dns, #reverse_domain, #reverse_host, #update_dns_a_record, #update_dns_ptr_record

Constructor Details

#initialize(deployment, network_spec) ⇒ VipNetwork

Creates a new network.

Parameters:

  • deployment (DeploymentPlan)

    associated deployment plan

  • network_spec (Hash)

    parsed deployment manifest network section



16
17
18
19
20
21
# File 'lib/bosh/director/deployment_plan/vip_network.rb', line 16

def initialize(deployment, network_spec)
  super
  @cloud_properties = safe_property(network_spec, "cloud_properties",
    class: Hash, default: {})
  @reserved_ips = Set.new
end

Instance Attribute Details

#cloud_propertiesHash (readonly)

Returns Network cloud properties.

Returns:

  • (Hash)

    Network cloud properties



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

def cloud_properties
  @cloud_properties
end

Instance Method Details

#network_settings(reservation, default_properties = VALID_DEFAULTS) ⇒ Hash

Returns the network settings for the specific reservation.

Parameters:

Returns:

  • (Hash)

    network settings that will be passed to the BOSH Agent



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

def network_settings(reservation, default_properties = VALID_DEFAULTS)
  if default_properties && !default_properties.empty?
    raise NetworkReservationVipDefaultProvided,
          "Can't provide any defaults since this is a VIP network"
  end

  {
    "type" => "vip",
    "ip" => ip_to_netaddr(reservation.ip).ip,
    "cloud_properties" => @cloud_properties
  }
end

#release(reservation) ⇒ void

This method returns an undefined value.

Releases a previous reservation that had been fulfilled.

Parameters:



51
52
53
54
55
56
57
# File 'lib/bosh/director/deployment_plan/vip_network.rb', line 51

def release(reservation)
  unless reservation.ip
    raise NetworkReservationIpMissing,
          "Can't release reservation without an IP"
  end
  @reserved_ips.delete(reservation.ip)
end

#reserve(reservation) ⇒ Boolean

Reserves a network resource.

This is either an already used reservation being verified or a new one waiting to be fulfilled.

Parameters:

Returns:

  • (Boolean)

    true if the reservation was fulfilled



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bosh/director/deployment_plan/vip_network.rb', line 30

def reserve(reservation)
  reservation.reserved = false
  if reservation.ip.nil?
    raise NetworkReservationIpMissing,
          "Must have IP for static reservations"
  elsif reservation.dynamic?
    reservation.error = NetworkReservation::WRONG_TYPE
  elsif @reserved_ips.include?(reservation.ip)
    reservation.error = NetworkReservation::USED
  else
    reservation.reserved = true
    reservation.type = NetworkReservation::STATIC
    @reserved_ips.add(reservation.ip)
  end
  reservation.reserved?
end