module GCEMetadata::Command
Constants
- DATA_KEY_ORDER
- META_DATA_KEY_ORDER
Public Class Methods
show(api_version = 'v1')
click to toggle source
# File lib/gce_metadata/command.rb, line 29 def show(api_version = 'v1') timeout do v = (api_version || '').strip keys = GCEMetadata.instance.keys unless keys.include?(v.gsub(%r'([^/])$', '\1/')) puts("#{self.class.name}.instance.keys\n#{keys.ai}") raise ArgumentError, "API version must be one of #{GCEMetadata.instance.keys.inspect} but was #{api_version.inspect}" end show_yaml_path_if_loaded data = GCEMetadata.instance.to_hash data = data[v] data.extend(HashKeyOrderable) data.key_order = DATA_KEY_ORDER meta_data = data['instance'] meta_data.extend(HashKeyOrderable) meta_data.key_order = META_DATA_KEY_ORDER puts YAML.dump(data) end end
show_api_versions()
click to toggle source
# File lib/gce_metadata/command.rb, line 49 def show_api_versions timeout do show_yaml_path_if_loaded puts GCEMetadata.instance.keys end end
show_dummy_yaml()
click to toggle source
# File lib/gce_metadata/command.rb, line 56 def show_dummy_yaml show_yaml_path_if_loaded puts IO.read(File.expand_path(File.join(File.dirname(__FILE__), 'dummy.yml'))) end
Private Class Methods
show_yaml_path_if_loaded()
click to toggle source
# File lib/gce_metadata/command.rb, line 70 def show_yaml_path_if_loaded if path = GCEMetadata::Dummy.loaded_yaml_path puts "Actually these data is based on a DUMMY yaml file: #{path}" end end
timeout() { || ... }
click to toggle source
# File lib/gce_metadata/command.rb, line 62 def timeout begin yield rescue Timeout::Error, SystemCallError => error puts "HTTP request timed out. You can use dummy YAML for non GCE Instance. #{Dummy.yaml_paths.inspect}" end end