deltacloud-core 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/config.ru +19 -1
  2. data/deltacloud.rb +20 -1
  3. data/lib/deltacloud/backend_capability.rb +18 -0
  4. data/lib/deltacloud/base_driver.rb +1 -1
  5. data/lib/deltacloud/base_driver/base_driver.rb +3 -0
  6. data/lib/deltacloud/drivers/azure/azure_driver.rb +32 -1
  7. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +17 -11
  8. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +18 -0
  9. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +0 -1
  10. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +20 -5
  11. data/lib/deltacloud/drivers/mock/mock_driver.rb +1 -1
  12. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +1 -1
  13. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +28 -1
  14. data/lib/deltacloud/hardware_profile.rb +17 -0
  15. data/lib/deltacloud/helpers.rb +18 -0
  16. data/lib/deltacloud/helpers/application_helper.rb +2 -2
  17. data/lib/deltacloud/helpers/blob_stream.rb +5 -1
  18. data/lib/deltacloud/helpers/conversion_helper.rb +1 -2
  19. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +17 -0
  20. data/lib/deltacloud/method_serializer.rb +1 -1
  21. data/lib/deltacloud/models/base_model.rb +1 -1
  22. data/lib/deltacloud/models/blob.rb +3 -1
  23. data/lib/deltacloud/models/bucket.rb +2 -1
  24. data/lib/deltacloud/models/image.rb +3 -2
  25. data/lib/deltacloud/models/instance.rb +1 -2
  26. data/lib/deltacloud/models/instance_profile.rb +2 -1
  27. data/lib/deltacloud/models/key.rb +2 -1
  28. data/lib/deltacloud/models/load_balancer.rb +1 -1
  29. data/lib/deltacloud/models/realm.rb +1 -1
  30. data/lib/deltacloud/models/storage_snapshot.rb +1 -1
  31. data/lib/deltacloud/models/storage_volume.rb +1 -1
  32. data/lib/deltacloud/state_machine.rb +17 -0
  33. data/lib/deltacloud/validation.rb +18 -0
  34. data/lib/drivers.rb +69 -43
  35. data/lib/sinatra/lazy_auth.rb +1 -1
  36. data/lib/sinatra/rabbit.rb +4 -4
  37. data/lib/sinatra/rack_driver_select.rb +21 -0
  38. data/server.rb +44 -15
  39. data/views/api/drivers.xml.haml +6 -0
  40. data/views/api/show.html.haml +2 -2
  41. data/views/api/show.xml.haml +1 -1
  42. data/views/buckets/index.html.haml +2 -1
  43. data/views/buckets/show.html.haml +4 -3
  44. data/views/errors/backend_error.xml.haml +1 -1
  45. data/views/images/index.xml.haml +5 -1
  46. data/views/keys/show.xml.haml +2 -0
  47. data/views/layout.html.haml +1 -1
  48. data/views/realms/index.html.haml +4 -7
  49. metadata +35 -34
  50. data/lib/deltacloud/drivers/gogrid/test.rb +0 -13
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009,2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -17,10 +17,12 @@
17
17
  # under the License.
18
18
 
19
19
  class Blob < BaseModel
20
+
20
21
  #already has an id from basemodel (for the key)
21
22
  attr_accessor :bucket
22
23
  attr_accessor :content_length
23
24
  attr_accessor :content_type
24
25
  attr_accessor :last_modified
25
26
  attr_accessor :content
27
+
26
28
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -21,4 +21,5 @@ class Bucket < BaseModel
21
21
  attr_accessor :name
22
22
  attr_accessor :size
23
23
  attr_accessor :blob_list
24
+
24
25
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -23,5 +23,6 @@ class Image < BaseModel
23
23
  attr_accessor :owner_id
24
24
  attr_accessor :description
25
25
  attr_accessor :architecture
26
+ attr_accessor :state
26
27
 
27
- end
28
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -16,7 +16,6 @@
16
16
  # License for the specific language governing permissions and limitations
17
17
  # under the License.
18
18
 
19
-
20
19
  class Instance < BaseModel
21
20
 
22
21
  attr_accessor :owner_id
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -18,6 +18,7 @@
18
18
 
19
19
  # Model to store the hardware profile applied to an instance together with
20
20
  # any instance-specific overrides
21
+
21
22
  class InstanceProfile < BaseModel
22
23
  attr_accessor :memory
23
24
  attr_accessor :storage
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -23,6 +23,7 @@ class Key < BaseModel
23
23
  attr_accessor :username
24
24
  attr_accessor :password
25
25
  attr_accessor :pem_rsa_key
26
+ attr_accessor :state
26
27
 
27
28
  def is_password?
28
29
  true if @credential_type.eql?(:password)
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
2
+ # Copyright (C) 2009, 2010 Red Hat, Inc.
3
3
  #
4
4
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
5
  # contributor license agreements. See the NOTICE file distributed with
@@ -1,3 +1,20 @@
1
+ #
2
+ # Copyright (C) 2009,2010 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.
1
18
 
2
19
  module Deltacloud
3
20
  class StateMachine
@@ -1,3 +1,21 @@
1
+ #
2
+ # Copyright (C) 2009,2010 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
+
1
19
  module Deltacloud::Validation
2
20
 
3
21
  class Failure < StandardError
data/lib/drivers.rb CHANGED
@@ -1,51 +1,77 @@
1
- DRIVERS = {
2
- :ec2 => { :name => "EC2" },
3
- :rackspace => { :name => "Rackspace" },
4
- :gogrid => { :name => "Gogrid" },
5
- :rhevm => { :name => "RHEVM" },
6
- :rimuhosting => { :name => "RimuHosting"},
7
- :opennebula => { :name => "Opennebula", :class => "OpennebulaDriver" },
8
- :terremark => { :name => "Terremark"},
9
- :azure => { :name => "Azure" },
10
- :mock => { :name => "Mock" }
11
- }
12
-
13
- DEFAULT_COLLECTIONS = [
14
- :hardware_profiles,
15
- :images,
16
- :instances,
17
- :instance_states,
18
- :realms,
19
- :storage_volumes,
20
- :storage_snapshots
21
- ]
22
-
23
- DRIVER=ENV['API_DRIVER'] ? ENV['API_DRIVER'].to_sym : :mock
24
-
25
- def driver_name
26
- DRIVERS[DRIVER][:name]
27
- end
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.
28
17
 
29
- def driver_class_name
30
- basename = DRIVERS[DRIVER][:class] || "#{driver_name}Driver"
31
- "Deltacloud::Drivers::#{driver_name}::#{basename}"
32
- end
18
+ module Deltacloud
19
+ DRIVERS = {
20
+ :ec2 => { :name => "EC2" },
21
+ :rackspace => { :name => "Rackspace" },
22
+ :gogrid => { :name => "Gogrid" },
23
+ :rhevm => { :name => "RHEVM" },
24
+ :rimuhosting => { :name => "RimuHosting"},
25
+ :opennebula => { :name => "Opennebula", :class => "OpennebulaDriver" },
26
+ :terremark => { :name => "Terremark"},
27
+ :azure => { :name => "Azure" },
28
+ :mock => { :name => "Mock" }
29
+ }
33
30
 
34
- def driver_source_name
35
- File.join("deltacloud", "drivers", "#{DRIVER}", "#{DRIVER}_driver.rb")
36
- end
31
+ DEFAULT_COLLECTIONS = [
32
+ :hardware_profiles,
33
+ :images,
34
+ :instances,
35
+ :instance_states,
36
+ :realms,
37
+ :storage_volumes,
38
+ :storage_snapshots
39
+ ]
37
40
 
38
- def driver_mock_source_name
39
- return File.join('deltacloud', 'drivers', DRIVER.to_s, "#{DRIVER}_driver.rb") if driver_name.eql? 'Mock'
40
- end
41
+ DRIVER=ENV['API_DRIVER'] ? ENV['API_DRIVER'].to_sym : :mock
41
42
 
42
- def driver
43
- require driver_source_name
44
- #require 'deltacloud/base_driver/mock_driver.rb'
43
+ def driver_symbol
44
+ (Thread.current[:driver] || DRIVER).to_sym
45
+ end
46
+
47
+ def driver_name
48
+ DRIVERS[:"#{driver_symbol}"][:name]
49
+ end
45
50
 
46
- if Sinatra::Application.environment.eql? :test
47
- require driver_mock_source_name if driver_mock_source_name
51
+ def driver_class_name
52
+ basename = DRIVERS[:"#{driver_symbol}"][:class] || "#{driver_name}Driver"
53
+ "Deltacloud::Drivers::#{driver_name}::#{basename}"
48
54
  end
49
55
 
50
- @driver ||= eval( driver_class_name ).new
56
+ def driver_source_name
57
+ File.join("deltacloud", "drivers", "#{driver_symbol}", "#{driver_symbol}_driver.rb")
58
+ end
59
+
60
+ def driver_mock_source_name
61
+ return File.join('deltacloud', 'drivers', "#{driver_symbol}",
62
+ "#{driver_symbol}_driver.rb") if driver_name.eql? 'Mock'
63
+ end
64
+
65
+ def driver
66
+ require driver_source_name
67
+ #require 'deltacloud/base_driver/mock_driver.rb'
68
+
69
+ if Sinatra::Application.environment.eql? :test
70
+ require driver_mock_source_name if driver_mock_source_name
71
+ end
72
+
73
+ @driver ||= eval( driver_class_name ).new
74
+ end
51
75
  end
76
+
77
+ include Deltacloud
@@ -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
@@ -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,21 @@
1
+ class RackDriverSelect
2
+
3
+ def initialize(app, opts={})
4
+ @app = app
5
+ @opts = opts
6
+ end
7
+
8
+ def call(env)
9
+ original_driver = Thread.current[:driver]
10
+ new_driver = extract_driver(env)
11
+ Thread.current[:driver] = new_driver if new_driver
12
+ @app.call(env)
13
+ ensure
14
+ Thread.current[:driver] = original_driver
15
+ end
16
+
17
+ def extract_driver(env)
18
+ driver_name = env['HTTP_X_DELTACLOUD_DRIVER'].downcase if env['HTTP_X_DELTACLOUD_DRIVER']
19
+ end
20
+
21
+ 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
@@ -48,23 +71,28 @@ Sinatra::Application.register Sinatra::RespondTo
48
71
  # Redirect to /api
49
72
  get '/' do redirect url_for('/api'); end
50
73
 
74
+ get '/api/drivers\/?' do
75
+ respond_to do |format|
76
+ format.xml { haml :"api/drivers" }
77
+ end
78
+ end
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
@@ -505,6 +533,7 @@ get '/api/buckets/:bucket/:blob/content' do
505
533
  @blob = driver.blob(credentials, { :id => params[:blob], 'bucket' => params[:bucket]})
506
534
  params['content_length'] = @blob.content_length
507
535
  params['content_type'] = @blob.content_type
536
+ params['content_disposition'] = "attachment; filename=#{@blob.id}"
508
537
  BlobStream.call(env, credentials, params)
509
538
  end
510
539