Class: Bosh::Director::DesiredNetworkReservation

Inherits:
NetworkReservation show all
Defined in:
lib/bosh/director/network_reservation.rb

Instance Attribute Summary

Attributes inherited from NetworkReservation

#instance_model, #ip, #network, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NetworkReservation

#dynamic?, #mark_reserved, #reserved?, #resolve_network, #static?

Methods included from IpUtil

#each_ip, #format_ip, #ip_to_i, #ip_to_netaddr

Constructor Details

#initialize(instance_model, network, ip, type) ⇒ DesiredNetworkReservation

Returns a new instance of DesiredNetworkReservation.



72
73
74
75
76
# File 'lib/bosh/director/network_reservation.rb', line 72

def initialize(instance_model, network, ip, type)
  super(instance_model, network)
  @ip = ip_to_i(ip) if ip
  @type = type
end

Class Method Details

.new_dynamic(instance_model, network) ⇒ Object



64
65
66
# File 'lib/bosh/director/network_reservation.rb', line 64

def self.new_dynamic(instance_model, network)
  new(instance_model, network, nil, :dynamic)
end

.new_static(instance_model, network, ip) ⇒ Object



68
69
70
# File 'lib/bosh/director/network_reservation.rb', line 68

def self.new_static(instance_model, network, ip)
  new(instance_model, network, ip, :static)
end

Instance Method Details

#descObject



91
92
93
# File 'lib/bosh/director/network_reservation.rb', line 91

def desc
  "#{type} reservation with IP '#{formatted_ip}' for instance #{@instance_model}"
end

#resolve_ip(ip) ⇒ Object



78
79
80
# File 'lib/bosh/director/network_reservation.rb', line 78

def resolve_ip(ip)
  @ip = ip_to_i(ip)
end

#resolve_type(type) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/bosh/director/network_reservation.rb', line 82

def resolve_type(type)
  if @type != type
    raise NetworkReservationWrongType,
      "IP '#{formatted_ip}' on network '#{@network.name}' does not belong to #{@type} pool"
  end

  @type = type
end

#to_sObject



95
96
97
# File 'lib/bosh/director/network_reservation.rb', line 95

def to_s
  "{type=#{type}, ip=#{formatted_ip}, network=#{@network.name}, instance=#{@instance_model}}"
end