fog 0.2.15 → 0.2.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/fog.gemspec +12 -2
  2. data/lib/fog.rb +3 -3
  3. data/lib/fog/aws/ec2.rb +2 -0
  4. data/lib/fog/aws/models/ec2/server.rb +12 -0
  5. data/lib/fog/aws/parsers/ec2/start_stop_instances.rb +41 -0
  6. data/lib/fog/aws/requests/ec2/describe_instances.rb +1 -1
  7. data/lib/fog/aws/requests/ec2/start_instances.rb +38 -0
  8. data/lib/fog/aws/requests/ec2/stop_instances.rb +38 -0
  9. data/lib/fog/aws/requests/ec2/terminate_instances.rb +4 -2
  10. data/lib/fog/linode.rb +10 -10
  11. data/lib/fog/linode/requests/avail_distributions.rb +6 -3
  12. data/lib/fog/linode/requests/avail_linodeplans.rb +6 -2
  13. data/lib/fog/linode/requests/linode_list.rb +6 -3
  14. data/lib/fog/model.rb +2 -2
  15. data/lib/fog/rackspace/models/files/file.rb +2 -2
  16. data/lib/fog/rackspace/models/servers/server.rb +1 -1
  17. data/lib/fog/slicehost/models/server.rb +5 -0
  18. data/lib/fog/vcloud.rb +24 -13
  19. data/lib/fog/vcloud/extension.rb +0 -7
  20. data/lib/fog/vcloud/requests/login.rb +1 -1
  21. data/lib/fog/vcloud/terremark/ecloud.rb +3 -20
  22. data/lib/fog/vcloud/terremark/vcloud.rb +3 -14
  23. data/spec/vcloud/requests/get_versions_spec.rb +40 -14
  24. data/spec/vcloud/requests/login_spec.rb +15 -2
  25. data/spec/vcloud/spec_helper.rb +57 -8
  26. data/tests/aws/models/s3/directory_tests.rb +8 -0
  27. data/tests/helper.rb +2 -0
  28. data/tests/helpers/model_helper.rb +76 -0
  29. data/tests/linode/helper.rb +25 -0
  30. data/tests/linode/requests/datacenter_tests.rb +18 -0
  31. data/tests/linode/requests/distribution_tests.rb +30 -0
  32. data/tests/linode/requests/linode_tests.rb +79 -0
  33. data/tests/linode/requests/linodeplans_tests.rb +37 -0
  34. data/tests/slicehost/requests/slice_tests.rb +1 -1
  35. metadata +13 -3
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  ## If your rubyforge_project name is different, then edit it and comment out
8
8
  ## the sub! line in the Rakefile
9
9
  s.name = 'fog'
10
- s.version = '0.2.15'
11
- s.date = '2010-07-17'
10
+ s.version = '0.2.16'
11
+ s.date = '2010-07-22'
12
12
  s.rubyforge_project = 'fog'
13
13
 
14
14
  ## Make sure your summary is short. The description may be as long
@@ -116,6 +116,7 @@ Gem::Specification.new do |s|
116
116
  lib/fog/aws/parsers/ec2/detach_volume.rb
117
117
  lib/fog/aws/parsers/ec2/get_console_output.rb
118
118
  lib/fog/aws/parsers/ec2/run_instances.rb
119
+ lib/fog/aws/parsers/ec2/start_stop_instances.rb
119
120
  lib/fog/aws/parsers/ec2/terminate_instances.rb
120
121
  lib/fog/aws/parsers/elb/create_load_balancer.rb
121
122
  lib/fog/aws/parsers/elb/delete_load_balancer.rb
@@ -169,6 +170,8 @@ Gem::Specification.new do |s|
169
170
  lib/fog/aws/requests/ec2/release_address.rb
170
171
  lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb
171
172
  lib/fog/aws/requests/ec2/run_instances.rb
173
+ lib/fog/aws/requests/ec2/start_instances.rb
174
+ lib/fog/aws/requests/ec2/stop_instances.rb
172
175
  lib/fog/aws/requests/ec2/terminate_instances.rb
173
176
  lib/fog/aws/requests/elb/create_load_balancer.rb
174
177
  lib/fog/aws/requests/elb/delete_load_balancer.rb
@@ -570,6 +573,7 @@ Gem::Specification.new do |s|
570
573
  spec/vcloud/terremark/ecloud/requests/login_spec.rb
571
574
  spec/vcloud/vcloud_spec.rb
572
575
  tests/aws/helper.rb
576
+ tests/aws/models/s3/directory_tests.rb
573
577
  tests/aws/requests/ec2/address_tests.rb
574
578
  tests/aws/requests/ec2/availability_zone_tests.rb
575
579
  tests/aws/requests/ec2/instance_tests.rb
@@ -584,6 +588,12 @@ Gem::Specification.new do |s|
584
588
  tests/bluebox/requests/template_tests.rb
585
589
  tests/helper.rb
586
590
  tests/helper_tests.rb
591
+ tests/helpers/model_helper.rb
592
+ tests/linode/helper.rb
593
+ tests/linode/requests/datacenter_tests.rb
594
+ tests/linode/requests/distribution_tests.rb
595
+ tests/linode/requests/linode_tests.rb
596
+ tests/linode/requests/linodeplans_tests.rb
587
597
  tests/rackspace/helper.rb
588
598
  tests/rackspace/requests/servers/address_tests.rb
589
599
  tests/rackspace/requests/servers/flavor_tests.rb
data/lib/fog.rb CHANGED
@@ -40,7 +40,7 @@ require 'fog/vcloud'
40
40
  module Fog
41
41
 
42
42
  unless const_defined?(:VERSION)
43
- VERSION = '0.2.15'
43
+ VERSION = '0.2.16'
44
44
  end
45
45
 
46
46
  module Mock
@@ -68,11 +68,11 @@ module Fog
68
68
  !!@mocking
69
69
  end
70
70
 
71
- def self.wait_for(timeout = 600, &block)
71
+ def self.wait_for(timeout=600, interval=1, &block)
72
72
  duration = 0
73
73
  start = Time.now
74
74
  until yield || duration > timeout
75
- sleep(1)
75
+ sleep(interval)
76
76
  duration = Time.now - start
77
77
  end
78
78
  if duration > timeout
@@ -57,6 +57,8 @@ module Fog
57
57
  request 'revoke_security_group_ingress'
58
58
  request 'run_instances'
59
59
  request 'terminate_instances'
60
+ request 'start_instances'
61
+ request 'stop_instances'
60
62
 
61
63
  class Mock
62
64
  include Collections
@@ -132,6 +132,18 @@ module Fog
132
132
  true
133
133
  end
134
134
 
135
+ def start
136
+ requires :id
137
+ connection.stop_instances(@id)
138
+ true
139
+ end
140
+
141
+ def stop
142
+ requires :id
143
+ connection.stop_instances(@id)
144
+ true
145
+ end
146
+
135
147
  def volumes
136
148
  requires :id
137
149
 
@@ -0,0 +1,41 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module EC2
5
+
6
+ class StartStopInstances < Fog::Parsers::Base
7
+
8
+ def reset
9
+ @instance = { 'currentState' => {}, 'previousState' => {} }
10
+ @response = { 'instancesSet' => [] }
11
+ @state = nil
12
+ end
13
+
14
+ def start_element(name, attrs = [])
15
+ super
16
+ case name
17
+ when 'currentState', 'previousState'
18
+ @state = name
19
+ end
20
+ end
21
+
22
+ def end_element(name)
23
+ case name
24
+ when 'code'
25
+ @instance[@state][name] = @value.to_s
26
+ when 'instanceId'
27
+ @instance[name] = @value
28
+ when 'item'
29
+ @response['instancesSet'] << @instance
30
+ @instance = { 'currentState' => {}, 'previousState' => {} }
31
+ when 'name'
32
+ @instance[@state][name] = @value
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -93,7 +93,7 @@ module Fog
93
93
  @data[:deleted_at].delete(instance['instanceId'])
94
94
  @data[:instances].delete(instance['instanceId'])
95
95
  elsif Time.now - @data[:deleted_at][instance['instanceId']] > Fog::Mock.delay
96
- instance['instanceState'] = { 'code' => 16, 'name' => 'terminating' }
96
+ instance['instanceState'] = { 'code' => 48, 'name' => 'terminating' }
97
97
  end
98
98
  when 'terminating'
99
99
  if Time.now - @data[:deleted_at][instance['instanceId']] > Fog::Mock.delay
@@ -0,0 +1,38 @@
1
+ module Fog
2
+ module AWS
3
+ module EC2
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/ec2/start_stop_instances'
7
+
8
+ # Start specified instance
9
+ #
10
+ # ==== Parameters
11
+ # * instance_id<~Array> - Id of instance to start
12
+ #
13
+ # ==== Returns
14
+ # * response<~Excon::Response>:
15
+ # * body<~Hash>:
16
+ # * 'requestId'<~String> - Id of request
17
+ # * TODO: fill in the blanks
18
+ def start_instances(instance_id)
19
+ params = AWS.indexed_param('InstanceId', instance_id)
20
+ request({
21
+ 'Action' => 'StartInstances',
22
+ :idempotent => true,
23
+ :parser => Fog::Parsers::AWS::EC2::StartStopInstances.new
24
+ }.merge!(params))
25
+ end
26
+
27
+ end
28
+
29
+ class Mock
30
+
31
+ def start_instances(instance_id)
32
+ Fog::Mock.not_implemented
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ module Fog
2
+ module AWS
3
+ module EC2
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/ec2/start_stop_instances'
7
+
8
+ # Stop specified instance
9
+ #
10
+ # ==== Parameters
11
+ # * instance_id<~Array> - Id of instance to start
12
+ #
13
+ # ==== Returns
14
+ # * response<~Excon::Response>:
15
+ # * body<~Hash>:
16
+ # * 'requestId'<~String> - Id of request
17
+ # * TODO: fill in the blanks
18
+ def stop_instances(instance_id)
19
+ params = AWS.indexed_param('InstanceId', instance_id)
20
+ request({
21
+ 'Action' => 'StopInstances',
22
+ :idempotent => true,
23
+ :parser => Fog::Parsers::AWS::EC2::StartStopInstances.new
24
+ }.merge!(params))
25
+ end
26
+
27
+ end
28
+
29
+ class Mock
30
+
31
+ def stop_instances(instance_id)
32
+ Fog::Mock.not_implemented
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -55,9 +55,11 @@ module Fog
55
55
  when 'shutting-down'
56
56
  32
57
57
  when 'terminated'
58
+ 48
59
+ when 'stopping'
58
60
  64
59
- when 'rebooting'
60
- 128
61
+ when 'stopped'
62
+ 80
61
63
  end
62
64
  state = { 'name' => 'shutting-down', 'code' => 32}
63
65
  response.body['instancesSet'] << {
@@ -58,19 +58,19 @@ module Fog
58
58
  params[:query] ||= {}
59
59
  params[:query].merge!(:api_key => @linode_api_key)
60
60
 
61
- begin
62
- response = @connection.request(params.merge!({:host => @host}))
63
- rescue Excon::Errors::Error => error
64
- raise case error
65
- when Excon::Errors::NotFound
66
- Fog::Linode::NotFound.slurp(error)
67
- else
68
- error
69
- end
70
- end
61
+ response = @connection.request(params.merge!({:host => @host}))
71
62
 
72
63
  unless response.body.empty?
73
64
  response.body = JSON.parse(response.body)
65
+ if data = response.body['ERRORARRAY'].first
66
+ error = case data['ERRORCODE']
67
+ when 5
68
+ Fog::Linode::NotFound
69
+ else
70
+ Fog::Linode::Error
71
+ end
72
+ raise error.new(data['ERRORMESSAGE'])
73
+ end
74
74
  end
75
75
  response
76
76
  end
@@ -5,14 +5,17 @@ module Fog
5
5
  # Get available distributions
6
6
  #
7
7
  # ==== Parameters
8
- # * options<~Hash>:
9
- # * distributionId<~Integer>: id to limit results to
8
+ # * distributionId<~Integer>: id to limit results to
10
9
  #
11
10
  # ==== Returns
12
11
  # * response<~Excon::Response>:
13
12
  # * body<~Array>:
14
13
  # TODO: docs
15
- def avail_distributions(options={})
14
+ def avail_distributions(distribution_id=nil)
15
+ options = {}
16
+ if distribution_id
17
+ options.merge!(:distributionId => distribution_id)
18
+ end
16
19
  request(
17
20
  :expects => 200,
18
21
  :method => 'GET',
@@ -8,11 +8,15 @@ module Fog
8
8
  # * response<~Excon::Response>:
9
9
  # * body<~Array>:
10
10
  # TODO: docs
11
- def avail_linodeplans
11
+ def avail_linodeplans(linodeplan_id=nil)
12
+ options = {}
13
+ if linodeplan_id
14
+ options.merge!(:planId => linodeplan_id)
15
+ end
12
16
  request(
13
17
  :expects => 200,
14
18
  :method => 'GET',
15
- :query => { :api_action => 'avail.linodeplans' }
19
+ :query => { :api_action => 'avail.linodeplans' }.merge!(options)
16
20
  )
17
21
  end
18
22
 
@@ -5,14 +5,17 @@ module Fog
5
5
  # List all linodes user has access or delete to
6
6
  #
7
7
  # ==== Parameters
8
- # * options<~Hash>:
9
- # * linodeId<~Integer>: Limit the list to the specified LinodeID
8
+ # * linodeId<~Integer>: Limit the list to the specified LinodeID
10
9
  #
11
10
  # ==== Returns
12
11
  # * response<~Excon::Response>:
13
12
  # * body<~Array>:
14
13
  # TODO: docs
15
- def linode_list(options={})
14
+ def linode_list(linode_id=nil)
15
+ options = {}
16
+ if linode_id
17
+ options.merge!(:linodeId => linode_id)
18
+ end
16
19
  request(
17
20
  :expects => 200,
18
21
  :method => 'GET',
@@ -39,9 +39,9 @@ module Fog
39
39
  attributes.to_json
40
40
  end
41
41
 
42
- def wait_for(timeout = 600, &block)
42
+ def wait_for(timeout=600, interval=1, &block)
43
43
  reload
44
- Fog.wait_for(timeout) do
44
+ Fog.wait_for(timeout, interval) do
45
45
  reload or raise StandardError.new("Reload failed, #{self.class} #{self.identity} went away.")
46
46
  instance_eval(&block)
47
47
  end
@@ -41,9 +41,9 @@ module Fog
41
41
  end
42
42
  end
43
43
 
44
- def save(options = {})
44
+ def save
45
45
  requires :body, :directory, :key
46
- data = connection.put_object(directory.name, @key, @body, options)
46
+ data = connection.put_object(directory.name, @key, @body)
47
47
  @etag = data.headers['ETag']
48
48
  true
49
49
  end
@@ -65,7 +65,7 @@ module Fog
65
65
  end
66
66
 
67
67
  def save
68
- requires :flavor_id, :image_id
68
+ requires :flavor_id, :image_id, :name
69
69
  options = {
70
70
  'metadata' => @metadata,
71
71
  'name' => @name,
@@ -18,6 +18,11 @@ module Fog
18
18
  attribute :progress
19
19
  attribute :status
20
20
 
21
+ def initialize(attributes={})
22
+ @flavor_id ||= 1
23
+ super
24
+ end
25
+
21
26
  def destroy
22
27
  requires :id
23
28
  connection.delete_slice(@id)
@@ -3,8 +3,9 @@ require 'fog/vcloud/model'
3
3
  require 'fog/vcloud/collection'
4
4
  require 'fog/vcloud/generators'
5
5
  require 'fog/vcloud/extension'
6
- require 'fog/vcloud/terremark/vcloud'
7
6
  require 'fog/vcloud/terremark/ecloud'
7
+ require 'fog/vcloud/terremark/vcloud'
8
+
8
9
 
9
10
  module URI
10
11
  class Generic
@@ -46,6 +47,10 @@ module Fog
46
47
  attr_accessor :login_uri
47
48
  attr_reader :versions_uri
48
49
 
50
+ def supporting_versions
51
+ ["v0.8"]
52
+ end
53
+
49
54
  def initialize(options = {})
50
55
  @connections = {}
51
56
  @versions_uri = URI.parse(options[:versions_uri])
@@ -138,18 +143,21 @@ module Fog
138
143
  end
139
144
  end
140
145
 
141
- # Load up @all_versions and supported_versions from the provided :versions_uri
142
- # If there are no supported versions raise an error
143
- # And choose a default version is none is specified
146
+ # If we don't support any versions the service does, then raise an error.
147
+ # If the @version that super selected isn't in our supported list, then select one that is.
144
148
  def check_versions
145
- supported_versions = get_versions(@versions_uri).body[:VersionInfo]
146
-
147
- if supported_versions.empty?
148
- raise UnsupportedVersion.new("No supported versions found @ #{@version_uri}")
149
- end
150
-
151
- unless @version
152
- @version = supported_version_numbers.first
149
+ if @version
150
+ unless supported_version_numbers.include?(@version.to_s)
151
+ raise UnsupportedVersion.new("#{@version} is not supported by the server.")
152
+ end
153
+ unless supporting_versions.include?(@version.to_s)
154
+ raise UnsupportedVersion.new("#{@version} is not supported by #{self.class}")
155
+ end
156
+ else
157
+ unless @version = (supported_version_numbers & supporting_versions).sort.first
158
+ raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_numbers.join(', ')}\n" +
159
+ "#{self.class} supports: #{supporting_versions.join(', ')}")
160
+ end
153
161
  end
154
162
  end
155
163
 
@@ -163,10 +171,13 @@ module Fog
163
171
  "Basic #{Base64.encode64("#{@username}:#{@password}").chomp!}"
164
172
  end
165
173
 
174
+ def login_uri
175
+ @login_uri ||= get_login_uri
176
+ end
177
+
166
178
  # login handles the auth, but we just need the Set-Cookie
167
179
  # header from that call.
168
180
  def do_login
169
- @login_uri ||= get_login_uri
170
181
  @login_results = login
171
182
  @cookie = @login_results.headers['Set-Cookie']
172
183
  end
@@ -12,9 +12,6 @@ module Fog
12
12
  end
13
13
  module #{other}::Mock
14
14
  end
15
- def self.supported_versions
16
- @versions
17
- end
18
15
  def self.extended(klass)
19
16
  unless @required
20
17
  models.each do |model|
@@ -35,10 +32,6 @@ module Fog
35
32
  EOS
36
33
  end
37
34
 
38
- def versions(*args)
39
- @versions = args
40
- end
41
-
42
35
  end
43
36
  end
44
37
  end
@@ -12,7 +12,7 @@ module Fog
12
12
  },
13
13
  :method => 'POST',
14
14
  :parse => true,
15
- :uri => @login_uri
15
+ :uri => login_uri
16
16
  })
17
17
  end
18
18
 
@@ -63,8 +63,6 @@ module Fog
63
63
  request :power_reset
64
64
  request :power_shutdown
65
65
 
66
- versions "v0.8b-ext2.3", "0.8b-ext2.3"
67
-
68
66
  module Mock
69
67
  def self.base_url
70
68
  "https://fakey.com/api/v0.8b-ext2.3"
@@ -190,26 +188,11 @@ module Fog
190
188
  end
191
189
 
192
190
  module Real
193
- private
194
-
195
- # If we don't support any versions the service does, then raise an error.
196
- # If the @version that super selected isn't in our supported list, then select one that is.
197
- def check_versions
198
- if @version
199
- unless supported_version_numbers.include?(@version.to_s)
200
- raise UnsupportedVersion.new("#{@version} is not supported by the server.")
201
- end
202
- unless Fog::Vcloud::Terremark::Ecloud.supported_versions.include?(@version.to_s)
203
- raise UnsupportedVersion.new("#{@version} is not supported by Fog::Vcloud::Terremark::Ecloud")
204
- end
205
- else
206
- unless @version = (supported_version_numbers & Fog::Vcloud::Terremark::Ecloud.supported_versions).sort.first
207
- raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_numbers.join(', ')}\n" +
208
- "Fog::Vcloud::Terremark::Ecloud supports: #{Fog::Vcloud::Terremark::Ecloud.supported_versions.join(', ')}")
209
- end
210
- end
191
+ def supporting_versions
192
+ ["v0.8b-ext2.3", "0.8b-ext2.3"]
211
193
  end
212
194
  end
195
+
213
196
  end
214
197
  end
215
198
  end
@@ -4,23 +4,12 @@ module Fog
4
4
  module Vcloud
5
5
  extend Fog::Vcloud::Extension
6
6
 
7
- versions "v0.8"
8
-
9
7
  request_path 'fog/vcloud/terremark/vcloud/requests'
10
8
  request :get_vdc
11
9
 
12
- private
13
-
14
- # If we don't support any versions the service does, then raise an error.
15
- # If the @version that super selected isn't in our supported list, then select one that is.
16
- def check_versions
17
- super
18
- unless (supported_version_ids & Versions::SUPPORTED).length > 0
19
- raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_ids.join(', ')}\n" +
20
- "Fog::Vcloud::Terremark::Vcloud supports: #{Versions::SUPPORTED.join(', ')}")
21
- end
22
- unless supported_version_ids.include?(@version)
23
- @version = (supported_version_ids & Versions::SUPPORTED).sort.first
10
+ module Real
11
+ def supporting_versions
12
+ ["0.8", "0.8a-ext1.6"]
24
13
  end
25
14
  end
26
15
  end
@@ -1,28 +1,54 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
- if Fog.mocking?
4
- describe Fog::Vcloud, :type => :mock_vcloud_request do
5
- subject { @vcloud }
3
+ shared_examples_for "real or mock get_versions requests" do
4
+
5
+ subject { @vcloud }
6
+
7
+ it { should respond_to :get_versions }
6
8
 
7
- it { should respond_to :get_versions }
9
+ describe "#get_versions" do
10
+ subject { @vcloud.get_versions( @vcloud.versions_uri ) }
8
11
 
9
- describe "#get_versions" do
10
- before { @versions = @vcloud.get_versions( @vcloud.versions_uri ) }
11
- subject { @versions }
12
+ it_should_behave_like "all responses"
12
13
 
13
- it_should_behave_like "all responses"
14
+ describe "body" do
15
+ subject { @vcloud.get_versions( @vcloud.versions_uri ).body }
14
16
 
15
- describe "body" do
16
- subject { @versions.body }
17
+ it { should have(4).keys }
18
+ it_should_behave_like "it has the standard xmlns attributes" # 2 keys
17
19
 
18
- it { should have(4).keys }
19
- it_should_behave_like "it has the standard xmlns attributes" # 2 keys
20
+ its(:xmlns) { should == "http://www.vmware.com/vcloud/versions" }
20
21
 
21
- its(:xmlns) { should == "http://www.vmware.com/vcloud/versions" }
22
- its(:VersionInfo) { should == { :LoginUrl => @mock_version[:login_url] , :Version => @mock_version[:version] } }
22
+ its(:VersionInfo) { should be_either_a_hash_or_array }
23
23
 
24
+ describe ":VersionInfo" do
25
+ subject { arrayify(@vcloud.get_versions( @vcloud.versions_uri ).body[:VersionInfo]) }
26
+
27
+ specify {
28
+ subject.each do |version_info|
29
+ version_info.should include(:LoginUrl)
30
+ version_info[:LoginUrl].should be_a_url
31
+ version_info.should include(:Version)
32
+ version_info[:Version].should be_an_instance_of String
33
+ end
34
+ }
24
35
  end
25
36
  end
26
37
  end
38
+ end
39
+
40
+ if Fog.mocking?
41
+ describe Fog::Vcloud, :type => :mock_vcloud_request do
42
+
43
+ it_should_behave_like "real or mock get_versions requests"
44
+
45
+ describe "body" do
46
+ subject { @vcloud.get_versions( @vcloud.versions_uri ).body }
47
+ its(:VersionInfo) { should == { :LoginUrl => @mock_version[:login_url] , :Version => @mock_version[:version] } }
48
+ end
49
+ end
27
50
  else
51
+ describe Fog::Vcloud, :type => :vcloud_request do
52
+ it_should_behave_like "real or mock get_versions requests"
53
+ end
28
54
  end
@@ -1,11 +1,24 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
+ shared_examples_for "real or mock login requests" do
4
+ subject { @vcloud }
5
+ it_should_behave_like "all login requests"
6
+ end
7
+
3
8
  if Fog.mocking?
4
9
  describe Fog::Vcloud, :type => :mock_vcloud_request do
5
- subject { @vcloud }
10
+ it_should_behave_like "real or mock login requests"
6
11
 
7
- it_should_behave_like "all login requests"
12
+ describe "#body" do
13
+ subject { @vcloud.login.body }
14
+ its(:Org) { should == { :type => "application/vnd.vmware.vcloud.org+xml",
15
+ :href => @mock_organization[:info][:href],
16
+ :name => @mock_organization[:info][:name]} }
17
+ end
8
18
  end
9
19
  else
20
+ describe Fog::Vcloud, :type => :vcloud_request do
21
+ it_should_behave_like "real or mock login requests"
22
+ end
10
23
  end
11
24
 
@@ -27,6 +27,10 @@ Fog.mock! if ENV['FOG_MOCK']
27
27
 
28
28
  require "#{current_directory}/../../lib/fog/vcloud/bin"
29
29
 
30
+ def arrayify(item)
31
+ item.is_a?(Array) ? item : [ item ]
32
+ end
33
+
30
34
  shared_examples_for "all responses" do
31
35
  it { should be_an_instance_of Excon::Response }
32
36
  it { should respond_to :body }
@@ -98,17 +102,27 @@ shared_examples_for "all login requests" do
98
102
 
99
103
  its(:headers) { should include "Set-Cookie" }
100
104
 
101
- it { should have_headers_denoting_a_content_type_of "application/vnd.vmware.vcloud.orgslist+xml" }
102
-
103
105
  describe "#body" do
104
106
  subject { @login.body }
105
107
 
106
- it { should have(4).organizations }
107
-
108
+ it { should have(4).items }
108
109
  it_should_behave_like "it has the standard vcloud v0.8 xmlns attributes" # 3 keys
109
- its(:Org) { should == { :type => "application/vnd.vmware.vcloud.org+xml",
110
- :href => @mock_organization[:info][:href],
111
- :name => @mock_organization[:info][:name]} }
110
+ it { should include(:Org) }
111
+
112
+ describe ":Org" do
113
+ subject { arrayify(@login.body[:Org]) }
114
+
115
+ specify do
116
+ subject.each do |org|
117
+ org.should include(:type)
118
+ org[:type].should be_of_type "application/vnd.vmware.vcloud.org+xml"
119
+ org.should include(:name)
120
+ org[:name].should be_an_instance_of String
121
+ org.should include(:href)
122
+ org[:href].should be_a_url
123
+ end
124
+ end
125
+ end
112
126
  end
113
127
  end
114
128
  end
@@ -218,7 +232,12 @@ Spec::Runner.configure do |config|
218
232
  config.after(:all) do
219
233
  Fog::Vcloud::Mock.data_reset
220
234
  end
221
- config.before(:each, :type => :mock_vcloud_model) do
235
+
236
+ config.before(:each, :type => :vcloud_request) do
237
+ @vcloud = Fog.services.detect { |service| service == Vcloud }[:vcloud]
238
+ end
239
+
240
+ config.before(:all, :type => :mock_vcloud_model) do
222
241
  @vcloud = Fog::Vcloud.new(:username => "foo", :password => "bar", :versions_uri => "http://fakey.com/api/versions")
223
242
  end
224
243
  config.before(:all, :type => :mock_vcloud_model) do
@@ -332,3 +351,33 @@ Spec::Matchers.define :have_all_attributes_be_nil do
332
351
  actual.class.attributes.all? { |attribute| actual.send(attribute.to_sym) == nil }
333
352
  end
334
353
  end
354
+
355
+ Spec::Matchers.define :be_a_url do
356
+ match do |actual|
357
+ actual.match(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix)
358
+ end
359
+ end
360
+
361
+ Spec::Matchers.define :be_either_a_hash_or_array do
362
+ match do |actual|
363
+ actual.is_a?(Hash) || actual.is_a?(Array)
364
+ end
365
+ end
366
+
367
+ Spec::Matchers.define :be_a_known_vmware_type do
368
+ match do |actual|
369
+ ["application/vnd.vmware.vcloud.org+xml"].include?(actual)
370
+ end
371
+ end
372
+
373
+ Spec::Matchers.define :be_of_type do |type|
374
+ match do |actual|
375
+ actual == type ||
376
+ if actual.is_a?(Hash) && actual[:type]
377
+ actual[:type] == type
378
+ end ||
379
+ if actual.respond_to(:type)
380
+ actual.type == type
381
+ end
382
+ end
383
+ end
@@ -0,0 +1,8 @@
1
+ Shindo.tests('AWS::S3 | directory models', ['aws']) do
2
+
3
+ @collection = AWS[:s3].directories
4
+ @model = @collection.new(:key => Time.now.to_f.to_s)
5
+
6
+ tests_models
7
+
8
+ end
@@ -1,6 +1,8 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog'))
2
2
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog', 'bin'))
3
3
 
4
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'model_helper'))
5
+
4
6
  if ENV["FOG_MOCK"] == "true"
5
7
  Fog.mock!
6
8
  end
@@ -0,0 +1,76 @@
1
+ def tests_models
2
+
3
+ after do
4
+ if @model && !@model.new_record?
5
+ if @model.respond_to?(:ready?)
6
+ @model.wait_for { ready? }
7
+ end
8
+ @model.destroy
9
+ end
10
+ end
11
+
12
+ tests('collection') do
13
+
14
+ test('#all includes persisted models') do
15
+ @model.save
16
+ @collection.all.map {|model| model.identity}.include? @model.identity
17
+ end
18
+
19
+ tests('#get') do
20
+
21
+ test 'should return a matching model if one exists' do
22
+ @model.save
23
+ get = @collection.get(@model.identity)
24
+ @model.attributes == get.attributes
25
+ end
26
+
27
+ test 'should return nil if no matching model exists' do
28
+ !@collection.get('0')
29
+ end
30
+
31
+ end
32
+
33
+ test('#reload') do
34
+ @model.save
35
+ @collection.all
36
+ reloaded = @collection.reload
37
+ @collection.attributes == reloaded.attributes
38
+ end
39
+
40
+ end
41
+
42
+ tests('model') do
43
+
44
+ test('#reload') do
45
+ @model.save
46
+ if @model.respond_to?(:ready?)
47
+ @model.wait_for { ready? }
48
+ end
49
+ reloaded = @model.reload
50
+ @model.attributes == reloaded.attributes
51
+ end
52
+
53
+ tests('#save') do
54
+
55
+ test('does not exist remotely before save') do
56
+ !@collection.get(@model.identity)
57
+ end
58
+
59
+ test('succeeds') do
60
+ @model.save
61
+ end
62
+
63
+ test('does exist remotely after save') do
64
+ @model.save
65
+ if @model.respond_to?(:ready?)
66
+ @model.wait_for { ready? }
67
+ end
68
+ reloaded = @model.reload
69
+ @model.attributes == reloaded.attributes
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,25 @@
1
+ module Linode
2
+
3
+ def self.[](service)
4
+ @@connections ||= Hash.new do |hash, key|
5
+ credentials = Fog.credentials.reject do |k,v|
6
+ ![:linode_api_key].include?(k)
7
+ end
8
+ hash[key] = case key
9
+ when :linode
10
+ Fog::Linode.new(credentials)
11
+ end
12
+ end
13
+ @@connections[service]
14
+ end
15
+
16
+ module Formats
17
+
18
+ BASIC = {
19
+ 'ERRORARRAY' => [],
20
+ 'ACTION' => String
21
+ }
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,18 @@
1
+ Shindo.tests('Linode | datacenter requests', ['linode']) do
2
+
3
+ @datacenters_format = Linode::Formats::BASIC.merge({
4
+ 'DATA' => [{
5
+ 'DATACENTERID' => Integer,
6
+ 'LOCATION' => String
7
+ }]
8
+ })
9
+
10
+ tests('success') do
11
+
12
+ tests('#avail_datacenters').formats(@datacenters_format) do
13
+ Linode[:linode].avail_datacenters.body
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,30 @@
1
+ Shindo.tests('Linode | distribution requests', ['linode']) do
2
+
3
+ @distributions_format = Linode::Formats::BASIC.merge({
4
+ 'DATA' => [{
5
+ 'CREATE_DT' => String,
6
+ 'DISTRIBUTIONID' => Integer,
7
+ 'IS64BIT' => Integer,
8
+ 'LABEL' => String,
9
+ 'MINIMAGESIZE' => Integer,
10
+ 'REQUIRESPVOPSKERNEL' => Integer
11
+ }]
12
+ })
13
+
14
+ tests('success') do
15
+
16
+ @distribution_id = nil
17
+
18
+ tests('#avail_distributions').formats(@distributions_format) do
19
+ data = Linode[:linode].avail_distributions.body
20
+ @distribution_id = data['DATA'].first['DISTRIBUTIONID']
21
+ data
22
+ end
23
+
24
+ tests("@avail_distributions(#{@distribution_id})").formats(@distributions_format) do
25
+ Linode[:linode].avail_distributions(@distribution_id).body
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,79 @@
1
+ Shindo.tests('Linode | linode requests', ['linode']) do
2
+
3
+ @linode_format = Linode::Formats::BASIC.merge({
4
+ 'DATA' => { 'LinodeID' => Integer }
5
+ })
6
+
7
+ @linodes_format = Linode::Formats::BASIC.merge({
8
+ 'DATA' => [{
9
+ 'ALERT_BWIN_ENABLED' => Integer,
10
+ 'ALERT_CPU_THRESHOLD' => Integer,
11
+ 'ALERT_BWOUT_ENABLED' => Integer,
12
+ 'ALERT_BWOUT_THRESHOLD' => Integer,
13
+ 'ALERT_BWQUOTA_ENABLED' => Integer,
14
+ 'ALERT_BWQUOTA_THRESHOLD' => Integer,
15
+ 'ALERT_BWIN_THRESHOLD' => Integer,
16
+ 'ALERT_CPU_ENABLED' => Integer,
17
+ 'ALERT_DISKIO_ENABLED' => Integer,
18
+ 'ALERT_DISKIO_THRESHOLD' => Integer,
19
+ 'BACKUPSENABLED' => Integer,
20
+ 'BACKUPWEEKLYDAY' => Integer,
21
+ 'BACKUPWINDOW' => Integer,
22
+ 'DATACENTERID' => Integer,
23
+ 'LABEL' => String,
24
+ 'LINODEID' => Integer,
25
+ 'LPM_DISPLAYGROUP' => String,
26
+ 'STATUS' => Integer,
27
+ 'TOTALHD' => Integer,
28
+ 'TOTALRAM' => Integer,
29
+ 'TOTALXFER' => Integer,
30
+ 'WATCHDOG' => Integer,
31
+ }]
32
+ })
33
+
34
+ @reboot_format = Linode::Formats::BASIC.merge({
35
+ 'DATA' => { 'JobID' => Integer }
36
+ })
37
+
38
+ tests('success') do
39
+
40
+ @linode_id = nil
41
+
42
+ # (2 => Dallas, TX, USA), (1 => 1 month), (1 => Linode 512)
43
+ tests('#linode_create(2, 1, 1)').formats(@linode_format) do
44
+ data = Linode[:linode].linode_create(2, 1, 1).body
45
+ @linode_id = data['DATA']['LinodeID']
46
+ data
47
+ end
48
+
49
+ tests("#linode_list(#{@linode_id})").formats(@linodes_format) do
50
+ Linode[:linode].linode_list(@linode_id).body
51
+ end
52
+
53
+ tests('#linode_list').formats(@linodes_format) do
54
+ Linode[:linode].linode_list.body
55
+ end
56
+
57
+ # tests("#linode_reboot(#{@linode_id})").formats(@reboot_format) do
58
+ # Linode[:linode].linode_reboot(@linode_id).body
59
+ # end
60
+
61
+ tests('#linode_delete(#{@linode_id})').succeeds do
62
+ Linode[:linode].linode_delete(@linode_id)
63
+ end
64
+
65
+ end
66
+
67
+ tests('failure') do
68
+
69
+ tests('#linode_reboot(0)').raises(Fog::Linode::NotFound) do
70
+ Linode[:linode].linode_reboot(0)
71
+ end
72
+
73
+ tests('#linode_delete(0)').raises(Fog::Linode::NotFound) do
74
+ Linode[:linode].linode_delete(0)
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,37 @@
1
+ Shindo.tests('Linode | linodeplans requests', ['linode']) do
2
+
3
+ @linodeplans_format = Linode::Formats::BASIC.merge({
4
+ 'DATA' => [{
5
+ 'AVAIL' => {
6
+ '2' => Integer,
7
+ '3' => Integer,
8
+ '4' => Integer,
9
+ '6' => Integer,
10
+ '7' => Integer
11
+ },
12
+ 'DISK' => Integer,
13
+ 'PLANID' => Integer,
14
+ 'PRICE' => Float,
15
+ 'RAM' => Integer,
16
+ 'LABEL' => String,
17
+ 'XFER' => Integer
18
+ }]
19
+ })
20
+
21
+ tests('success') do
22
+
23
+ @linodeplan_id = nil
24
+
25
+ tests('#avail_linodeplans').formats(@linodeplans_format) do
26
+ data = Linode[:linode].avail_linodeplans.body
27
+ @linodeplan_id = data['DATA'].first['PLANID']
28
+ data
29
+ end
30
+
31
+ tests("#avail_linodeplans(#{@linodeplan_id})").formats(@linodeplans_format) do
32
+ Linode[:linode].avail_linodeplans(@linodeplan_id).body
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -54,7 +54,7 @@ Shindo.tests('Slicehost | slice requests', ['slicehost']) do
54
54
  Slicehost[:slices].reboot_slice(0)
55
55
  end
56
56
 
57
- tests('delete_slice(0)').raises(Fog::Slicehost::NotFound) do
57
+ tests('#delete_slice(0)').raises(Fog::Slicehost::NotFound) do
58
58
  Slicehost[:slices].delete_slice(0)
59
59
  end
60
60
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 15
9
- version: 0.2.15
8
+ - 16
9
+ version: 0.2.16
10
10
  platform: ruby
11
11
  authors:
12
12
  - geemus (Wesley Beary)
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-17 00:00:00 -05:00
17
+ date: 2010-07-22 00:00:00 -07:00
18
18
  default_executable: fog
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -205,6 +205,7 @@ files:
205
205
  - lib/fog/aws/parsers/ec2/detach_volume.rb
206
206
  - lib/fog/aws/parsers/ec2/get_console_output.rb
207
207
  - lib/fog/aws/parsers/ec2/run_instances.rb
208
+ - lib/fog/aws/parsers/ec2/start_stop_instances.rb
208
209
  - lib/fog/aws/parsers/ec2/terminate_instances.rb
209
210
  - lib/fog/aws/parsers/elb/create_load_balancer.rb
210
211
  - lib/fog/aws/parsers/elb/delete_load_balancer.rb
@@ -258,6 +259,8 @@ files:
258
259
  - lib/fog/aws/requests/ec2/release_address.rb
259
260
  - lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb
260
261
  - lib/fog/aws/requests/ec2/run_instances.rb
262
+ - lib/fog/aws/requests/ec2/start_instances.rb
263
+ - lib/fog/aws/requests/ec2/stop_instances.rb
261
264
  - lib/fog/aws/requests/ec2/terminate_instances.rb
262
265
  - lib/fog/aws/requests/elb/create_load_balancer.rb
263
266
  - lib/fog/aws/requests/elb/delete_load_balancer.rb
@@ -659,6 +662,7 @@ files:
659
662
  - spec/vcloud/terremark/ecloud/requests/login_spec.rb
660
663
  - spec/vcloud/vcloud_spec.rb
661
664
  - tests/aws/helper.rb
665
+ - tests/aws/models/s3/directory_tests.rb
662
666
  - tests/aws/requests/ec2/address_tests.rb
663
667
  - tests/aws/requests/ec2/availability_zone_tests.rb
664
668
  - tests/aws/requests/ec2/instance_tests.rb
@@ -673,6 +677,12 @@ files:
673
677
  - tests/bluebox/requests/template_tests.rb
674
678
  - tests/helper.rb
675
679
  - tests/helper_tests.rb
680
+ - tests/helpers/model_helper.rb
681
+ - tests/linode/helper.rb
682
+ - tests/linode/requests/datacenter_tests.rb
683
+ - tests/linode/requests/distribution_tests.rb
684
+ - tests/linode/requests/linode_tests.rb
685
+ - tests/linode/requests/linodeplans_tests.rb
676
686
  - tests/rackspace/helper.rb
677
687
  - tests/rackspace/requests/servers/address_tests.rb
678
688
  - tests/rackspace/requests/servers/flavor_tests.rb