foreman_wds 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintrc.json +20 -0
  3. data/.gitignore +17 -0
  4. data/.rubocop.yml +66 -0
  5. data/.travis.yml +5 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +33 -0
  9. data/Rakefile +10 -0
  10. data/app/assets/javascripts/foreman_wds/wds_servers.js +19 -0
  11. data/app/assets/javascripts/host_edit_extensions.js +50 -0
  12. data/app/controllers/concerns/foreman/controller/parameters/wds_server.rb +19 -0
  13. data/app/controllers/concerns/foreman_wds/hosts_controller_extensions.rb +18 -0
  14. data/app/controllers/concerns/foreman_wds/unattended_controller_extensions.rb +21 -0
  15. data/app/controllers/wds_servers_controller.rb +85 -0
  16. data/app/lib/foreman_wds/wds_boot_image.rb +11 -0
  17. data/app/lib/foreman_wds/wds_image.rb +89 -0
  18. data/app/lib/foreman_wds/wds_install_image.rb +14 -0
  19. data/app/models/concerns/foreman_wds/compute_resource_extensions.rb +7 -0
  20. data/app/models/concerns/foreman_wds/host_extensions.rb +109 -0
  21. data/app/models/concerns/foreman_wds/nic_extensions.rb +40 -0
  22. data/app/models/foreman_wds/wds_facet.rb +48 -0
  23. data/app/models/wds_server.rb +239 -0
  24. data/app/services/wds_image_cache.rb +66 -0
  25. data/app/views/foreman_wds/unattend_2016.xml.erb +220 -0
  26. data/app/views/foreman_wds/windows_ptable.xml.erb +43 -0
  27. data/app/views/hosts/provision_method/wds/_form.html.erb +12 -0
  28. data/app/views/wds_servers/_form.html.erb +28 -0
  29. data/app/views/wds_servers/_image_select.html.erb +27 -0
  30. data/app/views/wds_servers/_server_select.html.erb +12 -0
  31. data/app/views/wds_servers/clients/_list.html.erb +43 -0
  32. data/app/views/wds_servers/edit.html.erb +3 -0
  33. data/app/views/wds_servers/images/_list.html.erb +36 -0
  34. data/app/views/wds_servers/index.html.erb +25 -0
  35. data/app/views/wds_servers/new.html.erb +3 -0
  36. data/app/views/wds_servers/show.html.erb +46 -0
  37. data/config/routes.rb +26 -0
  38. data/db/migrate/20180426133700_add_wds_servers.rb +23 -0
  39. data/db/seeds.d/50_ptable_templates.rb +16 -0
  40. data/db/seeds.d/50_unattend_templates.rb +19 -0
  41. data/foreman_wds.gemspec +23 -0
  42. data/lib/foreman_wds.rb +4 -0
  43. data/lib/foreman_wds/engine.rb +70 -0
  44. data/lib/foreman_wds/version.rb +3 -0
  45. data/test/foreman_wds_test.rb +11 -0
  46. data/test/test_helper.rb +4 -0
  47. metadata +147 -0
@@ -0,0 +1,3 @@
1
+ <% title _('Edit WDS Server %s') % @wds_server.name %>
2
+
3
+ <%= render 'form' %>
@@ -0,0 +1,36 @@
1
+ <% title _('WDS Images') %>
2
+
3
+ <table id="wds_images" class="<%= table_css_classes %>" data-table='inline'>
4
+ <thead>
5
+ <tr>
6
+ <th><%= s_("Image|Name") %></th>
7
+ <th><%= s_("Image|Group Name") %></th>
8
+ <th><%= s_("Image|File Name") %></th>
9
+ <th><%= s_("Image|Version") %></th>
10
+ <th><%= s_("Image|Architecture") %></th>
11
+ <th><%= s_("Image|Enabled") %></th>
12
+ <th><%= s_("Image|Type") %></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <%- @images.each do |image| -%>
17
+ <tr>
18
+ <td><%= image.name %></td>
19
+ <td><%= image.image_group if image.respond_to? :image_group %></td>
20
+ <td><%= image.file_name %></td>
21
+ <td><%= image.version %></td>
22
+ <td><%= image.architecture_name %></td>
23
+ <td>
24
+ <%- if image.enabled -%>
25
+ <%= icon_text 'toggle-on', _('Enabled'),
26
+ { kind: 'fa', class: 'center text-success fa-lg', title: _('Enabled') } %>
27
+ <%- else -%>
28
+ <%= icon_text 'toggle-off', _('Disabled'),
29
+ { kind: 'fa', class: 'center fa-lg', title: _('Disabled') } %>
30
+ <%- end -%>
31
+ </td>
32
+ <td><%= image.type_name %></td>
33
+ </tr>
34
+ <%- end -%>
35
+ </tbody>
36
+ </table>
@@ -0,0 +1,25 @@
1
+ <% title _('WDS Servers') %>
2
+ <% title_actions new_link(_('Create WDS Server connection')),
3
+ documentation_button('5.2ComputeResources') %>
4
+
5
+ <table class="<%= table_css_classes 'table-fixed' %>">
6
+ <thead>
7
+ <tr>
8
+ <th class="col-md-6"><%= sort :name, :as => s_("WDS Server|Name") %></th>
9
+ <th><%= _('Actions') %></th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <% @wds_servers.each do |server| %>
14
+ <tr>
15
+ <td class="ellipsis"><%= link_to server.name, server %></td>
16
+ <td>
17
+ <%= action_buttons(link_to_if_authorized(_('Edit'), hash_for_edit_wds_server_path(server).merge(:auth_object => server, :authorizer => authorizer)),
18
+ display_delete_if_authorized(hash_for_edit_wds_server_path(:id => server).merge(:auth_object => server, :authorizer => authorizer), :data => { :confirm => _("Delete %s?") % server.name })) %>
19
+ </td>
20
+ </tr>
21
+ <% end %>
22
+ </tbody>
23
+ </table>
24
+
25
+ <%= will_paginate_with_info @wds_servers %>
@@ -0,0 +1,3 @@
1
+ <% title _('Create WDS Server connection') %>
2
+
3
+ <%= render 'form' %>
@@ -0,0 +1,46 @@
1
+ <% title @wds_server.name %>
2
+ <% title_actions \
3
+ display_link_if_authorized(_('Refresh Cache'), hash_for_refresh_cache_wds_server_path(@wds_server).merge(:auth_object => @wds_server), method: :post, class: 'btn btn-default'),
4
+ link_to_if_authorized(_('Edit'), hash_for_edit_wds_server_path(@wds_server).merge(:auth_object => @wds_server), class: 'btn btn-default') %>
5
+ <% javascript 'foreman_wds/wds_servers' %>
6
+
7
+ <ul class="nav nav-tabs" data-tabs="tabs">
8
+ <li class="active"><a href="#primary" data-toggle="tab"><%= _("WDS Server") %></a></li>
9
+ <li><a href="#images" data-toggle="tab"><%= _("Images") %></a></li>
10
+ <li><a href="#clients" data-toggle="tab"><%= _("Clients") %></a></li>
11
+ </ul>
12
+
13
+ <div class="tab-content">
14
+ <div class="tab-pane active" id="primary">
15
+ <table class="<%= table_css_classes 'table-fixed' %>">
16
+ <thead>
17
+ <tr>
18
+ <th class="col-md-1"><%= _('Property') %></th>
19
+ <th class="col-md-11"><%= _('Value') %></th>
20
+ </tr>
21
+ </thead>
22
+ <tbody>
23
+ <%- unless @wds_server.description.empty? -%>
24
+ <tr>
25
+ <td><%= _('Description') %></td>
26
+ <td><%= @wds_server.description %></td>
27
+ </tr>
28
+ <%- end -%>
29
+ <tr>
30
+ <td><%= _('Url') %></td>
31
+ <td><%= @wds_server.url %></td>
32
+ </tr>
33
+ <tr>
34
+ <td><%= _('User') %></td>
35
+ <td><%= @wds_server.user %></td>
36
+ </tr>
37
+ </tbody>
38
+ </table>
39
+ </div>
40
+ <div id="images" class="tab-pane" data-url="<%= wds_images_wds_server_path(@wds_server) %>#wds_images">
41
+ <%= spinner(_('Loading image information ...')) %>
42
+ </div>
43
+ <div id="clients" class="tab-pane" data-url="<%= wds_clients_wds_server_path(@wds_server) %>#wds_clients">
44
+ <%= spinner(_('Loading image information ...')) %>
45
+ </div>
46
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,26 @@
1
+ Rails.application.routes.draw do
2
+ scope '/foreman_wds' do
3
+ constraints(id: %r{[^\/]+}) do
4
+ resources :wds_servers do
5
+ collection do
6
+ get 'auto_complete_search'
7
+ post 'test_connection'
8
+ end
9
+ member do
10
+ post 'refresh_cache'
11
+ get 'wds_clients'
12
+ get 'wds_images'
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ constraints(id: /[^\/]+/) do
19
+ resources :hosts do
20
+ collection do
21
+ post 'wds_server_selected'
22
+ post 'wds_image_selected'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ class AddWdsServers < ActiveRecord::Migration[4.2]
2
+ def change
3
+ create_table :wds_servers do |t|
4
+ t.string :name, null: false, unique: true
5
+ t.string :description, limit: 255
6
+ t.string :url, limit: 255
7
+ t.string :user, limit: 255
8
+ t.text :password
9
+
10
+ t.timestamps null: false
11
+ end
12
+
13
+ create_table :wds_facets do |t|
14
+ t.references :host, null: false, foreign_key: true, index: true, unique: true
15
+ t.references :wds_server, foreign_key: true, index: true
16
+
17
+ t.string :boot_image_name, limit: 255
18
+ t.string :install_image_name, limit: 255
19
+
20
+ t.timestamps null: false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ Ptable.without_auditing do
2
+ { 'windows_ptable.xml.erb' => 'Windows default' }.each do |tmpl_file, tmpl_name|
3
+ content = File.read(File.join(ForemanWds::Engine.root, 'app', 'views', 'foreman_wds', tmpl_file))
4
+ tmpl = Ptable.unscoped.where(name: tmpl_name).first_or_create(
5
+ snippet: false,
6
+ template: content
7
+ )
8
+ tmpl.attributes = {
9
+ template: content,
10
+ default: true,
11
+ vendor: 'Foreman WDS',
12
+ locked: false
13
+ }
14
+ tmpl.save!(validate: false) if tmpl.changes.present?
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ kind = TemplateKind.unscoped.where(name: 'wds_unattend').first_or_create
2
+
3
+ ProvisioningTemplate.without_auditing do
4
+ { 'unattend_2016.xml.erb' => 'Windows Server 2016' }.each do |tmpl_name, os_name|
5
+ content = File.read(File.join(ForemanWds::Engine.root, 'app', 'views', 'foreman_wds', tmpl_name))
6
+ tmpl = ProvisioningTemplate.unscoped.where(name: "Unattend #{os_name}").first_or_create(
7
+ template_kind_id: kind.id,
8
+ snippet: false,
9
+ template: content
10
+ )
11
+ tmpl.attributes = {
12
+ template: content,
13
+ default: true,
14
+ vendor: 'Foreman WDS',
15
+ locked: false
16
+ }
17
+ tmpl.save!(validate: false) if tmpl.changes.present?
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('lib/foreman_wds/version', __dir__)
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'foreman_wds'
5
+ spec.version = ForemanWds::VERSION
6
+ spec.authors = ['Alexander Olofsson']
7
+ spec.email = ['alexander.olofsson@liu.se']
8
+
9
+ spec.summary = 'WDS support for Foreman.'
10
+ spec.description = 'Adds support for orchestrating WDS deployments with Foreman.'
11
+ spec.homepage = 'https://github.com/ananace/foreman_wds'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.test_files = spec.files.grep(%r{^test\/})
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_runtime_dependency 'winrm', '~> 2.2'
19
+
20
+ spec.add_development_dependency 'bundler'
21
+ spec.add_development_dependency 'minitest'
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1,4 @@
1
+ require 'foreman_wds/engine'
2
+
3
+ module ForemanWds
4
+ end
@@ -0,0 +1,70 @@
1
+ module ForemanWds
2
+ class Engine < ::Rails::Engine
3
+ engine_name 'foreman_wds'
4
+
5
+ config.autoload_paths += Dir["#{config.root}/app/lib"]
6
+ config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
7
+ config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
8
+ config.autoload_paths += Dir["#{config.root}/app/services"]
9
+
10
+ initializer 'foreman_wds.load_app_instance_data' do |app|
11
+ ForemanWds::Engine.paths['db/migrate'].existent.each do |path|
12
+ app.config.paths['db/migrate'] << path
13
+ end
14
+ end
15
+
16
+ initializer 'foreman_wds.register_plugin', before: :finisher_hook do |_app|
17
+ Foreman::Plugin.register :foreman_wds do
18
+ requires_foreman '>= 1.16'
19
+
20
+ # add menu entry
21
+ menu :top_menu, :wds_servers,
22
+ url_hash: { controller: :wds_servers, action: :index },
23
+ caption: N_('WDS Servers'),
24
+ parent: :infrastructure_menu
25
+
26
+ register_facet ForemanWds::WdsFacet, :wds_facet
27
+ parameter_filter Host::Managed, wds_facet_attributes: %i[wds_server_id boot_image_name install_image_name]
28
+
29
+ provision_method 'wds', N_('WDS Server')
30
+ template_labels 'wds_unattend' => N_('WDS Unattend file template')
31
+ end
32
+ end
33
+
34
+ assets_to_precompile =
35
+ Dir.chdir(root) do
36
+ Dir['app/assets/javascripts/**/*'].map do |f|
37
+ f.split(File::SEPARATOR, 4).last
38
+ end
39
+ end
40
+
41
+ initializer 'foreman_wds.assets.precompile' do |app|
42
+ app.config.assets.precompile += assets_to_precompile
43
+ end
44
+
45
+ initializer 'foreman_wds.configure_assets', group: :assets do
46
+ SETTINGS[:foreman_wds] = { assets: { precompile: assets_to_precompile } }
47
+ end
48
+
49
+ config.to_prepare do
50
+ begin
51
+ Host::Managed.send(:prepend, ForemanWds::HostExtensions)
52
+ Nic::Managed.send(:prepend, ForemanWds::NicExtensions)
53
+ HostsController.send(:prepend, ForemanWds::HostsControllerExtensions)
54
+ UnattendedController.send(:prepend, ForemanWds::UnattendedControllerExtensions)
55
+
56
+ ComputeResource.providers.each do |_k, const|
57
+ Kernel.const_get(const).send(:prepend, ForemanWds::ComputeResourceExtensions)
58
+ end
59
+ rescue StandardError => e
60
+ Rails.logger.fatal "foreman_wds: skipping engine hook (#{e})"
61
+ end
62
+ end
63
+
64
+ rake_tasks do
65
+ Rake::Task['db:seed'].enhance do
66
+ ForemanWds::Engine.load_seed
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module ForemanWds
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,11 @@
1
+ require "test_helper"
2
+
3
+ class ForemanWdsTest < Minitest::Test
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::ForemanWds::VERSION
6
+ end
7
+
8
+ def test_it_does_something_useful
9
+ assert false
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "foreman_wds"
3
+
4
+ require "minitest/autorun"
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman_wds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Olofsson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: winrm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Adds support for orchestrating WDS deployments with Foreman.
70
+ email:
71
+ - alexander.olofsson@liu.se
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".eslintrc.json"
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - app/assets/javascripts/foreman_wds/wds_servers.js
85
+ - app/assets/javascripts/host_edit_extensions.js
86
+ - app/controllers/concerns/foreman/controller/parameters/wds_server.rb
87
+ - app/controllers/concerns/foreman_wds/hosts_controller_extensions.rb
88
+ - app/controllers/concerns/foreman_wds/unattended_controller_extensions.rb
89
+ - app/controllers/wds_servers_controller.rb
90
+ - app/lib/foreman_wds/wds_boot_image.rb
91
+ - app/lib/foreman_wds/wds_image.rb
92
+ - app/lib/foreman_wds/wds_install_image.rb
93
+ - app/models/concerns/foreman_wds/compute_resource_extensions.rb
94
+ - app/models/concerns/foreman_wds/host_extensions.rb
95
+ - app/models/concerns/foreman_wds/nic_extensions.rb
96
+ - app/models/foreman_wds/wds_facet.rb
97
+ - app/models/wds_server.rb
98
+ - app/services/wds_image_cache.rb
99
+ - app/views/foreman_wds/unattend_2016.xml.erb
100
+ - app/views/foreman_wds/windows_ptable.xml.erb
101
+ - app/views/hosts/provision_method/wds/_form.html.erb
102
+ - app/views/wds_servers/_form.html.erb
103
+ - app/views/wds_servers/_image_select.html.erb
104
+ - app/views/wds_servers/_server_select.html.erb
105
+ - app/views/wds_servers/clients/_list.html.erb
106
+ - app/views/wds_servers/edit.html.erb
107
+ - app/views/wds_servers/images/_list.html.erb
108
+ - app/views/wds_servers/index.html.erb
109
+ - app/views/wds_servers/new.html.erb
110
+ - app/views/wds_servers/show.html.erb
111
+ - config/routes.rb
112
+ - db/migrate/20180426133700_add_wds_servers.rb
113
+ - db/seeds.d/50_ptable_templates.rb
114
+ - db/seeds.d/50_unattend_templates.rb
115
+ - foreman_wds.gemspec
116
+ - lib/foreman_wds.rb
117
+ - lib/foreman_wds/engine.rb
118
+ - lib/foreman_wds/version.rb
119
+ - test/foreman_wds_test.rb
120
+ - test/test_helper.rb
121
+ homepage: https://github.com/ananace/foreman_wds
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.7.6
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: WDS support for Foreman.
145
+ test_files:
146
+ - test/foreman_wds_test.rb
147
+ - test/test_helper.rb