steamcannon-deltacloud-core 0.0.7.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/COPYING +176 -0
  2. data/Rakefile +106 -0
  3. data/bin/deltacloudd +120 -0
  4. data/config.ru +5 -0
  5. data/deltacloud.rb +20 -0
  6. data/lib/deltacloud/base_driver/base_driver.rb +259 -0
  7. data/lib/deltacloud/base_driver/features.rb +173 -0
  8. data/lib/deltacloud/base_driver/mock_driver.rb +58 -0
  9. data/lib/deltacloud/base_driver.rb +20 -0
  10. data/lib/deltacloud/drivers/azure/azure_driver.rb +127 -0
  11. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +580 -0
  12. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +170 -0
  13. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +50 -0
  14. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +343 -0
  15. data/lib/deltacloud/drivers/gogrid/test.rb +13 -0
  16. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml +5 -0
  17. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml +5 -0
  18. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml +5 -0
  19. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml +5 -0
  20. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml +5 -0
  21. data/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml +2 -0
  22. data/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml +2 -0
  23. data/lib/deltacloud/drivers/mock/data/images/img1.yml +3 -0
  24. data/lib/deltacloud/drivers/mock/data/images/img2.yml +3 -0
  25. data/lib/deltacloud/drivers/mock/data/images/img3.yml +3 -0
  26. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +16 -0
  27. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +9 -0
  28. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +9 -0
  29. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +4 -0
  30. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +4 -0
  31. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +4 -0
  32. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +6 -0
  33. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +6 -0
  34. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +6 -0
  35. data/lib/deltacloud/drivers/mock/mock_driver.rb +356 -0
  36. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +116 -0
  37. data/lib/deltacloud/drivers/opennebula/occi_client.rb +204 -0
  38. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +241 -0
  39. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +130 -0
  40. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +290 -0
  41. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +258 -0
  42. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +85 -0
  43. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +166 -0
  44. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +295 -0
  45. data/lib/deltacloud/hardware_profile.rb +153 -0
  46. data/lib/deltacloud/helpers/application_helper.rb +122 -0
  47. data/lib/deltacloud/helpers/blob_stream.rb +51 -0
  48. data/lib/deltacloud/helpers/conversion_helper.rb +39 -0
  49. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
  50. data/lib/deltacloud/helpers.rb +5 -0
  51. data/lib/deltacloud/method_serializer.rb +85 -0
  52. data/lib/deltacloud/models/base_model.rb +59 -0
  53. data/lib/deltacloud/models/blob.rb +26 -0
  54. data/lib/deltacloud/models/bucket.rb +24 -0
  55. data/lib/deltacloud/models/image.rb +27 -0
  56. data/lib/deltacloud/models/instance.rb +38 -0
  57. data/lib/deltacloud/models/instance_profile.rb +48 -0
  58. data/lib/deltacloud/models/key.rb +35 -0
  59. data/lib/deltacloud/models/realm.rb +26 -0
  60. data/lib/deltacloud/models/storage_snapshot.rb +27 -0
  61. data/lib/deltacloud/models/storage_volume.rb +28 -0
  62. data/lib/deltacloud/state_machine.rb +84 -0
  63. data/lib/deltacloud/validation.rb +70 -0
  64. data/lib/drivers.rb +51 -0
  65. data/lib/sinatra/accept_media_types.rb +128 -0
  66. data/lib/sinatra/lazy_auth.rb +56 -0
  67. data/lib/sinatra/rabbit.rb +279 -0
  68. data/lib/sinatra/respond_to.rb +238 -0
  69. data/lib/sinatra/static_assets.rb +83 -0
  70. data/lib/sinatra/url_for.rb +53 -0
  71. data/public/favicon.ico +0 -0
  72. data/public/images/grid.png +0 -0
  73. data/public/images/logo-wide.png +0 -0
  74. data/public/images/rails.png +0 -0
  75. data/public/images/topbar-bg.png +0 -0
  76. data/public/javascripts/application.js +32 -0
  77. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  78. data/public/stylesheets/compiled/application.css +613 -0
  79. data/public/stylesheets/compiled/ie.css +31 -0
  80. data/public/stylesheets/compiled/print.css +27 -0
  81. data/public/stylesheets/compiled/screen.css +456 -0
  82. data/server.rb +516 -0
  83. data/support/fedora/deltacloudd +68 -0
  84. data/support/fedora/rubygem-deltacloud-core.spec +91 -0
  85. data/tests/api_test.rb +37 -0
  86. data/tests/hardware_profiles_test.rb +120 -0
  87. data/tests/images_test.rb +111 -0
  88. data/tests/instance_states_test.rb +51 -0
  89. data/tests/instances_test.rb +222 -0
  90. data/tests/realms_test.rb +78 -0
  91. data/tests/url_for_test.rb +50 -0
  92. data/views/accounts/index.html.haml +11 -0
  93. data/views/accounts/show.html.haml +30 -0
  94. data/views/api/show.html.haml +15 -0
  95. data/views/api/show.xml.haml +5 -0
  96. data/views/blobs/show.html.haml +20 -0
  97. data/views/blobs/show.xml.haml +7 -0
  98. data/views/buckets/index.html.haml +33 -0
  99. data/views/buckets/index.xml.haml +10 -0
  100. data/views/buckets/new.html.haml +13 -0
  101. data/views/buckets/show.html.haml +19 -0
  102. data/views/buckets/show.xml.haml +8 -0
  103. data/views/docs/collection.html.haml +37 -0
  104. data/views/docs/collection.xml.haml +14 -0
  105. data/views/docs/index.html.haml +15 -0
  106. data/views/docs/index.xml.haml +5 -0
  107. data/views/docs/operation.html.haml +31 -0
  108. data/views/docs/operation.xml.haml +10 -0
  109. data/views/errors/auth_exception.html.haml +8 -0
  110. data/views/errors/auth_exception.xml.haml +2 -0
  111. data/views/errors/backend_error.html.haml +19 -0
  112. data/views/errors/backend_error.xml.haml +8 -0
  113. data/views/errors/not_found.html.haml +6 -0
  114. data/views/errors/not_found.xml.haml +2 -0
  115. data/views/errors/validation_failure.html.haml +11 -0
  116. data/views/errors/validation_failure.xml.haml +7 -0
  117. data/views/hardware_profiles/index.html.haml +25 -0
  118. data/views/hardware_profiles/index.xml.haml +4 -0
  119. data/views/hardware_profiles/show.html.haml +19 -0
  120. data/views/hardware_profiles/show.xml.haml +18 -0
  121. data/views/images/index.html.haml +30 -0
  122. data/views/images/index.xml.haml +8 -0
  123. data/views/images/show.html.haml +21 -0
  124. data/views/images/show.xml.haml +5 -0
  125. data/views/instance_states/show.html.haml +31 -0
  126. data/views/instance_states/show.png.erb +45 -0
  127. data/views/instance_states/show.xml.haml +8 -0
  128. data/views/instances/index.html.haml +30 -0
  129. data/views/instances/index.xml.haml +21 -0
  130. data/views/instances/new.html.haml +55 -0
  131. data/views/instances/show.html.haml +43 -0
  132. data/views/instances/show.xml.haml +49 -0
  133. data/views/keys/index.html.haml +26 -0
  134. data/views/keys/index.xml.haml +4 -0
  135. data/views/keys/new.html.haml +8 -0
  136. data/views/keys/show.html.haml +22 -0
  137. data/views/keys/show.xml.haml +20 -0
  138. data/views/layout.html.haml +26 -0
  139. data/views/realms/index.html.haml +29 -0
  140. data/views/realms/index.xml.haml +10 -0
  141. data/views/realms/show.html.haml +15 -0
  142. data/views/realms/show.xml.haml +9 -0
  143. data/views/root/index.html.haml +4 -0
  144. data/views/storage_snapshots/index.html.haml +20 -0
  145. data/views/storage_snapshots/index.xml.haml +9 -0
  146. data/views/storage_snapshots/show.html.haml +14 -0
  147. data/views/storage_snapshots/show.xml.haml +7 -0
  148. data/views/storage_volumes/index.html.haml +21 -0
  149. data/views/storage_volumes/index.xml.haml +23 -0
  150. data/views/storage_volumes/show.html.haml +20 -0
  151. data/views/storage_volumes/show.xml.haml +24 -0
  152. metadata +367 -0
@@ -0,0 +1,173 @@
1
+ require 'deltacloud/validation'
2
+
3
+ # Add advertising of optional features to the base driver
4
+ module Deltacloud
5
+
6
+ class FeatureError < StandardError; end
7
+ class DuplicateFeatureDeclError < FeatureError; end
8
+ class UndeclaredFeatureError < FeatureError; end
9
+
10
+ class BaseDriver
11
+
12
+ # An operation on a collection like cretae or show. Features
13
+ # can add parameters to operations
14
+ class Operation
15
+ attr_reader :name
16
+
17
+ include Deltacloud::Validation
18
+
19
+ def initialize(name, &block)
20
+ @name = name
21
+ @params = {}
22
+ instance_eval &block
23
+ end
24
+ end
25
+
26
+ # The declaration of a feature, defines what operations
27
+ # are modified by it
28
+ class FeatureDecl
29
+ attr_reader :name, :operations
30
+
31
+ def initialize(name, &block)
32
+ @name = name
33
+ @operations = []
34
+ instance_eval &block
35
+ end
36
+
37
+ def description(text=nil)
38
+ @description = text if text
39
+ @description
40
+ end
41
+
42
+ # Add a new operation or modify an existing one through BLOCK
43
+ def operation(name, &block)
44
+ unless op = @operations.find { |op| op.name == name }
45
+ op = Operation.new(name, &block)
46
+ @operations << op
47
+ else
48
+ op.instance_eval(&block) if block_given?
49
+ end
50
+ op
51
+ end
52
+ end
53
+
54
+ # A specific feature enabled by a driver (see +feature+)
55
+ class Feature
56
+ attr_reader :decl
57
+
58
+ def initialize(decl, &block)
59
+ @decl = decl
60
+ instance_eval &block if block_given?
61
+ end
62
+
63
+ def name
64
+ decl.name
65
+ end
66
+
67
+ def operations
68
+ decl.operations
69
+ end
70
+
71
+ def description
72
+ decl.description
73
+ end
74
+ end
75
+
76
+ def self.feature_decls
77
+ @@feature_decls ||= {}
78
+ end
79
+
80
+ def self.feature_decl_for(collection, name)
81
+ decls = feature_decls[collection]
82
+ if decls
83
+ decls.find { |dcl| dcl.name == name }
84
+ else
85
+ nil
86
+ end
87
+ end
88
+
89
+ # Declare a new feature
90
+ def self.declare_feature(collection, name, &block)
91
+ feature_decls[collection] ||= []
92
+ raise DuplicateFeatureDeclError if feature_decl_for(collection, name)
93
+ feature_decls[collection] << FeatureDecl.new(name, &block)
94
+ end
95
+
96
+ def self.features
97
+ @@features ||= {}
98
+ end
99
+
100
+ # Declare in a driver that it supports a specific feature
101
+ #
102
+ # The same feature can be declared multiple times in a driver, so that
103
+ # it can be changed successively by passing in different blocks.
104
+ def self.feature(collection, name, &block)
105
+ features[collection] ||= []
106
+ if f = features[collection].find { |f| f.name == name }
107
+ f.instance_eval(&block) if block_given?
108
+ return f
109
+ end
110
+ unless decl = feature_decl_for(collection, name)
111
+ raise UndeclaredFeatureError, "No feature #{name} for #{collection}"
112
+ end
113
+ features[collection] << Feature.new(decl, &block)
114
+ end
115
+
116
+ def features(collection)
117
+ self.class.features[collection] || []
118
+ end
119
+
120
+ #
121
+ # Declaration of optional features
122
+ #
123
+ declare_feature :images, :owner_id do
124
+ description "Filter images using owner id"
125
+ operation :index do
126
+ param :owner_id, :string, :optional, nil, "Owner ID"
127
+ end
128
+ end
129
+
130
+ declare_feature :instances, :user_name do
131
+ description "Accept a user-defined name on instance creation"
132
+ operation :create do
133
+ param :name, :string, :optional, nil,
134
+ "The user-defined name"
135
+ end
136
+ end
137
+
138
+ declare_feature :instances, :user_data do
139
+ description "Make user-defined data available on a special webserver"
140
+ operation :create do
141
+ param :user_data, :string, :optional, nil,
142
+ "Base64 encoded user data will be published to internal webserver"
143
+ end
144
+ end
145
+
146
+ declare_feature :instances, :authentication_key do
147
+ operation :create do
148
+ param :keyname, :string, :optional, nil
149
+ "EC2 key authentification method"
150
+ end
151
+ operation :show do
152
+ end
153
+ end
154
+
155
+ declare_feature :instances, :authentication_password do
156
+ operation :create do
157
+ param :password, :string, :optional
158
+ end
159
+ end
160
+
161
+ declare_feature :instances, :hardware_profiles do
162
+ description "Size instances according to changes to a hardware profile"
163
+ # The parameters are filled in from the hardware profiles
164
+ end
165
+
166
+ declare_feature :buckets, :bucket_location do
167
+ description "Take extra location parameter for Bucket creation (e.g. S3, 'eu' or 'us-west-1')"
168
+ operation :create do
169
+ param :location, :string, :optional
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,58 @@
1
+ require 'deltacloud/method_serializer'
2
+
3
+ # Create 'mock' version of original driver client/gem:
4
+
5
+ module Mock
6
+
7
+ class S3 < RightAws::S3
8
+ include MethodSerializer::Cache
9
+
10
+ def self.cached_methods
11
+ [
12
+ :buckets
13
+ ]
14
+ end
15
+
16
+ MethodSerializer::Cache::wrap_methods(self, :cache_dir => File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'tests', 'ec2', 'support'))
17
+ end
18
+
19
+ class EC2 < AWS::EC2::Base
20
+
21
+ include MethodSerializer::Cache
22
+
23
+ def self.cached_methods
24
+ [
25
+ :describe_images,
26
+ :describe_availability_zones,
27
+ :describe_keypairs,
28
+ :create_keypair,
29
+ :run_instances,
30
+ :describe_instances,
31
+ :reboot_instances,
32
+ :terminate_instances,
33
+ :delete_keypair
34
+ ]
35
+ end
36
+
37
+ MethodSerializer::Cache::wrap_methods(self, :cache_dir => File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'tests', 'ec2', 'support'))
38
+ end
39
+ end
40
+
41
+
42
+ # Replace original client with mock client
43
+ Deltacloud::Drivers::EC2::EC2Driver.class_eval do
44
+ alias_method :original_new_client, :new_client
45
+ alias_method :original_s3_client, :s3_client
46
+
47
+ def new_client(credentials, opts={})
48
+ Mock::EC2.new(
49
+ :access_key_id => credentials.user,
50
+ :secret_access_key => credentials.password
51
+ )
52
+ end
53
+
54
+ def s3_client(credentials)
55
+ Mock::S3.new(credentials.user, credentials.password)
56
+ end
57
+
58
+ end
@@ -0,0 +1,20 @@
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
+ require 'deltacloud/base_driver/base_driver'
20
+ require 'deltacloud/base_driver/features'
@@ -0,0 +1,127 @@
1
+ #
2
+ # Copyright (C) 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
+
19
+ #Windows Azure (WAZ) gem at http://github.com/johnnyhalife/waz-storage
20
+ require 'waz-blobs'
21
+ require 'deltacloud/base_driver'
22
+ module Deltacloud
23
+ module Drivers
24
+ module Azure
25
+
26
+ class AzureDriver < Deltacloud::BaseDriver
27
+
28
+ def supported_collections; [:buckets]
29
+ end
30
+
31
+ #--
32
+ # Buckets
33
+ #--
34
+ def buckets(credentials, opts)
35
+ buckets = []
36
+ azure_connect(credentials)
37
+ safely do
38
+ WAZ::Blobs::Container.list.each do |waz_container|
39
+ buckets << convert_container(waz_container)
40
+ end
41
+ end
42
+ buckets = filter_on(buckets, :id, opts)
43
+ end
44
+
45
+ #--
46
+ # Create bucket
47
+ #--
48
+ def create_bucket(credentials, name, opts)
49
+ bucket = nil
50
+ azure_connect(credentials)
51
+ safely do
52
+ waz_container = WAZ::Blobs::Container.create(name)
53
+ bucket = convert_container(waz_container)
54
+ end
55
+ bucket
56
+ end
57
+
58
+ #--
59
+ # Delete bucket
60
+ #--
61
+ def delete_bucket(credentials, name, opts)
62
+ azure_connect(credentials)
63
+ safely do
64
+ WAZ::Blobs::Container.find(name).destroy!
65
+ end
66
+ end
67
+
68
+ #--
69
+ # Blobs
70
+ #--
71
+ def blobs(credentials, opts)
72
+ blob_list = []
73
+ azure_connect(credentials)
74
+ safely do
75
+ the_bucket = WAZ::Blobs::Container.find(opts['bucket'])
76
+ the_bucket.blobs.each do |waz_blob|
77
+ blob_list << convert_blob(waz_blob)
78
+ end
79
+ end
80
+ blob_list = filter_on(blob_list, :id, opts)
81
+ blob_list
82
+ end
83
+
84
+ def blob_data(credentials, bucket_id, blob_id, opts)
85
+ azure_connect(credentials)
86
+ # WAZ get blob data methods cant accept blocks for 'streaming'... FIXME
87
+ yield WAZ::Blobs::Container.find(bucket_id)[blob_id].value
88
+ end
89
+
90
+ private
91
+
92
+ def azure_connect(credentials)
93
+ options = {:account_name => credentials.user, :access_key => credentials.password}
94
+ safely do
95
+ WAZ::Storage::Base.establish_connection!(options)
96
+ end
97
+ end
98
+
99
+ def convert_container(waz_container)
100
+ blob_list = []
101
+ waz_container.blobs.each do |blob|
102
+ blob_list << blob.name
103
+ end
104
+ Bucket.new({ :id => waz_container.name,
105
+ :name => waz_container.name,
106
+ :size => blob_list.size,
107
+ :blob_list => blob_list
108
+ })
109
+ end
110
+
111
+ def convert_blob(waz_blob)
112
+ url = waz_blob.url.split('/')
113
+ bucket = url[url.length-2] #FIXME
114
+ Blob.new({ :id => waz_blob.name,
115
+ :bucket => bucket,
116
+ :content_length => waz_blob.metadata[:content_length],
117
+ :content_type => waz_blob.metadata[:content_type],
118
+ :last_modified => waz_blob.metadata[:last_modified]
119
+ })
120
+ end
121
+
122
+
123
+ end
124
+
125
+ end #module Azure
126
+ end #module Drivers
127
+ end #module Deltacloud