Class: CloudProviders::Ec2Response
- Defined in:
- lib/cloud_providers/ec2/ec2_response.rb
Overview
Convert the standard right_aws gem’s response object to the poolparty format
Class Method Summary collapse
-
.convert_from_ec2_dns_to_ip(str = nil) ⇒ Object
parse IP address from aws dns name.
-
.describe_instance(response_array, index = 0) ⇒ Object
Selects the first instance if an index is not given.
-
.describe_instances(response) ⇒ Object
Convert the standard response hash to format used throughout the rest of PoolParty code.
- .parse_datetime(str) ⇒ Object
- .pp_format(response_hash) ⇒ Object
Class Method Details
.convert_from_ec2_dns_to_ip(str = nil) ⇒ Object
parse IP address from aws dns name
66 67 68 69 70 71 |
# File 'lib/cloud_providers/ec2/ec2_response.rb', line 66 def self.convert_from_ec2_dns_to_ip(str=nil) return str if str.nil? # if using eucalyptus we may have the raw IP already, if so just return it return str if str.match( /^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/ ) str.scan(/-(\d{1,3})-(\d{1,3})-(\d{1,3})-(\d{1,3})/).flatten.join('.') end |
.describe_instance(response_array, index = 0) ⇒ Object
Selects the first instance if an index is not given.
44 45 46 |
# File 'lib/cloud_providers/ec2/ec2_response.rb', line 44 def self.describe_instance(response_array, index=0) pp_format(response_array[index]) end |
.describe_instances(response) ⇒ Object
Convert the standard response hash to format used throughout the rest of PoolParty code.
49 50 51 |
# File 'lib/cloud_providers/ec2/ec2_response.rb', line 49 def self.describe_instances(response) response.collect{|inst| pp_format(inst) } end |
.parse_datetime(str) ⇒ Object
73 74 75 |
# File 'lib/cloud_providers/ec2/ec2_response.rb', line 73 def self.parse_datetime(str) Time.parse( str.chomp ) end |
.pp_format(response_hash) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cloud_providers/ec2/ec2_response.rb', line 53 def self.pp_format(response_hash) munged = {} response_hash.each{|k,v| munged[k.to_s.gsub('aws_', '').to_sym] = v} munged[:internal_ip] = convert_from_ec2_dns_to_ip(munged[:private_dns_name]) if munged[:private_dns_name] munged[:public_ip] = convert_from_ec2_dns_to_ip(munged[:dns_name]) if munged[:dns_name] munged[:launch_time] = parse_datetime(munged[:launch_time]) if munged[:launch_time] munged[:ami_launch_index] = munged[:launch_index] if munged[:launch_index] #TODO: deprecate ami_launch_index munged[:keypair_name] = munged.delete(:ssh_key_name) munged[:status] = munged.delete(:state) || munged[:shutdown_state] munged end |