steamcannon-deltacloud-client 0.1.0.5 → 0.1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/deltacloud.rb CHANGED
@@ -34,8 +34,9 @@ module DeltaCloud
34
34
  # @param [String, password] API password
35
35
  # @param [String, user_name] API URL (eg. http://localhost:3001/api)
36
36
  # @return [DeltaCloud::API]
37
- def self.new(user_name, password, api_url, &block)
38
- API.new(user_name, password, api_url, &block)
37
+ def self.new(user_name, password, api_url, opts={}, &block)
38
+ opts ||= {}
39
+ API.new(user_name, password, api_url, opts, &block)
39
40
  end
40
41
 
41
42
  # Check given credentials if their are valid against
@@ -45,8 +46,8 @@ module DeltaCloud
45
46
  # @param [String, password] API password
46
47
  # @param [String, user_name] API URL (eg. http://localhost:3001/api)
47
48
  # @return [true|false]
48
- def self.valid_credentials?(user_name, password, api_url)
49
- api=API.new(user_name, password, api_url)
49
+ def self.valid_credentials?(user_name, password, api_url, opts={})
50
+ api=API.new(user_name, password, api_url, opts)
50
51
  result = false
51
52
  api.request(:get, '', :force_auth => '1') do |response|
52
53
  result = true if response.code.eql?(200)
@@ -62,11 +63,13 @@ module DeltaCloud
62
63
  end
63
64
 
64
65
  class API
65
- attr_reader :api_uri, :driver_name, :api_version, :features, :entry_points
66
+ attr_reader :api_uri, :driver_name, :api_version, :features, :entry_points
67
+ attr_reader :api_driver, :api_provider
66
68
 
67
69
  def initialize(user_name, password, api_url, opts={}, &block)
68
70
  opts[:version] = true
69
- @username, @password = user_name, password
71
+ @api_driver, @api_provider = opts[:driver], opts[:provider]
72
+ @username, @password = opts[:username] || user_name, opts[:password] || password
70
73
  @api_uri = URI.parse(api_url)
71
74
  @features, @entry_points = {}, {}
72
75
  @verbose = opts[:verbose] || false
@@ -159,7 +162,7 @@ module DeltaCloud
159
162
  end
160
163
  end
161
164
 
162
- # If there are actions, add them to ActionObject/StatefulObject
165
+ # If there are actions, add they to ActionObject/StateFullObject
163
166
  if attribute.name == 'actions'
164
167
  (attribute/'link').each do |link|
165
168
  obj.add_action_link!(item['id'], link)
@@ -241,6 +244,25 @@ module DeltaCloud
241
244
  raise NoMethodError
242
245
  end
243
246
 
247
+ def use_driver(driver, opts={})
248
+ if driver
249
+ @api_driver = driver
250
+ @driver_name = driver
251
+ discover_entry_points
252
+ end
253
+ @username = opts[:username] if opts[:username]
254
+ @password = opts[:password] if opts[:password]
255
+ @api_provider = opts[:provider] if opts[:provider]
256
+ return self
257
+ end
258
+
259
+ def extended_headers
260
+ headers = {}
261
+ headers["X-Deltacloud-Driver"] = @api_driver.to_s if @api_driver
262
+ headers["X-Deltacloud-Provider"] = @api_provider.to_s if @api_provider
263
+ headers
264
+ end
265
+
244
266
  # Basic request method
245
267
  #
246
268
  def request(*args, &block)
@@ -255,7 +277,7 @@ module DeltaCloud
255
277
  end
256
278
 
257
279
  if conf[:method].eql?(:post)
258
- RestClient.send(:post, conf[:path], conf[:form_data], default_headers) do |response, request, block|
280
+ RestClient.send(:post, conf[:path], conf[:form_data], default_headers.merge(extended_headers)) do |response, request, block|
259
281
  handle_backend_error(response) if response.code.eql?(500)
260
282
  if response.respond_to?('body')
261
283
  yield response.body if block_given?
@@ -264,7 +286,7 @@ module DeltaCloud
264
286
  end
265
287
  end
266
288
  else
267
- RestClient.send(conf[:method], conf[:path], default_headers) do |response, request, block|
289
+ RestClient.send(conf[:method], conf[:path], default_headers.merge(extended_headers)) do |response, request, block|
268
290
  handle_backend_error(response) if response.code.eql?(500)
269
291
  if conf[:method].eql?(:get) and [301, 302, 307].include? response.code
270
292
  response.follow_redirection(request) do |response, request, block|
@@ -0,0 +1,4 @@
1
+ :description: Fedora 10
2
+ :owner_id: fedoraproject
3
+ :architecture: x86_64
4
+ :id: img1
@@ -0,0 +1,4 @@
1
+ :description: Fedora 10
2
+ :owner_id: fedoraproject
3
+ :architecture: i386
4
+ :id: img2
@@ -0,0 +1,4 @@
1
+ :description: JBoss
2
+ :owner_id: mockuser
3
+ :architecture: i386
4
+ :id: img3
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,9 @@
1
+ :name: MockUserInstance
2
+ :state: RUNNING
3
+ :image_id: img3
4
+ :owner_id: mockuser
5
+ :public_addresses: [ img3.inst1.public.com ]
6
+ :private_addresses: [ img3.inst1.private.com ]
7
+ :realm_id: us
8
+ :instance_profile: !ruby/object:InstanceProfile
9
+ id: m1-small
@@ -0,0 +1,9 @@
1
+ :name: AnotherInstance
2
+ :state: RUNNING
3
+ :image_id: img1
4
+ :owner_id: anotheruser
5
+ :public_addresses: [ img1.inst2.public.com ]
6
+ :private_addresses: [ img1.inst2.private.com ]
7
+ :realm_id: us
8
+ :instance_profile: !ruby/object:InstanceProfile
9
+ id: m1-large
@@ -0,0 +1,4 @@
1
+ :owner_id: fedoraproject
2
+ :created: Wed Jul 29 18:15:24 UTC 2009
3
+ :state: COMPLETED
4
+ :storage_volume_id: vol1
@@ -0,0 +1,4 @@
1
+ :owner_id: mockuser
2
+ :created: Wed Jul 29 18:15:24 UTC 2009
3
+ :state: COMPLETED
4
+ :storage_volume_id: vol2
@@ -0,0 +1,4 @@
1
+ :owner_id: mockuser
2
+ :created: Wed Jul 29 18:15:24 UTC 2009
3
+ :state: COMPLETED
4
+ :storage_volume_id: vol2
@@ -0,0 +1,6 @@
1
+ :owner_id: fedoraproject
2
+ :created: Thu Jul 30 14:35:11 UTC 2009
3
+ :state: AVAILABLE
4
+ :capacity: 1
5
+ :device:
6
+ :instance_id:
@@ -0,0 +1,6 @@
1
+ :owner_id: mockuser
2
+ :created: Thu Jul 30 14:35:11 UTC 2009
3
+ :state: AVAILABLE
4
+ :capacity: 1
5
+ :device:
6
+ :instance_id:
@@ -0,0 +1,6 @@
1
+ :owner_id: mockuser
2
+ :created: Thu Jul 30 14:35:11 UTC 2009
3
+ :state: IN-USE
4
+ :capacity: 1
5
+ :device: /dev/sda1
6
+ :instance_id: inst1
@@ -34,9 +34,9 @@ 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 be_a( DeltaCloud::API::Image )
37
+ instance.image.should be_a( DeltaCloud::API::Base::Image )
38
38
  instance.hardware_profile.should_not be_nil
39
- instance.hardware_profile.should be_a( DeltaCloud::API::HardwareProfile )
39
+ instance.hardware_profile.should be_a( DeltaCloud::API::Base::HardwareProfile )
40
40
  instance.state.should_not be_nil
41
41
  instance.state.should be_a( String )
42
42
  instance.public_addresses.should_not be_nil
metadata CHANGED
@@ -1,112 +1,126 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steamcannon-deltacloud-client
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 65
4
5
  prerelease: false
5
6
  segments:
6
- - 0
7
- - 1
8
- - 0
9
- - 5
10
- version: 0.1.0.5
7
+ - 0
8
+ - 1
9
+ - 1
10
+ - 1
11
+ version: 0.1.1.1
11
12
  platform: ruby
12
13
  authors:
13
- - Red Hat, Inc.
14
+ - Red Hat, Inc.
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-12-08 00:00:00 -05:00
19
+ date: 2010-12-23 00:00:00 -05:00
19
20
  default_executable: deltacloudc
20
21
  dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: rest-client
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 1
31
- - 6
32
- - 1
33
- version: 1.6.1
34
- type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: nokogiri
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 1
46
- - 5
47
- - 0
48
- - beta
49
- - 2
50
- version: 1.5.0.beta.2
51
- type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: rspec
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- segments:
62
- - 1
63
- - 3
64
- - 0
65
- version: 1.3.0
66
- type: :development
67
- version_requirements: *id003
22
+ - !ruby/object:Gem::Dependency
23
+ name: rest-client
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 13
31
+ segments:
32
+ - 1
33
+ - 6
34
+ - 1
35
+ version: 1.6.1
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: nokogiri
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 1
47
+ segments:
48
+ - 1
49
+ - 4
50
+ - 3
51
+ version: 1.4.3
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 27
63
+ segments:
64
+ - 1
65
+ - 3
66
+ - 0
67
+ version: 1.3.0
68
+ type: :development
69
+ version_requirements: *id003
68
70
  description: Deltacloud REST Client for API
69
71
  email: deltacloud-users@lists.fedorahosted.org
70
72
  executables:
71
- - deltacloudc
73
+ - deltacloudc
72
74
  extensions: []
73
75
 
74
76
  extra_rdoc_files:
75
- - COPYING
77
+ - COPYING
76
78
  files:
77
- - Rakefile
78
- - lib/plain_formatter.rb
79
- - lib/string.rb
80
- - lib/deltacloud.rb
81
- - lib/base_object.rb
82
- - lib/hwp_properties.rb
83
- - lib/instance_state.rb
84
- - lib/documentation.rb
85
- - init.rb
86
- - bin/deltacloudc
87
- - specs/storage_snapshot_spec.rb
88
- - specs/hardware_profiles_spec.rb
89
- - specs/images_spec.rb
90
- - specs/realms_spec.rb
91
- - specs/instances_spec.rb
92
- - specs/storage_volume_spec.rb
93
- - specs/spec_helper.rb
94
- - specs/instance_states_spec.rb
95
- - specs/initialization_spec.rb
96
- - specs/fixtures/storage_volumes/vol3.yml
97
- - specs/fixtures/storage_volumes/vol1.yml
98
- - specs/fixtures/storage_volumes/vol2.yml
99
- - specs/fixtures/images/img2.yml
100
- - specs/fixtures/images/img3.yml
101
- - specs/fixtures/images/img1.yml
102
- - specs/fixtures/instances/inst2.yml
103
- - specs/fixtures/instances/inst1.yml
104
- - specs/fixtures/instances/inst0.yml
105
- - specs/fixtures/storage_snapshots/snap3.yml
106
- - specs/fixtures/storage_snapshots/snap1.yml
107
- - specs/fixtures/storage_snapshots/snap2.yml
108
- - specs/shared/resources.rb
109
- - COPYING
79
+ - Rakefile
80
+ - lib/plain_formatter.rb
81
+ - lib/string.rb
82
+ - lib/deltacloud.rb
83
+ - lib/base_object.rb
84
+ - lib/hwp_properties.rb
85
+ - lib/instance_state.rb
86
+ - lib/documentation.rb
87
+ - init.rb
88
+ - bin/deltacloudc
89
+ - specs/data/storage_volumes/vol3.yml
90
+ - specs/data/storage_volumes/vol1.yml
91
+ - specs/data/storage_volumes/vol2.yml
92
+ - specs/data/images/img2.yml
93
+ - specs/data/images/img3.yml
94
+ - specs/data/images/img1.yml
95
+ - specs/data/instances/inst2.yml
96
+ - specs/data/instances/inst1.yml
97
+ - specs/data/instances/inst0.yml
98
+ - specs/data/storage_snapshots/snap3.yml
99
+ - specs/data/storage_snapshots/snap1.yml
100
+ - specs/data/storage_snapshots/snap2.yml
101
+ - specs/fixtures/storage_volumes/vol3.yml
102
+ - specs/fixtures/storage_volumes/vol1.yml
103
+ - specs/fixtures/storage_volumes/vol2.yml
104
+ - specs/fixtures/images/img2.yml
105
+ - specs/fixtures/images/img3.yml
106
+ - specs/fixtures/images/img1.yml
107
+ - specs/fixtures/instances/inst2.yml
108
+ - specs/fixtures/instances/inst1.yml
109
+ - specs/fixtures/instances/inst0.yml
110
+ - specs/fixtures/storage_snapshots/snap3.yml
111
+ - specs/fixtures/storage_snapshots/snap1.yml
112
+ - specs/fixtures/storage_snapshots/snap2.yml
113
+ - specs/storage_snapshot_spec.rb
114
+ - specs/hardware_profiles_spec.rb
115
+ - specs/images_spec.rb
116
+ - specs/realms_spec.rb
117
+ - specs/instances_spec.rb
118
+ - specs/storage_volume_spec.rb
119
+ - specs/spec_helper.rb
120
+ - specs/instance_states_spec.rb
121
+ - specs/shared/resources.rb
122
+ - specs/initialization_spec.rb
123
+ - COPYING
110
124
  has_rdoc: true
111
125
  homepage: http://www.deltacloud.org
112
126
  licenses: []
@@ -115,23 +129,25 @@ post_install_message:
115
129
  rdoc_options: []
116
130
 
117
131
  require_paths:
118
- - lib
132
+ - lib
119
133
  required_ruby_version: !ruby/object:Gem::Requirement
120
134
  none: false
121
135
  requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- segments:
125
- - 0
126
- version: "0"
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 3
139
+ segments:
140
+ - 0
141
+ version: "0"
127
142
  required_rubygems_version: !ruby/object:Gem::Requirement
128
143
  none: false
129
144
  requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- segments:
133
- - 0
134
- version: "0"
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ hash: 3
148
+ segments:
149
+ - 0
150
+ version: "0"
135
151
  requirements: []
136
152
 
137
153
  rubyforge_project:
@@ -140,25 +156,37 @@ signing_key:
140
156
  specification_version: 3
141
157
  summary: Deltacloud REST Client
142
158
  test_files:
143
- - specs/storage_snapshot_spec.rb
144
- - specs/hardware_profiles_spec.rb
145
- - specs/images_spec.rb
146
- - specs/realms_spec.rb
147
- - specs/instances_spec.rb
148
- - specs/storage_volume_spec.rb
149
- - specs/spec_helper.rb
150
- - specs/instance_states_spec.rb
151
- - specs/initialization_spec.rb
152
- - specs/fixtures/storage_volumes/vol3.yml
153
- - specs/fixtures/storage_volumes/vol1.yml
154
- - specs/fixtures/storage_volumes/vol2.yml
155
- - specs/fixtures/images/img2.yml
156
- - specs/fixtures/images/img3.yml
157
- - specs/fixtures/images/img1.yml
158
- - specs/fixtures/instances/inst2.yml
159
- - specs/fixtures/instances/inst1.yml
160
- - specs/fixtures/instances/inst0.yml
161
- - specs/fixtures/storage_snapshots/snap3.yml
162
- - specs/fixtures/storage_snapshots/snap1.yml
163
- - specs/fixtures/storage_snapshots/snap2.yml
164
- - specs/shared/resources.rb
159
+ - specs/data/storage_volumes/vol3.yml
160
+ - specs/data/storage_volumes/vol1.yml
161
+ - specs/data/storage_volumes/vol2.yml
162
+ - specs/data/images/img2.yml
163
+ - specs/data/images/img3.yml
164
+ - specs/data/images/img1.yml
165
+ - specs/data/instances/inst2.yml
166
+ - specs/data/instances/inst1.yml
167
+ - specs/data/instances/inst0.yml
168
+ - specs/data/storage_snapshots/snap3.yml
169
+ - specs/data/storage_snapshots/snap1.yml
170
+ - specs/data/storage_snapshots/snap2.yml
171
+ - specs/fixtures/storage_volumes/vol3.yml
172
+ - specs/fixtures/storage_volumes/vol1.yml
173
+ - specs/fixtures/storage_volumes/vol2.yml
174
+ - specs/fixtures/images/img2.yml
175
+ - specs/fixtures/images/img3.yml
176
+ - specs/fixtures/images/img1.yml
177
+ - specs/fixtures/instances/inst2.yml
178
+ - specs/fixtures/instances/inst1.yml
179
+ - specs/fixtures/instances/inst0.yml
180
+ - specs/fixtures/storage_snapshots/snap3.yml
181
+ - specs/fixtures/storage_snapshots/snap1.yml
182
+ - specs/fixtures/storage_snapshots/snap2.yml
183
+ - specs/storage_snapshot_spec.rb
184
+ - specs/hardware_profiles_spec.rb
185
+ - specs/images_spec.rb
186
+ - specs/realms_spec.rb
187
+ - specs/instances_spec.rb
188
+ - specs/storage_volume_spec.rb
189
+ - specs/spec_helper.rb
190
+ - specs/instance_states_spec.rb
191
+ - specs/shared/resources.rb
192
+ - specs/initialization_spec.rb