Class: OpenStack::Compute::Address
- Inherits:
-
Object
- Object
- OpenStack::Compute::Address
- Defined in:
- lib/openstack/compute/address.rb
Constant Summary collapse
- NON_ROUTABLE_ADDRESSES =
[IPAddr.new("10.0.0.0/8"), IPAddr.new("192.168.0.0/16"), IPAddr.new("172.16.0.0/12")]
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.fix_labels(addresses_info) ⇒ Object
IN: { “private”=> [“version”=>4, “version”=>4]} OUT: { “private”=> [“version”=>4], “public”=> [“version”=>4] }.
- .is_private?(address_string) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(label, address, version = 4) ⇒ Address
constructor
A new instance of Address.
Constructor Details
#initialize(label, address, version = 4) ⇒ Address
Returns a new instance of Address.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/openstack/compute/address.rb', line 27 def initialize(label, address, version = 4) @label = label if address.class == Hash then @address = address["addr"] @version = address["version"] else @address = address @version = version end end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
23 24 25 |
# File 'lib/openstack/compute/address.rb', line 23 def address @address end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
24 25 26 |
# File 'lib/openstack/compute/address.rb', line 24 def label @label end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
25 26 27 |
# File 'lib/openstack/compute/address.rb', line 25 def version @version end |
Class Method Details
.fix_labels(addresses_info) ⇒ Object
IN: { “private”=> [“version”=>4, “version”=>4]} OUT: { “private”=> [“version”=>4],
"public"=> [{"addr"=>"15.185.160.208", "version"=>4}] }
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/openstack/compute/address.rb', line 50 def self.fix_labels(addresses_info) addresses_info.inject({"public"=>[], "private"=>[]}) do |res, (label,address_struct_list)| address_struct_list.each do |address_struct| if(address_struct["version"==6])#v6 addresses are all routable... res["public"] << address_struct else is_private?(address_struct["addr"])? res["private"] << address_struct : res["public"] << address_struct end end res end end |
.is_private?(address_string) ⇒ Boolean
40 41 42 43 44 45 |
# File 'lib/openstack/compute/address.rb', line 40 def self.is_private?(address_string) NON_ROUTABLE_ADDRESSES.each do |no_route| return true if no_route.include?(address_string) end false end |