deltacloud-core 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. data/LICENSE +145 -0
  2. data/NOTICE +10 -1
  3. data/Rakefile +50 -2
  4. data/bin/deltacloudd +111 -14
  5. data/config/addresses.xml +14 -0
  6. data/config/condor.yaml +30 -0
  7. data/config/drivers/azure.yaml +3 -0
  8. data/config/drivers/condor.yaml +3 -0
  9. data/config/{drivers.yaml → drivers/ec2.yaml} +5 -34
  10. data/config/drivers/eucalyptus.yaml +8 -0
  11. data/config/drivers/gogrid.yaml +3 -0
  12. data/config/drivers/mock.yaml +3 -0
  13. data/config/drivers/opennebula.yaml +4 -0
  14. data/config/drivers/rackspace.yaml +3 -0
  15. data/config/drivers/rhevm.yaml +3 -0
  16. data/config/drivers/rimuhosting.yaml +3 -0
  17. data/config/drivers/sbc.yaml +2 -0
  18. data/config/drivers/terremark.yaml +3 -0
  19. data/config/drivers/vsphere.yaml +8 -0
  20. data/deltacloud-core.gemspec +13 -5
  21. data/deltacloud.rb +4 -2
  22. data/lib/deltacloud/backend_capability.rb +2 -2
  23. data/lib/deltacloud/base_driver/base_driver.rb +23 -52
  24. data/lib/deltacloud/base_driver/exceptions.rb +168 -0
  25. data/lib/deltacloud/base_driver/features.rb +31 -12
  26. data/lib/deltacloud/base_driver/mock_driver.rb +2 -1
  27. data/lib/deltacloud/core_ext/string.rb +2 -0
  28. data/lib/deltacloud/drivers/azure/azure_driver.rb +5 -5
  29. data/lib/deltacloud/drivers/condor/condor_client.rb +273 -0
  30. data/lib/deltacloud/drivers/condor/condor_driver.rb +236 -0
  31. data/lib/deltacloud/drivers/condor/ip_agents/confserver.rb +75 -0
  32. data/lib/deltacloud/drivers/condor/ip_agents/default.rb +84 -0
  33. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +326 -95
  34. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +3 -3
  35. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +40 -8
  36. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +7 -7
  37. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +42 -25
  38. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob1.yml +6 -4
  39. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob2.yml +7 -5
  40. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob3.yml +6 -4
  41. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob4.yml +6 -4
  42. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob5.yml +6 -4
  43. data/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml +7 -1
  44. data/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml +6 -1
  45. data/lib/deltacloud/drivers/mock/data/images/img1.yml +6 -2
  46. data/lib/deltacloud/drivers/mock/data/images/img2.yml +6 -2
  47. data/lib/deltacloud/drivers/mock/data/images/img3.yml +6 -2
  48. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +11 -10
  49. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +14 -7
  50. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +14 -7
  51. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +3 -2
  52. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +3 -2
  53. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +3 -2
  54. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +4 -3
  55. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +4 -3
  56. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +4 -3
  57. data/lib/deltacloud/drivers/mock/mock_client.rb +101 -0
  58. data/lib/deltacloud/drivers/mock/mock_driver.rb +367 -429
  59. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -0
  60. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +59 -9
  61. data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +62 -8
  62. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +100 -45
  63. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +3 -2
  64. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +8 -11
  65. data/lib/deltacloud/drivers/sbc/sbc_client.rb +6 -6
  66. data/lib/deltacloud/drivers/sbc/sbc_driver.rb +16 -0
  67. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +17 -12
  68. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +140 -0
  69. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +405 -0
  70. data/lib/deltacloud/drivers/vsphere/vsphere_filemanager.rb +182 -0
  71. data/lib/deltacloud/hardware_profile.rb +1 -1
  72. data/lib/deltacloud/helpers.rb +2 -1
  73. data/lib/deltacloud/helpers/application_helper.rb +92 -20
  74. data/lib/deltacloud/helpers/blob_stream.rb +160 -12
  75. data/lib/deltacloud/helpers/conversion_helper.rb +6 -2
  76. data/lib/deltacloud/helpers/json_helper.rb +31 -0
  77. data/lib/deltacloud/models/address.rb +28 -0
  78. data/lib/deltacloud/models/base_model.rb +5 -1
  79. data/lib/deltacloud/models/blob.rb +1 -1
  80. data/lib/deltacloud/models/bucket.rb +10 -0
  81. data/lib/deltacloud/models/firewall.rb +22 -0
  82. data/lib/deltacloud/models/firewall_rule.rb +23 -0
  83. data/lib/deltacloud/models/image.rb +12 -0
  84. data/lib/deltacloud/models/instance.rb +20 -2
  85. data/lib/deltacloud/models/key.rb +1 -1
  86. data/lib/deltacloud/runner.rb +3 -3
  87. data/lib/deltacloud/validation.rb +3 -7
  88. data/lib/drivers.rb +7 -1
  89. data/lib/sinatra/body_proxy.rb +34 -0
  90. data/lib/sinatra/lazy_auth.rb +5 -0
  91. data/lib/sinatra/rabbit.rb +54 -31
  92. data/lib/sinatra/rack_accept.rb +157 -0
  93. data/lib/sinatra/rack_date.rb +38 -0
  94. data/lib/sinatra/rack_etag.rb +2 -3
  95. data/lib/sinatra/rack_matrix_params.rb +51 -29
  96. data/lib/sinatra/rack_runtime.rb +1 -1
  97. data/lib/sinatra/rack_syslog.rb +86 -0
  98. data/lib/sinatra/url_for.rb +14 -1
  99. data/public/images/address.png +0 -0
  100. data/public/images/balancer.png +0 -0
  101. data/public/images/blob.png +0 -0
  102. data/public/images/bucket.png +0 -0
  103. data/public/images/cloud.png +0 -0
  104. data/public/images/firewall.png +0 -0
  105. data/public/images/image.png +0 -0
  106. data/public/images/key.png +0 -0
  107. data/public/images/machine.png +0 -0
  108. data/public/images/profile.png +0 -0
  109. data/public/images/realm.png +0 -0
  110. data/public/images/snapshot.png +0 -0
  111. data/public/images/volume.png +0 -0
  112. data/public/javascripts/application.js +119 -16
  113. data/public/javascripts/jquery.min.js +18 -0
  114. data/public/javascripts/jquery.mobile-1.0b1.min.js +146 -0
  115. data/public/stylesheets/compiled/application.css +8 -0
  116. data/public/stylesheets/images/ajax-loader.png +0 -0
  117. data/public/{images → stylesheets/images}/bread-bg.png +0 -0
  118. data/public/{images → stylesheets/images}/error.png +0 -0
  119. data/public/{images → stylesheets/images}/grid.png +0 -0
  120. data/public/stylesheets/images/icon-search-black.png +0 -0
  121. data/public/stylesheets/images/icons-18-black.png +0 -0
  122. data/public/stylesheets/images/icons-18-white.png +0 -0
  123. data/public/stylesheets/images/icons-36-black.png +0 -0
  124. data/public/stylesheets/images/icons-36-white.png +0 -0
  125. data/public/{images → stylesheets/images}/logo-wide.png +0 -0
  126. data/public/{images → stylesheets/images}/pending.png +0 -0
  127. data/public/{images → stylesheets/images}/rails.png +0 -0
  128. data/public/{images → stylesheets/images}/running.png +0 -0
  129. data/public/{images → stylesheets/images}/stopped.png +0 -0
  130. data/public/{images → stylesheets/images}/topbar-bg.png +0 -0
  131. data/public/stylesheets/jquery.mobile-1.0b1.min.css +8 -0
  132. data/public/stylesheets/new.css +53 -0
  133. data/server.rb +487 -175
  134. data/support/condor/bash/cached_images.sh +8 -0
  135. data/support/condor/bash/cloud_exit_hook.sh +17 -0
  136. data/support/condor/bash/cloud_functions +175 -0
  137. data/support/condor/bash/cloud_prepare_hook.sh +20 -0
  138. data/support/condor/bash/libvirt_cloud_script.sh +13 -0
  139. data/support/condor/config/50condor_cloud.config +37 -0
  140. data/support/condor/config/50condor_cloud_node.config +37 -0
  141. data/support/condor/config/condor-cloud +2 -0
  142. data/support/condor/config/condor_config.local +44 -0
  143. data/support/fedora/deltacloud-core +48 -26
  144. data/support/fedora/deltacloud-core-config +26 -0
  145. data/support/fedora/deltacloud-core.spec +314 -68
  146. data/support/fedora/deltacloudd-fedora +5 -0
  147. data/tests/common.rb +34 -4
  148. data/tests/drivers/mock/api_test.rb +3 -3
  149. data/tests/drivers/mock/images_test.rb +12 -0
  150. data/tests/drivers/mock/instances_test.rb +2 -0
  151. data/tests/rabbit_test.rb +2 -2
  152. data/views/addresses/_address.html.haml +6 -0
  153. data/views/addresses/associate.html.haml +12 -0
  154. data/views/addresses/index.html.haml +9 -0
  155. data/views/addresses/index.xml.haml +4 -0
  156. data/views/addresses/show.html.haml +21 -0
  157. data/views/addresses/show.xml.haml +14 -0
  158. data/views/api/show.html.haml +6 -11
  159. data/views/api/show.xml.haml +2 -0
  160. data/views/blobs/new.html.haml +24 -23
  161. data/views/blobs/show.html.haml +30 -31
  162. data/views/buckets/index.html.haml +9 -21
  163. data/views/buckets/index.xml.haml +3 -7
  164. data/views/buckets/new.html.haml +13 -12
  165. data/views/buckets/show.html.haml +22 -22
  166. data/views/buckets/show.xml.haml +5 -3
  167. data/views/docs/collection.html.haml +23 -34
  168. data/views/docs/collection.xml.haml +2 -2
  169. data/views/docs/index.html.haml +9 -13
  170. data/views/docs/index.xml.haml +1 -1
  171. data/views/docs/operation.html.haml +28 -38
  172. data/views/docs/operation.xml.haml +1 -1
  173. data/views/drivers/index.html.haml +8 -13
  174. data/views/drivers/show.html.haml +18 -18
  175. data/views/error.html.haml +32 -27
  176. data/views/errors/400.html.haml +41 -0
  177. data/views/errors/{validation_failure.xml.haml → 400.xml.haml} +0 -4
  178. data/views/errors/401.html.haml +41 -0
  179. data/views/errors/{auth_exception.xml.haml → 401.xml.haml} +0 -0
  180. data/views/errors/403.html.haml +42 -0
  181. data/views/errors/{not_allowed.xml.haml → 403.xml.haml} +0 -0
  182. data/views/errors/404.html.haml +29 -0
  183. data/views/errors/{not_found.xml.haml → 404.xml.haml} +1 -1
  184. data/views/errors/405.html.haml +29 -0
  185. data/views/errors/405.xml.haml +5 -0
  186. data/views/errors/500.html.haml +43 -0
  187. data/views/errors/500.xml.haml +5 -0
  188. data/views/errors/502.html.haml +43 -0
  189. data/views/errors/{backend_error.xml.haml → 502.xml.haml} +1 -2
  190. data/views/errors/backend_capability_failure.html.haml +27 -9
  191. data/views/firewalls/index.html.haml +15 -0
  192. data/views/firewalls/index.xml.haml +28 -0
  193. data/views/firewalls/new.html.haml +11 -0
  194. data/views/firewalls/new_rule.html.haml +20 -0
  195. data/views/firewalls/show.html.haml +42 -0
  196. data/views/firewalls/show.xml.haml +26 -0
  197. data/views/hardware_profiles/index.html.haml +15 -23
  198. data/views/hardware_profiles/show.html.haml +22 -18
  199. data/views/images/index.html.haml +11 -23
  200. data/views/images/index.xml.haml +4 -13
  201. data/views/images/new.html.haml +12 -13
  202. data/views/images/show.html.haml +26 -20
  203. data/views/images/show.xml.haml +2 -1
  204. data/views/instance_states/show.html.haml +21 -25
  205. data/views/instances/index.html.haml +13 -30
  206. data/views/instances/index.xml.haml +2 -23
  207. data/views/instances/new.html.haml +83 -88
  208. data/views/instances/show.html.haml +53 -55
  209. data/views/instances/show.xml.haml +12 -10
  210. data/views/keys/index.html.haml +13 -24
  211. data/views/keys/new.html.haml +7 -7
  212. data/views/keys/show.html.haml +26 -21
  213. data/views/layout.html.haml +28 -27
  214. data/views/load_balancers/index.html.haml +11 -31
  215. data/views/load_balancers/index.xml.haml +0 -1
  216. data/views/load_balancers/new.html.haml +1 -1
  217. data/views/load_balancers/show.html.haml +33 -34
  218. data/views/load_balancers/show.xml.haml +2 -2
  219. data/views/realms/index.html.haml +11 -24
  220. data/views/realms/index.xml.haml +2 -8
  221. data/views/realms/show.html.haml +17 -15
  222. data/views/realms/show.xml.haml +2 -1
  223. data/views/storage_snapshots/index.html.haml +11 -21
  224. data/views/storage_snapshots/index.xml.haml +2 -5
  225. data/views/storage_snapshots/new.html.haml +1 -1
  226. data/views/storage_snapshots/show.html.haml +21 -13
  227. data/views/storage_snapshots/show.xml.haml +2 -1
  228. data/views/storage_volumes/index.html.haml +11 -34
  229. data/views/storage_volumes/new.html.haml +1 -1
  230. data/views/storage_volumes/show.html.haml +33 -27
  231. data/views/storage_volumes/show.xml.haml +2 -1
  232. metadata +266 -178
  233. data/lib/sinatra/respond_to.rb +0 -248
  234. data/support/fedora/deltacloudd +0 -128
  235. data/support/fedora/rubygem-deltacloud-core.spec +0 -127
  236. data/views/accounts/index.html.haml +0 -11
  237. data/views/accounts/show.html.haml +0 -30
  238. data/views/errors/auth_exception.html.haml +0 -8
  239. data/views/errors/backend_error.html.haml +0 -22
  240. data/views/errors/not_allowed.html.haml +0 -6
  241. data/views/errors/not_found.html.haml +0 -6
  242. data/views/errors/validation_failure.html.haml +0 -11
@@ -1,248 +0,0 @@
1
- # respond_to (The MIT License)
2
-
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4
- # and associated documentation files (the 'Software'), to deal in the Software without restriction,
5
- # including without limitation the rights to use, copy, modify, merge, publish, distribute,
6
- # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
7
- # furnished to do so, subject to the following conditions:
8
- #
9
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
10
- # NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
12
- # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
13
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
14
-
15
- require 'sinatra/base'
16
- require 'rack/accept'
17
-
18
- use Rack::Accept
19
-
20
- module Sinatra
21
- module RespondTo
22
-
23
- class MissingTemplate < Sinatra::NotFound; end
24
-
25
- # Define all MIME types you want to support here.
26
- # This conversion table will be used for auto-negotiation
27
- # with browser in sinatra when no 'format' parameter is specified.
28
-
29
- SUPPORTED_ACCEPT_HEADERS = {
30
- :xml => [
31
- 'text/xml',
32
- 'application/xml'
33
- ],
34
- :html => [
35
- 'text/html',
36
- 'application/xhtml+xml'
37
- ],
38
- :json => [
39
- 'application/json'
40
- ]
41
- }
42
-
43
- # We need to pass array of available response types to
44
- # best_media_type method
45
- def accept_to_array
46
- SUPPORTED_ACCEPT_HEADERS.keys.collect do |key|
47
- SUPPORTED_ACCEPT_HEADERS[key]
48
- end.flatten
49
- end
50
-
51
- # Then, when we get best media type for response, we need
52
- # to know which format to choose
53
- def lookup_format_from_mime(mime)
54
- SUPPORTED_ACCEPT_HEADERS.keys.each do |format|
55
- return format if SUPPORTED_ACCEPT_HEADERS[format].include?(mime)
56
- end
57
- end
58
-
59
- def self.registered(app)
60
-
61
- app.helpers RespondTo::Helpers
62
-
63
- app.before do
64
-
65
- # Skip development error image and static content
66
- next if self.class.development? && request.path_info =~ %r{/__sinatra__/.*?.png}
67
- next if options.static? && options.public? && (request.get? || request.head?) && static_file?(request.path_info)
68
-
69
- # Remove extension from URI
70
- # Extension will be available as a 'extension' method (extension=='txt')
71
-
72
- extension request.path_info.match(/\.([^\.\/]+)$/).to_a.first
73
-
74
- # If ?format= is present, ignore all Accept negotiations because
75
- # we are not dealing with browser
76
- if request.params.has_key? 'format'
77
- format params['format'].to_sym
78
- end
79
-
80
- # Let's make a little exception here to handle
81
- # /api/instance_states[.gv/.png] calls
82
- if extension.eql?('gv')
83
- format :gv
84
- elsif extension.eql?('png')
85
- format :png
86
- end
87
-
88
- # Get Rack::Accept::Response object and find best possible
89
- # mime type to output.
90
- # This negotiation works fine with latest rest-client gem:
91
- #
92
- # RestClient.get 'http://localhost:3001/api', {:accept => :json } =>
93
- # 'application/json'
94
- # RestClient.get 'http://localhost:3001/api', {:accept => :xml } =>
95
- # 'application/xml'
96
- #
97
- # Also browsers like Firefox (3.6.x) and Chromium reporting
98
- # 'application/xml+xhtml' which is recognized as :html reponse
99
- # In browser you can force output using ?format=[format] parameter.
100
-
101
- rack_accept = env['rack-accept.request']
102
-
103
- if rack_accept.media_type.to_s.strip.eql?('Accept:')
104
- format :xml
105
- elsif is_chrome?
106
- format :html
107
- else
108
- format lookup_format_from_mime(rack_accept.best_media_type(accept_to_array))
109
- end
110
-
111
- end
112
-
113
- app.class_eval do
114
-
115
- # Simple helper to detect Chrome based browsers
116
- # which have screwed up they Accept headers.
117
- # Set HTML as default output format here
118
- def is_chrome?
119
- true if env['HTTP_USER_AGENT'] =~ /Chrome/
120
- end
121
-
122
- # This code was copied from respond_to plugin
123
- # http://github.com/cehoffman/sinatra-respond_to
124
- # MIT License
125
- alias :render_without_format :render
126
- def render(*args, &block)
127
- assumed_layout = args[1] == :layout
128
- args[1] = "#{args[1]}.#{format}".to_sym if args[1].is_a?(::Symbol)
129
- render_without_format *args, &block
130
- rescue Errno::ENOENT => e
131
- raise MissingTemplate, "#{args[1]}.#{args[0]}" unless assumed_layout
132
- raise e
133
- end
134
- private :render
135
- end
136
-
137
- # This code was copied from respond_to plugin
138
- # http://github.com/cehoffman/sinatra-respond_to
139
- app.configure :development do |dev|
140
- dev.error MissingTemplate do
141
- content_type :html, :charset => 'utf-8'
142
- response.status = request.env['sinatra.error'].code
143
-
144
- engine = request.env['sinatra.error'].message.split('.').last
145
- engine = 'haml' unless ['haml', 'builder', 'erb'].include? engine
146
-
147
- path = File.basename(request.path_info)
148
- path = "root" if path.nil? || path.empty?
149
-
150
- format = engine == 'builder' ? 'xml' : 'html'
151
-
152
- layout = case engine
153
- when 'haml' then "!!!\n%html\n %body= yield"
154
- when 'erb' then "<html>\n <body>\n <%= yield %>\n </body>\n</html>"
155
- end
156
-
157
- layout = "<small>app.#{format}.#{engine}</small>\n<pre>#{escape_html(layout)}</pre>"
158
-
159
- (<<-HTML).gsub(/^ {10}/, '')
160
- <!DOCTYPE html>
161
- <html>
162
- <head>
163
- <style type="text/css">
164
- body { text-align:center;font-family:helvetica,arial;font-size:22px;
165
- color:#888;margin:20px}
166
- #c {margin:0 auto;width:500px;text-align:left;}
167
- small {float:right;clear:both;}
168
- pre {clear:both;text-align:left;font-size:70%;width:500px;margin:0 auto;}
169
- </style>
170
- </head>
171
- <body>
172
- <h2>Sinatra can't find #{request.env['sinatra.error'].message}</h2>
173
- <img src='/__sinatra__/500.png'>
174
- <pre>#{request.env['sinatra.error'].backtrace.join("\n")}</pre>
175
- <div id="c">
176
- <small>application.rb</small>
177
- <pre>#{request.request_method.downcase} '#{request.path_info}' do\n respond_to do |wants|\n wants.#{format} { #{engine} :#{path} }\n end\nend</pre>
178
- </div>
179
- </body>
180
- </html>
181
- HTML
182
- end
183
-
184
- end
185
- end
186
-
187
- module Helpers
188
-
189
- # This code was copied from respond_to plugin
190
- # http://github.com/cehoffman/sinatra-respond_to
191
- def self.included(klass)
192
- klass.class_eval do
193
- alias :content_type_without_save :content_type
194
- def content_type(*args)
195
- content_type_without_save *args
196
- @_format = args.first.to_sym
197
- response['Content-Type']
198
- end
199
- end
200
- end
201
-
202
- def static_file?(path)
203
- public_dir = File.expand_path(options.public)
204
- path = File.expand_path(File.join(public_dir, unescape(path)))
205
-
206
- path[0, public_dir.length] == public_dir && File.file?(path)
207
- end
208
-
209
-
210
- # Extension holds trimmed extension. This is extra usefull
211
- # when you want to build original URI (with extension)
212
- # You can simply call "#{request.env['REQUEST_URI']}.#{extension}"
213
- def extension(val=nil)
214
- @_extension ||= val
215
- @_extension
216
- end
217
-
218
- # This helper will holds current format. Helper should be
219
- # accesible from all places in Sinatra
220
- def format(val=nil)
221
- @_format ||= val
222
- @_format
223
- end
224
-
225
- def respond_to(&block)
226
- wants = {}
227
-
228
- def wants.method_missing(type, *args, &handler)
229
- self[type] = handler
230
- end
231
-
232
- # Set proper content-type and encoding for
233
- # text based formats
234
- if [:xml, :gv, :html, :json].include?(format)
235
- content_type format, :charset => 'utf-8'
236
- end
237
- yield wants
238
- # Raise this error if requested format is not defined
239
- # in respond_to { } block.
240
- raise MissingTemplate if wants[format].nil?
241
-
242
- wants[format].call
243
- end
244
-
245
- end
246
-
247
- end
248
- end
@@ -1,128 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'optparse'
5
-
6
- # See if we can require +name+ and return +true+ if the library is there,
7
- # +false+ otherwise. Note that, as a side effect, the library will be
8
- # loaded
9
- def library_present?(name)
10
- begin
11
- require name
12
- true
13
- rescue LoadError
14
- false
15
- end
16
- end
17
-
18
- options = {
19
- :env => 'development'
20
- }
21
- optparse = OptionParser.new do |opts|
22
-
23
- opts.banner = <<BANNER
24
- Usage:
25
- deltacloudd -i <driver> [options]
26
-
27
- Options:
28
- BANNER
29
- opts.on( '-i', '--driver DRIVER', 'Driver to use') do |driver|
30
- ENV["API_DRIVER"] = driver
31
- end
32
- opts.on( '-r', '--hostname HOSTNAME',
33
- 'Bind to HOST address (default: localhost)') do |host|
34
- ENV["API_HOST"] = host
35
- end
36
- opts.on( '-p', '--port PORT', 'Use PORT (default: 3001)') do |port|
37
- ENV["API_PORT"] = port
38
- end
39
- opts.on( '-P', '--provider PROVIDER', 'Use PROVIDER (default is set in the driver)') do |provider|
40
- ENV['API_PROVIDER'] = provider
41
- end
42
- opts.on( '-e', '--env ENV', 'Environment (default: "development")') { |env| options[:env] = env }
43
- opts.on( '-h', '--help', '') { options[:help] = true }
44
- end
45
-
46
- optparse.parse!
47
-
48
- if options[:help]
49
- puts optparse
50
- exit(0)
51
- end
52
-
53
- unless ENV["API_DRIVER"]
54
- puts "You need to specify a driver to use (-i <driver>)"
55
- exit(1)
56
- end
57
-
58
- ENV["API_HOST"] = "localhost" unless ENV["API_HOST"]
59
- ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
60
-
61
- msg = "Starting Deltacloud API :: #{ENV["API_DRIVER"]} "
62
- msg << ":: #{ENV['API_PROVIDER']} " if ENV['API_PROVIDER']
63
- msg << ":: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
64
- puts msg
65
- puts
66
-
67
- dirname="#{File.dirname(__FILE__)}/.."
68
-
69
- have_thin = library_present?('thin')
70
- have_rerun = library_present?('rerun')
71
-
72
- unless have_thin
73
- require 'rack'
74
-
75
- # We can't chdir with webrick so add our root directory
76
- # onto the load path
77
- $: << dirname
78
-
79
- # Read in config.ru and convert it to an instance of Rack::Builder
80
- cfgfile = File.read(File.join(dirname, 'config.ru'))
81
- inner_app = eval("Rack::Builder.new {(" + cfgfile + "\n )}.to_app",
82
- nil, 'config.ru')
83
-
84
- app = Rack::Builder.new {
85
- use Rack::CommonLogger # apache-like logging
86
- use Rack::Reloader if options[:env] == "development"
87
- set :root, dirname # Set Sinatra root since we can't chdir to ../
88
- run inner_app
89
- }.to_app
90
-
91
- # There's a bug with string ports on JRuby so convert to int
92
- # http://jira.codehaus.org/browse/JRUBY-4868
93
- port = ENV["API_PORT"].to_i
94
-
95
- puts "=> Ctrl-C to shutdown server"
96
- Rack::Handler::WEBrick.run(app,
97
- :Host => ENV["API_HOST"],
98
- :Port => port,
99
- :AccessLog => [])
100
- else
101
- argv_opts = ARGV.clone
102
- argv_opts << ['start'] unless Thin::Runner.commands.include?(options[0])
103
- argv_opts << ['--address', ENV["API_HOST"] ]
104
- argv_opts << ['--port', ENV["API_PORT"] ]
105
- argv_opts << ['--rackup', 'config.ru' ]
106
- argv_opts << ['--chdir', dirname ]
107
- argv_opts << ['-e', options[:env] ]
108
- argv_opts << ['--threaded', '-D', '--stats', '/stats']
109
-
110
- argv_opts.flatten!
111
-
112
- if have_rerun && options[:env] == "development"
113
- argv_opts.unshift "thin"
114
- command = argv_opts.join(" ")
115
- topdir = File::expand_path(File::join(File::dirname(__FILE__), ".."))
116
- rerun = Rerun::Runner.new(command, :dir => topdir)
117
- rerun.start
118
- rerun.join
119
- else
120
- thin = Thin::Runner.new(argv_opts)
121
-
122
- begin
123
- thin.run!
124
- rescue Exception => e
125
- puts "ERROR: #{e.message}"
126
- end
127
- end
128
- end
@@ -1,127 +0,0 @@
1
- %global ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
2
- %global gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
3
- %global gemname deltacloud-core
4
- %global geminstdir %{gemdir}/gems/%{gemname}-%{version}
5
-
6
- Summary: Deltacloud REST API
7
- Name: rubygem-%{gemname}
8
- Version: 0.3.0
9
- Release: 1%{?dist}
10
- Group: Development/Languages
11
- License: ASL 2.0 and MIT
12
- URL: http://incubator.apache.org/deltacloud
13
- Source0: http://gems.rubyforge.org/gems/%{gemname}-%{version}.gem
14
- BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
15
- Requires: rubygems
16
- Requires: ruby(abi) = 1.8
17
- Requires: rubygem(haml)
18
- Requires: rubygem(sinatra) >= 1.0
19
- Requires: rubygem(rack) >= 1.1.0
20
- Requires: rubygem(thin)
21
- Requires: rubygem(json) >= 1.4.0
22
- Requires(post): chkconfig
23
- Requires(preun): chkconfig
24
- Requires(preun): initscripts
25
- Requires(postun): initscripts
26
- BuildRequires: rubygems
27
- BuildRequires: ruby(abi) = 1.8
28
- BuildRequires: rubygem(json) >= 1.4.0
29
- BuildRequires: rubygem(rake) >= 0.8.7
30
- BuildRequires: rubygem(rack-test) >= 0.5.0
31
- BuildRequires: rubygem(rspec) >= 1.3.0
32
- BuildArch: noarch
33
- Provides: rubygem(%{gemname}) = %{version}
34
-
35
- %description
36
- The Deltacloud API is built as a service-based REST API.
37
- You do not directly link a Deltacloud library into your program to use it.
38
- Instead, a client speaks the Deltacloud API over HTTP to a server
39
- which implements the REST interface.
40
-
41
- %package doc
42
- Summary: Documentation for %{name}
43
- Group: Documentation
44
- Requires:%{name} = %{version}-%{release}
45
-
46
- %description doc
47
- Documentation for %{name}
48
-
49
- %prep
50
-
51
- %build
52
-
53
- %install
54
- rm -rf %{buildroot}
55
- mkdir -p %{buildroot}%{gemdir}
56
- mkdir -p %{buildroot}%{_initddir}
57
- gem install --local --install-dir %{buildroot}%{gemdir} \
58
- --force --rdoc %{SOURCE0}
59
- mkdir -p %{buildroot}/%{_bindir}
60
- mkdir -p %{buildroot}/config
61
- mv %{buildroot}%{gemdir}/bin/* %{buildroot}/%{_bindir}
62
- mv %{buildroot}%{geminstdir}/support/fedora/%{gemname} %{buildroot}%{_initddir}
63
- mv -f %{buildroot}%{geminstdir}/support/fedora/deltacloudd %{buildroot}%{geminstdir}/bin
64
- rmdir %{buildroot}%{gemdir}/bin
65
- find %{buildroot}%{geminstdir}/bin -type f | xargs chmod 755
66
- find %{buildroot}%{geminstdir}/lib -type f | xargs chmod -x
67
- chmod 755 %{buildroot}%{_initddir}/%{gemname}
68
-
69
- %check
70
- pushd %{geminstdir}
71
- rake test:mock
72
- popd
73
-
74
- %clean
75
- rm -rf %{buildroot}
76
-
77
- %post
78
- # This adds the proper /etc/rc*.d links for the script
79
- /sbin/chkconfig --add %{gemname}
80
-
81
- %preun
82
- if [ $1 -eq 0 ] ; then
83
- /sbin/service %{gemname} stop >/dev/null 2>&1
84
- /sbin/chkconfig --del %{gemname}
85
- fi
86
-
87
- %postun
88
- if [ "$1" -ge "1" ] ; then
89
- /sbin/service %{gemname} condrestart >/dev/null 2>&1 || :
90
- fi
91
-
92
- %files
93
- %defattr(-, root, root, -)
94
- %{_initddir}/%{gemname}
95
- %{_bindir}/deltacloudd
96
- %dir %{geminstdir}/
97
- %{geminstdir}/bin
98
- %{geminstdir}/LICENSE
99
- %{geminstdir}/NOTICE
100
- %{geminstdir}/DISCLAIMER
101
- %{geminstdir}/config.ru
102
- %{geminstdir}/*.rb
103
- %{geminstdir}/Rakefile
104
- %{geminstdir}/views
105
- %{geminstdir}/lib
106
- %{geminstdir}/public/images
107
- %{geminstdir}/public/stylesheets
108
- %{geminstdir}/public/favicon.ico
109
- %{gemdir}/cache/%{gemname}-%{version}.gem
110
- %{gemdir}/specifications/%{gemname}-%{version}.gemspec
111
- %{geminstdir}/config/drivers.yaml
112
- # MIT
113
- %{gemdir}/gems/%{gemname}-%{version}/public/javascripts
114
-
115
- %files doc
116
- %defattr(-, root, root, -)
117
- %{gemdir}/doc/%{gemname}-%{version}
118
- %{geminstdir}/tests
119
- %{geminstdir}/support
120
- %{geminstdir}/%{gemname}.gemspec
121
-
122
- %changelog
123
- * Fri Apr 8 2011 David Lutterkort <lutter@redhat.com> - 0.3.0-1
124
- - - Renamed COPYING to LICENSE, include NOTICE and DISCLAIMER
125
-
126
- * Mon Jan 31 2011 Michal Fojtik <mfojtik@redhat.com> - 0.2.0-1
127
- - Initial package