fog 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/Gemfile.lock +3 -6
  2. data/fog.gemspec +3 -3
  3. data/lib/fog.rb +1 -1
  4. data/lib/fog/aws/parsers/ses/delete_verified_email_address.rb +24 -0
  5. data/lib/fog/aws/parsers/ses/get_send_quota.rb +26 -0
  6. data/lib/fog/aws/parsers/ses/get_send_statistics.rb +29 -0
  7. data/lib/fog/aws/parsers/ses/list_verified_email_addresses.rb +25 -0
  8. data/lib/fog/aws/parsers/ses/send_email.rb +26 -0
  9. data/lib/fog/aws/parsers/ses/send_raw_email.rb +26 -0
  10. data/lib/fog/aws/parsers/ses/verify_email_address.rb +24 -0
  11. data/lib/fog/aws/requests/elb/create_load_balancer.rb +1 -1
  12. data/lib/fog/aws/requests/ses/delete_verified_email_address.rb +37 -0
  13. data/lib/fog/aws/requests/ses/get_send_quota.rb +40 -0
  14. data/lib/fog/aws/requests/ses/get_send_statistics.rb +43 -0
  15. data/lib/fog/aws/requests/ses/list_verified_email_addresses.rb +37 -0
  16. data/lib/fog/aws/requests/ses/send_email.rb +82 -0
  17. data/lib/fog/aws/requests/ses/send_raw_email.rb +50 -0
  18. data/lib/fog/aws/requests/ses/verify_email_address.rb +37 -0
  19. data/lib/fog/aws/ses.rb +106 -0
  20. data/lib/fog/bin/aws.rb +5 -1
  21. data/lib/fog/cdn.rb +1 -1
  22. data/lib/fog/compute/aws.rb +1 -0
  23. data/lib/fog/compute/models/aws/server.rb +5 -2
  24. data/lib/fog/compute/models/bluebox/server.rb +5 -2
  25. data/lib/fog/compute/models/go_grid/images.rb +1 -1
  26. data/lib/fog/compute/models/go_grid/server.rb +55 -8
  27. data/lib/fog/compute/models/go_grid/servers.rb +2 -2
  28. data/lib/fog/compute/models/rackspace/server.rb +5 -2
  29. data/lib/fog/compute/models/slicehost/server.rb +5 -2
  30. data/lib/fog/compute/parsers/aws/describe_reserved_instances_offerings.rb +34 -0
  31. data/lib/fog/compute/rackspace.rb +28 -7
  32. data/lib/fog/compute/requests/aws/describe_images.rb +48 -1
  33. data/lib/fog/compute/requests/aws/describe_reserved_instances_offerings.rb +45 -0
  34. data/lib/fog/compute/requests/go_grid/grid_server_add.rb +2 -2
  35. data/lib/fog/core/ssh.rb +7 -3
  36. data/lib/fog/dns.rb +1 -1
  37. data/lib/fog/dns/requests/aws/create_hosted_zone.rb +8 -8
  38. data/lib/fog/providers/aws.rb +1 -0
  39. data/lib/fog/storage/aws.rb +49 -30
  40. data/lib/fog/storage/google.rb +48 -29
  41. data/lib/fog/storage/local.rb +2 -0
  42. data/lib/fog/storage/models/aws/file.rb +1 -1
  43. data/lib/fog/storage/models/google/file.rb +1 -1
  44. data/lib/fog/storage/models/local/file.rb +9 -1
  45. data/lib/fog/storage/requests/aws/put_bucket.rb +6 -6
  46. data/lib/fog/storage/requests/aws/put_object.rb +7 -7
  47. data/lib/fog/storage/requests/google/put_bucket.rb +5 -6
  48. data/lib/fog/storage/requests/google/put_object.rb +7 -7
  49. data/lib/fog/storage/requests/rackspace/get_container.rb +1 -0
  50. data/lib/fog/storage/requests/rackspace/get_containers.rb +1 -0
  51. data/tests/aws/requests/ses/helper.rb +15 -0
  52. data/tests/aws/requests/ses/verified_email_address_tests.rb +27 -0
  53. data/tests/compute/requests/terremark_ecloud/catalog_tests.rb +1 -1
  54. data/tests/compute/requests/terremark_ecloud/network_tests.rb +1 -1
  55. data/tests/compute/requests/terremark_ecloud/organization_tests.rb +1 -1
  56. data/tests/compute/requests/terremark_ecloud/vdc_tests.rb +1 -1
  57. data/tests/helper.rb +4 -36
  58. data/tests/helpers/mock_helper.rb +33 -0
  59. metadata +32 -9
@@ -0,0 +1,50 @@
1
+ module Fog
2
+ module AWS
3
+ class SES
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/ses/send_raw_email'
7
+
8
+ # Delete an existing verified email address
9
+ #
10
+ # ==== Parameters
11
+ # * RawMessage <~String> - The message to be sent.
12
+ # * Options <~Hash>
13
+ # * Source <~String> - The sender's email address
14
+ # * Destinations <~Array> - The destination for this email, composed of To:, From:, and CC: fields.
15
+ #
16
+ # ==== Returns
17
+ # * response<~Excon::Response>:
18
+ # * body<~Hash>:
19
+ # * 'MessageId'<~String> - Id of message
20
+ # * 'ResponseMetadata'<~Hash>:
21
+ # * 'RequestId'<~String> - Id of request
22
+ def send_raw_email(raw_message, options = {})
23
+ params = {}
24
+ if options.has_key?('Destinations')
25
+ params['Destinations'] = AWS.indexed_param('Destinations.member', [*options['Destinations']])
26
+ end
27
+ if options.has_key?('Source')
28
+ params['Source'] = options['Source']
29
+ end
30
+
31
+ request({
32
+ 'Action' => 'SendRawEmail',
33
+ 'RawMessage.Data' => Base64.encode64(raw_message).chomp!,
34
+ :parser => Fog::Parsers::AWS::SES::SendRawEmail.new
35
+ }.merge(params))
36
+ end
37
+
38
+ end
39
+
40
+ class Mock
41
+
42
+ def send_raw_email(source, destinations, raw_message)
43
+ Fog::Mock.not_implemented
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,37 @@
1
+ module Fog
2
+ module AWS
3
+ class SES
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/ses/verify_email_address'
7
+
8
+ # Verifies an email address. This action causes a confirmation email message to be sent to the specified address.
9
+ #
10
+ # ==== Parameters
11
+ # * email_address<~String> - The email address to be verified
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'ResponseMetadata'<~Hash>:
16
+ # * 'RequestId'<~String> - Id of request
17
+ def verify_email_address(email_address)
18
+ request({
19
+ 'Action' => 'VerifyEmailAddress',
20
+ 'EmailAddress' => email_address,
21
+ :parser => Fog::Parsers::AWS::SES::VerifyEmailAddress.new
22
+ })
23
+ end
24
+
25
+ end
26
+
27
+ class Mock
28
+
29
+ def verify_email_address(email_address)
30
+ Fog::Mock.not_implemented
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,106 @@
1
+ module Fog
2
+ module AWS
3
+ class SES < Fog::Service
4
+
5
+ requires :aws_access_key_id, :aws_secret_access_key
6
+ recognizes :region, :host, :path, :port, :scheme, :persistent
7
+
8
+ request_path 'fog/aws/requests/ses'
9
+ request :delete_verified_email_address
10
+ request :verify_email_address
11
+ request :get_send_quota
12
+ request :get_send_statistics
13
+ request :list_verified_email_addresses
14
+ request :send_email
15
+ request :send_raw_email
16
+
17
+ class Mock
18
+
19
+ def initialize(options={})
20
+ end
21
+
22
+ end
23
+
24
+ class Real
25
+
26
+ # Initialize connection to SES
27
+ #
28
+ # ==== Notes
29
+ # options parameter must include values for :aws_access_key_id and
30
+ # :aws_secret_access_key in order to create a connection
31
+ #
32
+ # ==== Examples
33
+ # ses = SES.new(
34
+ # :aws_access_key_id => your_aws_access_key_id,
35
+ # :aws_secret_access_key => your_aws_secret_access_key
36
+ # )
37
+ #
38
+ # ==== Parameters
39
+ # * options<~Hash> - config arguments for connection. Defaults to {}.
40
+ # * region<~String> - optional region to use, in ['eu-west-1', 'us-east-1', 'us-west-1'i, 'ap-southeast-1']
41
+ #
42
+ # ==== Returns
43
+ # * SES object with connection to AWS.
44
+ def initialize(options={})
45
+ @aws_access_key_id = options[:aws_access_key_id]
46
+ @aws_secret_access_key = options[:aws_secret_access_key]
47
+ @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
48
+ options[:region] ||= 'us-east-1'
49
+ @host = options[:host] || case options[:region]
50
+ when 'us-east-1'
51
+ 'email.us-east-1.amazonaws.com'
52
+ else
53
+ raise ArgumentError, "Unknown region: #{options[:region].inspect}"
54
+ end
55
+ @path = options[:path] || '/'
56
+ @port = options[:port] || 443
57
+ @scheme = options[:scheme] || 'https'
58
+ @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent])
59
+ end
60
+
61
+ def reload
62
+ @connection.reset
63
+ end
64
+
65
+ private
66
+
67
+ def request(params)
68
+ idempotent = params.delete(:idempotent)
69
+ parser = params.delete(:parser)
70
+
71
+ headers = {
72
+ 'Content-Type' => 'application/x-www-form-urlencoded',
73
+ 'Date' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
74
+ }
75
+
76
+ #AWS3-HTTPS AWSAccessKeyId=<Your AWS Access Key ID>, Algorithm=HmacSHA256, Signature=<Signature>
77
+ headers['X-Amzn-Authorization'] = 'AWS3-HTTPS '
78
+ headers['X-Amzn-Authorization'] << 'AWSAccessKeyId=' << @aws_access_key_id
79
+ headers['X-Amzn-Authorization'] << ', Algorithm=HmacSHA256'
80
+ headers['X-Amzn-Authorization'] << ', Signature=' << Base64.encode64(@hmac.sign(headers['Date'])).chomp!
81
+
82
+ body = ''
83
+ for key in params.keys.sort
84
+ unless (value = params[key]).nil?
85
+ body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
86
+ end
87
+ end
88
+ body.chop! # remove trailing '&'
89
+
90
+ response = @connection.request({
91
+ :body => body,
92
+ :expects => 200,
93
+ :headers => headers,
94
+ :idempotent => idempotent,
95
+ :host => @host,
96
+ :method => 'POST',
97
+ :parser => parser
98
+ })
99
+
100
+ response
101
+ end
102
+
103
+ end
104
+ end
105
+ end
106
+ end
@@ -15,6 +15,8 @@ class AWS < Fog::Bin
15
15
  Fog::AWS::IAM
16
16
  when :sdb
17
17
  Fog::AWS::SimpleDB
18
+ when :ses
19
+ Fog::AWS::SES
18
20
  when :eu_storage, :s3, :storage
19
21
  Fog::AWS::Storage
20
22
  else
@@ -48,6 +50,8 @@ class AWS < Fog::Bin
48
50
  Fog::Storage.new(:provider => 'AWS', :region => 'eu-west-1')
49
51
  when :sdb
50
52
  Fog::AWS::SimpleDB.new
53
+ when :ses
54
+ Fog::AWS::SES.new
51
55
  when :s3
52
56
  location = caller.first
53
57
  warning = "[yellow][WARN] AWS[:s3] is deprecated, use AWS[:storage] instead[/]"
@@ -64,7 +68,7 @@ class AWS < Fog::Bin
64
68
  end
65
69
 
66
70
  def services
67
- [:cdn, :compute, :dns, :elb, :iam, :sdb, :storage]
71
+ [:cdn, :compute, :dns, :elb, :iam, :sdb, :ses, :storage]
68
72
  end
69
73
 
70
74
  end
@@ -11,7 +11,7 @@ module Fog
11
11
  require 'fog/cdn/rackspace'
12
12
  Fog::Rackspace::CDN.new(attributes)
13
13
  else
14
- raise ArgumentError.new("#{provider} is not a recognized storage provider")
14
+ raise ArgumentError.new("#{provider} is not a recognized cdn provider")
15
15
  end
16
16
  end
17
17
 
@@ -68,6 +68,7 @@ module Fog
68
68
  request :describe_reserved_instances
69
69
  request :describe_key_pairs
70
70
  request :describe_regions
71
+ request :describe_reserved_instances_offerings
71
72
  request :describe_security_groups
72
73
  request :describe_snapshots
73
74
  request :describe_tags
@@ -177,8 +177,11 @@ module Fog
177
177
  end
178
178
 
179
179
  def ssh(commands)
180
- requires :identity, :ip_address, :private_key, :username
181
- Fog::SSH.new(ip_address, username, :key_data => [private_key]).run(commands)
180
+ requires :identity, :ip_address, :username
181
+
182
+ options = {}
183
+ options[:key_data] = [private_key] if private_key
184
+ Fog::SSH.new(ip_address, username, options).run(commands)
182
185
  end
183
186
 
184
187
  def start
@@ -108,8 +108,11 @@ module Fog
108
108
  end
109
109
 
110
110
  def ssh(commands)
111
- requires :identity, :ips, :private_key, :username
112
- Fog::SSH.new(ips.first['address'], username, :key_data => [private_key]).run(commands)
111
+ requires :identity, :ips, :username
112
+
113
+ options = {}
114
+ options[:key_data] = [private_key] if private_key
115
+ Fog::SSH.new(ips.first['address'], username, options).run(commands)
113
116
  end
114
117
 
115
118
  def username
@@ -1,5 +1,5 @@
1
1
  require 'fog/core/collection'
2
- require 'fog/go_grid/models/compute/image'
2
+ require 'fog/compute/models/go_grid/image'
3
3
 
4
4
  module Fog
5
5
  module GoGrid
@@ -11,7 +11,7 @@ module Fog
11
11
  identity :id
12
12
 
13
13
  attribute :name
14
- attribute :image_id # id or name
14
+ attribute :image_id # id or name
15
15
  attribute :ip
16
16
  attribute :memory # server.ram
17
17
  attribute :state
@@ -24,30 +24,77 @@ module Fog
24
24
 
25
25
  def destroy
26
26
  requires :id
27
- connection.grid_server_destroy(id)
27
+ connection.grid_server_delete(id)
28
28
  true
29
29
  end
30
30
 
31
31
  def image
32
32
  requires :image_id
33
- connection.grid_image_get(image_id)
33
+ connection.grid_image_get(:image => image_id)
34
34
  end
35
35
 
36
36
  def ready?
37
- @state == 'On'
37
+ @state && @state["name"] == 'On'
38
+ end
39
+
40
+ def reload
41
+ requires :name
42
+ begin
43
+ if data = collection.get(name)
44
+ new_attributes = data.attributes
45
+ merge_attributes(new_attributes)
46
+ self
47
+ end
48
+ rescue Excon::Errors::BadRequest
49
+ false
50
+ end
38
51
  end
39
52
 
40
53
  def save
41
54
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
42
55
  requires :name, :image_id, :ip, :memory
43
- options['isSandbox'] = sandbox if sandbox
44
- options['server.ram'] = memory
45
- options['image'] = image_id
46
- data = connection.grid_server_add(name, image, ip, options)
56
+ options = {
57
+ 'isSandbox' => sandbox,
58
+ 'image' => image_id
59
+ }
60
+ options = options.reject {|key, value| value.nil?}
61
+ data = connection.grid_server_add(image, ip, name, memory, options)
47
62
  merge_attributes(data.body)
48
63
  true
49
64
  end
50
65
 
66
+ def ssh(commands)
67
+ requires :ip, :identity, :username
68
+
69
+ options = {}
70
+ options[:key_data] = [private_key] if private_key
71
+ Fog::SSH.new(ip['ip'], username, options).run(commands)
72
+ end
73
+
74
+ def setup(credentials = {})
75
+ requires :ip, :identity, :public_key, :username
76
+ Fog::SSH.new(ip['ip'], username, credentials).run([
77
+ %{mkdir .ssh},
78
+ %{echo "#{public_key}" >> ~/.ssh/authorized_keys},
79
+ %{passwd -l root},
80
+ %{echo "#{attributes.to_json}" >> ~/attributes.json},
81
+ %{echo "#{metadata.to_json}" >> ~/metadata.json}
82
+ ])
83
+ rescue Errno::ECONNREFUSED
84
+ sleep(1)
85
+ retry
86
+ end
87
+
88
+ def username
89
+ @username ||= 'root'
90
+ end
91
+
92
+ private
93
+
94
+ def adminPass=(new_admin_pass)
95
+ @password = new_admin_pass
96
+ end
97
+
51
98
  end
52
99
 
53
100
  end
@@ -1,5 +1,5 @@
1
1
  require 'fog/core/collection'
2
- require 'fog/go_grid/models/compute/server'
2
+ require 'fog/compute/models/go_grid/server'
3
3
 
4
4
  module Fog
5
5
  module GoGrid
@@ -21,7 +21,7 @@ module Fog
21
21
  end
22
22
 
23
23
  def get(server_id)
24
- if server_id && server = connection.grid_server_get(server_id).body['list']
24
+ if server_id && server = connection.grid_server_get(server_id).body['list'].first
25
25
  new(server)
26
26
  end
27
27
  rescue Fog::GoGrid::Compute::NotFound
@@ -104,8 +104,11 @@ module Fog
104
104
  end
105
105
 
106
106
  def ssh(commands)
107
- requires :addresses, :identity, :private_key, :username
108
- Fog::SSH.new(addresses['public'].first, username, :key_data => [private_key]).run(commands)
107
+ requires :addresses, :identity, :username
108
+
109
+ options = {}
110
+ options[:key_data] = [private_key] if private_key
111
+ Fog::SSH.new(addresses['public'].first, username, options).run(commands)
109
112
  end
110
113
 
111
114
  def username
@@ -94,8 +94,11 @@ module Fog
94
94
  end
95
95
 
96
96
  def ssh(commands)
97
- requires :addresses, :identity, :private_key, :username
98
- Fog::SSH.new(addresses.first, username, :key_data => [private_key]).run(commands)
97
+ requires :addresses, :identity, :username
98
+
99
+ options = {}
100
+ options[:key_data] = [private_key] if private_key
101
+ Fog::SSH.new(addresses.first, username, options).run(commands)
99
102
  end
100
103
 
101
104
  def username
@@ -0,0 +1,34 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module Compute
5
+
6
+ class DescribeReservedInstancesOfferings < Fog::Parsers::Base
7
+
8
+ def reset
9
+ @reserved_instances_offering = {}
10
+ @response = { 'reservedInstancesOfferingsSet' => [] }
11
+ end
12
+
13
+ def end_element(name)
14
+ case name
15
+ when 'availabilityZone', 'instanceType', 'productDescription', 'reservedInstancesOfferingId'
16
+ @reserved_instances_offering[name] = @value
17
+ when 'duration'
18
+ @reserved_instances_offering[name] = @value.to_i
19
+ when 'fixedPrice', 'usagePrice'
20
+ @reserved_instances_offering[name] = @value.to_f
21
+ when 'item'
22
+ @response['reservedInstancesOfferingsSet'] << @reserved_instances_offering
23
+ @reserved_instances_offering = {}
24
+ when 'requestId'
25
+ @response[name] = @value
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end