Class: Visor::Meta::Server

Inherits:
Sinatra::Base
  • Object
show all
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

Instance Method Details

#delete('/images/: id') ⇒ JSON

Delete an image metadata and returns it.

Parameters:

  • id (String)

    The image _id to delete.

Returns:

  • (JSON)

    The already deleted image detailed metadata.

Raises:

  • (HTTP Error 404)

    If image not found.



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.message
  rescue => e
    json_error 500, e.message
  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.

Parameters:

  • name (String)

    The image name.

  • architecture (String)

    The image architecture.

  • type (String)

    The image type.

  • format (String)

    The image format.

  • store (String)

    The image store.

  • size (Fixnum)

    The image size.

  • created_at (Date)

    The image creation timestamp.

  • sort (String)

    (‘_id’) The image attribute to sort results.

  • dir (String)

    (‘asc’) The sorting order (‘asc’/‘desc’).

Returns:

  • (JSON)

    The public images brief metadata.

Raises:

  • (HTTP Error 404)

    If there is no public images.



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.message
  rescue => e
    json_error 500, e.message
  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.

Parameters:

  • name (String)

    The image name.

  • architecture (String)

    The image architecture.

  • access (String)

    The image access permission.

  • type (String)

    The image type.

  • format (String)

    The image format.

  • store (String)

    The image store.

  • size (Fixnum)

    The image size.

  • created_at (Date)

    The image creation timestamp.

  • updated_at (Date)

    The image update timestamp.

  • kernel (String)

    The image associated kernel image’s _id.

  • ramdisk (String)

    The image associated kernel image’s _id.

  • sort (String)

    (_id) The image attribute to sort results.

  • dir (String)

    (‘asc’) The sorting order (‘asc’/‘desc’).

Returns:

  • (JSON)

    The public images detailed metadata.

Raises:

  • (HTTP Error 404)

    If there is no public images.



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.message
  rescue => e
    json_error 500, e.message
  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>,
    ...
}}

Parameters:

  • id (String)

    The wanted image _id.

Returns:

  • (JSON)

    The image detailed metadata.

Raises:

  • (HTTP Error 404)

    If image not found.



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.message
  rescue => e
    json_error 500, e.message
  end
end

#post('/images') ⇒ JSON

Create a new image metadata and returns it.

Parameters:

  • http-body (JSON)

    The image metadata.

Returns:

  • (JSON)

    The already created image detailed metadata.

Raises:

  • (HTTP Error 400)

    Image metadata validation errors.



208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/meta/server.rb', line 208

post '/images' do
  begin
    meta  = JSON.parse(request.body.read, @parse_opts)
    image = DB.post_image(meta[:image])
    {image: image}.to_json
  rescue NotFound => e
    json_error 404, e.message
  rescue ArgumentError => e
    json_error 400, e.message
  rescue => e
    json_error 500, e.message
  end
end

#put('/images/: id') ⇒ JSON

Update an existing image metadata and return it.

Parameters:

  • id (String)

    The wanted image _id.

  • http-body (JSON)

    The image metadata.

Returns:

  • (JSON)

    The already updated image detailed metadata.

Raises:

  • (HTTP Error 400)

    Image metadata update validation errors.



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
    meta  = JSON.parse(request.body.read, @parse_opts)
    image = DB.put_image(id, meta[:image])
    {image: image}.to_json
  rescue NotFound => e
    json_error 404, e.message
  rescue ArgumentError => e
    json_error 400, e.message
  rescue => e
    json_error 500, e.message
  end
end