Class: StorageController

Inherits:
ApplicationController show all
Defined in:
app/controllers/storage_controller.rb

Overview

Controller class handling all storage-related requests. Implements listing, retrieval, creation, deletion and triggering actions on storage instances.

Constant Summary

Constants inherited from ApplicationController

ApplicationController::INDEX_LINK_FORMATS

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate!, #current_user, #request_occi_collection, #warden

Methods included from Mixins::ErrorHandling

#handle_auth_err, #handle_authz_err, #handle_backend_unavailable_err, #handle_internal_backend_err, #handle_invalid_resource_err, #handle_not_impl_err, #handle_parser_input_err, #handle_parser_type_err, #handle_resource_not_found_err, #handle_wrong_args_err

Instance Method Details

#createObject

POST /storage/


35
36
37
38
39
40
# File 'app/controllers/storage_controller.rb', line 35

def create
  storage = request_occi_collection.resources.first
  storage_location = backend_instance.storage_create(storage)

  respond_with("#{server_url}/storage/#{storage_location}", status: 201, flag: :link_only)
end

#deleteObject

DELETE /storage/ DELETE /storage/:id


90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/storage_controller.rb', line 90

def delete
  if params[:id]
    result = backend_instance.storage_delete(params[:id])
  else
    result = backend_instance.storage_delete_all
  end

  if result
    respond_with(Occi::Collection.new)
  else
    respond_with(Occi::Collection.new, status: 304)
  end
end

#indexObject

GET /storage/


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/storage_controller.rb', line 6

def index
  if INDEX_LINK_FORMATS.include?(request.format)
    @storages = backend_instance.storage_list_ids
    @storages.map! { |c| "#{server_url}/storage/#{c}" }
    options = { flag: :links_only }
  else
    @storages = Occi::Collection.new
    @storages.resources = backend_instance.storage_list
    update_mixins_in_coll(@storages)
    options = {}
  end

  respond_with(@storages, options)
end

#partial_updateObject

POST /storage/:id


62
63
64
65
# File 'app/controllers/storage_controller.rb', line 62

def partial_update
  # TODO: impl
  respond_with(Occi::Collection.new, status: 501)
end

#showObject

GET /storage/:id


22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/storage_controller.rb', line 22

def show
  @storage = Occi::Collection.new
  @storage << backend_instance.storage_get(params[:id])

  unless @storage.empty?
    update_mixins_in_coll(@storage)
    respond_with(@storage)
  else
    respond_with(Occi::Collection.new, status: 404)
  end
end

#triggerObject

POST /storage/?action=:action POST /storage/:id?action=:action


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/storage_controller.rb', line 44

def trigger
  ai = request_occi_collection(Occi::Core::ActionInstance).action
  check_ai!(ai, request.query_string)

  if params[:id]
    result = backend_instance.storage_trigger_action(params[:id], ai)
  else
    result = backend_instance.storage_trigger_action_on_all(ai)
  end

  if result
    respond_with(Occi::Collection.new)
  else
    respond_with(Occi::Collection.new, status: 304)
  end
end

#updateObject

PUT /storage/:id


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/storage_controller.rb', line 68

def update
  storage = request_occi_collection.resources.first
  storage.id = params[:id] if storage
  result = backend_instance.storage_update(storage)

  if result
    storage = Occi::Collection.new
    storage << backend_instance.storage_get(params[:id])

    unless storage.empty?
      update_mixins_in_coll(storage)
      respond_with(storage)
    else
      respond_with(Occi::Collection.new, status: 404)
    end
  else
    respond_with(Occi::Collection.new, status: 304)
  end
end