Class: Visor::Image::DeleteImage

Inherits:
Goliath::API
  • Object
show all
Includes:
Common::Exception, Common::Util
Defined in:
lib/image/routes/delete_image.rb

Overview

Delete the metadata and data of the image with the given id.

Instance Method Summary collapse

Instance Method Details

#exit_error(code, message) ⇒ Array

Produce an HTTP response with an error code and message.

Parameters:

  • code (Fixnum)

    The error code.

  • message (String)

    The error message.

Returns:

  • (Array)

    The HTTP response containing an error code and its message.



57
58
59
60
# File 'lib/image/routes/delete_image.rb', line 57

def exit_error(code, message)
  logger.error message
  [code, {}, {code: code, message: message}]
end

#on_headers(env, headers) ⇒ Object

Pre-process headers as they arrive and load them into a environment variable.

Parameters:

  • env (Object)

    The Goliath environment variables.

  • headers (Object)

    The incoming request HTTP headers.



18
19
20
21
# File 'lib/image/routes/delete_image.rb', line 18

def on_headers(env, headers)
  logger.debug "Received headers: #{headers.inspect}"
  env['headers'] = headers
end

#response(env) ⇒ Array

Query database to delete the wanted image based on its id.

Parameters:

  • env (Object)

    The Goliath environment variables.

Returns:

  • (Array)

    The HTTP response containing the image metadata or an error code and its messages if anything was raised.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/image/routes/delete_image.rb', line 30

def response(env)
  authorize(env, vas)
  meta = vms.delete_image(params[:id])
  uri  = meta[:location]
  name = meta[:store]

  if uri && name
    store = Visor::Image::Store.get_backend(uri, configs)
    store.delete unless name == 'http'
  end
rescue Forbidden => e
  exit_error(403, e.message)
rescue NotFound => e
  exit_error(404, e.message)
rescue InternalError => e
  exit_error(503, e.message)
else
  [200, {}, {image: meta}]
end