Module: GCEMetadata

Extended by:
HttpClient
Defined in:
lib/gce_metadata.rb,
lib/gce_metadata/base.rb,
lib/gce_metadata/root.rb,
lib/gce_metadata/dummy.rb,
lib/gce_metadata/command.rb,
lib/gce_metadata/version.rb,
lib/gce_metadata/revision.rb,
lib/gce_metadata/http_client.rb

Defined Under Namespace

Modules: Command, Dummy, HttpClient Classes: Base, NotFoundError, Revision, Root

Constant Summary collapse

DEFAULT_HOST =
"metadata.google.internal".freeze
DEFAULT_REVISION =
'v1'
VERSION =

gce-metadata version

'0.1.0'

Constants included from HttpClient

HttpClient::DEFAULT_OPEN_TIMEOUT, HttpClient::DEFAULT_READ_TIMEOUT

Instance Attribute Summary

Attributes included from HttpClient

#open_timeout_sec, #read_timeout_sec

Class Method Summary collapse

Methods included from HttpClient

extended, get

Class Method Details

.[](key) ⇒ Object



29
30
31
# File 'lib/gce_metadata.rb', line 29

def [](key)
	instance[key]
end

.clear_instanceObject



25
26
27
# File 'lib/gce_metadata.rb', line 25

def clear_instance
	@instance = nil
end

.formalize_key(key) ⇒ Object



46
47
48
49
# File 'lib/gce_metadata.rb', line 46

def formalize_key(key)
	#key.to_s.gsub(/_/, '-')
	key
end

.from_hash(hash, revision = DEFAULT_REVISION) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/gce_metadata.rb', line 37

def from_hash(hash, revision = DEFAULT_REVISION)
	# hash = {revision => hash}
	# instance.from_hash(hash)
	rev_obj = instance.new_child(revision)
	instance.instance_variable_set(:@children, {revision => rev_obj})
	instance.instance_variable_set(:@child_keys, [revision])
	rev_obj.from_hash(hash)
end

.instanceObject



21
22
23
# File 'lib/gce_metadata.rb', line 21

def instance
	@instance ||= Root.new['computeMetadata']
end

.logging(msg) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gce_metadata.rb', line 51

def logging(msg)
	@indent ||= 0
	disp = (" " * @indent) << msg
	# puts(disp)
	@indent += 2
	begin
		result = yield
	ensure
		@indent -= 2
	end
	# puts "#{disp} => #{result.inspect}"
	result
end

.to_hash(revision = DEFAULT_REVISION) ⇒ Object



33
34
35
# File 'lib/gce_metadata.rb', line 33

def to_hash(revision = DEFAULT_REVISION)
	self[revision].to_hash
end