Class: Bosh::AwsCloud::NetworkConfigurator
- Inherits:
-
Object
- Object
- Bosh::AwsCloud::NetworkConfigurator
- Includes:
- Helpers
- Defined in:
- lib/cloud/aws/network_configurator.rb
Overview
Represents AWS instance network config. EC2 instance has single NIC with dynamic IP address and (optionally) a single elastic IP address which instance itself is not aware of (vip). Thus we should perform a number of sanity checks for the network spec provided by director to make sure we don’t apply something EC2 doesn’t understand how to deal with.
Instance Attribute Summary collapse
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#vip_network ⇒ Object
readonly
Returns the value of attribute vip_network.
Instance Method Summary collapse
-
#configure(ec2, instance) ⇒ Object
Applies network configuration to the vm.
-
#initialize(spec) ⇒ NetworkConfigurator
constructor
Creates new network spec.
- #private_ip ⇒ Object
- #subnet ⇒ Object
- #vpc? ⇒ Boolean
Methods included from Helpers
#cloud_error, #extract_security_group_names
Constructor Details
#initialize(spec) ⇒ NetworkConfigurator
Creates new network spec
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cloud/aws/network_configurator.rb', line 21 def initialize(spec) unless spec.is_a?(Hash) raise ArgumentError, "Invalid spec, Hash expected, " \ "#{spec.class} provided" end @logger = Bosh::Clouds::Config.logger @network = nil @vip_network = nil spec.each_pair do |name, network_spec| network_type = network_spec["type"] || "manual" case network_type when "dynamic" cloud_error("Must have exactly one dynamic or manual network per instance") if @network @network = DynamicNetwork.new(name, network_spec) when "manual" cloud_error("Must have exactly one dynamic or manual network per instance") if @network @network = ManualNetwork.new(name, network_spec) when "vip" cloud_error("More than one vip network for '#{name}'") if @vip_network @vip_network = VipNetwork.new(name, network_spec) else cloud_error("Invalid network type '#{network_type}' for AWS, " \ "can only handle 'dynamic', 'vip', or 'manual' network types") end end unless @network cloud_error("Exactly one dynamic or manual network must be defined") end end |
Instance Attribute Details
#network ⇒ Object (readonly)
Returns the value of attribute network.
15 16 17 |
# File 'lib/cloud/aws/network_configurator.rb', line 15 def network @network end |
#vip_network ⇒ Object (readonly)
Returns the value of attribute vip_network.
15 16 17 |
# File 'lib/cloud/aws/network_configurator.rb', line 15 def vip_network @vip_network end |
Instance Method Details
#configure(ec2, instance) ⇒ Object
Applies network configuration to the vm
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cloud/aws/network_configurator.rb', line 73 def configure(ec2, instance) if @vip_network @vip_network.configure(ec2, instance) else # If there is no vip network we should disassociate any elastic IP # currently held by instance (as it might have had elastic IP before) elastic_ip = instance.elastic_ip if elastic_ip @logger.info("Disassociating elastic IP `#{elastic_ip}' " \ "from instance `#{instance.id}'") instance.disassociate_elastic_ip end end end |
#private_ip ⇒ Object
62 63 64 |
# File 'lib/cloud/aws/network_configurator.rb', line 62 def private_ip vpc? ? @network.private_ip : nil end |
#subnet ⇒ Object
58 59 60 |
# File 'lib/cloud/aws/network_configurator.rb', line 58 def subnet @network.subnet end |
#vpc? ⇒ Boolean
66 67 68 |
# File 'lib/cloud/aws/network_configurator.rb', line 66 def vpc? @network.is_a? ManualNetwork end |