Module: Ec2Metadata::Command

Defined in:
lib/ec2_metadata/command.rb

Constant Summary collapse

DATA_KEY_ORDER =
%w(meta-data user-data)
META_DATA_KEY_ORDER =

%w(…)の中に改行を入れるとrcovがパスしていることを認識してくれないので、各行毎に%w(..)します

%w(ami-id ami-launch-index ami-manifest-path ancestor-ami-ids) +
%w(instance-id instance-type instance-action) +
%w(public-keys/ placement/ security-groups) +
%w(hostname) +
%w(public-hostname public-ipv4) +
%w(local-hostname  local-ipv4) +
%w(block-device-mapping/) +
%w(kernel-id) +
%w(ramdisk-id) +
%w(reservation-id)

Class Method Summary collapse

Class Method Details

.show(api_version = 'latest') ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ec2_metadata/command.rb', line 23

def show(api_version = 'latest')
  timeout do
    v = (api_version || '').strip
    unless Ec2Metadata.instance.keys.include?(v)
      raise ArgumentError, "API version must be one of #{Ec2Metadata.instance.keys.inspect} but was #{api_version.inspect}"
    end
    show_yaml_path_if_loaded
    data = Ec2Metadata[v].to_hash
    data.extend(HashKeyOrderable)
    data.key_order = DATA_KEY_ORDER
     = data['meta-data']
    .extend(HashKeyOrderable)
    .key_order = META_DATA_KEY_ORDER
    puts YAML.dump(data)
  end
end

.show_api_versionsObject



40
41
42
43
44
45
# File 'lib/ec2_metadata/command.rb', line 40

def show_api_versions
  timeout do
    show_yaml_path_if_loaded
    puts Ec2Metadata.instance.keys
  end
end

.show_dummy_yamlObject



47
48
49
50
# File 'lib/ec2_metadata/command.rb', line 47

def show_dummy_yaml
  show_yaml_path_if_loaded
  puts IO.read(File.expand_path(File.join(File.dirname(__FILE__), 'dummy.yml')))
end