the_foreman_proxmox 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +102 -0
  4. data/Rakefile +47 -0
  5. data/app/assets/javascripts/the_foreman_proxmox/proxmox.js +110 -0
  6. data/app/controllers/concerns/the_foreman_proxmox/controller/parameters/compute_resource.rb +41 -0
  7. data/app/controllers/the_foreman_proxmox/compute_resources_controller.rb +38 -0
  8. data/app/helpers/proxmox_compute_helper.rb +154 -0
  9. data/app/helpers/proxmox_compute_selectors_helper.rb +148 -0
  10. data/app/models/concerns/fog_extensions/proxmox/disk.rb +29 -0
  11. data/app/models/concerns/fog_extensions/proxmox/server.rb +82 -0
  12. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +49 -0
  13. data/app/models/concerns/fog_extensions/proxmox/volume.rb +29 -0
  14. data/app/models/the_foreman_proxmox/options_select.rb +36 -0
  15. data/app/models/the_foreman_proxmox/proxmox.rb +394 -0
  16. data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -0
  17. data/app/views/compute_resources/form/_proxmox.html.erb +24 -0
  18. data/app/views/compute_resources/show/_proxmox.html.erb +21 -0
  19. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +45 -0
  20. data/app/views/compute_resources_vms/form/proxmox/_config.html.erb +55 -0
  21. data/app/views/compute_resources_vms/form/proxmox/_network.html.erb +24 -0
  22. data/app/views/compute_resources_vms/form/proxmox/_volume.html.erb +23 -0
  23. data/app/views/compute_resources_vms/index/_proxmox.html.erb +45 -0
  24. data/app/views/compute_resources_vms/show/_proxmox.html.erb +36 -0
  25. data/app/views/dashboard/_the_foreman_proxmox_widget.erb +19 -0
  26. data/app/views/images/form/_proxmox.html.erb +4 -0
  27. data/config/routes.rb +24 -0
  28. data/lib/tasks/the_foreman_proxmox_tasks.rake +47 -0
  29. data/lib/the_foreman_proxmox.rb +23 -0
  30. data/lib/the_foreman_proxmox/engine.rb +92 -0
  31. data/lib/the_foreman_proxmox/version.rb +22 -0
  32. data/locale/Makefile +60 -0
  33. data/locale/en/foreman_proxmox.po +19 -0
  34. data/locale/gemspec.rb +2 -0
  35. data/locale/the_foreman_proxmox.pot +19 -0
  36. data/test/factories/the_foreman_proxmox_factories.rb +33 -0
  37. data/test/helpers/proxmox_compute_helper_test.rb +130 -0
  38. data/test/test_plugin_helper.rb +15 -0
  39. data/test/unit/the_foreman_proxmox_test.rb +11 -0
  40. metadata +143 -0
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanProxmox.
6
+
7
+ # ForemanProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module TheForemanProxmox
21
+ VERSION = '0.3.0'.freeze
22
+ end
@@ -0,0 +1,60 @@
1
+ #
2
+ # Makefile for PO merging and MO generation. More info in the README.
3
+ #
4
+ # make all-mo (default) - generate MO files
5
+ # make check - check translations using translate-tool
6
+ # make tx-update - download and merge translations from Transifex
7
+ # make clean - clean everything
8
+ #
9
+ DOMAIN = the_foreman_proxmox
10
+ VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
11
+ POTFILE = $(DOMAIN).pot
12
+ MOFILE = $(DOMAIN).mo
13
+ POFILES = $(shell find . -name '$(DOMAIN).po')
14
+ MOFILES = $(patsubst %.po,%.mo,$(POFILES))
15
+ POXFILES = $(patsubst %.po,%.pox,$(POFILES))
16
+ EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
17
+
18
+ %.mo: %.po
19
+ mkdir -p $(shell dirname $@)/LC_MESSAGES
20
+ msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<
21
+
22
+ # Generate MO files from PO files
23
+ all-mo: $(MOFILES)
24
+
25
+ # Check for malformed strings
26
+ %.pox: %.po
27
+ msgfmt -c $<
28
+ pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
29
+ -t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
30
+ cat $@
31
+ ! grep -q msgid $@
32
+
33
+ %.edit.po:
34
+ touch $@
35
+
36
+ check: $(POXFILES)
37
+
38
+ # Unify duplicate translations
39
+ uniq-po:
40
+ for f in $(shell find ./ -name "*.po") ; do \
41
+ msguniq $$f -o $$f ; \
42
+ done
43
+
44
+ tx-pull: $(EDITFILES)
45
+ tx pull -f
46
+ for f in $(EDITFILES) ; do \
47
+ sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
48
+ done
49
+
50
+ tx-update: tx-pull
51
+ @echo
52
+ @echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
53
+ @echo
54
+
55
+ mo-files: $(MOFILES)
56
+ git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
57
+ git commit -m "i18n - pulling from tx"
58
+ @echo
59
+ @echo Changes commited!
60
+ @echo
@@ -0,0 +1,19 @@
1
+ # foreman_proxmox
2
+ #
3
+ # This file is distributed under the same license as foreman_proxmox.
4
+ #
5
+ #, fuzzy
6
+ msgid ""
7
+ msgstr ""
8
+ "Project-Id-Version: version 0.0.1\n"
9
+ "Report-Msgid-Bugs-To: \n"
10
+ "POT-Creation-Date: 2014-08-20 08:46+0100\n"
11
+ "PO-Revision-Date: 2014-08-20 08:54+0100\n"
12
+ "Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
13
+ "Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
14
+ "Language: \n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
+
@@ -0,0 +1,2 @@
1
+ # Matches the_foreman_proxmox.gemspec
2
+ _('TheForemanProxmox plugin adds Proxmox VE compute resource to Foreman using fog-proxmox gem.')
@@ -0,0 +1,19 @@
1
+ # the_foreman_proxmox
2
+ #
3
+ # This file is distributed under the same license as the_foreman_proxmox.
4
+ #
5
+ #, fuzzy
6
+ msgid ""
7
+ msgstr ""
8
+ "Project-Id-Version: version 0.0.1\n"
9
+ "Report-Msgid-Bugs-To: \n"
10
+ "POT-Creation-Date: 2014-08-20 08:46+0100\n"
11
+ "PO-Revision-Date: 2014-08-20 08:46+0100\n"
12
+ "Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
13
+ "Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
14
+ "Language: \n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
19
+
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of TheForemanProxmox.
6
+
7
+ # TheForemanProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # TheForemanProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with TheForemanProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ FactoryBot.define do
21
+ factory :container_resource, :class => ComputeResource do
22
+ sequence(:name) { |n| "compute_resource#{n}" }
23
+
24
+ trait :proxmox do
25
+ provider 'proxmox'
26
+ url 'https://192.168.56.101:8006/api2/json'
27
+ user 'root@pam'
28
+ password 'proxmox01'
29
+ end
30
+
31
+ factory :proxmox_cr, :class => TheForemanProxmox::Proxmox, :traits => [:proxmox]
32
+ end
33
+ end
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of TheForemanProxmox.
6
+
7
+ # TheForemanProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # TheForemanProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with TheForemanProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'test_plugin_helper'
21
+
22
+ class ProxmoxComputeHelperTest < ActiveSupport::TestCase
23
+ include ProxmoxComputeHelper
24
+
25
+ describe 'parse' do
26
+
27
+ setup { Fog.mock! }
28
+ teardown { Fog.unmock! }
29
+
30
+ let(:host) do
31
+ { 'vmid' => '100',
32
+ 'name' => 'test',
33
+ 'node' => 'pve',
34
+ 'config_attributes' => {
35
+ 'memory' => '512',
36
+ 'min_memory' => '',
37
+ 'ballon' => '',
38
+ 'shares' => '',
39
+ 'cpu_type' => 'kvm64',
40
+ 'spectre' => '1',
41
+ 'pcid' => '0',
42
+ 'cores' => '1',
43
+ 'sockets' => '1'
44
+ },
45
+ 'volumes_attributes' => {'0'=> { 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' }},
46
+ 'interfaces_attributes' => {
47
+ '0' => { 'id' => 'net0', 'model' => 'virtio', 'bridge' => 'vmbr0' },
48
+ '1' => { 'id' => 'net1', 'model' => 'e1000', 'bridge' => 'vmbr0' }
49
+ }
50
+ }
51
+ end
52
+
53
+ let(:host_delete) do
54
+ { 'vmid' => '100',
55
+ 'name' => 'test',
56
+ 'volumes_attributes' => { '0' => { '_delete' => '1', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824' }},
57
+ 'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'model' => 'virtio' } }
58
+ }
59
+ end
60
+
61
+ test '#memory' do
62
+ memory = parse_memory(host['config_attributes'])
63
+ assert memory.has_key?(:memory)
64
+ assert_equal memory[:memory], 512
65
+ end
66
+
67
+ test '#cpu' do
68
+ cpu = parse_cpu(host['config_attributes'])
69
+ assert cpu.has_key?(:cpu)
70
+ assert_equal cpu[:cpu], 'cputype=kvm64,flags=+spec-ctrl'
71
+ end
72
+
73
+ test '#vm' do
74
+ vm = parse_vm(host)
75
+ assert_equal vm['cores'], '1'
76
+ assert_equal vm['sockets'], '1'
77
+ assert_equal vm[:cpu], 'cputype=kvm64,flags=+spec-ctrl'
78
+ assert_equal vm[:memory], 512
79
+ assert_equal vm[:scsi0], 'local-lvm:1073741824,cache=none'
80
+ assert_equal vm[:net0], 'model=virtio,bridge=vmbr0'
81
+ assert !vm.has_key?(:config)
82
+ assert !vm.has_key?(:node)
83
+ end
84
+
85
+ test '#volume with scsi 1Gb' do
86
+ volumes = parse_volumes(host['volumes_attributes'])
87
+ assert !volumes.empty?
88
+ assert volume = volumes.first
89
+ assert volume.has_key?(:scsi0)
90
+ assert_equal volume[:scsi0], 'local-lvm:1073741824,cache=none'
91
+ end
92
+
93
+ test '#volume delete scsi0' do
94
+ volumes = parse_volumes(host_delete['volumes_attributes'])
95
+ assert !volumes.empty?
96
+ assert_equal volumes.length, 1
97
+ assert volume = volumes.first
98
+ assert volume.has_key?(:delete)
99
+ assert_match(/(net0,){0,1}scsi0(,net0){0,1}/, volume[:delete])
100
+ end
101
+
102
+ test '#interface with model virtio and bridge' do
103
+ interface = parse_interface(host['interfaces_attributes']['0'].merge(device: '0'))
104
+ assert interface.has_key?(:net0)
105
+ assert_equal interface[:net0], 'model=virtio,bridge=vmbr0'
106
+ end
107
+
108
+ test '#interface with model e1000 and bridge' do
109
+ interface = parse_interface(host['interfaces_attributes']['1'].merge(device: '1'))
110
+ assert interface.has_key?(:net1)
111
+ assert_equal interface[:net1], 'model=e1000,bridge=vmbr0'
112
+ end
113
+
114
+ test '#interface delete net0' do
115
+ interface = parse_interface(host_delete['interfaces_attributes']['0'].merge(device: '0'))
116
+ assert interface.has_key?(:delete)
117
+ assert_match(/(scsi0,){0,1}net0(,scsi0){0,1}/, interface[:delete])
118
+ assert_equal interface.length, 1
119
+ end
120
+
121
+ test '#interfaces' do
122
+ interfaces = parse_interfaces(host['interfaces_attributes'])
123
+ assert !interfaces.empty?
124
+ assert_equal interfaces.length, 2
125
+ assert interfaces.include?({ net0: 'model=virtio,bridge=vmbr0'})
126
+ assert interfaces.include?({ net1: 'model=e1000,bridge=vmbr0'})
127
+ end
128
+
129
+ end
130
+ end
@@ -0,0 +1,15 @@
1
+ # This calls the main test_helper in Foreman-core
2
+
3
+ require 'simplecov'
4
+
5
+ SimpleCov.start do
6
+ add_filter '/test/'
7
+ add_group 'App', 'app'
8
+ add_group 'Lib', 'lib'
9
+ end
10
+
11
+ require 'test_helper'
12
+
13
+ # Add plugin to FactoryBot's paths
14
+ FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
15
+ FactoryBot.reload
@@ -0,0 +1,11 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class TheForemanProxmoxTest < ActiveSupport::TestCase
4
+ setup do
5
+ User.current = User.find_by login: 'admin'
6
+ end
7
+
8
+ test 'the truth' do
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_foreman_proxmox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Tristan Robert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fog-proxmox
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
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: rubocop
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: simplecov
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: Foreman plugin adds Proxmox VE compute resource using fog-proxmox. It
70
+ is compatible with Foreman 1.17
71
+ email:
72
+ - tristan.robert.44@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - app/assets/javascripts/the_foreman_proxmox/proxmox.js
81
+ - app/controllers/concerns/the_foreman_proxmox/controller/parameters/compute_resource.rb
82
+ - app/controllers/the_foreman_proxmox/compute_resources_controller.rb
83
+ - app/helpers/proxmox_compute_helper.rb
84
+ - app/helpers/proxmox_compute_selectors_helper.rb
85
+ - app/models/concerns/fog_extensions/proxmox/disk.rb
86
+ - app/models/concerns/fog_extensions/proxmox/server.rb
87
+ - app/models/concerns/fog_extensions/proxmox/server_config.rb
88
+ - app/models/concerns/fog_extensions/proxmox/volume.rb
89
+ - app/models/the_foreman_proxmox/options_select.rb
90
+ - app/models/the_foreman_proxmox/proxmox.rb
91
+ - app/views/api/v2/compute_resources/proxmox.json.rabl
92
+ - app/views/compute_resources/form/_proxmox.html.erb
93
+ - app/views/compute_resources/show/_proxmox.html.erb
94
+ - app/views/compute_resources_vms/form/proxmox/_base.html.erb
95
+ - app/views/compute_resources_vms/form/proxmox/_config.html.erb
96
+ - app/views/compute_resources_vms/form/proxmox/_network.html.erb
97
+ - app/views/compute_resources_vms/form/proxmox/_volume.html.erb
98
+ - app/views/compute_resources_vms/index/_proxmox.html.erb
99
+ - app/views/compute_resources_vms/show/_proxmox.html.erb
100
+ - app/views/dashboard/_the_foreman_proxmox_widget.erb
101
+ - app/views/images/form/_proxmox.html.erb
102
+ - config/routes.rb
103
+ - lib/tasks/the_foreman_proxmox_tasks.rake
104
+ - lib/the_foreman_proxmox.rb
105
+ - lib/the_foreman_proxmox/engine.rb
106
+ - lib/the_foreman_proxmox/version.rb
107
+ - locale/Makefile
108
+ - locale/en/foreman_proxmox.po
109
+ - locale/gemspec.rb
110
+ - locale/the_foreman_proxmox.pot
111
+ - test/factories/the_foreman_proxmox_factories.rb
112
+ - test/helpers/proxmox_compute_helper_test.rb
113
+ - test/test_plugin_helper.rb
114
+ - test/unit/the_foreman_proxmox_test.rb
115
+ homepage: https://github.com/tristanrobert/foreman_proxmox
116
+ licenses:
117
+ - GPL-3.0
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.5.2.3
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Foreman plugin that adds Proxmox VE compute resource using fog-proxmox
139
+ test_files:
140
+ - test/helpers/proxmox_compute_helper_test.rb
141
+ - test/test_plugin_helper.rb
142
+ - test/factories/the_foreman_proxmox_factories.rb
143
+ - test/unit/the_foreman_proxmox_test.rb