fog 0.0.42 → 0.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/README.rdoc +1 -1
  2. data/Rakefile +1 -0
  3. data/VERSION.yml +2 -2
  4. data/bin/fog +23 -102
  5. data/fog.gemspec +48 -2
  6. data/lib/fog.rb +17 -46
  7. data/lib/fog/aws.rb +10 -4
  8. data/lib/fog/aws/bin.rb +69 -0
  9. data/lib/fog/aws/ec2.rb +82 -86
  10. data/lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb +20 -16
  11. data/lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb +19 -15
  12. data/lib/fog/aws/requests/s3/get_object.rb +4 -0
  13. data/lib/fog/aws/requests/simpledb/select.rb +42 -24
  14. data/lib/fog/aws/s3.rb +28 -25
  15. data/lib/fog/aws/simpledb.rb +21 -17
  16. data/lib/fog/bin.rb +79 -0
  17. data/lib/fog/collection.rb +20 -9
  18. data/lib/fog/model.rb +9 -4
  19. data/lib/fog/rackspace.rb +10 -3
  20. data/lib/fog/rackspace/bin.rb +44 -0
  21. data/lib/fog/rackspace/files.rb +16 -9
  22. data/lib/fog/rackspace/requests/files/delete_container.rb +2 -1
  23. data/lib/fog/rackspace/requests/files/delete_object.rb +2 -1
  24. data/lib/fog/rackspace/requests/files/get_container.rb +2 -1
  25. data/lib/fog/rackspace/requests/files/get_containers.rb +2 -1
  26. data/lib/fog/rackspace/requests/files/head_container.rb +2 -1
  27. data/lib/fog/rackspace/requests/files/head_containers.rb +2 -1
  28. data/lib/fog/rackspace/requests/files/put_container.rb +2 -1
  29. data/lib/fog/rackspace/requests/files/put_object.rb +2 -1
  30. data/lib/fog/rackspace/requests/servers/get_flavor_details.rb +1 -0
  31. data/lib/fog/rackspace/requests/servers/list_flavors.rb +1 -0
  32. data/lib/fog/rackspace/requests/servers/list_flavors_detail.rb +1 -0
  33. data/lib/fog/rackspace/requests/servers/list_images.rb +0 -1
  34. data/lib/fog/rackspace/requests/servers/reboot_server.rb +2 -1
  35. data/lib/fog/rackspace/servers.rb +31 -26
  36. data/lib/fog/slicehost.rb +35 -17
  37. data/lib/fog/slicehost/bin.rb +42 -0
  38. data/lib/fog/slicehost/models/flavor.rb +41 -0
  39. data/lib/fog/slicehost/models/flavors.rb +33 -0
  40. data/lib/fog/slicehost/models/image.rb +13 -0
  41. data/lib/fog/slicehost/models/images.rb +35 -0
  42. data/lib/fog/slicehost/models/server.rb +55 -0
  43. data/lib/fog/slicehost/models/servers.rb +37 -0
  44. data/lib/fog/slicehost/parsers/get_flavor.rb +24 -0
  45. data/lib/fog/slicehost/parsers/get_image.rb +24 -0
  46. data/lib/fog/slicehost/parsers/get_slice.rb +29 -0
  47. data/lib/fog/slicehost/requests/create_slice.rb +2 -1
  48. data/lib/fog/slicehost/requests/delete_slice.rb +2 -1
  49. data/lib/fog/slicehost/requests/get_backups.rb +1 -0
  50. data/lib/fog/slicehost/requests/get_flavor.rb +42 -0
  51. data/lib/fog/slicehost/requests/get_flavors.rb +1 -0
  52. data/lib/fog/slicehost/requests/get_image.rb +40 -0
  53. data/lib/fog/slicehost/requests/get_images.rb +1 -0
  54. data/lib/fog/slicehost/requests/get_slice.rb +48 -0
  55. data/lib/fog/slicehost/requests/get_slices.rb +1 -0
  56. data/lib/fog/slicehost/requests/reboot_slice.rb +49 -0
  57. data/lib/fog/terremark.rb +71 -0
  58. data/lib/fog/terremark/bin.rb +30 -0
  59. data/lib/fog/terremark/parsers/get_catalog.rb +43 -0
  60. data/lib/fog/terremark/parsers/get_catalog_item.rb +44 -0
  61. data/lib/fog/terremark/parsers/get_organization.rb +44 -0
  62. data/lib/fog/terremark/parsers/get_organizations.rb +26 -0
  63. data/lib/fog/terremark/parsers/get_vapp_template.rb +44 -0
  64. data/lib/fog/terremark/parsers/get_vdc.rb +105 -0
  65. data/lib/fog/terremark/requests/get_catalog.rb +44 -0
  66. data/lib/fog/terremark/requests/get_catalog_item.rb +47 -0
  67. data/lib/fog/terremark/requests/get_organization.rb +46 -0
  68. data/lib/fog/terremark/requests/get_organizations.rb +42 -0
  69. data/lib/fog/terremark/requests/get_vapp_template.rb +47 -0
  70. data/lib/fog/terremark/requests/get_vdc.rb +47 -0
  71. data/spec/slicehost/models/server_spec.rb +51 -0
  72. data/spec/slicehost/models/servers_spec.rb +22 -0
  73. data/spec/slicehost/requests/get_flavor_spec.rb +24 -0
  74. data/spec/slicehost/requests/get_image_spec.rb +24 -0
  75. data/spec/slicehost/requests/get_slice_spec.rb +41 -0
  76. data/spec/slicehost/requests/get_slices_spec.rb +20 -9
  77. data/spec/slicehost/requests/reboot_slice_spec.rb +41 -0
  78. data/spec/spec_helper.rb +10 -0
  79. metadata +55 -2
data/lib/fog/slicehost.rb CHANGED
@@ -10,28 +10,45 @@ module Fog
10
10
  end
11
11
  end
12
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"
13
+ def self.dependencies
14
+ [
15
+ "fog/slicehost/models/flavor.rb",
16
+ "fog/slicehost/models/flavors.rb",
17
+ "fog/slicehost/models/image.rb",
18
+ "fog/slicehost/models/images.rb",
19
+ "fog/slicehost/models/server.rb",
20
+ "fog/slicehost/models/servers.rb",
21
+ "fog/slicehost/parsers/create_slice.rb",
22
+ "fog/slicehost/parsers/get_backups.rb",
23
+ "fog/slicehost/parsers/get_flavor.rb",
24
+ "fog/slicehost/parsers/get_flavors.rb",
25
+ "fog/slicehost/parsers/get_image.rb",
26
+ "fog/slicehost/parsers/get_images.rb",
27
+ "fog/slicehost/parsers/get_slice.rb",
28
+ "fog/slicehost/parsers/get_slices.rb",
29
+ "fog/slicehost/requests/create_slice.rb",
30
+ "fog/slicehost/requests/delete_slice.rb",
31
+ "fog/slicehost/requests/get_backups.rb",
32
+ "fog/slicehost/requests/get_flavor.rb",
33
+ "fog/slicehost/requests/get_flavors.rb",
34
+ "fog/slicehost/requests/get_image.rb",
35
+ "fog/slicehost/requests/get_images.rb",
36
+ "fog/slicehost/requests/get_slice.rb",
37
+ "fog/slicehost/requests/get_slices.rb",
38
+ "fog/slicehost/requests/reboot_slice.rb"
39
+ ]
40
+ end
26
41
 
42
+ def self.reload
43
+ self.dependencies.each {|dependency| load(dependency)}
27
44
  if Fog.mocking?
28
45
  reset_data
29
46
  end
30
47
  end
31
48
 
32
49
  def initialize(options={})
33
- unless @password = options[:password]
34
- raise ArgumentError.new('password is required to access slicehost')
50
+ unless @slicehost_password = options[:slicehost_password]
51
+ raise ArgumentError.new('slicehost_password is required to access slicehost')
35
52
  end
36
53
  @host = options[:host] || "api.slicehost.com"
37
54
  @port = options[:port] || 443
@@ -41,7 +58,7 @@ module Fog
41
58
  def request(params)
42
59
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
43
60
  headers = {
44
- 'Authorization' => "Basic #{Base64.encode64(@password).gsub("\n",'')}"
61
+ 'Authorization' => "Basic #{Base64.encode64(@slicehost_password).chomp!}"
45
62
  }
46
63
  case params[:method]
47
64
  when 'DELETE', 'GET', 'HEAD'
@@ -59,10 +76,11 @@ module Fog
59
76
  :parser => params[:parser],
60
77
  :path => params[:path]
61
78
  })
79
+
62
80
  response
63
81
  end
64
82
 
65
83
  end
66
84
  end
67
85
 
68
- Fog::Slicehost.reload
86
+ Fog::Slicehost.dependencies.each {|dependency| require(dependency)}
@@ -0,0 +1,42 @@
1
+ module Slicehost
2
+ class << self
3
+ if Fog.credentials[:slicehost_password]
4
+
5
+ def initialized?
6
+ true
7
+ end
8
+
9
+ def [](service)
10
+ @@connections ||= Hash.new do |hash, key|
11
+ credentials = Fog.credentials.reject do |k,v|
12
+ ![:slicehost_password].include?(k)
13
+ end
14
+ hash[key] = case key
15
+ when :slices
16
+ Fog::Slicehost.new(credentials)
17
+ end
18
+ end
19
+ @@connections[service]
20
+ end
21
+
22
+ def flavors
23
+ self[:slices].flavors
24
+ end
25
+
26
+ def images
27
+ self[:slices].images
28
+ end
29
+
30
+ def servers
31
+ self[:slices].servers
32
+ end
33
+
34
+ else
35
+
36
+ def initialized?
37
+ false
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ module Fog
2
+ class Slicehost
3
+
4
+ class Flavor < Fog::Model
5
+
6
+ identity :id
7
+
8
+ attribute :name
9
+ attribute :price
10
+ attribute :ram
11
+
12
+ def bits
13
+ # 64
14
+ raise StandardError.new("Figure me out!?!")
15
+ end
16
+
17
+ def cores
18
+ # # 2 quad-cores >= 2Ghz = 8 cores
19
+ # 8 * case ram
20
+ # when 256
21
+ # 1/64.0
22
+ # when 512
23
+ # 1/32.0
24
+ # when 1024
25
+ # 1/16.0
26
+ # when 2048
27
+ # 1/8.0
28
+ # when 4096
29
+ # 1/4.0
30
+ # when 8192
31
+ # 1/2.0
32
+ # when 15872
33
+ # 1
34
+ # end
35
+ raise StandardError.new("Figure me out!?!")
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ module Fog
2
+ class Slicehost
3
+
4
+ def flavors
5
+ Fog::Slicehost::Flavors.new(:connection => self)
6
+ end
7
+
8
+ class Flavors < Fog::Collection
9
+
10
+ model Fog::Slicehost::Flavor
11
+
12
+ def all
13
+ if @loaded
14
+ clear
15
+ end
16
+ @loaded = true
17
+ data = connection.get_flavors.body
18
+ for flavor in data['flavors']
19
+ self << new(flavor)
20
+ end
21
+ self
22
+ end
23
+
24
+ def get(flavor_id)
25
+ connection.get_flavor(flavor_id)
26
+ rescue Excon::Errors::Forbidden
27
+ nil
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ module Fog
2
+ class Slicehost
3
+
4
+ class Image < Fog::Model
5
+
6
+ identity :id
7
+
8
+ attribute :name
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ module Fog
2
+ class Slicehost
3
+
4
+ def images(attributes = {})
5
+ Fog::Slicehost::Images.new({
6
+ :connection => self
7
+ }.merge!(attributes))
8
+ end
9
+
10
+ class Images < Fog::Collection
11
+
12
+ model Fog::Slicehost::Image
13
+
14
+ def all
15
+ if @loaded
16
+ clear
17
+ end
18
+ @loaded = true
19
+ data = connection.get_images.body
20
+ for image in data['images']
21
+ self << new(image)
22
+ end
23
+ self
24
+ end
25
+
26
+ def get(image_id)
27
+ connection.get_image(image_id)
28
+ rescue Excon::Errors::Forbidden
29
+ nil
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,55 @@
1
+ module Fog
2
+ class Slicehost
3
+
4
+ class Server < Fog::Model
5
+
6
+ identity :id
7
+
8
+ attribute :addresses
9
+ attribute :backup_id, 'backup-id'
10
+ attribute :bandwidth_in, 'bw-in'
11
+ attribute :bandwidth_out, 'bw-out'
12
+ attribute :flavor_id, 'flavor-id'
13
+ attribute :image_id, 'image-id'
14
+ attribute :name
15
+ attribute :password, 'root-password'
16
+ attribute :progress
17
+ attribute :status
18
+
19
+ def destroy
20
+ requires :id
21
+ connection.delete_slice(@id)
22
+ true
23
+ end
24
+
25
+ def flavor
26
+ requires :flavor_id
27
+ connection.flavors.get(@flavor_id)
28
+ end
29
+
30
+ def image
31
+ requires :image_id
32
+ connection.images.get(@image_id)
33
+ end
34
+
35
+ def ready?
36
+ @status == 'active'
37
+ end
38
+
39
+ def reboot(type = 'SOFT')
40
+ requires :id
41
+ connection.reboot_server(@id, type)
42
+ true
43
+ end
44
+
45
+ def save
46
+ requires :flavor_id, :image_id, :name
47
+ data = connection.create_slice(@flavor_id, @image_id, @name)
48
+ merge_attributes(data.body)
49
+ true
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,37 @@
1
+ module Fog
2
+ class Slicehost
3
+
4
+ def servers
5
+ Fog::Slicehost::Servers.new(:connection => self)
6
+ end
7
+
8
+ class Servers < Fog::Collection
9
+
10
+ model Fog::Slicehost::Server
11
+
12
+ def all
13
+ if @loaded
14
+ clear
15
+ end
16
+ @loaded = true
17
+ data = connection.get_slices.body['slices']
18
+ for server in data
19
+ self << new(server)
20
+ end
21
+ self
22
+ end
23
+
24
+ def get(server_id)
25
+ if server_id && server = connection.get_slice(server_id).body
26
+ new(server)
27
+ elsif !server_id
28
+ nil
29
+ end
30
+ rescue Excon::Errors::Forbidden
31
+ nil
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ module Fog
2
+ module Parsers
3
+ module Slicehost
4
+
5
+ class GetFlavor < Fog::Parsers::Base
6
+
7
+ def reset
8
+ @response = {}
9
+ end
10
+
11
+ def end_element(name)
12
+ case name
13
+ when 'id', 'price', 'ram'
14
+ @response[name] = @value.to_i
15
+ when 'name'
16
+ @response[name] = @value
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Fog
2
+ module Parsers
3
+ module Slicehost
4
+
5
+ class GetImage < Fog::Parsers::Base
6
+
7
+ def reset
8
+ @response = {}
9
+ end
10
+
11
+ def end_element(name)
12
+ case name
13
+ when 'id'
14
+ @response[name] = @value.to_i
15
+ when 'name'
16
+ @response[name] = @value
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ module Fog
2
+ module Parsers
3
+ module Slicehost
4
+
5
+ class GetSlice < 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', 'status'
21
+ @response[name] = @value
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -41,7 +41,8 @@ else
41
41
  module Fog
42
42
  class Slicehost
43
43
 
44
- def get_slices
44
+ def create_slice(flavor_id, image_id, name)
45
+ raise MockNotImplemented.new("Contributions welcome!")
45
46
  end
46
47
 
47
48
  end
@@ -39,7 +39,8 @@ else
39
39
  module Fog
40
40
  class Slicehost
41
41
 
42
- def get_slices
42
+ def delete_slice(slice_id)
43
+ raise MockNotImplemented.new("Contributions welcome!")
43
44
  end
44
45
 
45
46
  end