Class: Bosh::Director::DeploymentPlan::InstanceNetworkReservations
- Includes:
- IpUtil, Enumerable
- Defined in:
- lib/bosh/director/deployment_plan/instance_network_reservations.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
- .create_from_db(instance_model, deployment, logger) ⇒ Object
- .create_from_state(instance_model, state, deployment, logger) ⇒ Object
Instance Method Summary collapse
- #add_existing(instance_model, deployment, network_name, ip, ip_type, existing_network_type) ⇒ Object
- #clean ⇒ Object
- #delete(reservation) ⇒ Object
- #each(&block) ⇒ Object
- #find_for_network(network) ⇒ Object
-
#initialize(logger) ⇒ InstanceNetworkReservations
constructor
A new instance of InstanceNetworkReservations.
Methods included from IpUtil
#each_ip, #format_ip, #ip_to_i, #ip_to_netaddr
Constructor Details
#initialize(logger) ⇒ InstanceNetworkReservations
Returns a new instance of InstanceNetworkReservations.
39 40 41 42 |
# File 'lib/bosh/director/deployment_plan/instance_network_reservations.rb', line 39 def initialize(logger) @reservations = [] @logger = TaggedLogger.new(logger, 'network-configuration') end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
44 45 46 |
# File 'lib/bosh/director/deployment_plan/instance_network_reservations.rb', line 44 def logger @logger end |
Class Method Details
.create_from_db(instance_model, deployment, logger) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bosh/director/deployment_plan/instance_network_reservations.rb', line 18 def self.create_from_db(instance_model, deployment, logger) reservations = new(logger) reservations.logger.debug("Creating instance network reservations from database for instance '#{instance_model}'") ip_addresses = instance_model.ip_addresses.clone ip_addresses.each do |ip_address| reservations.add_existing(instance_model, deployment, ip_address.network_name, ip_address.address, ip_address.type, 'manual') end unless instance_model.spec.nil? # Dynamic network reservations are not saved in DB, recreating from instance spec instance_model.spec.fetch('networks', []).each do |network_name, network_config| next unless network_config['type'] == 'dynamic' reservations.add_existing(instance_model, deployment, network_name, network_config['ip'], '', network_config['type']) end end reservations end |
.create_from_state(instance_model, state, deployment, logger) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/bosh/director/deployment_plan/instance_network_reservations.rb', line 7 def self.create_from_state(instance_model, state, deployment, logger) reservations = new(logger) reservations.logger.debug("Creating instance network reservations from agent state for instance '#{instance_model}'") state.fetch('networks', []).each do |network_name, network_config| reservations.add_existing(instance_model, deployment, network_name, network_config['ip'], '', network_config['type']) end reservations end |
Instance Method Details
#add_existing(instance_model, deployment, network_name, ip, ip_type, existing_network_type) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/bosh/director/deployment_plan/instance_network_reservations.rb', line 62 def add_existing(instance_model, deployment, network_name, ip, ip_type, existing_network_type) network = deployment.network(network_name) || deployment.deleted_network(network_name) @logger.debug("Registering existing reservation with #{ip_type} IP '#{format_ip(ip)}' for instance '#{instance_model}' on network '#{network.name}'") reservation = ExistingNetworkReservation.new(instance_model, network, ip, existing_network_type) deployment.ip_provider.reserve_existing_ips(reservation) @reservations << reservation end |
#clean ⇒ Object
50 51 52 |
# File 'lib/bosh/director/deployment_plan/instance_network_reservations.rb', line 50 def clean @reservations = [] end |
#delete(reservation) ⇒ Object
58 59 60 |
# File 'lib/bosh/director/deployment_plan/instance_network_reservations.rb', line 58 def delete(reservation) @reservations.delete(reservation) end |
#each(&block) ⇒ Object
54 55 56 |
# File 'lib/bosh/director/deployment_plan/instance_network_reservations.rb', line 54 def each(&block) @reservations.each(&block) end |
#find_for_network(network) ⇒ Object
46 47 48 |
# File 'lib/bosh/director/deployment_plan/instance_network_reservations.rb', line 46 def find_for_network(network) @reservations.find { |r| r.network == network } end |