ec2meta 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +19 -0
  2. data/ec2meta.gemspec +19 -0
  3. data/lib/ec2meta.rb +42 -0
  4. data/test/test_ec2meta.rb +39 -0
  5. metadata +57 -0
data/README ADDED
@@ -0,0 +1,19 @@
1
+ ec2meta-rb ~ ec2 instance metadata wrapper for ruby
2
+
3
+ $ irb
4
+ >> require "ec2meta"
5
+ => true
6
+ >> EC2M.instance_id
7
+ => "i-12345"
8
+ >> EC2M.public_ipv4
9
+ => "12.32.41.12"
10
+
11
+ ec2meta-rb is available from gemcutter, named `ec2meta`.
12
+
13
+ implemented/available commands:
14
+
15
+ ami_id, ami_launch_index, ami_manifest_path, ancestor_ami_ids,
16
+ availability_zone, block_device_mapping(device), hostname,
17
+ instance_action, instance_id, instance_type, kernel_id
18
+ local_hostname, local_ipv4, public_hostname, public_ipv4
19
+ ramdisk_id, reservation_id
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ec2meta"
3
+ s.version = "0.1"
4
+ s.date = "2010-01-05"
5
+ s.summary = "ec2 instance metadata wrapper for ruby"
6
+ s.email = "harry@vangberg.name"
7
+ s.homepage = "http://github.com/ichverstehe/ec2meta-rb"
8
+ s.description = "ec2 instance metadata wrapper for ruby"
9
+ s.has_rdoc = false
10
+ s.authors = ["Harry Vangberg"]
11
+ s.files = [
12
+ "README",
13
+ "ec2meta.gemspec",
14
+ "lib/ec2meta.rb"
15
+ ]
16
+ s.test_files = [
17
+ "test/test_ec2meta.rb"
18
+ ]
19
+ end
@@ -0,0 +1,42 @@
1
+ require 'net/http'
2
+
3
+ module EC2M
4
+ VERSION = '0.1'
5
+ API_VERSION = '2009-04-04'
6
+
7
+ extend self
8
+
9
+ def get name
10
+ path = [API_VERSION, 'meta-data', name].join '/'
11
+ Net::HTTP.get '169.254.169.254', path
12
+ end
13
+
14
+ COMMANDS = %w(ami_id ami_launch_index ami_manifest_path hostname
15
+ instance_action instance_id instance_type kernel_id
16
+ local_hostname local_ipv4 public_hostname public_ipv4
17
+ ramdisk_id reservation_id)
18
+
19
+ COMMANDS.each do |name|
20
+ define_method(name) {get name.gsub('_', '-')}
21
+ end
22
+
23
+ def ancestor_ami_ids
24
+ get('ancestor-ami-ids').split
25
+ end
26
+
27
+ def availability_zone
28
+ get 'placement/availability-zone'
29
+ end
30
+
31
+ def block_device_mapping device=nil
32
+ if device
33
+ get "block-device-mapping/#{device}"
34
+ else
35
+ get('block-device-mapping/').split
36
+ end
37
+ end
38
+
39
+ def public_keys
40
+ raise "Not implemented"
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ $:.unshift 'lib'
2
+ require 'test/unit'
3
+ require 'rr'
4
+ require 'ec2meta'
5
+
6
+ class TestEC2M < Test::Unit::TestCase
7
+ include RR::Adapters::TestUnit
8
+
9
+ def setup
10
+ end
11
+
12
+ def test_ami_id
13
+ mock(EC2M).get('ami-id') {"ami-32bd12d2"}
14
+ assert_equal "ami-32bd12d2", EC2M.ami_id
15
+ end
16
+
17
+ def test_ancestor_ami_ids
18
+ mock(EC2M).get('ancestor-ami-ids') {
19
+ "ami-11111111\nami-23456789\nami-87878787"
20
+ }
21
+ assert_equal %w(ami-11111111 ami-23456789 ami-87878787),
22
+ EC2M.ancestor_ami_ids
23
+ end
24
+
25
+ def test_block_device_mapping_unspecified
26
+ mock(EC2M).get('block-device-mapping/') {"ami\nephemeral0\nroot\nswap"}
27
+ assert_equal %w(ami ephemeral0 root swap), EC2M.block_device_mapping
28
+ end
29
+
30
+ def test_block_device_mapping_specified
31
+ mock(EC2M).get('block-device-mapping/ami') {"sda1"}
32
+ assert_equal "sda1", EC2M.block_device_mapping('ami')
33
+ end
34
+
35
+ def test_availability_zone
36
+ mock(EC2M).get('placement/availability-zone') {"eu-west-1a"}
37
+ assert_equal "eu-west-1a", EC2M.availability_zone
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ec2meta
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Harry Vangberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-05 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ec2 instance metadata wrapper for ruby
17
+ email: harry@vangberg.name
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README
26
+ - ec2meta.gemspec
27
+ - lib/ec2meta.rb
28
+ has_rdoc: false
29
+ homepage: http://github.com/ichverstehe/ec2meta-rb
30
+ licenses: []
31
+
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.3.3
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: ec2 instance metadata wrapper for ruby
56
+ test_files:
57
+ - test/test_ec2meta.rb