steamcannon-deltacloud-core 0.1.1.3 → 0.1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/bin/deltacloudd +7 -1
  2. data/config.ru +19 -1
  3. data/deltacloud.rb +20 -1
  4. data/lib/deltacloud/backend_capability.rb +33 -1
  5. data/lib/deltacloud/base_driver.rb +1 -1
  6. data/lib/deltacloud/base_driver/base_driver.rb +62 -73
  7. data/lib/deltacloud/base_driver/features.rb +6 -6
  8. data/lib/deltacloud/drivers/azure/azure_driver.rb +32 -1
  9. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +107 -23
  10. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +18 -0
  11. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +0 -1
  12. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +20 -5
  13. data/lib/deltacloud/drivers/mock/mock_driver.rb +1 -1
  14. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +1 -1
  15. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +28 -1
  16. data/lib/deltacloud/hardware_profile.rb +17 -0
  17. data/lib/deltacloud/helpers.rb +18 -0
  18. data/lib/deltacloud/helpers/application_helper.rb +2 -2
  19. data/lib/deltacloud/helpers/blob_stream.rb +5 -1
  20. data/lib/deltacloud/helpers/conversion_helper.rb +1 -2
  21. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +17 -0
  22. data/lib/deltacloud/method_serializer.rb +1 -1
  23. data/lib/deltacloud/models/base_model.rb +1 -1
  24. data/lib/deltacloud/models/blob.rb +3 -1
  25. data/lib/deltacloud/models/bucket.rb +2 -1
  26. data/lib/deltacloud/models/image.rb +1 -1
  27. data/lib/deltacloud/models/instance.rb +1 -2
  28. data/lib/deltacloud/models/instance_profile.rb +2 -1
  29. data/lib/deltacloud/models/key.rb +1 -1
  30. data/lib/deltacloud/models/load_balancer.rb +1 -1
  31. data/lib/deltacloud/models/realm.rb +1 -1
  32. data/lib/deltacloud/models/storage_snapshot.rb +1 -1
  33. data/lib/deltacloud/models/storage_volume.rb +1 -1
  34. data/lib/deltacloud/state_machine.rb +17 -0
  35. data/lib/deltacloud/validation.rb +18 -0
  36. data/lib/drivers.rb +69 -43
  37. data/lib/sinatra/lazy_auth.rb +1 -1
  38. data/lib/sinatra/rabbit.rb +5 -5
  39. data/lib/sinatra/rack_driver_select.rb +29 -0
  40. data/server.rb +45 -16
  41. data/views/api/drivers.xml.haml +6 -0
  42. data/views/api/show.html.haml +2 -2
  43. data/views/api/show.xml.haml +1 -1
  44. data/views/buckets/index.html.haml +2 -1
  45. data/views/buckets/show.html.haml +4 -3
  46. data/views/errors/backend_error.xml.haml +1 -1
  47. data/views/images/index.xml.haml +5 -1
  48. data/views/layout.html.haml +1 -1
  49. metadata +6 -5
  50. data/lib/deltacloud/drivers/gogrid/test.rb +0 -13
@@ -40,7 +40,7 @@ module Sinatra
40
40
  end
41
41
 
42
42
  def authorize!
43
- r = "#{DRIVER}-deltacloud@#{HOSTNAME}"
43
+ r = "#{driver_symbol}-deltacloud@#{HOSTNAME}"
44
44
  response['WWW-Authenticate'] = %(Basic realm="#{r}")
45
45
  throw(:halt, [401, "Not authorized\n"])
46
46
  end
@@ -60,7 +60,7 @@ module Sinatra
60
60
  def control(&block)
61
61
  op = self
62
62
  @control = Proc.new do
63
- op.check_capability(driver)
63
+ op.check_capability(Deltacloud::driver)
64
64
  op.validate(params)
65
65
  instance_eval(&block)
66
66
  end
@@ -72,7 +72,7 @@ module Sinatra
72
72
  end
73
73
 
74
74
  def path(args = {})
75
- l_prefix = args[:prefix] ? args[:prefix] : prefix
75
+ l_prefix = args[:prefix] || prefix
76
76
  if @member
77
77
  if standard?
78
78
  "#{l_prefix}/#{@collection.name}/:id"
@@ -133,7 +133,7 @@ module Sinatra
133
133
  end
134
134
 
135
135
  def generate_documentation
136
- coll, oper, features = self, @operations, driver.features(name)
136
+ coll, oper, features = self, @operations, Deltacloud::driver.features(name)
137
137
  ::Sinatra::Application.get("/api/docs/#{@name}") do
138
138
  @collection, @operations, @features = coll, oper, features
139
139
  respond_to do |format|
@@ -206,9 +206,9 @@ module Sinatra
206
206
  # operation on this collection.
207
207
  def collection(name, &block)
208
208
  raise DuplicateCollectionException if collections[name]
209
- return unless driver.has_collection?(name.to_sym)
209
+ return unless Deltacloud::driver.has_collection?(name.to_sym)
210
210
  collections[name] = Collection.new(name, &block)
211
- collections[name].add_feature_params(driver.features(name))
211
+ collections[name].add_feature_params(Deltacloud::driver.features(name))
212
212
  collections[name].generate
213
213
  end
214
214
 
@@ -0,0 +1,29 @@
1
+ class RackDriverSelect
2
+
3
+ def initialize(app, opts={})
4
+ @app = app
5
+ @opts = opts
6
+ end
7
+
8
+ HEADER_TO_ENV_MAP = {
9
+ 'HTTP_X_DELTACLOUD_DRIVER' => :driver,
10
+ 'HTTP_X_DELTACLOUD_PROVIDER' => :provider
11
+ }
12
+
13
+ def call(env)
14
+ original_settings = { }
15
+ HEADER_TO_ENV_MAP.each do |header, name|
16
+ original_settings[name] = Thread.current[name]
17
+ new_setting = extract_header(env, header)
18
+ Thread.current[name] = new_setting if new_setting
19
+ end
20
+ @app.call(env)
21
+ ensure
22
+ original_settings.each { |name, value| Thread.current[name] = value }
23
+ end
24
+
25
+ def extract_header(env, header)
26
+ env[header].downcase if env[header]
27
+ end
28
+
29
+ end
data/server.rb CHANGED
@@ -1,3 +1,20 @@
1
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one or more
4
+ # contributor license agreements. See the NOTICE file distributed with
5
+ # this work for additional information regarding copyright ownership. The
6
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance with the
8
+ # License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'sinatra'
2
19
  require 'deltacloud'
3
20
  require 'drivers'
@@ -10,6 +27,12 @@ require 'erb'
10
27
  require 'haml'
11
28
  require 'open3'
12
29
  require 'lib/deltacloud/helpers/blob_stream'
30
+ require 'sinatra/rack_driver_select'
31
+
32
+ set :version, '0.1.0'
33
+
34
+
35
+ use RackDriverSelect
13
36
 
14
37
  configure do
15
38
  set :raise_errors => false
@@ -46,25 +69,30 @@ end
46
69
  Sinatra::Application.register Sinatra::RespondTo
47
70
 
48
71
  # Redirect to /api
49
- get '/' do redirect url_for('/api'); end
72
+ get '/' do redirect url_for('/api'), 301; end
73
+
74
+ get '/api/drivers\/?' do
75
+ respond_to do |format|
76
+ format.xml { haml :"api/drivers" }
77
+ end
78
+ end
50
79
 
51
80
  get '/api\/?' do
52
- @version = 0.1
53
- if params[:force_auth]
54
- return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials)
55
- end
56
- respond_to do |format|
57
- format.xml { haml :"api/show" }
58
- format.json do
59
- { :api => {
60
- :version => @version,
61
- :driver => DRIVER,
62
- :links => entry_points.collect { |l| { :rel => l[0], :href => l[1]} }
63
- }
64
- }.to_json
65
- end
66
- format.html { haml :"api/show" }
81
+ if params[:force_auth]
82
+ return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials)
83
+ end
84
+ respond_to do |format|
85
+ format.xml { haml :"api/show" }
86
+ format.json do
87
+ { :api => {
88
+ :version => settings.version,
89
+ :driver => driver_symbol,
90
+ :links => entry_points.collect { |l| { :rel => l[0], :href => l[1]} }
91
+ }
92
+ }.to_json
67
93
  end
94
+ format.html { haml :"api/show" }
95
+ end
68
96
  end
69
97
 
70
98
  # Rabbit DSL
@@ -595,6 +623,7 @@ get '/api/buckets/:bucket/:blob/content' do
595
623
  @blob = driver.blob(credentials, { :id => params[:blob], 'bucket' => params[:bucket]})
596
624
  params['content_length'] = @blob.content_length
597
625
  params['content_type'] = @blob.content_type
626
+ params['content_disposition'] = "attachment; filename=#{@blob.id}"
598
627
  BlobStream.call(env, credentials, params)
599
628
  end
600
629
 
@@ -0,0 +1,6 @@
1
+ %api{ :version => settings.version }
2
+ %drivers
3
+ - DRIVERS.each do |id, details|
4
+ %driver{ :id => id }
5
+ %name<
6
+ =details[:name]
@@ -1,5 +1,5 @@
1
1
  %h1
2
- API v#{@version}
2
+ API v#{settings.version}
3
3
 
4
4
  %ul
5
5
  - collections.keys.sort_by { |k| k.to_s }.each do |key|
@@ -12,4 +12,4 @@
12
12
  = op
13
13
  %li
14
14
  %strong
15
- %a{:href => url_for("/api/docs")} Documentation (v#{@version})
15
+ %a{:href => url_for("/api/docs")} Documentation (#{settings.version})
@@ -1,4 +1,4 @@
1
- %api{ :version=>@version, :driver=>DRIVER }
1
+ %api{ :version => settings.version, :driver => driver_symbol }
2
2
  - for entry_point in entry_points
3
3
  %link{ :rel=>entry_point[0], :href=>entry_point[1] }
4
4
  - for feature in driver.features(entry_point[0])
@@ -30,4 +30,5 @@
30
30
  -bucket.blob_list.each do |blob|
31
31
  = blob
32
32
  %td
33
- =link_to_action 'Delete', destroy_bucket_url(bucket.name), :delete
33
+ -if bucket.size == 0
34
+ =link_to_action 'Delete', destroy_bucket_url(bucket.name), :delete
@@ -14,9 +14,10 @@
14
14
  %dd
15
15
  -@bucket.blob_list.each do |blob|
16
16
  = link_to blob, bucket_url(@bucket.name) + '/' + blob
17
- %dt Delete bucket (must be empty)
18
- %dd
19
17
  %dt Create a new blob
20
18
  %dd
21
19
  =link_to 'Create Blob', bucket_url(@bucket.name) + '/new_blob'
22
- =link_to_action 'Delete', destroy_bucket_url(@bucket.name), :delete
20
+ %dt Delete bucket (must be empty)
21
+ %dd
22
+ -if @bucket.size == 0
23
+ =link_to_action 'Delete', destroy_bucket_url(@bucket.name), :delete
@@ -1,6 +1,6 @@
1
1
  %error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
2
2
  %kind backend_error
3
- %backend{ :driver => DRIVER }
3
+ %backend{ :driver => driver_symbol }
4
4
  %code= @error.code
5
5
  %cause= @error.cause
6
6
  - if @error.details
@@ -4,5 +4,9 @@
4
4
  %image{:href => image_url(image.id), :id => image.id}
5
5
  - image.attributes.select{ |attr| attr!=:id }.each do |attribute|
6
6
  - haml_tag("#{attribute}".tr('-', '_'), :<) do
7
- - haml_concat image.send(attribute)
7
+ - if [:name, :description].include?(attribute)
8
+ =cdata do
9
+ - haml_concat image.send(attribute)
10
+ - else
11
+ - haml_concat image.send(attribute)
8
12
 
@@ -19,7 +19,7 @@
19
19
  = yield
20
20
  #footer
21
21
  #driver_info
22
- Driver: #{DRIVER}
22
+ Driver: #{driver_symbol} | API version: #{settings.version}
23
23
  #copyright
24
24
  Copyright 2009, 2010
25
25
  %a{:href => 'http://redhat.com'} Red Hat
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steamcannon-deltacloud-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 69
4
+ hash: 77
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
+ - 2
9
10
  - 1
10
- - 3
11
- version: 0.1.1.3
11
+ version: 0.1.2.1
12
12
  platform: ruby
13
13
  authors:
14
14
  - Red Hat, Inc.
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-15 00:00:00 -05:00
19
+ date: 2010-12-23 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -230,7 +230,6 @@ files:
230
230
  - lib/deltacloud/backend_capability.rb
231
231
  - lib/deltacloud/drivers/rackspace/rackspace_client.rb
232
232
  - lib/deltacloud/drivers/rackspace/rackspace_driver.rb
233
- - lib/deltacloud/drivers/gogrid/test.rb
234
233
  - lib/deltacloud/drivers/gogrid/gogrid_client.rb
235
234
  - lib/deltacloud/drivers/gogrid/gogrid_driver.rb
236
235
  - lib/deltacloud/drivers/opennebula/occi_client.rb
@@ -273,6 +272,7 @@ files:
273
272
  - lib/sinatra/url_for.rb
274
273
  - lib/sinatra/static_assets.rb
275
274
  - lib/sinatra/accept_media_types.rb
275
+ - lib/sinatra/rack_driver_select.rb
276
276
  - lib/sinatra/rabbit.rb
277
277
  - lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml
278
278
  - lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml
@@ -338,6 +338,7 @@ files:
338
338
  - views/images/show.html.haml
339
339
  - views/accounts/index.html.haml
340
340
  - views/accounts/show.html.haml
341
+ - views/api/drivers.xml.haml
341
342
  - views/api/show.xml.haml
342
343
  - views/api/show.html.haml
343
344
  - views/docs/collection.xml.haml
@@ -1,13 +0,0 @@
1
- require 'gogrid_client'
2
- require 'ap'
3
-
4
- user='fbb1de3897597ccf'
5
- password='ngieth10'
6
-
7
- client=GoGridClient.new('https://api.gogrid.com/api', user, password)
8
-
9
- ap client.request('grid/ip/list', {
10
- 'ip.type' => '1',
11
- 'ip.state' => '1',
12
- 'datacenter' => '1'
13
- })