deltacloud-client 0.3.1 → 0.4.0
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/NOTICE +1 -1
- data/Rakefile +11 -3
- data/bin/deltacloudc +3 -4
- data/lib/base_object.rb +33 -7
- data/lib/client_bucket_methods.rb +17 -2
- data/lib/deltacloud.rb +10 -5
- data/lib/documentation.rb +0 -3
- data/lib/hwp_properties.rb +0 -3
- data/lib/instance_state.rb +0 -2
- data/lib/plain_formatter.rb +3 -5
- data/lib/string.rb +0 -3
- data/specs/buckets_spec.rb +147 -0
- data/specs/content_spec.rb +155 -0
- data/specs/hardware_profiles_spec.rb +2 -2
- data/specs/initialization_spec.rb +2 -0
- data/specs/instances_spec.rb +8 -4
- data/specs/keys_spec.rb +97 -0
- metadata +66 -63
- data/init.rb +0 -20
data/NOTICE
CHANGED
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
# License for the specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
18
|
|
19
|
-
require '
|
19
|
+
require 'rubygems/package_task'
|
20
20
|
require 'rake/testtask'
|
21
21
|
|
22
22
|
load 'deltacloud-client.gemspec'
|
@@ -28,11 +28,19 @@ end
|
|
28
28
|
|
29
29
|
|
30
30
|
spec = Gem::Specification.load('deltacloud-client.gemspec')
|
31
|
-
|
31
|
+
Gem::PackageTask.new(spec) do |pkg|
|
32
32
|
pkg.need_tar = true
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
def available?(name)
|
36
|
+
Gem::Specification.find_by_name(name)
|
37
|
+
rescue Gem::LoadError
|
38
|
+
false
|
39
|
+
rescue
|
40
|
+
Gem.available?(name)
|
41
|
+
end
|
42
|
+
|
43
|
+
if available?('rspec')
|
36
44
|
require 'spec/rake/spectask'
|
37
45
|
desc "Run all examples"
|
38
46
|
Spec::Rake::SpecTask.new('spec') do |t|
|
data/bin/deltacloudc
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# Copyright (C) 2009 Red Hat, Inc.
|
4
|
-
#
|
5
3
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
6
4
|
# contributor license agreements. See the NOTICE file distributed with
|
7
5
|
# this work for additional information regarding copyright ownership. The
|
@@ -61,6 +59,7 @@ BANNER
|
|
61
59
|
opts.on( '-i', '--id ID', 'ID for operation') { |id| options[:id] = id }
|
62
60
|
opts.on( '-d', '--image-id ID', 'Image ID') { |id| options[:image_id] = id }
|
63
61
|
opts.on( '-b', '--bucket-id ID', 'Bucket ID') {|id| options[:bucket_id] = id }
|
62
|
+
opts.on( '-r', '--bucket-location NAME', 'Bucket location') {|name| options[:bucket_location] = name }
|
64
63
|
opts.on( '-a', '--arch ARCH', 'Architecture (x86, x86_64)') { |id| options[:architecture] = id }
|
65
64
|
opts.on( '-p', '--hardware-profile HARDWARE_PROFILE', 'Hardware Profile') { |id| options[:hwp_id] = id }
|
66
65
|
opts.on( '-n', '--name NAME', 'Name (for instance eg.)') { |name| options[:name] = name }
|
@@ -179,7 +178,7 @@ if options[:collection] and options[:operation]
|
|
179
178
|
params.merge!('metadata'=>options[:blob_metadata]) unless options[:blob_metadata].nil?
|
180
179
|
case options[:operation]
|
181
180
|
when 'show' then puts format(client.send( options[:collection], params))
|
182
|
-
when 'data' then puts
|
181
|
+
when 'data' then puts client.blob_data(params)
|
183
182
|
when 'create' then
|
184
183
|
invalid_usage("Specify the location of the new blob data (full local path) using -f option") unless options[:file_path]
|
185
184
|
params.merge!('file_path'=>options[:file_path])
|
@@ -217,7 +216,7 @@ if options[:collection] and options[:operation]
|
|
217
216
|
if options[:collection].eql?('buckets')
|
218
217
|
if options[:operation].eql?('create')
|
219
218
|
invalid_usage("Please specify an id for the new bucket with -i") unless options[:id]
|
220
|
-
bucket = client.create_bucket('id'=>options[:id])
|
219
|
+
bucket = client.create_bucket('id'=>options[:id], 'bucket_location'=>options[:bucket_location])
|
221
220
|
puts format(bucket)
|
222
221
|
elsif options[:operation].eql?('destroy')
|
223
222
|
invalid_usage("Please specify the bucket you wish to destroy with -i") unless options[:id]
|
data/lib/base_object.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2010 Red Hat, Inc.
|
3
|
-
#
|
4
1
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
5
2
|
# contributor license agreements. See the NOTICE file distributed with
|
6
3
|
# this work for additional information regarding copyright ownership. The
|
@@ -79,6 +76,35 @@ module DeltaCloud
|
|
79
76
|
}
|
80
77
|
end
|
81
78
|
|
79
|
+
def add_authentication!(auth_type, values=[])
|
80
|
+
value = { :key => (values/'login/keyname').text.strip } if auth_type == 'key'
|
81
|
+
if auth_type == 'password'
|
82
|
+
value = {
|
83
|
+
:username => (values/'login/username').text.strip,
|
84
|
+
:username => (values/'login/password').text.strip
|
85
|
+
}
|
86
|
+
end
|
87
|
+
@objects << {
|
88
|
+
:type => :collection,
|
89
|
+
:method_name => 'authentication',
|
90
|
+
:values => value
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# This method define collection of text elements inside REST model
|
96
|
+
# XML syntax: <addresses>
|
97
|
+
# <address>127.0.0.1</address>
|
98
|
+
# <address>127.0.0.2</address>
|
99
|
+
# </addresses>
|
100
|
+
def add_addresses!(collection_name, values=[])
|
101
|
+
@objects << {
|
102
|
+
:type => :collection,
|
103
|
+
:method_name => collection_name.sanitize,
|
104
|
+
:values => values.collect { |v| { :address => v.text.strip, :type => v[:type] }}
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
82
108
|
# This method define collection of text elements inside REST model
|
83
109
|
# XML syntax: <addresses>
|
84
110
|
# <address>127.0.0.1</address>
|
@@ -149,7 +175,7 @@ module DeltaCloud
|
|
149
175
|
@actions = []
|
150
176
|
end
|
151
177
|
|
152
|
-
# This trigger is called right after action.
|
178
|
+
# This trigger is called right after action.
|
153
179
|
# This method does nothing inside ActionObject
|
154
180
|
# but it can be redifined and used in meta-programming
|
155
181
|
def action_trigger(action)
|
@@ -314,14 +340,14 @@ module DeltaCloud
|
|
314
340
|
DeltaCloud::API.class_eval("class #{class_name} < DeltaCloud::#{parent_class}; end")
|
315
341
|
@defined_classes << class_name
|
316
342
|
end
|
317
|
-
|
343
|
+
|
318
344
|
DeltaCloud::API.const_get(parent.classify).const_get(name.classify)
|
319
345
|
end
|
320
346
|
|
321
347
|
def self.guess_model_type(response)
|
322
348
|
response = Nokogiri::XML(response.to_s)
|
323
|
-
return :action if ((response/'//actions').length
|
324
|
-
return :stateful if ((response/'//actions').length
|
349
|
+
return :action if ((response/'//actions').length >= 1) and ((response/'//state').length == 0)
|
350
|
+
return :stateful if ((response/'//actions').length >= 1) and ((response/'//state').length >= 1)
|
325
351
|
return :base
|
326
352
|
end
|
327
353
|
|
@@ -1,8 +1,23 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
1
16
|
module ClientBucketMethods
|
2
17
|
|
3
18
|
def create_bucket(params)
|
4
19
|
obj = nil
|
5
|
-
request(:post, "#{api_uri.to_s}/buckets", {:name => params['id'] }) do |response|
|
20
|
+
request(:post, "#{api_uri.to_s}/buckets", {:name => params['id'],:location=>params['bucket_location'] }) do |response|
|
6
21
|
handle_backend_error(response) if response.code!=201
|
7
22
|
obj = base_object(:bucket, response)
|
8
23
|
end
|
@@ -51,4 +66,4 @@ module ClientBucketMethods
|
|
51
66
|
end
|
52
67
|
end
|
53
68
|
|
54
|
-
end
|
69
|
+
end
|
data/lib/deltacloud.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
-
#
|
4
1
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
5
2
|
# contributor license agreements. See the NOTICE file distributed with
|
6
3
|
# this work for additional information regarding copyright ownership. The
|
@@ -213,7 +210,7 @@ module DeltaCloud
|
|
213
210
|
# If there are actions, add they to ActionObject/StateFullObject
|
214
211
|
if attribute.name == 'actions'
|
215
212
|
(attribute/'link').each do |link|
|
216
|
-
(obj.add_run_action!(item['id'], link) && next) if link[:rel] == 'run'
|
213
|
+
(obj.add_run_action!(item['id'], link) && next) if link[:rel] == 'run'
|
217
214
|
obj.add_action_link!(item['id'], link)
|
218
215
|
end && next
|
219
216
|
end
|
@@ -225,7 +222,7 @@ module DeltaCloud
|
|
225
222
|
end
|
226
223
|
|
227
224
|
#deal with blob metadata
|
228
|
-
if(attribute.name == 'user_metadata')
|
225
|
+
if (attribute.name == 'user_metadata')
|
229
226
|
meta = {}
|
230
227
|
attribute.children.select {|x| x.name=="entry" }.each do |element|
|
231
228
|
value = element.content.gsub!(/(\n) +/,'')
|
@@ -234,6 +231,14 @@ module DeltaCloud
|
|
234
231
|
obj.add_collection!(attribute.name, meta.inspect) && next
|
235
232
|
end
|
236
233
|
|
234
|
+
if (['public_addresses', 'private_addresses'].include? attribute.name)
|
235
|
+
obj.add_addresses!(attribute.name, (attribute/'*')) && next
|
236
|
+
end
|
237
|
+
|
238
|
+
if ('authentication'.include? attribute.name)
|
239
|
+
obj.add_authentication!(attribute[:type], (attribute/'*')) && next
|
240
|
+
end
|
241
|
+
|
237
242
|
# Deal with collections like public-addresses, private-addresses
|
238
243
|
if (attribute/'./*').length > 0
|
239
244
|
obj.add_collection!(attribute.name, (attribute/'*').collect { |value| value.text }) && next
|
data/lib/documentation.rb
CHANGED
data/lib/hwp_properties.rb
CHANGED
data/lib/instance_state.rb
CHANGED
data/lib/plain_formatter.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# Copyright (C) 2009, 2010 Red Hat, Inc.
|
2
|
-
#
|
3
1
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
4
2
|
# contributor license agreements. See the NOTICE file distributed with
|
5
3
|
# this work for additional information regarding copyright ownership. The
|
@@ -65,8 +63,8 @@ module DeltaCloud
|
|
65
63
|
@obj.name ? @obj.name[0,15] : 'unknown',
|
66
64
|
@obj.image.name ? @obj.image.name[0,15] : 'unknown',
|
67
65
|
@obj.state ? @obj.state.to_s[0,10] : 'unknown',
|
68
|
-
@obj.public_addresses.join(',')[0,32],
|
69
|
-
@obj.private_addresses.join(',')[0,32]
|
66
|
+
@obj.public_addresses.collect { |a| a[:address] }.join(',')[0,32],
|
67
|
+
@obj.private_addresses.collect { |a| a[:address] }.join(',')[0,32]
|
70
68
|
)
|
71
69
|
end
|
72
70
|
end
|
@@ -100,7 +98,7 @@ module DeltaCloud
|
|
100
98
|
@obj.id,
|
101
99
|
@obj.name,
|
102
100
|
@obj.size ? @obj.size : "0",
|
103
|
-
@obj.blob_list ? @obj.blob_list : ""
|
101
|
+
@obj.instance_variables.include?("@blob_list") ? @obj.blob_list : ""
|
104
102
|
)
|
105
103
|
end
|
106
104
|
end
|
data/lib/string.rb
CHANGED
@@ -0,0 +1,147 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2009-2011 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
9
|
+
# License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
16
|
+
# License for the specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
|
19
|
+
require 'specs/spec_helper'
|
20
|
+
|
21
|
+
describe "buckets" do
|
22
|
+
|
23
|
+
it_should_behave_like "all resources"
|
24
|
+
|
25
|
+
it "should allow retrieval of all buckets" do
|
26
|
+
[API_URL, API_URL_REDIRECT].each do |entry_point|
|
27
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client|
|
28
|
+
buckets = client.buckets
|
29
|
+
buckets.should_not be_empty
|
30
|
+
buckets.each do |bucket|
|
31
|
+
bucket.uri.should_not be_nil
|
32
|
+
bucket.uri.should be_a( String )
|
33
|
+
bucket.name.should_not be_nil
|
34
|
+
bucket.name.should be_a(String)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should allow retrieval of a named bucket" do
|
41
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
42
|
+
bucket = client.bucket("bucket1")
|
43
|
+
bucket.should_not be_nil
|
44
|
+
bucket.uri.should eql(API_URL + "/buckets/bucket1")
|
45
|
+
bucket.size.should eql(3.0)
|
46
|
+
bucket.name.should_not be_nil
|
47
|
+
bucket.name.should be_a(String)
|
48
|
+
blob_list = bucket.blob_list.split(", ")
|
49
|
+
blob_list.size.should eql(bucket.size.to_i)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "Operations on buckets" do
|
56
|
+
|
57
|
+
it "should allow creation of a new bucket" do
|
58
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
59
|
+
new_bucket = client.create_bucket({'id' => "my_new_bucket"})
|
60
|
+
new_bucket.should_not be_nil
|
61
|
+
new_bucket.uri.should eql(API_URL + "/buckets/my_new_bucket")
|
62
|
+
new_bucket.name.should_not be_nil
|
63
|
+
new_bucket.name.should be_a(String)
|
64
|
+
new_bucket.name.should eql("my_new_bucket")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should allow deletion of an existing bucket" do
|
69
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
70
|
+
new_bucket = client.bucket("my_new_bucket")
|
71
|
+
new_bucket.should_not be_nil
|
72
|
+
new_bucket.name.should eql("my_new_bucket")
|
73
|
+
lambda{
|
74
|
+
client.destroy_bucket({'id' => "my_new_bucket"})
|
75
|
+
}.should_not raise_error
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should throw error if you delete a non existing bucket" do
|
80
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
81
|
+
lambda{
|
82
|
+
client.destroy_bucket({'id' => "i_dont_exist"})
|
83
|
+
}.should raise_error
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "Blobs" do
|
90
|
+
|
91
|
+
it "should allow retrieval of a bucket's blobs" do
|
92
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
93
|
+
bucket = client.bucket("bucket1")
|
94
|
+
bucket.should_not be_nil
|
95
|
+
blob_list = bucket.blob_list.split(", ")
|
96
|
+
blob_list.size.should eql(bucket.size.to_i)
|
97
|
+
blob_list.each do |b_id|
|
98
|
+
blob = client.blob({"bucket" => bucket.name, :id => b_id})
|
99
|
+
blob.bucket.should_not be_nil
|
100
|
+
blob.bucket.should be_a(String)
|
101
|
+
blob.bucket.should eql(bucket.name)
|
102
|
+
blob.content_length.should_not be_nil
|
103
|
+
blob.content_length.should be_a(Float)
|
104
|
+
blob.content_length.should >= 0
|
105
|
+
blob_data = client.blob_data({"bucket" => bucket.name, :id => b_id})
|
106
|
+
blob_data.size.to_f.should == blob.content_length
|
107
|
+
blob.last_modified.should_not be_nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "Operations on blobs" do
|
115
|
+
|
116
|
+
it "should successfully create a new blob" do
|
117
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
118
|
+
blob_data = File.new("./blob_data_file", "w+")
|
119
|
+
|
120
|
+
blob_data.write("this is some blob data \n")
|
121
|
+
blob_data.rewind
|
122
|
+
some_new_blob = client.create_blob({:id => "some_new_blob",
|
123
|
+
'bucket' => "bucket1",
|
124
|
+
'file_path' => blob_data.path})
|
125
|
+
some_new_blob.should_not be_nil
|
126
|
+
some_new_blob.content_length.should_not be_nil
|
127
|
+
some_new_blob.content_length.should eql(24.0)
|
128
|
+
File.delete(blob_data.path)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should allow deletion of an existing blob" do
|
133
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
134
|
+
lambda{
|
135
|
+
client.destroy_blob({:id=>"some_new_blob", 'bucket'=>"bucket1"})
|
136
|
+
}.should_not raise_error
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should throw error if you delete a non existing blob" do
|
141
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
142
|
+
lambda{
|
143
|
+
client.destroy_blob({:id=>"no_such_blob", 'bucket'=>"bucket1"})
|
144
|
+
}.should raise_error
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2009-2011 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
9
|
+
# License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
16
|
+
# License for the specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
|
19
|
+
require 'specs/spec_helper'
|
20
|
+
|
21
|
+
def client
|
22
|
+
RestClient::Resource.new(API_URL)
|
23
|
+
end
|
24
|
+
|
25
|
+
def headers(header)
|
26
|
+
encoded_credentials = ["#{API_NAME}:#{API_PASSWORD}"].pack("m0").gsub(/\n/,'')
|
27
|
+
{ :authorization => "Basic " + encoded_credentials }.merge(header)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "return JSON" do
|
31
|
+
|
32
|
+
it 'should return JSON when using application/json, */*' do
|
33
|
+
header_hash = {
|
34
|
+
'Accept' => "application/json, */*"
|
35
|
+
}
|
36
|
+
client.get(header_hash) do |response, request, &block|
|
37
|
+
response.code.should == 200
|
38
|
+
response.headers[:content_type].should =~ /^application\/json/
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should return JSON when using just application/json' do
|
43
|
+
header_hash = {
|
44
|
+
'Accept' => "application/json"
|
45
|
+
}
|
46
|
+
client.get(header_hash) do |response, request, &block|
|
47
|
+
response.code.should == 200
|
48
|
+
response.headers[:content_type].should =~ /^application\/json/
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "return HTML in different browsers" do
|
55
|
+
|
56
|
+
it "wants XML using format parameter" do
|
57
|
+
client['?format=xml'].get('Accept' => 'application/xhtml+xml') do |response, request, &block|
|
58
|
+
response.code.should == 200
|
59
|
+
response.headers[:content_type].should =~ /^application\/xml/
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "raise 406 error on wrong accept" do
|
64
|
+
client['hardware_profiles'].get('Accept' => 'image/png;q=1') do |response, request, &block|
|
65
|
+
response.code.should == 406
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "wants HTML using format parameter and accept set to XML" do
|
70
|
+
client['?format=html'].get('Accept' => 'application/xml') do |response, request, &block|
|
71
|
+
response.code.should == 200
|
72
|
+
response.headers[:content_type].should =~ /^text\/html/
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# FIXME: This return 406 for some reason on GIT sinatra
|
77
|
+
# it "wants a PNG image" do
|
78
|
+
# client['instance_states'].get('Accept' => 'image/png') do |response, request, &block|
|
79
|
+
# response.code.should == 200
|
80
|
+
# response.headers[:content_type].should =~ /^image\/png/
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
|
84
|
+
it "doesn't have accept header" do
|
85
|
+
client.get('Accept' => '') do |response, request, &block|
|
86
|
+
response.code.should == 200
|
87
|
+
response.headers[:content_type].should =~ /^application\/xml/
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "can handle unknown formats" do
|
92
|
+
client.get('Accept' => 'format/unknown') do |response, request, &block|
|
93
|
+
response.code.should == 406
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "wants explicitly XML" do
|
98
|
+
client.get('Accept' => 'application/xml') do |response, request, &block|
|
99
|
+
response.code.should == 200
|
100
|
+
response.headers[:content_type].should =~ /^application\/xml/
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "Internet Explorer" do
|
105
|
+
header_hash = {
|
106
|
+
'Accept' => "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*",
|
107
|
+
'User-agent' => "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)"
|
108
|
+
}
|
109
|
+
client.get(header_hash) do |response, request, &block|
|
110
|
+
response.code.should == 200
|
111
|
+
response.headers[:content_type].should =~ /^text\/html/
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "Mozilla Firefox" do
|
116
|
+
client.get('Accept' => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") do |response, request, &block|
|
117
|
+
response.code.should == 200
|
118
|
+
response.headers[:content_type].should =~ /^text\/html/
|
119
|
+
end
|
120
|
+
end
|
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
|
+
it "Opera" do
|
145
|
+
header_hash = {
|
146
|
+
'Accept' => "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1",
|
147
|
+
'User-agent' => "Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11"
|
148
|
+
}
|
149
|
+
client.get(header_hash) do |response, request, &block|
|
150
|
+
response.code.should == 200
|
151
|
+
response.headers[:content_type].should =~ /^text\/html/
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
@@ -38,8 +38,8 @@ describe "hardware_profiles" do
|
|
38
38
|
hardware_profiles.each do |hwp|
|
39
39
|
hwp.uri.should_not be_nil
|
40
40
|
hwp.uri.should be_a(String)
|
41
|
-
prop_check(hwp.architecture, String)
|
42
|
-
|
41
|
+
prop_check(hwp.architecture, String) unless hwp.name.eql?("opaque")
|
42
|
+
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -35,6 +35,8 @@ describe "initializing the client" do
|
|
35
35
|
client.entry_points[:instances].should eql( "#{API_URL}/instances" )
|
36
36
|
client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage_volumes" )
|
37
37
|
client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage_snapshots" )
|
38
|
+
client.entry_points[:buckets].should eql( "#{API_URL}/buckets")
|
39
|
+
client.entry_points[:keys].should eql( "#{API_URL}/keys")
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
data/specs/instances_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe "instances" do
|
|
34
34
|
instance.owner_id.should_not be_nil
|
35
35
|
instance.owner_id.should be_a( String )
|
36
36
|
instance.image.should_not be_nil
|
37
|
-
instance.image.should
|
37
|
+
instance.image.to_s.should match(/DeltaCloud::API::.*::Image/)
|
38
38
|
instance.hardware_profile.should_not be_nil
|
39
39
|
instance.hardware_profile.should be_a( DeltaCloud::API::Base::HardwareProfile )
|
40
40
|
instance.state.should_not be_nil
|
@@ -70,7 +70,9 @@ describe "instances" do
|
|
70
70
|
instance.uri.should_not be_nil
|
71
71
|
instance.uri.should be_a( String )
|
72
72
|
instance.owner_id.should eql( "mockuser" )
|
73
|
-
instance.public_addresses.first.should eql(
|
73
|
+
instance.public_addresses.first.class.should eql(Hash)
|
74
|
+
instance.public_addresses.first[:type].should eql('hostname')
|
75
|
+
instance.public_addresses.first[:address].should eql('img1.inst0.public.com')
|
74
76
|
instance.image.should_not be_nil
|
75
77
|
instance.image.uri.should eql( API_URL + "/images/img1" )
|
76
78
|
instance.hardware_profile.should_not be_nil
|
@@ -185,9 +187,11 @@ describe "instances" do
|
|
185
187
|
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
186
188
|
instance = client.instance( 'inst1' )
|
187
189
|
instance.should_not be_nil
|
190
|
+
unless instance.state.eql?("RUNNING")
|
191
|
+
instance.start!
|
192
|
+
end
|
188
193
|
instance.state.should eql( "RUNNING" )
|
189
|
-
instance.start!
|
190
|
-
instance.state.should eql( "RUNNING" )
|
194
|
+
lambda{instance.start!}.should raise_error
|
191
195
|
end
|
192
196
|
end
|
193
197
|
|
data/specs/keys_spec.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2009-2011 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
9
|
+
# License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
16
|
+
# License for the specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
|
19
|
+
require 'specs/spec_helper'
|
20
|
+
|
21
|
+
def check_key(the_key, key_name = "")
|
22
|
+
the_key.should_not be_nil
|
23
|
+
the_key.id.should be_a(String)
|
24
|
+
the_key.id.should eql(key_name)
|
25
|
+
the_key.actions.should_not be_nil
|
26
|
+
the_key.actions.size.should eql(1)
|
27
|
+
the_key.actions.first[0].should eql("destroy")
|
28
|
+
the_key.actions.first[1].should eql("#{API_URL}/keys/#{key_name}")
|
29
|
+
the_key.fingerprint.should_not be_nil
|
30
|
+
the_key.fingerprint.should be_a(String)
|
31
|
+
the_key.pem.should_not be_nil
|
32
|
+
the_key.pem.first.should be_a(String)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_key_if_necessary(client, key_name)
|
36
|
+
the_key = client.key(key_name)
|
37
|
+
unless the_key
|
38
|
+
client.create_key()
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
describe "keys" do
|
44
|
+
|
45
|
+
it_should_behave_like "all resources"
|
46
|
+
|
47
|
+
it "should allow retrieval of all keys" do
|
48
|
+
[API_URL, API_URL_REDIRECT].each do |entry_point|
|
49
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client|
|
50
|
+
lambda{
|
51
|
+
client.keys
|
52
|
+
}.should_not raise_error
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "operations on keys" do
|
59
|
+
|
60
|
+
it "should allow successful creation of a new key" do
|
61
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
62
|
+
new_key = client.create_key({:name => "my_new_key"})
|
63
|
+
check_key(new_key, "my_new_key")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should allow retrieval of an existing named key" do
|
68
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
69
|
+
key_name = "my_new_key"
|
70
|
+
create_key_if_necessary(client, key_name)
|
71
|
+
the_key = client.key(key_name)
|
72
|
+
check_key(the_key, key_name)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should raise error if you create a key with the same name as an existing key" do
|
77
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
78
|
+
name = "my_new_key"
|
79
|
+
create_key_if_necessary(client, name)
|
80
|
+
lambda{
|
81
|
+
client.create_key({:name => name})
|
82
|
+
}.should raise_error
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should allow successful destruction of an existing key" do
|
87
|
+
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
|
88
|
+
name = "my_new_key"
|
89
|
+
create_key_if_necessary(client, name)
|
90
|
+
the_key = client.key(name)
|
91
|
+
lambda{
|
92
|
+
the_key.destroy!
|
93
|
+
}.should_not raise_error
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
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: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Red Hat, Inc.
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable: deltacloudc
|
18
|
+
date: 2011-08-23 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: rest-client
|
@@ -80,52 +79,53 @@ files:
|
|
80
79
|
- Rakefile
|
81
80
|
- lib/base_object.rb
|
82
81
|
- lib/client_bucket_methods.rb
|
83
|
-
- lib/deltacloud.rb
|
84
|
-
- lib/documentation.rb
|
85
|
-
- lib/hwp_properties.rb
|
86
82
|
- lib/instance_state.rb
|
83
|
+
- lib/deltacloud.rb
|
87
84
|
- lib/plain_formatter.rb
|
85
|
+
- lib/hwp_properties.rb
|
88
86
|
- lib/string.rb
|
89
|
-
-
|
87
|
+
- lib/documentation.rb
|
90
88
|
- bin/deltacloudc
|
91
|
-
-
|
92
|
-
-
|
93
|
-
-
|
94
|
-
- specs/
|
95
|
-
- specs/
|
96
|
-
- specs/data/
|
89
|
+
- specs/images_spec.rb
|
90
|
+
- specs/initialization_spec.rb
|
91
|
+
- specs/hardware_profiles_spec.rb
|
92
|
+
- specs/instance_states_spec.rb
|
93
|
+
- specs/instances_spec.rb
|
94
|
+
- specs/data/storage_snapshots/snap3.yml
|
95
|
+
- specs/data/storage_snapshots/snap1.yml
|
96
|
+
- specs/data/storage_snapshots/snap2.yml
|
97
97
|
- specs/data/instances/inst0.yml
|
98
98
|
- specs/data/instances/inst1.yml
|
99
99
|
- specs/data/instances/inst2.yml
|
100
|
-
- specs/data/
|
101
|
-
- specs/data/
|
102
|
-
- specs/data/
|
103
|
-
- specs/data/storage_volumes/vol1.yml
|
104
|
-
- specs/data/storage_volumes/vol2.yml
|
100
|
+
- specs/data/images/img3.yml
|
101
|
+
- specs/data/images/img2.yml
|
102
|
+
- specs/data/images/img1.yml
|
105
103
|
- specs/data/storage_volumes/vol3.yml
|
106
|
-
- specs/
|
107
|
-
- specs/
|
108
|
-
- specs/
|
104
|
+
- specs/data/storage_volumes/vol2.yml
|
105
|
+
- specs/data/storage_volumes/vol1.yml
|
106
|
+
- specs/keys_spec.rb
|
107
|
+
- specs/content_spec.rb
|
108
|
+
- specs/buckets_spec.rb
|
109
|
+
- specs/fixtures/storage_snapshots/snap3.yml
|
110
|
+
- specs/fixtures/storage_snapshots/snap1.yml
|
111
|
+
- specs/fixtures/storage_snapshots/snap2.yml
|
109
112
|
- specs/fixtures/instances/inst0.yml
|
110
113
|
- specs/fixtures/instances/inst1.yml
|
111
114
|
- specs/fixtures/instances/inst2.yml
|
112
|
-
- specs/fixtures/
|
113
|
-
- specs/fixtures/
|
114
|
-
- specs/fixtures/
|
115
|
-
- specs/fixtures/storage_volumes/vol1.yml
|
116
|
-
- specs/fixtures/storage_volumes/vol2.yml
|
115
|
+
- specs/fixtures/images/img3.yml
|
116
|
+
- specs/fixtures/images/img2.yml
|
117
|
+
- specs/fixtures/images/img1.yml
|
117
118
|
- specs/fixtures/storage_volumes/vol3.yml
|
118
|
-
- specs/
|
119
|
-
- specs/
|
120
|
-
- specs/initialization_spec.rb
|
121
|
-
- specs/instance_states_spec.rb
|
122
|
-
- specs/instances_spec.rb
|
123
|
-
- specs/realms_spec.rb
|
119
|
+
- specs/fixtures/storage_volumes/vol2.yml
|
120
|
+
- specs/fixtures/storage_volumes/vol1.yml
|
124
121
|
- specs/shared/resources.rb
|
125
|
-
- specs/spec_helper.rb
|
126
|
-
- specs/storage_snapshot_spec.rb
|
127
122
|
- specs/storage_volume_spec.rb
|
128
|
-
|
123
|
+
- specs/realms_spec.rb
|
124
|
+
- specs/storage_snapshot_spec.rb
|
125
|
+
- specs/spec_helper.rb
|
126
|
+
- LICENSE
|
127
|
+
- NOTICE
|
128
|
+
- DISCLAIMER
|
129
129
|
homepage: http://www.deltacloud.org
|
130
130
|
licenses: []
|
131
131
|
|
@@ -155,42 +155,45 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
requirements: []
|
156
156
|
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.
|
158
|
+
rubygems_version: 1.7.2
|
159
159
|
signing_key:
|
160
160
|
specification_version: 3
|
161
161
|
summary: Deltacloud REST Client
|
162
162
|
test_files:
|
163
|
-
- specs/
|
164
|
-
- specs/
|
165
|
-
- specs/
|
163
|
+
- specs/images_spec.rb
|
164
|
+
- specs/initialization_spec.rb
|
165
|
+
- specs/hardware_profiles_spec.rb
|
166
|
+
- specs/instance_states_spec.rb
|
167
|
+
- specs/instances_spec.rb
|
168
|
+
- specs/data/storage_snapshots/snap3.yml
|
169
|
+
- specs/data/storage_snapshots/snap1.yml
|
170
|
+
- specs/data/storage_snapshots/snap2.yml
|
166
171
|
- specs/data/instances/inst0.yml
|
167
172
|
- specs/data/instances/inst1.yml
|
168
173
|
- specs/data/instances/inst2.yml
|
169
|
-
- specs/data/
|
170
|
-
- specs/data/
|
171
|
-
- specs/data/
|
172
|
-
- specs/data/storage_volumes/vol1.yml
|
173
|
-
- specs/data/storage_volumes/vol2.yml
|
174
|
+
- specs/data/images/img3.yml
|
175
|
+
- specs/data/images/img2.yml
|
176
|
+
- specs/data/images/img1.yml
|
174
177
|
- specs/data/storage_volumes/vol3.yml
|
175
|
-
- specs/
|
176
|
-
- specs/
|
177
|
-
- specs/
|
178
|
+
- specs/data/storage_volumes/vol2.yml
|
179
|
+
- specs/data/storage_volumes/vol1.yml
|
180
|
+
- specs/keys_spec.rb
|
181
|
+
- specs/content_spec.rb
|
182
|
+
- specs/buckets_spec.rb
|
183
|
+
- specs/fixtures/storage_snapshots/snap3.yml
|
184
|
+
- specs/fixtures/storage_snapshots/snap1.yml
|
185
|
+
- specs/fixtures/storage_snapshots/snap2.yml
|
178
186
|
- specs/fixtures/instances/inst0.yml
|
179
187
|
- specs/fixtures/instances/inst1.yml
|
180
188
|
- specs/fixtures/instances/inst2.yml
|
181
|
-
- specs/fixtures/
|
182
|
-
- specs/fixtures/
|
183
|
-
- specs/fixtures/
|
184
|
-
- specs/fixtures/storage_volumes/vol1.yml
|
185
|
-
- specs/fixtures/storage_volumes/vol2.yml
|
189
|
+
- specs/fixtures/images/img3.yml
|
190
|
+
- specs/fixtures/images/img2.yml
|
191
|
+
- specs/fixtures/images/img1.yml
|
186
192
|
- specs/fixtures/storage_volumes/vol3.yml
|
187
|
-
- specs/
|
188
|
-
- specs/
|
189
|
-
- specs/initialization_spec.rb
|
190
|
-
- specs/instance_states_spec.rb
|
191
|
-
- specs/instances_spec.rb
|
192
|
-
- specs/realms_spec.rb
|
193
|
+
- specs/fixtures/storage_volumes/vol2.yml
|
194
|
+
- specs/fixtures/storage_volumes/vol1.yml
|
193
195
|
- specs/shared/resources.rb
|
194
|
-
- specs/spec_helper.rb
|
195
|
-
- specs/storage_snapshot_spec.rb
|
196
196
|
- specs/storage_volume_spec.rb
|
197
|
+
- specs/realms_spec.rb
|
198
|
+
- specs/storage_snapshot_spec.rb
|
199
|
+
- specs/spec_helper.rb
|
data/init.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2009 Red Hat, Inc.
|
3
|
-
#
|
4
|
-
# Licensed to the Apache Software Foundation (ASF) under one or more
|
5
|
-
# contributor license agreements. See the NOTICE file distributed with
|
6
|
-
# this work for additional information regarding copyright ownership. The
|
7
|
-
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
8
|
-
# "License"); you may not use this file except in compliance with the
|
9
|
-
# License. You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
15
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
16
|
-
# License for the specific language governing permissions and limitations
|
17
|
-
# under the License.
|
18
|
-
|
19
|
-
|
20
|
-
require 'deltacloud'
|