Class: ForemanDatacenter::DevicesController

Inherits:
ApplicationController
  • Object
show all
Includes:
Foreman::Controller::AutoCompleteSearch
Defined in:
app/controllers/foreman_datacenter/devices_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



52
53
54
55
56
57
58
59
60
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 52

def create
  @device = Device.new(device_params)

  if @device.save
    process_success object: @device
  else
    process_error object: @device
  end
end

#destroyObject



70
71
72
73
74
75
76
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 70

def destroy
  if @device.destroy
    process_success success_redirect: "/datacenter/devices"
  else
    process_error object: @device
  end
end

#destroy_interfacesObject



103
104
105
106
107
108
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 103

def destroy_interfaces
  @device.non_management_interfaces.
    where(id: params[:interfaces]).
    destroy_all
  redirect_to device_url(@device)
end

#device_type_sizeObject



83
84
85
86
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 83

def device_type_size
  @device_type_id = params[:device_type_id]
  render partial: 'device_type_size'
end

#device_typesObject



78
79
80
81
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 78

def device_types
  @manufacturer_id = params[:manufacturer_id]
  render partial: 'device_types'
end

#editObject



47
48
49
50
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 47

def edit
  @device = Device.find(params[:id])
  populate_from_host
end

#for_rackObject



98
99
100
101
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 98

def for_rack
  @rack = ForemanDatacenter::Rack.find(params[:rack_id])
  render partial: 'for_rack'
end

#indexObject



15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 15

def index
  begin
    search = resource_base.search_for(params[:search], :order => params[:order])
  rescue => e
    error e.to_s
    search = resource_base.search_for ''
  end
  @devices = search.includes(:device_role, :device_type, :site, :rack).
    paginate(:page => params[:page], :per_page => params[:per_page])
end

#inventoryObject



39
40
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 39

def inventory
end

#newObject



42
43
44
45
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 42

def new
  @device = Device.new
  populate_from_host
end

#qr_codeObject



110
111
112
113
114
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 110

def qr_code
  send_data(generate_qr_code(@device),
            filename: "#{@device.name_without_fqdn}.qr.pdf",
            type: 'application/pdf')
end

#racksObject



88
89
90
91
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 88

def racks
  @site_id = params[:site_id]
  render partial: 'racks'
end

#showObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 26

def show
  @device = Device.includes(
    device_bays: [:installed_device],
    console_server_ports: [:console_port],
    power_outlets: [:power_port],
    console_ports: [:console_server_port],
    power_ports: [:power_outlet]
  ).find(params[:id])
  @current_user = User.current
  @commentable = @device
  @comment = Comment.new
end

#site_racksObject



93
94
95
96
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 93

def site_racks
  @site = Site.find(params[:site_id])
  render partial: 'site_racks'
end

#sync_interfaces_with_hostObject



116
117
118
119
120
121
122
123
124
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 116

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

#updateObject



62
63
64
65
66
67
68
# File 'app/controllers/foreman_datacenter/devices_controller.rb', line 62

def update
  if @device.update(device_params)
    process_success object: @device
  else
    process_error object: @device
  end
end