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.
259 260 261 262 263 264 265 266 267 268 |
# File 'lib/meta/server.rb', line 259 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.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/meta/server.rb', line 91 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.
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/meta/server.rb', line 146 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>,
...
}}
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/meta/server.rb', line 186 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.
208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/meta/server.rb', line 208 post '/images' do begin = JSON.parse(request.body.read, @parse_opts) image = DB.post_image([: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 |
#put('/images/: id') ⇒ JSON
Update an existing image metadata and return it.
234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/meta/server.rb', line 234 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 |