steamcannon-deltacloud-client 0.0.9.7.2 → 0.0.9.8

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.
data/lib/deltacloud.rb CHANGED
@@ -105,7 +105,7 @@ module DeltaCloud
105
105
  API.instance_eval do
106
106
  entry_points.keys.select {|k| [:instance_states].include?(k)==false }.each do |model|
107
107
  define_method model do |*args|
108
- request(:get, "/#{model}", args.first) do |response|
108
+ request(:get, entry_points[model], args.first) do |response|
109
109
  # Define a new class based on model name
110
110
  c = DeltaCloud.define_class("#{model.to_s.classify}")
111
111
  # Create collection from index operation
@@ -114,7 +114,7 @@ module DeltaCloud
114
114
  end
115
115
  logger << "[API] Added method #{model}\n"
116
116
  define_method :"#{model.to_s.singularize}" do |*args|
117
- request(:get, "/#{model}/#{args[0]}") do |response|
117
+ request(:get, "#{entry_points[model]}/#{args[0]}") do |response|
118
118
  # Define a new class based on model name
119
119
  c = DeltaCloud.define_class("#{model.to_s.classify}")
120
120
  # Build class for returned object
@@ -149,6 +149,8 @@ module DeltaCloud
149
149
  c.instance_eval do
150
150
  attr_accessor :id
151
151
  attr_accessor :uri
152
+
153
+
152
154
  end
153
155
  obj = xml_to_class(c, item)
154
156
  end
@@ -162,6 +164,10 @@ module DeltaCloud
162
164
  obj.id = item['id']
163
165
  api = self
164
166
  c.instance_eval do
167
+ define_method :method_missing do |method|
168
+ warn "[WARNING] Method '#{method}' is not available for this resource (#{c.name})."
169
+ return nil
170
+ end
165
171
  define_method :client do
166
172
  api
167
173
  end
@@ -261,7 +267,7 @@ module DeltaCloud
261
267
  end
262
268
  declare_entry_points_methods(@entry_points)
263
269
  end
264
-
270
+
265
271
  def create_key(opts={}, &block)
266
272
  params = { :name => opts[:name] }
267
273
  key = nil
@@ -288,17 +294,18 @@ module DeltaCloud
288
294
  realm_id = opts[:realm]
289
295
  user_data = opts[:user_data]
290
296
  key_name = opts[:key_name]
297
+ security_group = opts[:security_group]
291
298
 
292
- params = opts.dup
299
+ params = {}
293
300
  ( params[:realm_id] = realm_id ) if realm_id
294
301
  ( params[:name] = name ) if name
295
302
  ( params[:user_data] = user_data ) if user_data
296
303
  ( params[:keyname] = key_name ) if key_name
304
+ ( params[:security_group] = security_group) if security_group
297
305
 
298
306
  if opts[:hardware_profile].is_a?(String)
299
307
  params[:hwp_id] = opts[:hardware_profile]
300
308
  elsif opts[:hardware_profile].is_a?(Hash)
301
- params.delete(:hardware_profile)
302
309
  opts[:hardware_profile].each do |k,v|
303
310
  params[:"hwp_#{k}"] = v
304
311
  end
@@ -354,10 +361,20 @@ module DeltaCloud
354
361
  end
355
362
  else
356
363
  RestClient.send(conf[:method], conf[:path], default_headers) do |response, request, block|
357
- if response.respond_to?('body')
358
- yield response.body if block_given?
364
+ if conf[:method].eql?(:get) and [301, 302, 307].include? response.code
365
+ response.follow_redirection(request) do |response, request, block|
366
+ if response.respond_to?('body')
367
+ yield response.body if block_given?
368
+ else
369
+ yield response.to_s if block_given?
370
+ end
371
+ end
359
372
  else
360
- yield response.to_s if block_given?
373
+ if response.respond_to?('body')
374
+ yield response.body if block_given?
375
+ else
376
+ yield response.to_s if block_given?
377
+ end
361
378
  end
362
379
  end
363
380
  end
@@ -31,13 +31,15 @@ describe "hardware_profiles" do
31
31
  it_should_behave_like "all resources"
32
32
 
33
33
  it "should allow retrieval of all hardware profiles" do
34
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
35
- hardware_profiles = client.hardware_profiles
36
- hardware_profiles.should_not be_empty
37
- hardware_profiles.each do |hwp|
38
- hwp.uri.should_not be_nil
39
- hwp.uri.should be_a(String)
40
- prop_check(hwp.architecture, String) if hwp.architecture
34
+ [API_URL, API_URL_REDIRECT].each do |entry_point|
35
+ DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client|
36
+ hardware_profiles = client.hardware_profiles
37
+ hardware_profiles.should_not be_empty
38
+ hardware_profiles.each do |hwp|
39
+ hwp.uri.should_not be_nil
40
+ hwp.uri.should be_a(String)
41
+ prop_check(hwp.architecture, String) if hwp.architecture
42
+ end
41
43
  end
42
44
  end
43
45
  end
data/specs/images_spec.rb CHANGED
@@ -24,19 +24,21 @@ describe "images" do
24
24
  it_should_behave_like "all resources"
25
25
 
26
26
  it "should allow retrieval of all images" do
27
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
28
- images = client.images
29
- images.should_not be_empty
30
- images.size.should eql( 3 )
31
- images.each do |image|
32
- image.uri.should_not be_nil
33
- image.uri.should be_a(String)
34
- image.description.should_not be_nil
35
- image.description.should be_a(String)
36
- image.architecture.should_not be_nil
37
- image.architecture.should be_a(String)
38
- image.owner_id.should_not be_nil
39
- image.owner_id.should be_a(String)
27
+ [API_URL, API_URL_REDIRECT].each do |entry_point|
28
+ DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client|
29
+ images = client.images
30
+ images.should_not be_empty
31
+ images.size.should eql( 3 )
32
+ images.each do |image|
33
+ image.uri.should_not be_nil
34
+ image.uri.should be_a(String)
35
+ image.description.should_not be_nil
36
+ image.description.should be_a(String)
37
+ image.architecture.should_not be_nil
38
+ image.architecture.should be_a(String)
39
+ image.owner_id.should_not be_nil
40
+ image.owner_id.should be_a(String)
41
+ end
40
42
  end
41
43
  end
42
44
  end
@@ -28,12 +28,14 @@ describe "initializing the client" do
28
28
  end
29
29
 
30
30
  it "should discover entry points upon connection" do
31
- DeltaCloud.new( "name", "password", API_URL ) do |client|
32
- client.entry_points[:hardware_profiles].should eql( "#{API_URL}/hardware_profiles" )
33
- client.entry_points[:images].should eql( "#{API_URL}/images" )
34
- client.entry_points[:instances].should eql( "#{API_URL}/instances" )
35
- client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage_volumes" )
36
- client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage_snapshots" )
31
+ [API_URL, API_URL_REDIRECT].each do |entry_point|
32
+ DeltaCloud.new( "name", "password", entry_point ) do |client|
33
+ client.entry_points[:hardware_profiles].should eql( "#{API_URL}/hardware_profiles" )
34
+ client.entry_points[:images].should eql( "#{API_URL}/images" )
35
+ client.entry_points[:instances].should eql( "#{API_URL}/instances" )
36
+ client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage_volumes" )
37
+ client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage_snapshots" )
38
+ end
37
39
  end
38
40
  end
39
41
 
@@ -33,23 +33,25 @@ describe "instance-states" do
33
33
  it_should_behave_like "all resources"
34
34
 
35
35
  it "should allow retrieval of instance-state information" do
36
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
37
- instance_states = client.instance_states
38
- instance_states.should_not be_nil
39
- instance_states.should_not be_empty
36
+ [API_URL, API_URL_REDIRECT].each do |entry_point|
37
+ DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client|
38
+ instance_states = client.instance_states
39
+ instance_states.should_not be_nil
40
+ instance_states.should_not be_empty
40
41
 
41
- instance_states[0].name.should eql( 'start' )
42
- instance_states[0].transitions.size.should eql( 1 )
43
- instance_states[0].transitions[0].should_not be_auto
42
+ instance_states[0].name.should eql( 'start' )
43
+ instance_states[0].transitions.size.should eql( 1 )
44
+ instance_states[0].transitions[0].should_not be_auto
44
45
 
45
- instance_states[1].name.should eql( 'pending' )
46
- instance_states[1].transitions.size.should eql( 1 )
47
- instance_states[1].transitions[0].should be_auto
46
+ instance_states[1].name.should eql( 'pending' )
47
+ instance_states[1].transitions.size.should eql( 1 )
48
+ instance_states[1].transitions[0].should be_auto
48
49
 
49
- instance_states[2].name.should eql( 'running' )
50
- instance_states[2].transitions.size.should eql( 2 )
51
- includes_transition( instance_states[2].transitions, :reboot, :running ).should be_true
52
- includes_transition( instance_states[2].transitions, :stop, :stopped ).should be_true
50
+ instance_states[2].name.should eql( 'running' )
51
+ instance_states[2].transitions.size.should eql( 2 )
52
+ includes_transition( instance_states[2].transitions, :reboot, :running ).should be_true
53
+ includes_transition( instance_states[2].transitions, :stop, :stopped ).should be_true
54
+ end
53
55
  end
54
56
  end
55
57
 
@@ -24,26 +24,28 @@ describe "instances" do
24
24
  it_should_behave_like "all resources"
25
25
 
26
26
  it "should allow retrieval of all instances" do
27
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
28
- instances = client.instances
29
- instances.should_not be_empty
30
- instances.each do |instance|
31
- instance.uri.should_not be_nil
32
- instance.uri.should be_a( String )
33
- instance.owner_id.should_not be_nil
34
- instance.owner_id.should be_a( String )
35
- instance.image.should_not be_nil
36
- instance.image.should be_a( DeltaCloud::API::Image )
37
- instance.hardware_profile.should_not be_nil
38
- instance.hardware_profile.should be_a( DeltaCloud::API::HardwareProfile )
39
- instance.state.should_not be_nil
40
- instance.state.should be_a( String )
41
- instance.public_addresses.should_not be_nil
42
- instance.public_addresses.should_not be_empty
43
- instance.public_addresses.should be_a( Array )
44
- instance.private_addresses.should_not be_nil
45
- instance.private_addresses.should_not be_empty
46
- instance.private_addresses.should be_a( Array )
27
+ [API_URL, API_URL_REDIRECT].each do |entry_point|
28
+ DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client|
29
+ instances = client.instances
30
+ instances.should_not be_empty
31
+ instances.each do |instance|
32
+ instance.uri.should_not be_nil
33
+ instance.uri.should be_a( String )
34
+ instance.owner_id.should_not be_nil
35
+ instance.owner_id.should be_a( String )
36
+ instance.image.should_not be_nil
37
+ instance.image.should be_a( DeltaCloud::API::Image )
38
+ instance.hardware_profile.should_not be_nil
39
+ instance.hardware_profile.should be_a( DeltaCloud::API::HardwareProfile )
40
+ instance.state.should_not be_nil
41
+ instance.state.should be_a( String )
42
+ instance.public_addresses.should_not be_nil
43
+ instance.public_addresses.should_not be_empty
44
+ instance.public_addresses.should be_a( Array )
45
+ instance.private_addresses.should_not be_nil
46
+ instance.private_addresses.should_not be_empty
47
+ instance.private_addresses.should be_a( Array )
48
+ end
47
49
  end
48
50
  end
49
51
  end
@@ -184,7 +186,8 @@ describe "instances" do
184
186
  instance = client.instance( 'inst1' )
185
187
  instance.should_not be_nil
186
188
  instance.state.should eql( "RUNNING" )
187
- lambda{instance.start}.should raise_error
189
+ instance.start!
190
+ instance.state.should eql( "RUNNING" )
188
191
  end
189
192
  end
190
193
  end
data/specs/realms_spec.rb CHANGED
@@ -23,16 +23,18 @@ describe "realms" do
23
23
  it_should_behave_like "all resources"
24
24
 
25
25
  it "should allow retrieval of all realms" do
26
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
27
- realms = client.realms
28
- realms.should_not be_empty
29
- realms.each do |realm|
30
- realm.uri.should_not be_nil
31
- realm.uri.should be_a(String)
32
- realm.id.should_not be_nil
33
- realm.id.should be_a(String)
34
- realm.name.should_not be_nil
35
- realm.name.should be_a(String)
26
+ [API_URL, API_URL_REDIRECT].each do |entry_point|
27
+ DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client|
28
+ realms = client.realms
29
+ realms.should_not be_empty
30
+ realms.each do |realm|
31
+ realm.uri.should_not be_nil
32
+ realm.uri.should be_a(String)
33
+ realm.id.should_not be_nil
34
+ realm.id.should be_a(String)
35
+ realm.name.should_not be_nil
36
+ realm.name.should be_a(String)
37
+ end
36
38
  end
37
39
  end
38
40
  end
data/specs/spec_helper.rb CHANGED
@@ -33,6 +33,7 @@ API_PORT = api_port
33
33
  API_PATH = '/api'
34
34
 
35
35
  API_URL = "http://#{API_HOST}:#{API_PORT}#{API_PATH}"
36
+ API_URL_REDIRECT = "http://#{API_HOST}:#{API_PORT}"
36
37
  API_NAME = 'mockuser'
37
38
  API_PASSWORD = 'mockpassword'
38
39
 
@@ -24,15 +24,17 @@ describe "storage snapshot" do
24
24
  it_should_behave_like "all resources"
25
25
 
26
26
  it "allow retrieval of all storage volumes owned by the current user" do
27
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
28
- client.connect do |client|
29
- storage_snapshots = client.storage_snapshots
30
- storage_snapshots.should_not be_nil
31
- storage_snapshots.should_not be_empty
32
- ids = storage_snapshots.collect{|e| e.id}
33
- ids.size.should eql( 2 )
34
- ids.should include( 'snap2' )
35
- ids.should include( 'snap3' )
27
+ [API_URL, API_URL_REDIRECT].each do |entry_point|
28
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, entry_point )
29
+ client.connect do |client|
30
+ storage_snapshots = client.storage_snapshots
31
+ storage_snapshots.should_not be_nil
32
+ storage_snapshots.should_not be_empty
33
+ ids = storage_snapshots.collect{|e| e.id}
34
+ ids.size.should eql( 2 )
35
+ ids.should include( 'snap2' )
36
+ ids.should include( 'snap3' )
37
+ end
36
38
  end
37
39
  end
38
40
 
@@ -24,15 +24,17 @@ describe "storage volumes" do
24
24
  it_should_behave_like "all resources"
25
25
 
26
26
  it "allow retrieval of all storage volumes owned by the current user" do
27
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
28
- client.connect do |client|
29
- storage_volumes = client.storage_volumes
30
- storage_volumes.should_not be_nil
31
- storage_volumes.should_not be_empty
32
- ids = storage_volumes.collect{|e| e.id}
33
- ids.size.should eql( 2 )
34
- ids.should include( 'vol2' )
35
- ids.should include( 'vol3' )
27
+ [API_URL, API_URL_REDIRECT].each do |entry_point|
28
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, entry_point )
29
+ client.connect do |client|
30
+ storage_volumes = client.storage_volumes
31
+ storage_volumes.should_not be_nil
32
+ storage_volumes.should_not be_empty
33
+ ids = storage_volumes.collect{|e| e.id}
34
+ ids.size.should eql( 2 )
35
+ ids.should include( 'vol2' )
36
+ ids.should include( 'vol3' )
37
+ end
36
38
  end
37
39
  end
38
40
 
metadata CHANGED
@@ -6,9 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 0
8
8
  - 9
9
- - 7
10
- - 2
11
- version: 0.0.9.7.2
9
+ - 8
10
+ version: 0.0.9.8
12
11
  platform: ruby
13
12
  authors:
14
13
  - Red Hat, Inc.
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-10-09 00:00:00 -04:00
18
+ date: 2010-10-21 00:00:00 -04:00
20
19
  default_executable: deltacloudc
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency