Class: NetworkController

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

Overview

Controller class handling all network-related requests. Implements listing, retrieval, creation, deletion and triggering actions on network 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 /network/


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

def create
  network = request_occi_collection.resources.first
  network_location = backend_instance.network_create(network)

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

#deleteObject

DELETE /network/ DELETE /network/:id


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

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

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

#indexObject

GET /network/


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

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

  respond_with(@networks, options)
end

#partial_updateObject

POST /network/:id


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

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

#showObject

GET /network/:id


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

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

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

#triggerObject

POST /network/?action=:action POST /network/:id?action=:action


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/network_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.network_trigger_action(params[:id], ai)
  else
    result = backend_instance.network_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 /network/:id


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

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

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

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