Class: Visor::Meta::Server
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Visor::Meta::Server
- Includes:
- Common::Config, Common::Exception
- Defined in:
- lib/meta/server.rb
Overview
The VISoR Meta Server class. This class supports all image metadata manipulation operations through the VISoR REST API implemented along the following routes.
After initialize the Server its possible to directly interact with the meta backend.
Instance Method Summary collapse
-
#delete('/images/: id') ⇒ JSON
Delete an image metadata and returns it.
-
#get('/images') ⇒ JSON
Get brief information about all public images.
-
#get('/images/detail') ⇒ JSON
Get detailed information about all public images.
-
#get('/images/: id') ⇒ JSON
Get detailed information about a specific image.
-
#post('/images') ⇒ JSON
Create a new image metadata and returns it.
-
#put('/images/: id') ⇒ JSON
Update an existing image metadata and return it.
Instance Method Details
#delete('/images/: id') ⇒ JSON
Delete an image metadata and returns it.
270 271 272 273 274 275 276 277 278 279 |
# File 'lib/meta/server.rb', line 270 delete '/images/:id' do begin image = DB.delete_image(params[:id]) {image: image}.to_json rescue NotFound => e json_error 404, e. rescue => e json_error 500, e. end end |
#get('/images') ⇒ JSON
Get brief information about all public images.
{ "images": [{
"_id":<_id>,
"uri":<uri>,
"name":<name>,
"architecture":<architecture>,
"type":<type>,
"format":<format>,
"store":<type>,
"size":<size>,
"created_at":<creation timestamp>
}, ...]}
The following options can be passed as query parameters, plus any other additional image attribute not defined in the schema.
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/meta/server.rb', line 101 get '/images' do begin images = DB.get_public_images(true, params) {images: images}.to_json rescue NotFound => e json_error 404, e. rescue => e json_error 500, e. end end |
#get('/images/detail') ⇒ JSON
Get detailed information about all public images.
{"images": [{
"_id":<_id>,
"uri":<uri>,
"name":<name>,
"architecture":<architecture>,
"access":<access>,
"status":<status>,
"size":<size>,
"type":<type>,
"format":<format>,
"store":<store>,
"created_at":<timestamp>
"updated_at":<timestamp>,
"kernel":<associated kernel>,
"ramdisk":<associated ramdisk>,
...
}, ...]}
The following options can be passed as query parameters, plus any other additional image attribute not defined in the schema.
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/meta/server.rb', line 156 get '/images/detail' do begin images = DB.get_public_images(false, params) {images: images}.to_json rescue NotFound => e json_error 404, e. rescue => e json_error 500, e. end end |
#get('/images/: id') ⇒ JSON
Get detailed information about a specific image.
{"image": {
"_id":<_id>,
"uri":<uri>,
"name":<name>,
"architecture":<architecture>,
"access":<access>,
"status":<status>,
"size":<size>,
"type":<type>,
"format":<format>,
"store":<type>,
"created_at":<creation timestamp>
"updated_at":<update timestamp>,
"kernel":<associated kernel>,
"ramdisk":<associated ramdisk>,
...
}}
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/meta/server.rb', line 196 get '/images/:id' do |id| begin image = DB.get_image(id) {image: image}.to_json rescue NotFound => e json_error 404, e. rescue => e json_error 500, e. end end |
#post('/images') ⇒ JSON
Create a new image metadata and returns it.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/meta/server.rb', line 218 post '/images' do begin = JSON.parse(request.body.read, @parse_opts) vis_address = request.user_agent ? request.user_agent.split(' - ').last : nil image = DB.post_image([:image], :vis_address => vis_address) {image: image}.to_json rescue NotFound => e json_error 404, e. rescue ArgumentError => e json_error 400, e. rescue => e json_error 500, e. end end |
#put('/images/: id') ⇒ JSON
Update an existing image metadata and return it.
245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/meta/server.rb', line 245 put '/images/:id' do |id| begin = JSON.parse(request.body.read, @parse_opts) image = DB.put_image(id, [:image]) {image: image}.to_json rescue NotFound => e json_error 404, e. rescue ArgumentError => e json_error 400, e. rescue => e json_error 500, e. end end |