foreman_datacenter 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76f5b1abf0cce09777cce5f45036844100f191d1
4
- data.tar.gz: 0d0bb581e1af837951a9faca94fda6918b9f77cc
3
+ metadata.gz: 237e1187fd250aedb5db2a901227e9a757ef16de
4
+ data.tar.gz: 1407ecbf059c7999b2d37683285a6dbc876927d3
5
5
  SHA512:
6
- metadata.gz: 830efe9ae3bbf0a6a1835a95b86841f1c9751434454762f6c65075c707b7801e703640aa56edb242355511e5cbdaf7423c89202d9a1a4257996b39ed56b0dabc
7
- data.tar.gz: dccfa972aefe23c9aa20cf81ebfe9c1bdce4e14188f777e9012aeec8ed0e5e9e85a5993f8cddbe5a49934bf8348f054951685e471b3daf6a890f3cdb4e2f7daf
6
+ metadata.gz: 99207133a189b7b02cd1b76cf8aa14544488721827d8b708b0d9658c577ef7a974d3a3cc1c1ca8390fc7cc779a9c323cb4379ec447f3c510f3212e08e20ecd20
7
+ data.tar.gz: 059d935882e4df99db85195e1f42d10c02bb610314be4af9b9e561689c657cc7e32cdec0f06c55d728b8cf70a016e26dd57c1f936a50cb61ec7abf15fc620db1
@@ -3,7 +3,7 @@ module ForemanDatacenter
3
3
  before_action :set_device, only: [:update, :destroy, :inventory]
4
4
 
5
5
  def index
6
- @devices = Device.includes(:device_role, :device_type, rack: [:site]).
6
+ @devices = Device.includes(:ipmi_interface, :device_role, :device_type, rack: [:site]).
7
7
  paginate(:page => params[:page])
8
8
  end
9
9
 
@@ -0,0 +1,52 @@
1
+ module ForemanDatacenter
2
+ class ManagementDevicesController < ApplicationController
3
+ before_action :set_management_device, only: [:edit, :update, :destroy]
4
+
5
+ def new
6
+ device = Device.find(params[:device_id])
7
+ @management_device = ManagementDevice.new(device: device)
8
+ end
9
+
10
+ def edit
11
+ end
12
+
13
+ def create
14
+ @management_device = ManagementDevice.new(management_device_params)
15
+
16
+ if @management_device.save
17
+ redirect_to device_url(@management_device.device),
18
+ notice: 'New management device was successfully created'
19
+ else
20
+ process_error object: @management_device
21
+ end
22
+ end
23
+
24
+ def update
25
+ if @management_device.update(management_device_params)
26
+ redirect_to device_url(@management_device.device),
27
+ notice: 'Management device was successfully updated'
28
+ else
29
+ process_error object: @management_device
30
+ end
31
+ end
32
+
33
+ def destroy
34
+ if @management_device.destroy
35
+ redirect_to device_url(@management_device.device),
36
+ notice: 'Management device was successfully destroyed'
37
+ else
38
+ process_error object: @management_device
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def set_management_device
45
+ @management_device = ManagementDevice.find(params[:id])
46
+ end
47
+
48
+ def management_device_params
49
+ params[:management_device].permit(:device_id, :name, :login, :password)
50
+ end
51
+ end
52
+ end
@@ -21,6 +21,7 @@ module ForemanDatacenter
21
21
  has_one :ipmi_interface, -> { where(name: 'ipmi', mgmt_only: true) },
22
22
  :class_name => 'ForemanDatacenter::DeviceInterface'
23
23
  belongs_to_host
24
+ has_one :management_device, :class_name => 'ForemanDatacenter::ManagementDevice'
24
25
 
25
26
  enum face: [:front, :rear]
26
27
  enum status: [:active, :offline]
@@ -101,8 +102,12 @@ module ForemanDatacenter
101
102
  def populate_from_host(host)
102
103
  self.host = host
103
104
  self.name = host.name
105
+
104
106
  device_type = DeviceType.for_host(host)
105
107
  self.device_type = device_type if device_type
108
+
109
+ self.device_role = DeviceRole.for_host unless self.device_role
110
+
106
111
  serial = host.fact_value_by_name('serialnumber')
107
112
  self.serial = serial.value if serial
108
113
  end
@@ -3,7 +3,7 @@ module ForemanDatacenter
3
3
  FORM_FACTORS = ['Virtual', '10/100M (100BASE-TX)',
4
4
  '1GE (1000BASE-T)', '1GE (SFP)', '10GE (10GBASE-T)',
5
5
  '10GE (SFP+)', '10GE (XFP)', '40GE (QSFP+)']
6
- DEFAULT_FORM_FACTOR = '10GE (SFP+)'
6
+ DEFAULT_FORM_FACTOR = '1GE (1000BASE-T)'
7
7
 
8
8
  belongs_to :device, :class_name => 'ForemanDatacenter::Device'
9
9
 
@@ -10,5 +10,14 @@ module ForemanDatacenter
10
10
  validates :name, presence: true, uniqueness: true, length: { maximum: 50 }
11
11
  validates :color, presence: true, length: { maximum: 30 },
12
12
  inclusion: { in: COLORS, message: "Color must be one of #{COLORS.join(', ')}"}
13
+
14
+ def self.for_host
15
+ role = find_by_name('Server')
16
+ if role
17
+ role
18
+ else
19
+ create!(name: 'Server', color: 'Green')
20
+ end
21
+ end
13
22
  end
14
23
  end
@@ -0,0 +1,7 @@
1
+ module ForemanDatacenter
2
+ class ManagementDevice < ActiveRecord::Base
3
+ belongs_to :device, :class_name => 'ForemanDatacenter::Device'
4
+
5
+ validates :name, presence: true, length: { maximum: 255 }
6
+ end
7
+ end
@@ -28,7 +28,7 @@
28
28
  </ul>
29
29
 
30
30
  <div class="row">
31
- <div class="col-sm-6">
31
+ <div class="col-md-6">
32
32
  <!-- Device -->
33
33
  <div class="panel panel-default">
34
34
  <div class="panel-heading">
@@ -68,72 +68,6 @@
68
68
  </table>
69
69
  </div>
70
70
 
71
- <!-- Management -->
72
- <div class="panel panel-default">
73
- <div class="panel-heading">
74
- <strong>Management</strong>
75
- </div>
76
- <table class="table table-hover panel-body">
77
- <tbody>
78
- <tr>
79
- <td>Role</td>
80
- <td>
81
- <%= link_to @device.device_role.name, device_role_path(@device.device_role) %>
82
- </td>
83
- </tr>
84
- <tr>
85
- <td>Platform</td>
86
- <td>
87
- <% if @device.platform %>
88
- <%= link_to @device.platform.name, platform_path(@device.platform) %>
89
- <% else %>
90
- <span class="text-warning">Not assigned</span>
91
- <% end %>
92
- </td>
93
- </tr>
94
- <tr>
95
- <td>Status</td>
96
- <td>
97
- <% if @device.active? %>
98
- <span class="label label-success">Active</span>
99
- <% elsif @device.offline? %>
100
- <span class="label label-danger">Offline</span>
101
- <% end %>
102
- </td>
103
- </tr>
104
- <tr>
105
- <td>Primary IPv4</td>
106
- <td>
107
- <% if @device.ip_address.blank? %>
108
- Not defined
109
- <% else %>
110
- <%= @device.ip_address %></td>
111
- <% end %>
112
- </tr>
113
- <tr>
114
- <td>Primary IPv6</td>
115
- <td>
116
- <% if @device.primary_ip6.blank? %>
117
- Not defined
118
- <% else %>
119
- <%= @device.primary_ip6 %>
120
- <% end %>
121
- </td>
122
- </tr>
123
- <tr>
124
- <td>MAC address</td>
125
- <td>
126
- <% if @device.mac_address.blank? %>
127
- Not defined
128
- <% else %>
129
- <%= @device.mac_address %>
130
- <% end %>
131
- </td>
132
- </tr>
133
- </tbody>
134
- </table>
135
- </div>
136
-
137
71
  <!-- Critical Connections -->
138
72
  <div class="panel panel-default">
139
73
  <div class="panel-heading">
@@ -219,6 +153,124 @@
219
153
  <% end %>
220
154
  </div>
221
155
  </div>
156
+ </div>
157
+
158
+ <div class="col-md-6">
159
+ <!-- Management -->
160
+ <div class="panel panel-default">
161
+ <div class="panel-heading">
162
+ <strong>Management</strong>
163
+ </div>
164
+ <table class="table table-hover panel-body">
165
+ <tbody>
166
+ <tr>
167
+ <td>Role</td>
168
+ <td>
169
+ <%= link_to @device.device_role.name, device_role_path(@device.device_role) %>
170
+ </td>
171
+ </tr>
172
+ <tr>
173
+ <td>Platform</td>
174
+ <td>
175
+ <% if @device.platform %>
176
+ <%= link_to @device.platform.name, platform_path(@device.platform) %>
177
+ <% else %>
178
+ <span class="text-warning">Not assigned</span>
179
+ <% end %>
180
+ </td>
181
+ </tr>
182
+ <tr>
183
+ <td>Status</td>
184
+ <td>
185
+ <% if @device.active? %>
186
+ <span class="label label-success">Active</span>
187
+ <% elsif @device.offline? %>
188
+ <span class="label label-danger">Offline</span>
189
+ <% end %>
190
+ </td>
191
+ </tr>
192
+ <tr>
193
+ <td>Primary IPv4</td>
194
+ <td>
195
+ <% if @device.ip_address.blank? %>
196
+ Not defined
197
+ <% else %>
198
+ <%= @device.ip_address %></td>
199
+ <% end %>
200
+ </tr>
201
+ <tr>
202
+ <td>Primary IPv6</td>
203
+ <td>
204
+ <% if @device.primary_ip6.blank? %>
205
+ Not defined
206
+ <% else %>
207
+ <%= @device.primary_ip6 %>
208
+ <% end %>
209
+ </td>
210
+ </tr>
211
+ <tr>
212
+ <td>MAC address</td>
213
+ <td>
214
+ <% if @device.mac_address.blank? %>
215
+ Not defined
216
+ <% else %>
217
+ <%= @device.mac_address %>
218
+ <% end %>
219
+ </td>
220
+ </tr>
221
+ </tbody>
222
+ </table>
223
+ </div>
224
+
225
+ <!-- Management device -->
226
+ <div class="panel panel-default">
227
+ <div class="panel-heading">
228
+ <strong>Management Device</strong>
229
+ </div>
230
+ <table class="table table-hover panel-body">
231
+ <tbody>
232
+ <% if @device.management_device %>
233
+ <tr>
234
+ <td>Name</td>
235
+ <td><%= h @device.management_device.name %></td>
236
+ </tr>
237
+ <tr>
238
+ <td>Login</td>
239
+ <td><%= h @device.management_device.login %></td>
240
+ </tr>
241
+ <tr>
242
+ <td>Password</td>
243
+ <td><%= h @device.management_device.password %></td>
244
+ </tr>
245
+ <% else %>
246
+ <tr>
247
+ <td>None</td>
248
+ </tr>
249
+ <% end %>
250
+ </tbody>
251
+ </table>
252
+ <div class="panel-footer text-right">
253
+ <% if @device.management_device %>
254
+ <%= link_to edit_management_device_path(@device.management_device),
255
+ class: 'btn btn-success btn-xs' do %>
256
+ <span class="glyphicon glyphicon-pencil"></span>
257
+ Edit
258
+ <% end %>
259
+ <%= link_to management_device_path(@device.management_device),
260
+ class: 'btn btn-danger btn-xs',
261
+ data: { confirm: 'Are you sure?' }, method: :delete do %>
262
+ <i class="glyphicon glyphicon-trash"></i>
263
+ Destroy
264
+ <% end %>
265
+ <% else %>
266
+ <%= link_to new_device_management_device_path(@device),
267
+ class: 'btn btn-primary btn-xs' do %>
268
+ <span class="glyphicon glyphicon-plus"></span>
269
+ Add
270
+ <% end %>
271
+ <% end %>
272
+ </div>
273
+ </div>
222
274
 
223
275
  <!-- Comments -->
224
276
  <div class="panel panel-default">
@@ -228,8 +280,10 @@
228
280
  <div class="panel-body"><%= simple_format @device.comments %></div>
229
281
  </div>
230
282
  </div>
283
+ </div>
231
284
 
232
- <div class="col-sm-6">
285
+ <div class="row">
286
+ <div class="col-md-12">
233
287
  <!-- Device Bays -->
234
288
  <% if @device.parent? %>
235
289
  <div class="panel panel-default">
@@ -0,0 +1,18 @@
1
+ <%= form_for @management_device, as: :management_device,
2
+ url: (@management_device.new_record? ? device_management_devices_path(@management_device.device) : management_device_path(@management_device)) do |f| %>
3
+ <%= base_errors_for @management_device %>
4
+
5
+ <div class="clearfix">
6
+ <div class="form-group">
7
+ <label class="col-md-2 control-label required">Device</label>
8
+ <div class="col-md-4"><%= @management_device.device.name %></div>
9
+ </div>
10
+ </div>
11
+ <%= f.hidden_field :device_id %>
12
+
13
+ <%= text_f f, :name, required: true %>
14
+ <%= text_f f, :login %>
15
+ <%= text_f f, :password %>
16
+
17
+ <%= submit_or_cancel f, false, cancel_path: device_path(@management_device.device) %>
18
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% title 'Editing management device' %>
2
+
3
+ <%= render 'form' %>
@@ -0,0 +1,3 @@
1
+ <% title 'New management device' %>
2
+
3
+ <%= render 'form' %>
@@ -76,6 +76,8 @@ Foreman::Application.routes.draw do
76
76
  end
77
77
  end
78
78
  resources :device_modules, except: [:show, :index], shallow: true
79
+ resources :management_devices, only: [:new, :create, :edit, :update, :destroy],
80
+ shallow: true
79
81
  end
80
82
  resources :device_interface_connections, only: [:index], path: 'connections' do
81
83
  get :interfaces, on: :collection
@@ -0,0 +1,16 @@
1
+ class CreateManagementDevices < ActiveRecord::Migration
2
+ def change
3
+ create_table :management_devices do |t|
4
+ t.references :device
5
+ t.string :name, null: false, limit: 255
6
+ t.string :login
7
+ t.string :password
8
+
9
+ t.timestamps null: false
10
+ end
11
+
12
+ add_index :management_devices, :device_id
13
+ add_foreign_key :management_devices, :devices, column: :device_id,
14
+ on_delete: :cascade
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanDatacenter
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_datacenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Ivanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -94,6 +94,7 @@ files:
94
94
  - app/controllers/foreman_datacenter/device_types_controller.rb
95
95
  - app/controllers/foreman_datacenter/devices_controller.rb
96
96
  - app/controllers/foreman_datacenter/interface_templates_controller.rb
97
+ - app/controllers/foreman_datacenter/management_devices_controller.rb
97
98
  - app/controllers/foreman_datacenter/manufacturers_controller.rb
98
99
  - app/controllers/foreman_datacenter/platforms_controller.rb
99
100
  - app/controllers/foreman_datacenter/power_outlet_templates_controller.rb
@@ -131,6 +132,7 @@ files:
131
132
  - app/models/foreman_datacenter/device_role.rb
132
133
  - app/models/foreman_datacenter/device_type.rb
133
134
  - app/models/foreman_datacenter/interface_template.rb
135
+ - app/models/foreman_datacenter/management_device.rb
134
136
  - app/models/foreman_datacenter/manufacturer.rb
135
137
  - app/models/foreman_datacenter/platform.rb
136
138
  - app/models/foreman_datacenter/power_outlet.rb
@@ -204,6 +206,9 @@ files:
204
206
  - app/views/foreman_datacenter/interface_templates/new.html.erb
205
207
  - app/views/foreman_datacenter/layouts/layouts/new_layout.html.erb
206
208
  - app/views/foreman_datacenter/layouts/new_layout.html.erb
209
+ - app/views/foreman_datacenter/management_devices/_form.html.erb
210
+ - app/views/foreman_datacenter/management_devices/edit.html.erb
211
+ - app/views/foreman_datacenter/management_devices/new.html.erb
207
212
  - app/views/foreman_datacenter/manufacturers/_form.html.erb
208
213
  - app/views/foreman_datacenter/manufacturers/edit.html.erb
209
214
  - app/views/foreman_datacenter/manufacturers/index.html.erb
@@ -272,6 +277,7 @@ files:
272
277
  - db/migrate/20160816224805_create_device_modules.rb
273
278
  - db/migrate/20160824212010_add_host_ref_to_devices.rb
274
279
  - db/migrate/20160828200938_add_ip_address_to_device_interfaces.rb
280
+ - db/migrate/20160905211522_create_management_devices.rb
275
281
  - lib/foreman_datacenter/engine.rb
276
282
  - lib/foreman_datacenter/version.rb
277
283
  - lib/foreman_datacenter.rb