foreman_datacenter 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/foreman_datacenter/hosts_controller_extensions.rb +37 -0
- data/app/controllers/foreman_datacenter/device_interfaces_controller.rb +1 -1
- data/app/controllers/foreman_datacenter/device_types_controller.rb +2 -1
- data/app/controllers/foreman_datacenter/devices_controller.rb +15 -3
- data/app/models/concerns/foreman_datacenter/host_extensions.rb +24 -0
- data/app/models/foreman_datacenter/device.rb +25 -2
- data/app/models/foreman_datacenter/device_interface.rb +1 -0
- data/app/models/foreman_datacenter/device_type.rb +18 -0
- data/app/models/foreman_datacenter/manufacturer.rb +12 -0
- data/app/views/foreman_datacenter/device_interfaces/_form.html.erb +1 -0
- data/app/views/foreman_datacenter/device_types/index.html.erb +2 -0
- data/app/views/foreman_datacenter/devices/_form.html.erb +2 -0
- data/app/views/foreman_datacenter/devices/_interface.html.erb +5 -0
- data/app/views/foreman_datacenter/devices/index.html.erb +6 -3
- data/app/views/foreman_datacenter/devices/show.html.erb +7 -0
- data/app/views/hosts/import_to_device.html.erb +60 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20160824212010_add_host_ref_to_devices.rb +5 -0
- data/db/migrate/20160828200938_add_ip_address_to_device_interfaces.rb +5 -0
- data/lib/foreman_datacenter/engine.rb +10 -0
- data/lib/foreman_datacenter/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e154fe5ab9be2e7d64a586a3395e9382c02c5722
|
4
|
+
data.tar.gz: 73b922e8071601cae1149d1e70044d402b02535e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3db7ebe2a0846f7d2a1e7550876c4ce35e0d4e9335abc2a0c452645d3e07494329b77a14eec855ef3d4eda1a165d47909ea1cc48cc4d858f6c74e6c24868f91
|
7
|
+
data.tar.gz: 3181025341807ee9b7a49d46731ede52571cef861606a0b562de39b0db13d7ad402ef320b9ea4dedd75e9ac326decbec3ebbab8b2a8eb0c7eb73036268d4fa71
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ForemanDatacenter
|
2
|
+
module HostsControllerExtensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_action :set_target_device_for_import, only: :import_to_device
|
7
|
+
end
|
8
|
+
|
9
|
+
def import_to_device
|
10
|
+
begin
|
11
|
+
search = resource_base.search_for(params[:search], :order => params[:order])
|
12
|
+
rescue => e
|
13
|
+
error e.to_s
|
14
|
+
search = resource_base.search_for ''
|
15
|
+
end
|
16
|
+
@hosts = search.includes(:device, :operatingsystem, :environment, :model, :compute_resource).
|
17
|
+
paginate(:page => params[:page])
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def action_permission
|
23
|
+
case params[:action]
|
24
|
+
when 'import_to_device'
|
25
|
+
'view'
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_target_device_for_import
|
32
|
+
if params[:target_device_id]
|
33
|
+
@target_device = Device.find(params[:target_device_id])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -59,7 +59,7 @@ module ForemanDatacenter
|
|
59
59
|
|
60
60
|
def device_interface_params
|
61
61
|
params[:device_interface].
|
62
|
-
permit(:device_id, :name, :form_factor, :mac_address, :mgmt_only, :description)
|
62
|
+
permit(:device_id, :name, :form_factor, :mac_address, :mgmt_only, :description, :ip_address)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -3,7 +3,8 @@ module ForemanDatacenter
|
|
3
3
|
before_action :set_device_type, only: [:show, :edit, :update, :destroy]
|
4
4
|
|
5
5
|
def index
|
6
|
-
@device_types = DeviceType.includes(:manufacturer).
|
6
|
+
@device_types = DeviceType.includes(:manufacturer).
|
7
|
+
paginate(:page => params[:page])
|
7
8
|
end
|
8
9
|
|
9
10
|
def show
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module ForemanDatacenter
|
2
2
|
class DevicesController < ApplicationController
|
3
|
-
before_action :set_device, only: [:
|
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(:device_role, :device_type, rack: [:site]).
|
7
|
+
paginate(:page => params[:page])
|
7
8
|
end
|
8
9
|
|
9
10
|
def show
|
@@ -21,9 +22,12 @@ module ForemanDatacenter
|
|
21
22
|
|
22
23
|
def new
|
23
24
|
@device = Device.new
|
25
|
+
populate_from_host
|
24
26
|
end
|
25
27
|
|
26
28
|
def edit
|
29
|
+
@device = Device.find(params[:id])
|
30
|
+
populate_from_host
|
27
31
|
end
|
28
32
|
|
29
33
|
def create
|
@@ -76,7 +80,15 @@ module ForemanDatacenter
|
|
76
80
|
def device_params
|
77
81
|
params[:device].permit(:device_type_id, :device_role_id, :platform_id,
|
78
82
|
:name, :serial, :rack_id, :position, :face,
|
79
|
-
:status, :primary_ip4, :primary_ip6, :comments
|
83
|
+
:status, :primary_ip4, :primary_ip6, :comments,
|
84
|
+
:host_id)
|
85
|
+
end
|
86
|
+
|
87
|
+
def populate_from_host
|
88
|
+
if params[:host_id]
|
89
|
+
host = Host.find(params[:host_id])
|
90
|
+
@device.populate_from_host(host)
|
91
|
+
end
|
80
92
|
end
|
81
93
|
end
|
82
94
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ForemanDatacenter
|
2
|
+
module HostExtensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_one :device, class_name: 'ForemanDatacenter::Device',
|
7
|
+
foreign_key: 'host_id', dependent: :nullify
|
8
|
+
after_destroy :update_device_on_destroy
|
9
|
+
end
|
10
|
+
|
11
|
+
def update_device_on_destroy
|
12
|
+
new_device_name = "Unassigned device (former: #{name})"
|
13
|
+
device.update(name: new_device_name)
|
14
|
+
device.interfaces.clear
|
15
|
+
end
|
16
|
+
|
17
|
+
def fact_value_by_name(name)
|
18
|
+
fact_name = FactName.find_by(name: name)
|
19
|
+
if fact_name
|
20
|
+
fact_values.find_by(fact_name: fact_name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -11,12 +11,14 @@ module ForemanDatacenter
|
|
11
11
|
has_many :power_ports, :class_name => 'ForemanDatacenter::PowerPort'
|
12
12
|
has_many :console_server_ports, :class_name => 'ForemanDatacenter::ConsoleServerPort'
|
13
13
|
has_many :console_ports, :class_name => 'ForemanDatacenter::ConsolePort'
|
14
|
-
has_many :interfaces, :class_name => 'ForemanDatacenter::DeviceInterface'
|
14
|
+
has_many :interfaces, :class_name => 'ForemanDatacenter::DeviceInterface',
|
15
|
+
dependent: :destroy
|
15
16
|
has_many :management_interfaces, -> { where(mgmt_only: true) },
|
16
17
|
:class_name => 'ForemanDatacenter::DeviceInterface'
|
17
18
|
has_many :non_management_interfaces, -> { where(mgmt_only: false) },
|
18
19
|
:class_name => 'ForemanDatacenter::DeviceInterface'
|
19
20
|
has_many :modules, :class_name => 'ForemanDatacenter::DeviceModule'
|
21
|
+
belongs_to_host
|
20
22
|
|
21
23
|
enum face: [:front, :rear]
|
22
24
|
enum status: [:active, :offline]
|
@@ -29,6 +31,7 @@ module ForemanDatacenter
|
|
29
31
|
validates :position, numericality: { only_integer: true }, allow_nil: true
|
30
32
|
|
31
33
|
after_create :create_interfaces
|
34
|
+
after_create :import_interfaces_from_host
|
32
35
|
after_create :create_console_ports
|
33
36
|
after_create :create_power_ports
|
34
37
|
after_create :create_console_server_ports
|
@@ -89,7 +92,14 @@ module ForemanDatacenter
|
|
89
92
|
where(power_ports: { power_outlet_id: nil })
|
90
93
|
end
|
91
94
|
|
92
|
-
|
95
|
+
def populate_from_host(host)
|
96
|
+
self.host = host
|
97
|
+
self.name = host.name
|
98
|
+
device_type = DeviceType.for_host(host)
|
99
|
+
self.device_type = device_type if device_type
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
93
103
|
|
94
104
|
def create_interfaces
|
95
105
|
device_type.interface_templates.each do |template|
|
@@ -97,6 +107,19 @@ module ForemanDatacenter
|
|
97
107
|
end
|
98
108
|
end
|
99
109
|
|
110
|
+
def import_interfaces_from_host
|
111
|
+
if host
|
112
|
+
host.interfaces.each do |interface|
|
113
|
+
interfaces.create(
|
114
|
+
name: interface.identifier,
|
115
|
+
form_factor: ForemanDatacenter::DeviceInterface::DEFAULT_FORM_FACTOR,
|
116
|
+
mac_address: interface.mac,
|
117
|
+
ip_address: interface.ip
|
118
|
+
)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
100
123
|
def create_console_ports
|
101
124
|
device_type.console_port_templates.each do |template|
|
102
125
|
console_ports.create(template.attrs_to_copy)
|
@@ -11,6 +11,7 @@ module ForemanDatacenter
|
|
11
11
|
validates :name, presence: true, length: {maximum: 30}
|
12
12
|
validates :form_factor, inclusion: {in: FORM_FACTORS}
|
13
13
|
validates :mac_address, length: {maximum: 128}
|
14
|
+
validates :ip_address, length: {maximum: 128}
|
14
15
|
validates :description, length: {maximum: 100}
|
15
16
|
|
16
17
|
def connection
|
@@ -24,6 +24,24 @@ module ForemanDatacenter
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.for_host(host)
|
28
|
+
fact = host.fact_value_by_name('productname')
|
29
|
+
if fact
|
30
|
+
device_type = find_by(model: fact.value)
|
31
|
+
if device_type
|
32
|
+
device_type
|
33
|
+
else
|
34
|
+
manufacturer = Manufacturer.for_host(host)
|
35
|
+
if manufacturer
|
36
|
+
create(
|
37
|
+
manufacturer: manufacturer,
|
38
|
+
model: fact.value
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
27
45
|
def parent?
|
28
46
|
subdevice_role == 'Parent'
|
29
47
|
end
|
@@ -3,5 +3,17 @@ module ForemanDatacenter
|
|
3
3
|
has_many :device_types, :class_name => 'ForemanDatacenter::DeviceType'
|
4
4
|
|
5
5
|
validates :name, presence: true, uniqueness: true, length: { maximum: 50 }
|
6
|
+
|
7
|
+
def self.for_host(host)
|
8
|
+
fact = host.fact_value_by_name('manufacturer')
|
9
|
+
if fact
|
10
|
+
manufacturer = find_by(name: fact.value)
|
11
|
+
if manufacturer
|
12
|
+
manufacturer
|
13
|
+
else
|
14
|
+
create(name: fact.value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
6
18
|
end
|
7
19
|
end
|
@@ -14,6 +14,7 @@
|
|
14
14
|
<%= selectable_f f, :form_factor,
|
15
15
|
ForemanDatacenter::DeviceInterface::FORM_FACTORS %>
|
16
16
|
<%= text_f f, :mac_address %>
|
17
|
+
<%= text_f f, :ip_address %>
|
17
18
|
<%= checkbox_f f, :mgmt_only, label: 'OOB Management',
|
18
19
|
help_inline: 'This interface is used only for out-of-band management' %>
|
19
20
|
<%= text_f f, :description %>
|
@@ -4,6 +4,8 @@
|
|
4
4
|
<span class="glyphicon glyphicon-transfer"></span>
|
5
5
|
<%= interface.name %>
|
6
6
|
</td>
|
7
|
+
<td><%= h interface.mac_address %></td>
|
8
|
+
<td><%= h interface.ip_address %></td>
|
7
9
|
<td>
|
8
10
|
<%= link_to interface.connected_interface.device.name,
|
9
11
|
device_path(interface.connected_interface.device) %>
|
@@ -46,6 +48,9 @@
|
|
46
48
|
<span class="glyphicon glyphicon-transfer"></span>
|
47
49
|
<%= interface.name %>
|
48
50
|
</td>
|
51
|
+
<td><%= h interface.mac_address %></td>
|
52
|
+
<td><%= h interface.ip_address %></td>
|
53
|
+
<td></td>
|
49
54
|
<td class="text-muted">Not connected</td>
|
50
55
|
<td></td>
|
51
56
|
<td class="text-right">
|
@@ -1,7 +1,8 @@
|
|
1
1
|
<% javascript 'foreman_datacenter/devices' %>
|
2
2
|
|
3
|
-
<% title _('Devices')
|
4
|
-
<% title_actions display_link_if_authorized(_('New device'), hash_for_new_device_path, class: 'btn btn-success'),
|
3
|
+
<% title _('Devices') %>
|
4
|
+
<% title_actions display_link_if_authorized(_('New device'), hash_for_new_device_path, class: 'btn btn-success'),
|
5
|
+
display_link_if_authorized(_('Import from host'), hash_for_import_to_device_path, class: 'btn btn-success') %>
|
5
6
|
|
6
7
|
<table class="table table-bordered table-striped table-two-pane">
|
7
8
|
<thead>
|
@@ -40,7 +41,7 @@
|
|
40
41
|
),
|
41
42
|
display_delete_if_authorized(
|
42
43
|
hash_for_device_path(:id => device).merge(:auth_object => device, :authorizer => authorizer),
|
43
|
-
:data => { :confirm => 'Are you sure?'},
|
44
|
+
:data => { :confirm => 'Are you sure?' },
|
44
45
|
:action => :destroy
|
45
46
|
)
|
46
47
|
) %>
|
@@ -49,3 +50,5 @@
|
|
49
50
|
<% end %>
|
50
51
|
</tbody>
|
51
52
|
</table>
|
53
|
+
|
54
|
+
<%= will_paginate_with_info @devices, :more => " - "+_("<b class='select_count'>0</b> selected") %>
|
@@ -13,6 +13,13 @@
|
|
13
13
|
:action => :destroy,
|
14
14
|
:class => 'btn btn-danger'
|
15
15
|
),
|
16
|
+
display_link_if_authorized(
|
17
|
+
_('Import from host'),
|
18
|
+
@device.host ?
|
19
|
+
hash_for_edit_device_path(@device, host_id: @device.host.id) :
|
20
|
+
hash_for_import_to_device_path(target_device_id: @device.id),
|
21
|
+
:class => 'btn btn-success'
|
22
|
+
),
|
16
23
|
help_path %>
|
17
24
|
|
18
25
|
<ul class="nav nav-tabs">
|
@@ -0,0 +1,60 @@
|
|
1
|
+
<div class="row form-group">
|
2
|
+
<div class="title_filter col-md-6">
|
3
|
+
<%= render "common/searchbar",
|
4
|
+
auto_complete_controller_name: 'import_to_device' %>
|
5
|
+
</div>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<% if @target_device %>
|
9
|
+
<div class="row form-group">
|
10
|
+
<div class="col-md-12">
|
11
|
+
<label class="col-md-2 control-label required">Target Device</label>
|
12
|
+
<div class="col-md-4"><%= @target_device.name %></div>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<table class="table table-bordered table-striped table-fixed">
|
18
|
+
<thead>
|
19
|
+
<tr>
|
20
|
+
<th>Name</th>
|
21
|
+
<th>Operating System</th>
|
22
|
+
<th>Environment</th>
|
23
|
+
<th>Model</th>
|
24
|
+
<th>Actions</th>
|
25
|
+
</tr>
|
26
|
+
</thead>
|
27
|
+
<tbody>
|
28
|
+
<% @hosts.each do |host| %>
|
29
|
+
<tr>
|
30
|
+
<td><%= link_to host %></td>
|
31
|
+
<td><%= h host.operatingsystem %></td>
|
32
|
+
<td><%= h host.environment %></td>
|
33
|
+
<td><%= model_name host %></td>
|
34
|
+
<td class="text-right">
|
35
|
+
<% if @target_device %>
|
36
|
+
<% if host.device %>
|
37
|
+
<span class="text-muted">Already has assigned device</span>
|
38
|
+
<% else %>
|
39
|
+
<%= link_to 'Import to device',
|
40
|
+
edit_device_path(@target_device, host_id: host.id),
|
41
|
+
class: 'btn btn-sm btn-success' %>
|
42
|
+
<% end %>
|
43
|
+
<% else %>
|
44
|
+
<% if host.device %>
|
45
|
+
<%= link_to 'Update assigned device',
|
46
|
+
edit_device_path(host.device, host_id: host.id),
|
47
|
+
class: 'btn btn-sm btn-info' %>
|
48
|
+
<% else %>
|
49
|
+
<%= link_to 'Import to device',
|
50
|
+
new_device_path(host_id: host.id),
|
51
|
+
class: 'btn btn-sm btn-success' %>
|
52
|
+
<% end %>
|
53
|
+
<% end %>
|
54
|
+
</td>
|
55
|
+
</tr>
|
56
|
+
<% end %>
|
57
|
+
</tbody>
|
58
|
+
</table>
|
59
|
+
|
60
|
+
<%= will_paginate_with_info @hosts, :more => " - "+_("<b class='select_count'>0</b> selected") %>
|
data/config/routes.rb
CHANGED
@@ -55,6 +55,16 @@ module ForemanDatacenter
|
|
55
55
|
SETTINGS[:foreman_datacenter] = { assets: { precompile: assets_to_precompile } }
|
56
56
|
end
|
57
57
|
|
58
|
+
# Include concerns in this config.to_prepare block
|
59
|
+
config.to_prepare do
|
60
|
+
begin
|
61
|
+
Host::Managed.send(:include, ForemanDatacenter::HostExtensions)
|
62
|
+
HostsController.send(:include, ForemanDatacenter::HostsControllerExtensions)
|
63
|
+
rescue => e
|
64
|
+
Rails.logger.warn "ForemanDatacenter: skipping engine hook (#{e})"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
58
68
|
rake_tasks do
|
59
69
|
Rake::Task['db:seed'].enhance do
|
60
70
|
ForemanDatacenter::Engine.load_seed
|
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.0
|
4
|
+
version: 0.1.0
|
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-
|
11
|
+
date: 2016-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deface
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- app/assets/javascripts/foreman_datacenter/racks.js
|
81
81
|
- app/assets/javascripts/foreman_datacenter/shared.js
|
82
82
|
- app/assets/stylesheets/foreman_datacenter/device_interface_connections.css
|
83
|
+
- app/controllers/concerns/foreman_datacenter/hosts_controller_extensions.rb
|
83
84
|
- app/controllers/foreman_datacenter/console_port_templates_controller.rb
|
84
85
|
- app/controllers/foreman_datacenter/console_ports_controller.rb
|
85
86
|
- app/controllers/foreman_datacenter/console_server_port_templates_controller.rb
|
@@ -116,6 +117,7 @@ files:
|
|
116
117
|
- app/helpers/foreman_datacenter/power_ports_helper.rb
|
117
118
|
- app/helpers/foreman_datacenter/racks_helper.rb
|
118
119
|
- app/helpers/foreman_datacenter/shared_helper.rb
|
120
|
+
- app/models/concerns/foreman_datacenter/host_extensions.rb
|
119
121
|
- app/models/foreman_datacenter/console_port.rb
|
120
122
|
- app/models/foreman_datacenter/console_port_template.rb
|
121
123
|
- app/models/foreman_datacenter/console_server_port.rb
|
@@ -244,6 +246,7 @@ files:
|
|
244
246
|
- app/views/foreman_datacenter/sites/index.html.erb
|
245
247
|
- app/views/foreman_datacenter/sites/new.html.erb
|
246
248
|
- app/views/foreman_datacenter/sites/show.html.erb
|
249
|
+
- app/views/hosts/import_to_device.html.erb
|
247
250
|
- config/routes.rb
|
248
251
|
- db/migrate/20160727161914_create_sites.rb
|
249
252
|
- db/migrate/20160728123353_create_rack_groups.rb
|
@@ -267,6 +270,8 @@ files:
|
|
267
270
|
- db/migrate/20160809112815_create_console_server_ports.rb
|
268
271
|
- db/migrate/20160809113846_create_console_ports.rb
|
269
272
|
- db/migrate/20160816224805_create_device_modules.rb
|
273
|
+
- db/migrate/20160824212010_add_host_ref_to_devices.rb
|
274
|
+
- db/migrate/20160828200938_add_ip_address_to_device_interfaces.rb
|
270
275
|
- lib/foreman_datacenter/engine.rb
|
271
276
|
- lib/foreman_datacenter/version.rb
|
272
277
|
- lib/foreman_datacenter.rb
|