Class: Discotheque::Metadata
- Inherits:
-
Object
- Object
- Discotheque::Metadata
- Defined in:
- lib/discotheque/metadata.rb
Instance Attribute Summary collapse
-
#availability_zone ⇒ Object
readonly
Returns the value of attribute availability_zone.
-
#group_name ⇒ Object
readonly
Returns the value of attribute group_name.
-
#image_id ⇒ Object
readonly
Returns the value of attribute image_id.
-
#instance_id ⇒ Object
readonly
Returns the value of attribute instance_id.
Instance Method Summary collapse
-
#initialize(mock = false) ⇒ Metadata
constructor
A new instance of Metadata.
Constructor Details
#initialize(mock = false) ⇒ Metadata
Returns a new instance of Metadata.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/discotheque/metadata.rb', line 6 def initialize(mock=false) if mock == true @image_id = "ami-221fec4b" # amazon linux ami @group_name = "default" @availability_zone = "us-east-1a" return else base_url = "http://169.254.169.254/latest/meta-data/" begin %w[instance-id ami-id security-groups availability-zone].each do |datum| datum == "availability-zone" ? url="#{base_url}/placement/#{datum}" : url="#{base_url}#{datum}" d = ::HTTParty.get("#{url}").parsed_response if datum == "security-groups" instance_variable_set "@group_name", d elsif datum == "ami-id" instance_variable_set "@image_id", d else instance_variable_set "@#{datum.gsub(/-/,"_")}", d end end rescue Errno::EHOSTUNREACH puts "This only makes sense on EC2 hosts" end end end |
Instance Attribute Details
#availability_zone ⇒ Object (readonly)
Returns the value of attribute availability_zone.
4 5 6 |
# File 'lib/discotheque/metadata.rb', line 4 def availability_zone @availability_zone end |
#group_name ⇒ Object (readonly)
Returns the value of attribute group_name.
4 5 6 |
# File 'lib/discotheque/metadata.rb', line 4 def group_name @group_name end |
#image_id ⇒ Object (readonly)
Returns the value of attribute image_id.
4 5 6 |
# File 'lib/discotheque/metadata.rb', line 4 def image_id @image_id end |
#instance_id ⇒ Object (readonly)
Returns the value of attribute instance_id.
4 5 6 |
# File 'lib/discotheque/metadata.rb', line 4 def instance_id @instance_id end |