deltacloud-client 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -3
- data/lib/base_object.rb +27 -0
- data/lib/deltacloud.rb +21 -8
- data/lib/string.rb +9 -0
- data/specs/content_spec.rb +0 -22
- data/specs/instances_spec.rb +3 -3
- data/specs/storage_snapshot_spec.rb +1 -1
- data/specs/storage_volume_spec.rb +1 -1
- metadata +48 -72
- data/specs/data/images/img1.yml +0 -4
- data/specs/data/images/img2.yml +0 -4
- data/specs/data/images/img3.yml +0 -4
- data/specs/data/instances/inst0.yml +0 -16
- data/specs/data/instances/inst1.yml +0 -9
- data/specs/data/instances/inst2.yml +0 -9
- data/specs/data/storage_snapshots/snap1.yml +0 -4
- data/specs/data/storage_snapshots/snap2.yml +0 -4
- data/specs/data/storage_snapshots/snap3.yml +0 -4
- data/specs/data/storage_volumes/vol1.yml +0 -7
- data/specs/data/storage_volumes/vol2.yml +0 -7
- data/specs/data/storage_volumes/vol3.yml +0 -7
data/Rakefile
CHANGED
@@ -41,10 +41,11 @@ rescue
|
|
41
41
|
end
|
42
42
|
|
43
43
|
if available?('rspec')
|
44
|
-
require '
|
44
|
+
require 'rspec/core/rake_task'
|
45
45
|
desc "Run all examples"
|
46
|
-
|
47
|
-
t.
|
46
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
47
|
+
t.pattern = FileList['specs/**/*_spec.rb']
|
48
|
+
t.rspec_opts = [ "--format", "nested", "--color"]
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
data/lib/base_object.rb
CHANGED
@@ -90,6 +90,18 @@ module DeltaCloud
|
|
90
90
|
:values => value
|
91
91
|
}
|
92
92
|
end
|
93
|
+
|
94
|
+
def add_provider!(provider_id, entrypoints)
|
95
|
+
@providers ||= []
|
96
|
+
@providers << {
|
97
|
+
provider_id.intern => entrypoints.map { |e| { :kind => e[:kind], :url => e.text } }
|
98
|
+
}
|
99
|
+
@objects << {
|
100
|
+
:type => :collection,
|
101
|
+
:method_name => 'providers',
|
102
|
+
:values => @providers
|
103
|
+
}
|
104
|
+
end
|
93
105
|
|
94
106
|
|
95
107
|
# This method define collection of text elements inside REST model
|
@@ -135,6 +147,12 @@ module DeltaCloud
|
|
135
147
|
# First of all search throught array for method name
|
136
148
|
m = search_for_method(method_name)
|
137
149
|
if m.nil?
|
150
|
+
if method_name == :"valid_provider?"
|
151
|
+
return providers.any? { |p| p.keys.include? args.first.to_sym }
|
152
|
+
end
|
153
|
+
if method_name == :"valid_provider_url?"
|
154
|
+
return providers.map { |p| !p.find { |k, v| v.find { |u| u[:url] == args.first } }.nil? }
|
155
|
+
end
|
138
156
|
super
|
139
157
|
else
|
140
158
|
# Call appropriate handler for method
|
@@ -221,6 +239,15 @@ module DeltaCloud
|
|
221
239
|
end
|
222
240
|
end
|
223
241
|
|
242
|
+
alias :original_method_missing :method_missing
|
243
|
+
|
244
|
+
def method_missing(name, *args)
|
245
|
+
if name.to_s =~ /^has_(\w+)\?$/
|
246
|
+
return actions.any? { |a| a[0] == $1 }
|
247
|
+
end
|
248
|
+
original_method_missing(name, args)
|
249
|
+
end
|
250
|
+
|
224
251
|
private
|
225
252
|
|
226
253
|
def do_action(m, args)
|
data/lib/deltacloud.rb
CHANGED
@@ -239,6 +239,11 @@ module DeltaCloud
|
|
239
239
|
obj.add_authentication!(attribute[:type], (attribute/'*')) && next
|
240
240
|
end
|
241
241
|
|
242
|
+
#deal with providers
|
243
|
+
if(attribute.name == 'provider')
|
244
|
+
obj.add_provider!(attribute.attributes['id'].value, (attribute/'entrypoint')) && next
|
245
|
+
end
|
246
|
+
|
242
247
|
# Deal with collections like public-addresses, private-addresses
|
243
248
|
if (attribute/'./*').length > 0
|
244
249
|
obj.add_collection!(attribute.name, (attribute/'*').collect { |value| value.text }) && next
|
@@ -280,7 +285,10 @@ module DeltaCloud
|
|
280
285
|
# Generate create_* methods dynamically
|
281
286
|
#
|
282
287
|
def method_missing(name, *args)
|
283
|
-
if name.to_s =~
|
288
|
+
if name.to_s =~ /^([\w_]+)_ids$/
|
289
|
+
return self.send(:"#{$1.pluralize}").map { |o| o.id }
|
290
|
+
end
|
291
|
+
if name.to_s =~ /^create_(\w+)/
|
284
292
|
params = args[0] if args[0] and args[0].class.eql?(Hash)
|
285
293
|
params ||= args[1] if args[1] and args[1].class.eql?(Hash)
|
286
294
|
params ||= {}
|
@@ -359,7 +367,7 @@ module DeltaCloud
|
|
359
367
|
if conf[:method].eql?(:post)
|
360
368
|
resource = RestClient::Resource.new(conf[:path], :open_timeout => conf[:open_timeout], :timeout => conf[:timeout])
|
361
369
|
resource.send(:post, conf[:form_data], default_headers.merge(extended_headers)) do |response, request, block|
|
362
|
-
handle_backend_error(response) if response.code
|
370
|
+
handle_backend_error(response) if [500, 502, 501, 401].include? response.code
|
363
371
|
if response.respond_to?('body')
|
364
372
|
yield response.body if block_given?
|
365
373
|
else
|
@@ -369,7 +377,7 @@ module DeltaCloud
|
|
369
377
|
else
|
370
378
|
resource = RestClient::Resource.new(conf[:path], :open_timeout => conf[:open_timeout], :timeout => conf[:timeout])
|
371
379
|
resource.send(conf[:method], default_headers.merge(extended_headers)) do |response, request, block|
|
372
|
-
handle_backend_error(response) if response.code
|
380
|
+
handle_backend_error(response) if [500, 502, 501, 401].include? response.code
|
373
381
|
if conf[:method].eql?(:get) and [301, 302, 307].include? response.code
|
374
382
|
response.follow_redirection(request) do |response, request, block|
|
375
383
|
if response.respond_to?('body')
|
@@ -392,16 +400,21 @@ module DeltaCloud
|
|
392
400
|
# Re-raise backend errors as on exception in client with message from
|
393
401
|
# backend
|
394
402
|
class BackendError < StandardError
|
403
|
+
|
395
404
|
def initialize(opts={})
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
@message
|
405
|
+
opts[:message] = "Not authorized / Invalid credentials" if opts[:code] == 401
|
406
|
+
super("#{opts[:code]} : #{opts[:message]}")
|
407
|
+
set_backtrace(opts[:backtrace].split("\n").map { |l| l.strip }[0..10]) if opts[:backtrace]
|
400
408
|
end
|
409
|
+
|
401
410
|
end
|
402
411
|
|
403
412
|
def handle_backend_error(response)
|
404
|
-
|
413
|
+
response_xml = Nokogiri::XML(response)
|
414
|
+
backtrace = (response_xml/'error/backtrace').empty? ? nil : (response_xml/'error/backtrace').text
|
415
|
+
raise BackendError.new(:message => (response_xml/'error/message').text,
|
416
|
+
:code => response.code,
|
417
|
+
:backtrace => backtrace)
|
405
418
|
end
|
406
419
|
|
407
420
|
# Check if specified collection have wanted feature
|
data/lib/string.rb
CHANGED
@@ -36,6 +36,15 @@ class String
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
unless method_defined?(:pluralize)
|
40
|
+
def pluralize
|
41
|
+
return self + 'es' if self =~ /ess$/
|
42
|
+
return self[0, self.length-1] + "ies" if self =~ /ty$/
|
43
|
+
return self if self =~ /data$/
|
44
|
+
self + "s"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
39
48
|
# Convert string to float if string value seems like Float
|
40
49
|
def convert
|
41
50
|
return self.to_f if self.strip =~ /^([\d\.]+$)/
|
data/specs/content_spec.rb
CHANGED
@@ -119,28 +119,6 @@ describe "return HTML in different browsers" do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
it "Chrome" do
|
123
|
-
header_hash = {
|
124
|
-
'Accept' => "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
|
125
|
-
'User-agent' => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.790.0 Safari/535.1"
|
126
|
-
}
|
127
|
-
client.get(header_hash) do |response, request, &block|
|
128
|
-
response.code.should == 200
|
129
|
-
response.headers[:content_type].should =~ /^text\/html/
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
it "Safari" do
|
134
|
-
header_hash = {
|
135
|
-
'Accept' => "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
|
136
|
-
'User-agent' => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
|
137
|
-
}
|
138
|
-
client.get(header_hash) do |response, request, &block|
|
139
|
-
response.code.should == 200
|
140
|
-
response.headers[:content_type].should =~ /^text\/html/
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
122
|
it "Opera" do
|
145
123
|
header_hash = {
|
146
124
|
'Accept' => "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1",
|
data/specs/instances_spec.rb
CHANGED
@@ -78,8 +78,8 @@ describe "instances" do
|
|
78
78
|
instance.hardware_profile.should_not be_nil
|
79
79
|
instance.hardware_profile.should_not be_nil
|
80
80
|
instance.hardware_profile.uri.should eql( API_URL + "/hardware_profiles/m1-large" )
|
81
|
-
instance.hardware_profile.memory.value.should eql(10240
|
82
|
-
instance.hardware_profile.storage.value.should eql(850
|
81
|
+
instance.hardware_profile.memory.value.should eql('10240')
|
82
|
+
instance.hardware_profile.storage.value.should eql('850')
|
83
83
|
instance.state.should eql( "RUNNING" )
|
84
84
|
instance.actions.should_not be_nil
|
85
85
|
end
|
@@ -132,7 +132,7 @@ describe "instances" do
|
|
132
132
|
instance.id.should match( /inst[0-9]+/ )
|
133
133
|
instance.image.id.should eql( 'img1' )
|
134
134
|
instance.hardware_profile.id.should eql( 'm1-xlarge' )
|
135
|
-
instance.hardware_profile.memory.value.should eql(12288
|
135
|
+
instance.hardware_profile.memory.value.should eql('12288')
|
136
136
|
instance.realm.id.should eql( 'us' )
|
137
137
|
end
|
138
138
|
end
|
@@ -31,7 +31,7 @@ describe "storage snapshot" do
|
|
31
31
|
storage_snapshots.should_not be_nil
|
32
32
|
storage_snapshots.should_not be_empty
|
33
33
|
ids = storage_snapshots.collect{|e| e.id}
|
34
|
-
ids.size.should eql(
|
34
|
+
ids.size.should eql( 3 )
|
35
35
|
ids.should include( 'snap2' )
|
36
36
|
ids.should include( 'snap3' )
|
37
37
|
end
|
@@ -31,7 +31,7 @@ describe "storage volumes" do
|
|
31
31
|
storage_volumes.should_not be_nil
|
32
32
|
storage_volumes.should_not be_empty
|
33
33
|
ids = storage_volumes.collect{|e| e.id}
|
34
|
-
ids.size.should eql(
|
34
|
+
ids.size.should eql( 3 )
|
35
35
|
ids.should include( 'vol2' )
|
36
36
|
ids.should include( 'vol3' )
|
37
37
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deltacloud-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Red Hat, Inc.
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-31 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rest-client
|
@@ -57,12 +57,12 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
60
|
+
hash: 15
|
61
61
|
segments:
|
62
|
-
-
|
63
|
-
- 3
|
62
|
+
- 2
|
64
63
|
- 0
|
65
|
-
|
64
|
+
- 0
|
65
|
+
version: 2.0.0
|
66
66
|
type: :development
|
67
67
|
version_requirements: *id003
|
68
68
|
description: Deltacloud REST Client for API
|
@@ -78,51 +78,39 @@ extra_rdoc_files:
|
|
78
78
|
files:
|
79
79
|
- Rakefile
|
80
80
|
- lib/documentation.rb
|
81
|
-
- lib/string.rb
|
82
|
-
- lib/client_bucket_methods.rb
|
83
|
-
- lib/hwp_properties.rb
|
84
|
-
- lib/base_object.rb
|
85
81
|
- lib/instance_state.rb
|
86
82
|
- lib/deltacloud.rb
|
83
|
+
- lib/base_object.rb
|
84
|
+
- lib/string.rb
|
85
|
+
- lib/hwp_properties.rb
|
87
86
|
- lib/plain_formatter.rb
|
87
|
+
- lib/client_bucket_methods.rb
|
88
88
|
- bin/deltacloudc
|
89
|
-
- specs/
|
90
|
-
- specs/
|
91
|
-
- specs/
|
92
|
-
- specs/
|
93
|
-
- specs/
|
94
|
-
- specs/fixtures/storage_snapshots/snap3.yml
|
95
|
-
- specs/fixtures/instances/inst0.yml
|
89
|
+
- specs/keys_spec.rb
|
90
|
+
- specs/images_spec.rb
|
91
|
+
- specs/content_spec.rb
|
92
|
+
- specs/initialization_spec.rb
|
93
|
+
- specs/buckets_spec.rb
|
96
94
|
- specs/fixtures/instances/inst2.yml
|
95
|
+
- specs/fixtures/instances/inst0.yml
|
97
96
|
- specs/fixtures/instances/inst1.yml
|
98
|
-
- specs/fixtures/storage_volumes/vol3.yml
|
99
97
|
- specs/fixtures/storage_volumes/vol2.yml
|
100
98
|
- specs/fixtures/storage_volumes/vol1.yml
|
101
|
-
- specs/
|
99
|
+
- specs/fixtures/storage_volumes/vol3.yml
|
100
|
+
- specs/fixtures/storage_snapshots/snap1.yml
|
101
|
+
- specs/fixtures/storage_snapshots/snap3.yml
|
102
|
+
- specs/fixtures/storage_snapshots/snap2.yml
|
103
|
+
- specs/fixtures/images/img1.yml
|
104
|
+
- specs/fixtures/images/img3.yml
|
105
|
+
- specs/fixtures/images/img2.yml
|
102
106
|
- specs/realms_spec.rb
|
103
|
-
- specs/
|
104
|
-
- specs/data/images/img1.yml
|
105
|
-
- specs/data/images/img2.yml
|
106
|
-
- specs/data/storage_snapshots/snap2.yml
|
107
|
-
- specs/data/storage_snapshots/snap1.yml
|
108
|
-
- specs/data/storage_snapshots/snap3.yml
|
109
|
-
- specs/data/instances/inst0.yml
|
110
|
-
- specs/data/instances/inst2.yml
|
111
|
-
- specs/data/instances/inst1.yml
|
112
|
-
- specs/data/storage_volumes/vol3.yml
|
113
|
-
- specs/data/storage_volumes/vol2.yml
|
114
|
-
- specs/data/storage_volumes/vol1.yml
|
115
|
-
- specs/initialization_spec.rb
|
116
|
-
- specs/keys_spec.rb
|
117
|
-
- specs/hardware_profiles_spec.rb
|
118
|
-
- specs/storage_snapshot_spec.rb
|
107
|
+
- specs/spec_helper.rb
|
119
108
|
- specs/instances_spec.rb
|
120
|
-
- specs/
|
109
|
+
- specs/shared/resources.rb
|
110
|
+
- specs/hardware_profiles_spec.rb
|
121
111
|
- specs/instance_states_spec.rb
|
122
|
-
- specs/content_spec.rb
|
123
112
|
- specs/storage_volume_spec.rb
|
124
|
-
- specs/
|
125
|
-
- specs/images_spec.rb
|
113
|
+
- specs/storage_snapshot_spec.rb
|
126
114
|
- LICENSE
|
127
115
|
- NOTICE
|
128
116
|
- DISCLAIMER
|
@@ -155,45 +143,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
143
|
requirements: []
|
156
144
|
|
157
145
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.
|
146
|
+
rubygems_version: 1.8.11
|
159
147
|
signing_key:
|
160
148
|
specification_version: 3
|
161
149
|
summary: Deltacloud REST Client
|
162
150
|
test_files:
|
163
|
-
- specs/
|
164
|
-
- specs/
|
165
|
-
- specs/
|
166
|
-
- specs/
|
167
|
-
- specs/
|
168
|
-
- specs/fixtures/storage_snapshots/snap3.yml
|
169
|
-
- specs/fixtures/instances/inst0.yml
|
151
|
+
- specs/keys_spec.rb
|
152
|
+
- specs/images_spec.rb
|
153
|
+
- specs/content_spec.rb
|
154
|
+
- specs/initialization_spec.rb
|
155
|
+
- specs/buckets_spec.rb
|
170
156
|
- specs/fixtures/instances/inst2.yml
|
157
|
+
- specs/fixtures/instances/inst0.yml
|
171
158
|
- specs/fixtures/instances/inst1.yml
|
172
|
-
- specs/fixtures/storage_volumes/vol3.yml
|
173
159
|
- specs/fixtures/storage_volumes/vol2.yml
|
174
160
|
- specs/fixtures/storage_volumes/vol1.yml
|
175
|
-
- specs/
|
161
|
+
- specs/fixtures/storage_volumes/vol3.yml
|
162
|
+
- specs/fixtures/storage_snapshots/snap1.yml
|
163
|
+
- specs/fixtures/storage_snapshots/snap3.yml
|
164
|
+
- specs/fixtures/storage_snapshots/snap2.yml
|
165
|
+
- specs/fixtures/images/img1.yml
|
166
|
+
- specs/fixtures/images/img3.yml
|
167
|
+
- specs/fixtures/images/img2.yml
|
176
168
|
- specs/realms_spec.rb
|
177
|
-
- specs/
|
178
|
-
- specs/data/images/img1.yml
|
179
|
-
- specs/data/images/img2.yml
|
180
|
-
- specs/data/storage_snapshots/snap2.yml
|
181
|
-
- specs/data/storage_snapshots/snap1.yml
|
182
|
-
- specs/data/storage_snapshots/snap3.yml
|
183
|
-
- specs/data/instances/inst0.yml
|
184
|
-
- specs/data/instances/inst2.yml
|
185
|
-
- specs/data/instances/inst1.yml
|
186
|
-
- specs/data/storage_volumes/vol3.yml
|
187
|
-
- specs/data/storage_volumes/vol2.yml
|
188
|
-
- specs/data/storage_volumes/vol1.yml
|
189
|
-
- specs/initialization_spec.rb
|
190
|
-
- specs/keys_spec.rb
|
191
|
-
- specs/hardware_profiles_spec.rb
|
192
|
-
- specs/storage_snapshot_spec.rb
|
169
|
+
- specs/spec_helper.rb
|
193
170
|
- specs/instances_spec.rb
|
194
|
-
- specs/
|
171
|
+
- specs/shared/resources.rb
|
172
|
+
- specs/hardware_profiles_spec.rb
|
195
173
|
- specs/instance_states_spec.rb
|
196
|
-
- specs/content_spec.rb
|
197
174
|
- specs/storage_volume_spec.rb
|
198
|
-
- specs/
|
199
|
-
- specs/images_spec.rb
|
175
|
+
- specs/storage_snapshot_spec.rb
|
data/specs/data/images/img1.yml
DELETED
data/specs/data/images/img2.yml
DELETED
data/specs/data/images/img3.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
---
|
2
|
-
:realm_id: us
|
3
|
-
:public_addresses:
|
4
|
-
- img1.inst0.public.com
|
5
|
-
:state: RUNNING
|
6
|
-
:name: "Mock Instance With Profile Change"
|
7
|
-
:private_addresses:
|
8
|
-
- img1.inst0.private.com
|
9
|
-
:image_id: img1
|
10
|
-
:instance_profile: !ruby/object:InstanceProfile
|
11
|
-
id: m1-large
|
12
|
-
memory: "12288"
|
13
|
-
:owner_id: mockuser
|
14
|
-
:actions:
|
15
|
-
- :reboot
|
16
|
-
- :stop
|