2012-05-15 14:54:20 -04:00
|
|
|
require 'fog/aws'
|
2011-08-31 16:52:53 -04:00
|
|
|
require 'fog/compute'
|
|
|
|
|
2010-09-08 17:40:02 -04:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class AWS < Fog::Service
|
2012-06-18 04:44:51 -04:00
|
|
|
extend Fog::AWS::CredentialFetcher::ServiceMethods
|
2010-09-08 17:40:02 -04:00
|
|
|
|
2010-12-16 18:31:24 -05:00
|
|
|
requires :aws_access_key_id, :aws_secret_access_key
|
2012-06-18 04:44:51 -04:00
|
|
|
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent, :aws_session_token, :use_iam_profile, :aws_credentials_expire_at
|
2010-09-08 17:40:02 -04:00
|
|
|
|
2012-06-08 19:36:08 -04:00
|
|
|
secrets :aws_secret_access_key, :hmac, :aws_session_token
|
|
|
|
|
2011-08-24 21:37:00 -04:00
|
|
|
model_path 'fog/aws/models/compute'
|
2010-09-08 17:40:02 -04:00
|
|
|
model :address
|
|
|
|
collection :addresses
|
2012-05-29 19:21:00 -04:00
|
|
|
model :dhcp_options
|
|
|
|
collection :dhcp_options
|
2010-09-08 17:40:02 -04:00
|
|
|
model :flavor
|
|
|
|
collection :flavors
|
|
|
|
model :image
|
|
|
|
collection :images
|
2012-05-21 14:37:00 -04:00
|
|
|
model :internet_gateway
|
|
|
|
collection :internet_gateways
|
2010-09-08 17:40:02 -04:00
|
|
|
model :key_pair
|
|
|
|
collection :key_pairs
|
2012-04-01 22:01:57 -04:00
|
|
|
model :network_interface
|
|
|
|
collection :network_interfaces
|
2010-09-08 17:40:02 -04:00
|
|
|
model :security_group
|
|
|
|
collection :security_groups
|
|
|
|
model :server
|
|
|
|
collection :servers
|
|
|
|
model :snapshot
|
|
|
|
collection :snapshots
|
2010-10-09 21:39:48 -04:00
|
|
|
model :tag
|
|
|
|
collection :tags
|
2010-09-08 17:40:02 -04:00
|
|
|
model :volume
|
|
|
|
collection :volumes
|
2011-07-02 00:30:32 -04:00
|
|
|
model :spot_request
|
|
|
|
collection :spot_requests
|
2012-03-08 10:45:33 -05:00
|
|
|
model :subnet
|
|
|
|
collection :subnets
|
2012-03-05 11:32:02 -05:00
|
|
|
model :vpc
|
|
|
|
collection :vpcs
|
2010-09-08 17:40:02 -04:00
|
|
|
|
2011-08-24 21:37:00 -04:00
|
|
|
request_path 'fog/aws/requests/compute'
|
2010-09-08 17:40:02 -04:00
|
|
|
request :allocate_address
|
|
|
|
request :associate_address
|
2012-05-29 19:21:00 -04:00
|
|
|
request :associate_dhcp_options
|
2012-04-01 22:01:57 -04:00
|
|
|
request :attach_network_interface
|
2012-05-21 14:37:00 -04:00
|
|
|
request :attach_internet_gateway
|
2010-09-08 17:40:02 -04:00
|
|
|
request :attach_volume
|
|
|
|
request :authorize_security_group_ingress
|
2011-06-27 20:45:37 -04:00
|
|
|
request :cancel_spot_instance_requests
|
2012-05-29 19:21:00 -04:00
|
|
|
request :create_dhcp_options
|
2012-05-21 14:37:00 -04:00
|
|
|
request :create_internet_gateway
|
2010-10-12 14:00:59 -04:00
|
|
|
request :create_image
|
2010-09-08 17:40:02 -04:00
|
|
|
request :create_key_pair
|
2012-04-01 22:01:57 -04:00
|
|
|
request :create_network_interface
|
2011-06-24 20:31:44 -04:00
|
|
|
request :create_placement_group
|
2010-09-08 17:40:02 -04:00
|
|
|
request :create_security_group
|
|
|
|
request :create_snapshot
|
2011-06-27 20:45:37 -04:00
|
|
|
request :create_spot_datafeed_subscription
|
2012-03-08 10:45:33 -05:00
|
|
|
request :create_subnet
|
2010-10-12 14:00:59 -04:00
|
|
|
request :create_tags
|
2010-09-08 17:40:02 -04:00
|
|
|
request :create_volume
|
2012-03-05 11:32:02 -05:00
|
|
|
request :create_vpc
|
2012-05-29 19:21:00 -04:00
|
|
|
request :delete_dhcp_options
|
2012-05-21 14:37:00 -04:00
|
|
|
request :delete_internet_gateway
|
2010-09-08 17:40:02 -04:00
|
|
|
request :delete_key_pair
|
2012-04-01 22:01:57 -04:00
|
|
|
request :delete_network_interface
|
2010-09-08 17:40:02 -04:00
|
|
|
request :delete_security_group
|
2011-06-24 20:31:44 -04:00
|
|
|
request :delete_placement_group
|
2010-09-08 17:40:02 -04:00
|
|
|
request :delete_snapshot
|
2011-06-27 20:45:37 -04:00
|
|
|
request :delete_spot_datafeed_subscription
|
2012-03-08 10:45:33 -05:00
|
|
|
request :delete_subnet
|
2010-10-12 14:00:59 -04:00
|
|
|
request :delete_tags
|
2010-09-08 17:40:02 -04:00
|
|
|
request :delete_volume
|
2012-03-05 11:32:02 -05:00
|
|
|
request :delete_vpc
|
2010-09-08 17:40:02 -04:00
|
|
|
request :deregister_image
|
|
|
|
request :describe_addresses
|
|
|
|
request :describe_availability_zones
|
2012-05-29 19:21:00 -04:00
|
|
|
request :describe_dhcp_options
|
2010-09-08 17:40:02 -04:00
|
|
|
request :describe_images
|
|
|
|
request :describe_instances
|
2012-05-21 14:37:00 -04:00
|
|
|
request :describe_internet_gateways
|
2010-09-08 17:40:02 -04:00
|
|
|
request :describe_reserved_instances
|
2011-12-02 18:27:08 -05:00
|
|
|
request :describe_instance_status
|
2010-09-08 17:40:02 -04:00
|
|
|
request :describe_key_pairs
|
2012-04-01 22:01:57 -04:00
|
|
|
request :describe_network_interface_attribute
|
|
|
|
request :describe_network_interfaces
|
2011-06-24 20:31:44 -04:00
|
|
|
request :describe_placement_groups
|
2010-09-08 17:40:02 -04:00
|
|
|
request :describe_regions
|
2011-01-26 16:35:22 -05:00
|
|
|
request :describe_reserved_instances_offerings
|
2010-09-08 17:40:02 -04:00
|
|
|
request :describe_security_groups
|
|
|
|
request :describe_snapshots
|
2011-06-27 20:45:37 -04:00
|
|
|
request :describe_spot_datafeed_subscription
|
|
|
|
request :describe_spot_instance_requests
|
|
|
|
request :describe_spot_price_history
|
2012-03-08 10:45:33 -05:00
|
|
|
request :describe_subnets
|
2010-10-09 21:39:48 -04:00
|
|
|
request :describe_tags
|
2010-09-08 17:40:02 -04:00
|
|
|
request :describe_volumes
|
2012-03-15 02:16:31 -04:00
|
|
|
request :describe_volume_status
|
2012-03-05 11:32:02 -05:00
|
|
|
request :describe_vpcs
|
2012-04-01 22:01:57 -04:00
|
|
|
request :detach_network_interface
|
2012-05-21 14:37:00 -04:00
|
|
|
request :detach_internet_gateway
|
2010-09-08 17:40:02 -04:00
|
|
|
request :detach_volume
|
|
|
|
request :disassociate_address
|
|
|
|
request :get_console_output
|
2011-05-09 18:28:54 -04:00
|
|
|
request :get_password_data
|
2010-09-22 15:06:25 -04:00
|
|
|
request :import_key_pair
|
2011-08-03 18:20:39 -04:00
|
|
|
request :modify_image_attribute
|
2011-08-04 11:12:20 -04:00
|
|
|
request :modify_instance_attribute
|
2012-04-01 22:01:57 -04:00
|
|
|
request :modify_network_interface_attribute
|
2010-09-08 17:40:02 -04:00
|
|
|
request :modify_snapshot_attribute
|
2011-07-13 02:54:13 -04:00
|
|
|
request :purchase_reserved_instances_offering
|
2010-09-08 17:40:02 -04:00
|
|
|
request :reboot_instances
|
|
|
|
request :release_address
|
|
|
|
request :register_image
|
2011-06-27 20:45:37 -04:00
|
|
|
request :request_spot_instances
|
2012-04-01 22:01:57 -04:00
|
|
|
request :reset_network_interface_attribute
|
2010-09-08 17:40:02 -04:00
|
|
|
request :revoke_security_group_ingress
|
|
|
|
request :run_instances
|
|
|
|
request :terminate_instances
|
|
|
|
request :start_instances
|
|
|
|
request :stop_instances
|
2011-03-11 16:06:44 -05:00
|
|
|
request :monitor_instances
|
|
|
|
request :unmonitor_instances
|
2010-09-08 17:40:02 -04:00
|
|
|
|
2011-08-03 18:20:39 -04:00
|
|
|
# deprecation
|
|
|
|
class Real
|
|
|
|
|
|
|
|
def modify_image_attributes(*params)
|
2011-10-19 15:49:34 -04:00
|
|
|
Fog::Logger.deprecation("modify_image_attributes is deprecated, use modify_image_attribute instead [light_black](#{caller.first})[/]")
|
2011-08-03 18:20:39 -04:00
|
|
|
modify_image_attribute(*params)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-09-08 17:40:02 -04:00
|
|
|
class Mock
|
2012-06-29 09:35:08 -04:00
|
|
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
2010-09-08 17:40:02 -04:00
|
|
|
|
|
|
|
def self.data
|
2010-09-24 16:50:44 -04:00
|
|
|
@data ||= Hash.new do |hash, region|
|
2010-10-13 16:20:18 -04:00
|
|
|
hash[region] = Hash.new do |region_hash, key|
|
2011-10-06 12:35:29 -04:00
|
|
|
owner_id = Fog::AWS::Mock.owner_id
|
2012-03-20 16:07:44 -04:00
|
|
|
security_group_id = Fog::AWS::Mock.security_group_id
|
2010-10-13 16:20:18 -04:00
|
|
|
region_hash[key] = {
|
2010-09-24 16:50:44 -04:00
|
|
|
:deleted_at => {},
|
|
|
|
:addresses => {},
|
2010-10-14 20:06:50 -04:00
|
|
|
:images => {},
|
2011-10-06 12:35:29 -04:00
|
|
|
:image_launch_permissions => Hash.new do |permissions_hash, image_key|
|
|
|
|
permissions_hash[image_key] = {
|
|
|
|
:users => []
|
|
|
|
}
|
|
|
|
end,
|
2010-09-24 16:50:44 -04:00
|
|
|
:instances => {},
|
2011-07-13 02:54:13 -04:00
|
|
|
:reserved_instances => {},
|
2010-09-24 16:50:44 -04:00
|
|
|
:key_pairs => {},
|
|
|
|
:limits => { :addresses => 5 },
|
|
|
|
:owner_id => owner_id,
|
|
|
|
:security_groups => {
|
|
|
|
'default' => {
|
2011-09-23 18:03:27 -04:00
|
|
|
'groupDescription' => 'default group',
|
|
|
|
'groupName' => 'default',
|
2012-03-20 16:07:44 -04:00
|
|
|
'groupId' => security_group_id,
|
2011-09-23 18:03:27 -04:00
|
|
|
'ipPermissionsEgress' => [],
|
|
|
|
'ipPermissions' => [
|
2010-09-24 16:50:44 -04:00
|
|
|
{
|
2012-03-20 16:07:44 -04:00
|
|
|
'groups' => [{'groupName' => 'default', 'userId' => owner_id, 'groupId' => security_group_id }],
|
2010-09-24 16:50:44 -04:00
|
|
|
'fromPort' => -1,
|
|
|
|
'toPort' => -1,
|
|
|
|
'ipProtocol' => 'icmp',
|
|
|
|
'ipRanges' => []
|
|
|
|
},
|
|
|
|
{
|
2012-03-20 16:07:44 -04:00
|
|
|
'groups' => [{'groupName' => 'default', 'userId' => owner_id, 'groupId' => security_group_id}],
|
2010-09-24 16:50:44 -04:00
|
|
|
'fromPort' => 0,
|
|
|
|
'toPort' => 65535,
|
|
|
|
'ipProtocol' => 'tcp',
|
|
|
|
'ipRanges' => []
|
|
|
|
},
|
|
|
|
{
|
2012-03-20 16:07:44 -04:00
|
|
|
'groups' => [{'groupName' => 'default', 'userId' => owner_id, 'groupId' => security_group_id}],
|
2010-09-24 16:50:44 -04:00
|
|
|
'fromPort' => 0,
|
|
|
|
'toPort' => 65535,
|
|
|
|
'ipProtocol' => 'udp',
|
|
|
|
'ipRanges' => []
|
|
|
|
}
|
|
|
|
],
|
2011-09-23 18:03:27 -04:00
|
|
|
'ownerId' => owner_id
|
2010-09-24 16:50:44 -04:00
|
|
|
}
|
|
|
|
},
|
2012-04-01 22:01:57 -04:00
|
|
|
:network_interfaces => {},
|
2010-09-24 16:50:44 -04:00
|
|
|
:snapshots => {},
|
2010-10-14 17:55:08 -04:00
|
|
|
:volumes => {},
|
2012-05-21 14:37:00 -04:00
|
|
|
:internet_gateways => {},
|
2011-10-06 16:49:28 -04:00
|
|
|
:tags => {},
|
|
|
|
:tag_sets => Hash.new do |tag_set_hash, resource_id|
|
|
|
|
tag_set_hash[resource_id] = {}
|
2012-07-02 08:23:23 -04:00
|
|
|
end,
|
2012-07-02 08:30:31 -04:00
|
|
|
:subnets => [],
|
2012-07-02 08:38:08 -04:00
|
|
|
:vpcs => [],
|
|
|
|
:dhcp_options => []
|
2010-09-24 16:50:44 -04:00
|
|
|
}
|
|
|
|
end
|
2010-09-08 17:40:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-17 14:02:28 -04:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2010-09-08 17:40:02 -04:00
|
|
|
def initialize(options={})
|
2012-06-18 04:44:51 -04:00
|
|
|
@use_iam_profile = options[:use_iam_profile]
|
2012-06-29 09:39:35 -04:00
|
|
|
@aws_credentials_expire_at = Time::now + 20
|
2012-06-18 04:44:51 -04:00
|
|
|
setup_credentials(options)
|
2010-09-24 16:50:44 -04:00
|
|
|
@region = options[:region] || 'us-east-1'
|
2011-03-11 16:06:44 -05:00
|
|
|
|
2011-12-16 22:37:14 -05:00
|
|
|
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
|
2011-05-18 14:38:18 -04:00
|
|
|
raise ArgumentError, "Unknown region: #{@region.inspect}"
|
|
|
|
end
|
2011-05-19 18:35:33 -04:00
|
|
|
end
|
2011-05-18 14:38:18 -04:00
|
|
|
|
2011-10-06 16:49:28 -04:00
|
|
|
def region_data
|
|
|
|
self.class.data[@region]
|
|
|
|
end
|
|
|
|
|
2011-05-19 18:35:33 -04:00
|
|
|
def data
|
2011-10-06 16:49:28 -04:00
|
|
|
self.region_data[@aws_access_key_id]
|
2011-03-10 14:16:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
2011-10-06 16:49:28 -04:00
|
|
|
self.region_data.delete(@aws_access_key_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def visible_images
|
|
|
|
images = self.data[:images].values.inject({}) do |h, image|
|
|
|
|
h.update(image['imageId'] => image)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.region_data.each do |aws_access_key_id, data|
|
|
|
|
data[:image_launch_permissions].each do |image_id, list|
|
|
|
|
if list[:users].include?(self.data[:owner_id])
|
|
|
|
images.update(image_id => data[:images][image_id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
images
|
2010-09-08 17:40:02 -04:00
|
|
|
end
|
|
|
|
|
2011-10-06 16:49:28 -04:00
|
|
|
def apply_tag_filters(resources, filters, resource_id_key)
|
|
|
|
tag_set_fetcher = lambda {|resource| self.data[:tag_sets][resource[resource_id_key]] }
|
|
|
|
|
2011-03-28 17:00:25 -04:00
|
|
|
# tag-key: match resources tagged with this key (any value)
|
|
|
|
if filters.has_key?('tag-key')
|
|
|
|
value = filters.delete('tag-key')
|
2011-10-06 16:49:28 -04:00
|
|
|
resources = resources.select{|r| tag_set_fetcher[r].has_key?(value)}
|
2011-03-28 17:00:25 -04:00
|
|
|
end
|
2011-10-06 12:35:29 -04:00
|
|
|
|
2011-03-28 17:00:25 -04:00
|
|
|
# tag-value: match resources tagged with this value (any key)
|
|
|
|
if filters.has_key?('tag-value')
|
|
|
|
value = filters.delete('tag-value')
|
2011-10-06 16:49:28 -04:00
|
|
|
resources = resources.select{|r| tag_set_fetcher[r].values.include?(value)}
|
2011-03-28 17:00:25 -04:00
|
|
|
end
|
2011-10-06 12:35:29 -04:00
|
|
|
|
2011-10-06 16:49:28 -04:00
|
|
|
# tag:key: match resources tagged with a key-value pair. Value may be an array, which is OR'd.
|
2011-03-23 13:33:27 -04:00
|
|
|
tag_filters = {}
|
2011-10-06 12:35:29 -04:00
|
|
|
filters.keys.each do |key|
|
2011-03-23 13:33:27 -04:00
|
|
|
tag_filters[key.gsub('tag:', '')] = filters.delete(key) if /^tag:/ =~ key
|
|
|
|
end
|
|
|
|
for tag_key, tag_value in tag_filters
|
2011-10-06 16:49:28 -04:00
|
|
|
resources = resources.select{|r| tag_value.include?(tag_set_fetcher[r][tag_key])}
|
2011-03-23 13:33:27 -04:00
|
|
|
end
|
2011-10-06 12:35:29 -04:00
|
|
|
|
2011-03-23 13:33:27 -04:00
|
|
|
resources
|
|
|
|
end
|
2012-06-18 04:44:51 -04:00
|
|
|
|
|
|
|
def setup_credentials(options)
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
end
|
2010-09-08 17:40:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
2012-06-18 04:44:51 -04:00
|
|
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
2010-09-08 17:40:02 -04:00
|
|
|
# Initialize connection to EC2
|
|
|
|
#
|
|
|
|
# ==== Notes
|
2011-10-06 12:35:29 -04:00
|
|
|
# options parameter must include values for :aws_access_key_id and
|
2010-09-08 17:40:02 -04:00
|
|
|
# :aws_secret_access_key in order to create a connection
|
|
|
|
#
|
|
|
|
# ==== Examples
|
|
|
|
# sdb = SimpleDB.new(
|
|
|
|
# :aws_access_key_id => your_aws_access_key_id,
|
|
|
|
# :aws_secret_access_key => your_aws_secret_access_key
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
2012-02-02 15:54:25 -05:00
|
|
|
# * region<~String> - optional region to use. For instance,
|
|
|
|
# 'eu-west-1', 'us-east-1', and etc.
|
2011-11-13 15:16:46 -05:00
|
|
|
# * aws_session_token<~String> - when using Session Tokens or Federated Users, a session_token must be presented
|
2010-09-08 17:40:02 -04:00
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * EC2 object with connection to aws.
|
2012-05-08 18:26:16 -04:00
|
|
|
|
|
|
|
attr_accessor :region
|
|
|
|
|
2010-09-08 17:40:02 -04:00
|
|
|
def initialize(options={})
|
2011-02-16 20:25:50 -05:00
|
|
|
require 'fog/core/parser'
|
|
|
|
|
2012-06-18 04:44:51 -04:00
|
|
|
@use_iam_profile = options[:use_iam_profile]
|
|
|
|
setup_credentials(options)
|
2011-09-12 11:01:48 -04:00
|
|
|
@connection_options = options[:connection_options] || {}
|
|
|
|
@region = options[:region] ||= 'us-east-1'
|
2011-04-14 19:31:58 -04:00
|
|
|
|
2010-09-29 20:53:32 -04:00
|
|
|
if @endpoint = options[:endpoint]
|
|
|
|
endpoint = URI.parse(@endpoint)
|
|
|
|
@host = endpoint.host
|
|
|
|
@path = endpoint.path
|
|
|
|
@port = endpoint.port
|
|
|
|
@scheme = endpoint.scheme
|
|
|
|
else
|
2012-02-02 15:54:25 -05:00
|
|
|
@host = options[:host] || "ec2.#{options[:region]}.amazonaws.com"
|
2011-09-12 11:01:48 -04:00
|
|
|
@path = options[:path] || '/'
|
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || 'https'
|
2010-09-29 20:53:32 -04:00
|
|
|
end
|
2011-09-12 11:01:48 -04:00
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
2010-09-08 17:40:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2012-06-18 04:44:51 -04:00
|
|
|
def setup_credentials(options)
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
@aws_secret_access_key = options[:aws_secret_access_key]
|
|
|
|
@aws_session_token = options[:aws_session_token]
|
|
|
|
@aws_credentials_expire_at = options[:aws_credentials_expire_at]
|
|
|
|
|
|
|
|
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
|
|
|
end
|
2011-10-06 12:35:29 -04:00
|
|
|
|
2010-09-08 17:40:02 -04:00
|
|
|
def request(params)
|
2012-06-18 04:44:51 -04:00
|
|
|
refresh_credentials_if_expired
|
2010-09-08 17:40:02 -04:00
|
|
|
idempotent = params.delete(:idempotent)
|
|
|
|
parser = params.delete(:parser)
|
|
|
|
|
2011-06-20 16:49:37 -04:00
|
|
|
body = Fog::AWS.signed_params(
|
2010-09-08 17:40:02 -04:00
|
|
|
params,
|
|
|
|
{
|
|
|
|
:aws_access_key_id => @aws_access_key_id,
|
2011-11-13 15:16:46 -05:00
|
|
|
:aws_session_token => @aws_session_token,
|
2010-09-08 17:40:02 -04:00
|
|
|
:hmac => @hmac,
|
|
|
|
:host => @host,
|
2010-09-29 20:53:32 -04:00
|
|
|
:path => @path,
|
2010-12-23 16:54:02 -05:00
|
|
|
:port => @port,
|
2012-06-18 04:44:51 -04:00
|
|
|
:version => '2012-06-01'
|
2010-09-08 17:40:02 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
begin
|
|
|
|
response = @connection.request({
|
|
|
|
:body => body,
|
|
|
|
:expects => 200,
|
|
|
|
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
|
|
|
:idempotent => idempotent,
|
|
|
|
:host => @host,
|
|
|
|
:method => 'POST',
|
|
|
|
:parser => parser
|
|
|
|
})
|
2010-11-29 23:07:47 -05:00
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
2010-09-08 17:40:02 -04:00
|
|
|
if match = error.message.match(/<Code>(.*)<\/Code><Message>(.*)<\/Message>/)
|
|
|
|
raise case match[1].split('.').last
|
2011-06-24 20:31:44 -04:00
|
|
|
when 'NotFound', 'Unknown'
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute::AWS::NotFound.slurp(error, match[2])
|
2010-09-08 17:40:02 -04:00
|
|
|
else
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute::AWS::Error.slurp(error, "#{match[1]} => #{match[2]}")
|
2010-09-08 17:40:02 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
raise error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|