Class: ForemanDatacenter::DevicesController
- Inherits:
-
ApplicationController
show all
- Includes:
- Foreman::Controller::AutoCompleteSearch, Controller::Parameters::Device
- Defined in:
- app/controllers/foreman_datacenter/devices_controller.rb
Instance Method Summary
collapse
#action_permission, #controller_permission, #find_resource, #not_found, #resource_class, #resource_class_for, #resource_finder, #resource_name, #resource_scope, #scope_for
Instance Method Details
#create ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 47
def create
@device = ForemanDatacenter::Device.new(device_params.merge(host_id: params[:host_id]))
if @device.save
process_success success_redirect: device_url(@device)
else
process_error object: @device
end
end
|
#destroy ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 65
def destroy
unless params['object_only']
if @device.destroy
process_success success_redirect: "/datacenter/devices"
else
process_error object: @device
end
else
if @device.host
@device.host.destroy
new_device_name = "Unassigned device (former: #{@device.name})"
@device.update(name: new_device_name)
process_success success_redirect: '/datacenter/devices', success_msg: 'Associated host deleted'
else
process_error success_redirect: '/datacenter/devices', error_msg: 'Associated host not found'
end
end
end
|
#destroy_interfaces ⇒ Object
109
110
111
112
113
114
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 109
def destroy_interfaces
@device.non_management_interfaces.
where(id: params[:interfaces]).
destroy_all
redirect_to device_url(@device)
end
|
#device_type_size ⇒ Object
89
90
91
92
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 89
def device_type_size
@device_type_id = params[:device_type_id]
render partial: 'device_type_size'
end
|
#device_types ⇒ Object
84
85
86
87
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 84
def device_types
@manufacturer_id = params[:manufacturer_id]
render partial: 'device_types'
end
|
#edit ⇒ Object
42
43
44
45
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 42
def edit
@device = ForemanDatacenter::Device.find(params[:id])
populate_from_host
end
|
#for_rack ⇒ Object
104
105
106
107
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 104
def for_rack
@rack = ForemanDatacenter::Rack.find(params[:rack_id])
render partial: 'for_rack'
end
|
#index ⇒ Object
14
15
16
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 14
def index
@devices = resource_base_search_and_page.includes(:device_role, :device_type, :site, :rack)
end
|
#inventory ⇒ Object
34
35
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 34
def inventory
end
|
#new ⇒ Object
37
38
39
40
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 37
def new
@device = ForemanDatacenter::Device.new
populate_from_host
end
|
#qr_code ⇒ Object
116
117
118
119
120
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 116
def qr_code
send_data(generate_qr_code(@device),
filename: "#{@device.name_without_fqdn}.qr.pdf",
type: 'application/pdf')
end
|
#racks ⇒ Object
94
95
96
97
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 94
def racks
@site_id = params[:site_id]
render partial: 'racks'
end
|
#show ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 18
def show
@device = ForemanDatacenter::Device.includes(
power_ports: [:power_outlet, :device],
power_outlets: [:device, :power_port],
console_ports: [:console_server_port, :device],
console_server_ports: [:console_port, :device],
device_bays: [:installed_device],
comments: [:user]
).find(params[:id])
@comments = @device.
@commentable = @device
@comment = ForemanDatacenter::Comment.new
@resource = request.path.split('/')[2]
@current_user = current_user
end
|
#site_racks ⇒ Object
99
100
101
102
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 99
def site_racks
@site = ForemanDatacenter::Site.find(params[:site_id])
render partial: 'site_racks'
end
|
#sync_interfaces_with_host ⇒ Object
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 122
def sync_interfaces_with_host
if @device.sync_interfaces_with_host
notice("Device successfully synchronized.")
redirect_to device_url(@device)
else
error("Unsuccessful synchronization.")
redirect_to device_url(@device)
end
end
|
#update ⇒ Object
57
58
59
60
61
62
63
|
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 57
def update
if @device.update(device_params)
process_success object: @device
else
process_error object: @device
end
end
|