fog 0.0.31 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.document +0 -2
  2. data/Rakefile +12 -7
  3. data/VERSION +1 -1
  4. data/bin/fog +16 -18
  5. data/fog.gemspec +34 -8
  6. data/lib/fog.rb +11 -0
  7. data/lib/fog/aws/models/ec2/address.rb +4 -0
  8. data/lib/fog/aws/models/ec2/instance.rb +17 -0
  9. data/lib/fog/aws/models/ec2/key_pair.rb +4 -0
  10. data/lib/fog/aws/models/ec2/security_group.rb +8 -0
  11. data/lib/fog/aws/models/ec2/snapshot.rb +7 -1
  12. data/lib/fog/aws/models/ec2/volume.rb +9 -1
  13. data/lib/fog/aws/models/s3/bucket.rb +10 -0
  14. data/lib/fog/aws/models/s3/buckets.rb +10 -4
  15. data/lib/fog/aws/models/s3/object.rb +5 -0
  16. data/lib/fog/aws/requests/ec2/allocate_address.rb +1 -1
  17. data/lib/fog/aws/requests/ec2/associate_address.rb +2 -2
  18. data/lib/fog/aws/requests/ec2/attach_volume.rb +2 -2
  19. data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +1 -1
  20. data/lib/fog/aws/requests/ec2/create_key_pair.rb +2 -2
  21. data/lib/fog/aws/requests/ec2/create_security_group.rb +2 -2
  22. data/lib/fog/aws/requests/ec2/create_snapshot.rb +2 -2
  23. data/lib/fog/aws/requests/ec2/create_volume.rb +1 -1
  24. data/lib/fog/aws/requests/ec2/delete_key_pair.rb +1 -1
  25. data/lib/fog/aws/requests/ec2/delete_security_group.rb +2 -2
  26. data/lib/fog/aws/requests/ec2/delete_snapshot.rb +2 -2
  27. data/lib/fog/aws/requests/ec2/delete_volume.rb +2 -2
  28. data/lib/fog/aws/requests/ec2/describe_addresses.rb +2 -2
  29. data/lib/fog/aws/requests/ec2/describe_availability_zones.rb +1 -1
  30. data/lib/fog/aws/requests/ec2/describe_images.rb +1 -1
  31. data/lib/fog/aws/requests/ec2/describe_instances.rb +2 -2
  32. data/lib/fog/aws/requests/ec2/describe_key_pairs.rb +2 -2
  33. data/lib/fog/aws/requests/ec2/describe_regions.rb +1 -1
  34. data/lib/fog/aws/requests/ec2/describe_security_groups.rb +2 -2
  35. data/lib/fog/aws/requests/ec2/describe_snapshots.rb +2 -2
  36. data/lib/fog/aws/requests/ec2/describe_volumes.rb +2 -2
  37. data/lib/fog/aws/requests/ec2/detach_volume.rb +2 -2
  38. data/lib/fog/aws/requests/ec2/disassociate_address.rb +2 -2
  39. data/lib/fog/aws/requests/ec2/get_console_output.rb +2 -2
  40. data/lib/fog/aws/requests/ec2/reboot_instances.rb +2 -2
  41. data/lib/fog/aws/requests/ec2/release_address.rb +2 -2
  42. data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +1 -1
  43. data/lib/fog/aws/requests/ec2/run_instances.rb +1 -1
  44. data/lib/fog/aws/requests/ec2/terminate_instances.rb +2 -2
  45. data/lib/fog/aws/requests/s3/copy_object.rb +2 -2
  46. data/lib/fog/aws/requests/s3/delete_bucket.rb +3 -3
  47. data/lib/fog/aws/requests/s3/delete_object.rb +8 -7
  48. data/lib/fog/aws/requests/s3/get_bucket.rb +2 -2
  49. data/lib/fog/aws/requests/s3/get_bucket_location.rb +2 -2
  50. data/lib/fog/aws/requests/s3/get_object.rb +2 -2
  51. data/lib/fog/aws/requests/s3/get_request_payment.rb +2 -2
  52. data/lib/fog/aws/requests/s3/get_service.rb +1 -1
  53. data/lib/fog/aws/requests/s3/put_bucket.rb +8 -6
  54. data/lib/fog/aws/requests/s3/put_object.rb +9 -9
  55. data/lib/fog/aws/requests/s3/put_request_payment.rb +2 -2
  56. data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +2 -2
  57. data/lib/fog/aws/requests/simpledb/create_domain.rb +1 -1
  58. data/lib/fog/aws/requests/simpledb/delete_attributes.rb +2 -2
  59. data/lib/fog/aws/requests/simpledb/delete_domain.rb +1 -1
  60. data/lib/fog/aws/requests/simpledb/domain_metadata.rb +2 -2
  61. data/lib/fog/aws/requests/simpledb/get_attributes.rb +2 -2
  62. data/lib/fog/aws/requests/simpledb/list_domains.rb +1 -1
  63. data/lib/fog/aws/s3.rb +1 -12
  64. data/lib/fog/collection.rb +16 -8
  65. data/lib/fog/model.rb +36 -14
  66. data/lib/fog/rackspace/models/servers/image.rb +40 -0
  67. data/lib/fog/rackspace/models/servers/images.rb +50 -0
  68. data/lib/fog/rackspace/models/servers/server.rb +18 -2
  69. data/lib/fog/rackspace/requests/servers/create_image.rb +18 -1
  70. data/lib/fog/rackspace/requests/servers/create_server.rb +5 -5
  71. data/lib/fog/rackspace/requests/servers/delete_image.rb +16 -1
  72. data/lib/fog/rackspace/requests/servers/delete_server.rb +4 -4
  73. data/lib/fog/rackspace/requests/servers/get_server_details.rb +2 -2
  74. data/lib/fog/rackspace/requests/servers/list_addresses.rb +2 -2
  75. data/lib/fog/rackspace/requests/servers/list_images.rb +10 -0
  76. data/lib/fog/rackspace/requests/servers/list_images_detail.rb +16 -1
  77. data/lib/fog/rackspace/requests/servers/list_private_addresses.rb +2 -2
  78. data/lib/fog/rackspace/requests/servers/list_public_addresses.rb +2 -2
  79. data/lib/fog/rackspace/requests/servers/list_servers.rb +1 -1
  80. data/lib/fog/rackspace/requests/servers/list_servers_detail.rb +2 -2
  81. data/lib/fog/rackspace/requests/servers/update_server.rb +2 -2
  82. data/lib/fog/rackspace/servers.rb +8 -2
  83. data/lib/fog/slicehost.rb +66 -0
  84. data/lib/fog/slicehost/parsers/create_slice.rb +29 -0
  85. data/lib/fog/slicehost/parsers/get_backups.rb +30 -0
  86. data/lib/fog/slicehost/parsers/get_flavors.rb +28 -0
  87. data/lib/fog/slicehost/parsers/get_images.rb +28 -0
  88. data/lib/fog/slicehost/parsers/get_slices.rb +33 -0
  89. data/lib/fog/slicehost/requests/create_slice.rb +50 -0
  90. data/lib/fog/slicehost/requests/delete_slice.rb +48 -0
  91. data/lib/fog/slicehost/requests/get_backups.rb +38 -0
  92. data/lib/fog/slicehost/requests/get_flavors.rb +38 -0
  93. data/lib/fog/slicehost/requests/get_images.rb +36 -0
  94. data/lib/fog/slicehost/requests/get_slices.rb +44 -0
  95. data/spec/aws/requests/s3/put_object_spec.rb +8 -0
  96. data/spec/rackspace/requests/servers/create_image_spec.rb +1 -1
  97. data/spec/rackspace/requests/servers/create_server_spec.rb +1 -1
  98. data/spec/rackspace/requests/servers/delete_image_spec.rb +7 -5
  99. data/spec/rackspace/requests/servers/delete_server_spec.rb +1 -1
  100. data/spec/rackspace/requests/servers/get_server_details_spec.rb +1 -1
  101. data/spec/rackspace/requests/servers/list_addresses_spec.rb +1 -1
  102. data/spec/rackspace/requests/servers/list_private_addresses_spec.rb +1 -1
  103. data/spec/rackspace/requests/servers/list_public_addresses_spec.rb +1 -1
  104. data/spec/rackspace/requests/servers/list_servers_detail_spec.rb +1 -1
  105. data/spec/rackspace/requests/servers/list_servers_spec.rb +1 -1
  106. data/spec/rackspace/requests/servers/reboot_server_spec.rb +1 -1
  107. data/spec/rackspace/requests/servers/update_server_spec.rb +1 -1
  108. data/spec/slicehost/requests/create_slice_spec.rb +29 -0
  109. data/spec/slicehost/requests/delete_slice_spec.rb +18 -0
  110. data/spec/slicehost/requests/get_backups_spec.rb +17 -0
  111. data/spec/slicehost/requests/get_flavors_spec.rb +17 -0
  112. data/spec/slicehost/requests/get_images_spec.rb +15 -0
  113. data/spec/slicehost/requests/get_slices_spec.rb +23 -0
  114. data/spec/spec_helper.rb +20 -22
  115. metadata +29 -4
  116. data/lib/fog/aws/models/s3/owner.rb +0 -18
@@ -32,13 +32,13 @@ else
32
32
  class Servers
33
33
 
34
34
  def list_private_addresses(server_id)
35
- response = Fog::Response.new
35
+ response = Excon::Response.new
36
36
  if server = list_servers_detail.body['servers'].detect { |server| server['id'] == server_id }
37
37
  response.status = [200, 203][rand(1)]
38
38
  response.body = { 'private' => server['addresses']['private'] }
39
39
  else
40
40
  response.status = 404
41
- raise(Excon::Errors.status_error(202, 404, response))
41
+ raise(Excon::Errors.status_error({:expects => 202}, response))
42
42
  end
43
43
  response
44
44
  end
@@ -32,13 +32,13 @@ else
32
32
  class Servers
33
33
 
34
34
  def list_public_addresses(server_id)
35
- response = Fog::Response.new
35
+ response = Excon::Response.new
36
36
  if server = list_servers_detail.body['servers'].detect { |server| server['id'] == server_id }
37
37
  response.status = [200, 203][rand(1)]
38
38
  response.body = { 'public' => server['addresses']['public'] }
39
39
  else
40
40
  response.status = 404
41
- raise(Excon::Errors.status_error(202, 404, response))
41
+ raise(Excon::Errors.status_error({:expects => 202}, response))
42
42
  end
43
43
  response
44
44
  end
@@ -31,7 +31,7 @@ else
31
31
  class Servers
32
32
 
33
33
  def list_servers
34
- response = Fog::Response.new
34
+ response = Excon::Response.new
35
35
  data = list_servers_detail.body['servers']
36
36
  servers = []
37
37
  for server in data
@@ -40,13 +40,13 @@ else
40
40
  class Servers
41
41
 
42
42
  def list_servers_detail
43
- response = Fog::Response.new
43
+ response = Excon::Response.new
44
44
 
45
45
  servers = Fog::Rackspace::Servers.data[:servers].values
46
46
  for server in servers
47
47
  case server['status']
48
48
  when 'BUILD'
49
- if Time.now - Fog::Rackspace::Servers.data[:last_modified][server['id']] > 2
49
+ if Time.now - Fog::Rackspace::Servers.data[:last_modified][:servers][server['id']] > 2
50
50
  server['status'] = 'ACTIVE'
51
51
  end
52
52
  end
@@ -31,7 +31,7 @@ else
31
31
  class Servers
32
32
 
33
33
  def update_server(server_id, options)
34
- response = Fog::Response.new
34
+ response = Excon::Response.new
35
35
  if server = list_servers_detail.body['servers'].detect { |server| server['id'] == server_id }
36
36
  if options['adminPass']
37
37
  server['adminPass'] = options['adminPass']
@@ -42,7 +42,7 @@ else
42
42
  response.status = 204
43
43
  else
44
44
  response.status = 404
45
- raise(Excon::Errors.status_error(202, 404, response))
45
+ raise(Excon::Errors.status_error({:expects => 202}, response))
46
46
  end
47
47
  response
48
48
  end
@@ -8,7 +8,11 @@ module Fog
8
8
  end
9
9
  def self.reset_data
10
10
  @data = {
11
- :last_modified => [],
11
+ :last_modified => {
12
+ :images => {},
13
+ :servers => {}
14
+ },
15
+ :images => {},
12
16
  :servers => {}
13
17
  }
14
18
  end
@@ -17,6 +21,8 @@ module Fog
17
21
  def self.reload
18
22
  load "fog/rackspace/models/servers/flavor.rb"
19
23
  load "fog/rackspace/models/servers/flavors.rb"
24
+ load "fog/rackspace/models/servers/image.rb"
25
+ load "fog/rackspace/models/servers/images.rb"
20
26
  load "fog/rackspace/models/servers/server.rb"
21
27
  load "fog/rackspace/models/servers/servers.rb"
22
28
 
@@ -60,7 +66,7 @@ module Fog
60
66
  :expects => params[:expects],
61
67
  :headers => {
62
68
  'X-Auth-Token' => @auth_token
63
- },
69
+ }.merge!(params[:headers] || {}),
64
70
  :host => @host,
65
71
  :method => params[:method],
66
72
  :path => "#{@path}/#{params[:path]}"
@@ -0,0 +1,66 @@
1
+ module Fog
2
+ class Slicehost
3
+
4
+ if Fog.mocking?
5
+ def self.data
6
+ @data
7
+ end
8
+ def self.reset_data
9
+ @data = {}
10
+ end
11
+ end
12
+
13
+ def self.reload
14
+ load "fog/slicehost/parsers/create_slice.rb"
15
+ load "fog/slicehost/parsers/get_backups.rb"
16
+ load "fog/slicehost/parsers/get_flavors.rb"
17
+ load "fog/slicehost/parsers/get_images.rb"
18
+ load "fog/slicehost/parsers/get_slices.rb"
19
+
20
+ load "fog/slicehost/requests/create_slice.rb"
21
+ load "fog/slicehost/requests/delete_slice.rb"
22
+ load "fog/slicehost/requests/get_backups.rb"
23
+ load "fog/slicehost/requests/get_flavors.rb"
24
+ load "fog/slicehost/requests/get_images.rb"
25
+ load "fog/slicehost/requests/get_slices.rb"
26
+
27
+ if Fog.mocking?
28
+ reset_data
29
+ end
30
+ end
31
+
32
+ def initialize(options={})
33
+ @password = options[:password]
34
+ @host = options[:host] || "api.slicehost.com"
35
+ @port = options[:port] || 443
36
+ @scheme = options[:scheme] || 'https'
37
+ @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
38
+ end
39
+
40
+ def request(params)
41
+ headers = {
42
+ 'Authorization' => "Basic #{Base64.encode64(@password).gsub("\n",'')}"
43
+ }
44
+ case params[:method]
45
+ when 'DELETE', 'GET', 'HEAD'
46
+ headers['Accept'] = 'application/xml'
47
+ when 'POST', 'PUT'
48
+ headers['Content-Type'] = 'application/xml'
49
+ end
50
+
51
+ response = @connection.request({
52
+ :body => params[:body],
53
+ :expects => params[:expects],
54
+ :headers => headers.merge!(params[:headers] || {}),
55
+ :host => @host,
56
+ :method => params[:method],
57
+ :parser => params[:parser],
58
+ :path => params[:path]
59
+ })
60
+ response
61
+ end
62
+
63
+ end
64
+ end
65
+
66
+ Fog::Slicehost.reload
@@ -0,0 +1,29 @@
1
+ module Fog
2
+ module Parsers
3
+ module Slicehost
4
+
5
+ class CreateSlice < Fog::Parsers::Base
6
+
7
+ def reset
8
+ @response = {}
9
+ end
10
+
11
+ def end_element(name)
12
+ case name
13
+ when 'address'
14
+ @response['addresses'] ||= []
15
+ @response['addresses'] << @value
16
+ when 'backup-id', 'flavor-id', 'id', 'image-id', 'progress'
17
+ @response[name] = @value.to_i
18
+ when 'bw-in', 'bw-out'
19
+ @response[name] = @value.to_f
20
+ when 'name', 'root-password', 'status'
21
+ @response[name] = @value
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Parsers
3
+ module Slicehost
4
+
5
+ class GetBackups < Fog::Parsers::Base
6
+
7
+ def reset
8
+ @backup = {}
9
+ @response = { 'backups' => [] }
10
+ end
11
+
12
+ def end_element(name)
13
+ case name
14
+ when 'backup'
15
+ @response['backups'] << @backup
16
+ @backup = {}
17
+ when 'date'
18
+ @backup[name] = Time.parse(@value)
19
+ when 'id', 'slice-id'
20
+ @backup[name] = @value.to_i
21
+ when 'name'
22
+ @backup[name] = @value
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Parsers
3
+ module Slicehost
4
+
5
+ class GetFlavors < Fog::Parsers::Base
6
+
7
+ def reset
8
+ @flavor = {}
9
+ @response = { 'flavors' => [] }
10
+ end
11
+
12
+ def end_element(name)
13
+ case name
14
+ when 'flavor'
15
+ @response['flavors'] << @flavor
16
+ @flavor = {}
17
+ when 'id', 'price', 'ram'
18
+ @flavor[name] = @value.to_i
19
+ when 'name'
20
+ @flavor[name] = @value
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Parsers
3
+ module Slicehost
4
+
5
+ class GetImages < Fog::Parsers::Base
6
+
7
+ def reset
8
+ @image = {}
9
+ @response = { 'images' => [] }
10
+ end
11
+
12
+ def end_element(name)
13
+ case name
14
+ when 'id'
15
+ @image[name] = @value.to_i
16
+ when 'image'
17
+ @response['images'] << @image
18
+ @image = {}
19
+ when 'name'
20
+ @image[name] = @value
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ module Fog
2
+ module Parsers
3
+ module Slicehost
4
+
5
+ class GetSlices < Fog::Parsers::Base
6
+
7
+ def reset
8
+ @slice = {}
9
+ @response = { 'slices' => [] }
10
+ end
11
+
12
+ def end_element(name)
13
+ case name
14
+ when 'address'
15
+ @slice['addresses'] ||= []
16
+ @slice['addresses'] << @value
17
+ when 'backup-id', 'flavor-id', 'id', 'image-id', 'progress'
18
+ @slice[name] = @value.to_i
19
+ when 'bw-in', 'bw-out'
20
+ @slice[name] = @value.to_f
21
+ when 'name', 'status'
22
+ @slice[name] = @value
23
+ when 'slice'
24
+ @response['slices'] << @slice
25
+ @slice = {}
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,50 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ class Slicehost
5
+
6
+ # Get list of slices
7
+ # ==== Parameters
8
+ # * flavor_id<~Integer> - Id of flavor to create slice with
9
+ # * image_id<~Integer> - Id of image to create slice with
10
+ # * name<~String> - Name of slice
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Array>:
15
+ # * 'addresses'<~Array> - Ip addresses for the slice
16
+ # * 'backup-id'<~Integer> - Id of backup slice was booted from
17
+ # * 'bw-in'<~Integer> - Incoming bandwidth total for current billing cycle, in Gigabytes
18
+ # * 'bw-out'<~Integer> - Outgoing bandwidth total for current billing cycle, in Gigabytes
19
+ # * 'flavor-id'<~Integer> - Id of flavor slice was booted from
20
+ # * 'id'<~Integer> - Id of the slice
21
+ # * 'image-id'<~Integer> - Id of image slice was booted from
22
+ # * 'name'<~String> - Name of the slice
23
+ # * 'progress'<~Integer> - Progress of current action, in percentage
24
+ # * 'root-password'<~String> - Root password of slice
25
+ # * 'status'<~String> - Current status of the slice
26
+ def create_slice(flavor_id, image_id, name)
27
+ request(
28
+ :body => %Q{<?xml version="1.0" encoding="UTF-8"?><slice><flavor-id type="integer">#{flavor_id}</flavor-id><image-id type="integer">#{image_id}</image-id><name>#{name}</name></slice>},
29
+ :expects => 201,
30
+ :method => 'POST',
31
+ :parser => Fog::Parsers::Slicehost::CreateSlice.new,
32
+ :path => 'slices.xml'
33
+ )
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ else
40
+
41
+ module Fog
42
+ class Slicehost
43
+
44
+ def get_slices
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,48 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ class Slicehost
5
+
6
+ # Get list of slices
7
+ # ==== Parameters
8
+ # * flavor_id<~Integer> - Id of flavor to create slice with
9
+ # * image_id<~Integer> - Id of image to create slice with
10
+ # * name<~String> - Name of slice
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Array>:
15
+ # * 'addresses'<~Array> - Ip addresses for the slice
16
+ # * 'backup-id'<~Integer> - Id of backup slice was booted from
17
+ # * 'bw-in'<~Integer> - Incoming bandwidth total for current billing cycle, in Gigabytes
18
+ # * 'bw-out'<~Integer> - Outgoing bandwidth total for current billing cycle, in Gigabytes
19
+ # * 'flavor-id'<~Integer> - Id of flavor slice was booted from
20
+ # * 'id'<~Integer> - Id of the slice
21
+ # * 'image-id'<~Integer> - Id of image slice was booted from
22
+ # * 'name'<~String> - Name of the slice
23
+ # * 'progress'<~Integer> - Progress of current action, in percentage
24
+ # * 'root-password'<~String> - Root password of slice
25
+ # * 'status'<~String> - Current status of the slice
26
+ def delete_slice(slice_id)
27
+ request(
28
+ :expects => 200,
29
+ :method => 'DELETE',
30
+ :path => "slices/#{slice_id}.xml"
31
+ )
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ else
38
+
39
+ module Fog
40
+ class Slicehost
41
+
42
+ def get_slices
43
+ end
44
+
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,38 @@
1
+ unless Fog.mocking?
2
+
3
+ module Fog
4
+ class Slicehost
5
+
6
+ # Get list of backups
7
+ #
8
+ # ==== Returns
9
+ # * response<~Excon::Response>:
10
+ # * body<~Array>:
11
+ # * 'date'<~Time> - Timestamp of backup creation
12
+ # * 'id'<~Integer> - Id of the backup
13
+ # * 'name'<~String> - Name of the backup
14
+ # * 'slice-id'<~Integer> - Id of slice the backup was made from
15
+ def get_backups
16
+ request(
17
+ :expects => 200,
18
+ :method => 'GET',
19
+ :parser => Fog::Parsers::Slicehost::GetBackups.new,
20
+ :path => 'backups.xml'
21
+ )
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+ else
28
+
29
+ module Fog
30
+ class Slicehost
31
+
32
+ def get_backups
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ end