foreman_proxmox 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,47 +1,47 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
14
-
15
- RDoc::Task.new(:rdoc) do |rdoc|
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'ForemanProxmox'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
23
- APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
24
-
25
- Bundler::GemHelper.install_tasks
26
-
27
- require 'rake/testtask'
28
-
29
- Rake::TestTask.new(:test) do |t|
30
- t.libs << 'lib'
31
- t.libs << 'test'
32
- t.pattern = 'test/**/*_test.rb'
33
- t.verbose = false
34
- end
35
-
36
- task default: :test
37
-
38
- begin
39
- require 'rubocop/rake_task'
40
- RuboCop::RakeTask.new
41
- rescue => _
42
- puts 'Rubocop not loaded.'
43
- end
44
-
45
- task :default do
46
- Rake::Task['rubocop'].execute
47
- end
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ForemanProxmox'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+ task default: :test
37
+
38
+ begin
39
+ require 'rubocop/rake_task'
40
+ RuboCop::RakeTask.new
41
+ rescue => _
42
+ puts 'Rubocop not loaded.'
43
+ end
44
+
45
+ task :default do
46
+ Rake::Task['rubocop'].execute
47
+ end
@@ -1,20 +1,11 @@
1
- require 'rest-client'
2
- module ForemanProxmox
3
- # Example: Plugin's HostsController inherits from Foreman's HostsController
4
- class HostsController < ::HostsController
5
- # change layout if needed
6
- # layout 'foreman_proxmox/layouts/new_layout'
7
-
8
- def new_action
9
- # automatically renders view/foreman_proxmox/hosts/new_action
10
- end
11
-
12
- def intializeProxmox
13
- @response = 'not yet authenticated'
14
- @proxmoxip = params[:proxmoxip]
15
- @proxmoxuser = params[:proxmoxuser]
16
- @proxmoxpassword = params[:proxmoxpassword]
17
- @response = RestClient.post 'http://'+@proxmoxip+':8006/api2/json/access/ticket', {:params => {:username => @proxmoxuser+'@pam', :password => @proxmoxpassword}}
18
- end
19
- end
20
- end
1
+ module ForemanProxmox
2
+ # Example: Plugin's HostsController inherits from Foreman's HostsController
3
+ class HostsController < ::HostsController
4
+ # change layout if needed
5
+ # layout 'foreman_proxmox/layouts/new_layout'
6
+
7
+ def new_action
8
+ # automatically renders view/foreman_proxmox/hosts/new_action
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module ForemanProxmox
2
+ class ProxmoxController < ::ApplicationController
3
+ before_filter :find_resource, :only => %w[host full_host]
4
+
5
+ def create_vm
6
+
7
+ end
8
+
9
+ private
10
+
11
+ def resource_scope(controller = controller_name)
12
+ Host::Managed.authorized(:view_hosts)
13
+ end
14
+ end
15
+ end
@@ -1,13 +1,36 @@
1
- module ForemanProxmox
2
- module HostsHelperExtensions
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- # execute callbacks
7
- end
8
-
9
- # create or overwrite instance methods...
10
- def instance_method_name
11
- end
12
- end
13
- end
1
+ module ForemanProxmox
2
+ module HostsHelperExtensions
3
+ extend ActiveSupport::Concern
4
+
5
+
6
+ included do
7
+ alias_method_chain :host_title_actions, :proxmox
8
+ end
9
+
10
+
11
+ def host_title_actions_with_proxmox(*args)
12
+ title_actions(
13
+ button_group(
14
+ display_proxmox_if_Authorized(_("Create VM"), {:controller => 'foreman_proxmox/proxmox', :action => 'create_vm',:id => @host}, :class => 'btn')
15
+ )
16
+ )
17
+ host_title_actions_without_proxmox(*args)
18
+ end
19
+
20
+ def display_proxmox_if_Authorized(name, options = {}, html_options = {})
21
+ if is_authorized(options)
22
+ link_to(name, proxmox_url(options), html_options)
23
+ else
24
+ ""
25
+ end
26
+ end
27
+
28
+ def proxmox_url(options)
29
+ ForemanProxmox::Engine.routes.url_for(options.merge(:only_path => true, :script_name => proxmox_create_path))
30
+ end
31
+
32
+ def is_authorized(options)
33
+ User.current.allowed_to?(options)
34
+ end
35
+ end
36
+ end
@@ -1,19 +1,19 @@
1
- module ForemanProxmox
2
- module HostExtensions
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- # execute callbacks
7
- end
8
-
9
- # create or overwrite instance methods...
10
- def instance_method_name
11
- end
12
-
13
- module ClassMethods
14
- # create or overwrite class methods...
15
- def class_method_name
16
- end
17
- end
18
- end
19
- end
1
+ module ForemanProxmox
2
+ module HostExtensions
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # execute callbacks
7
+ end
8
+
9
+ # create or overwrite instance methods...
10
+ def instance_method_name
11
+ end
12
+
13
+ module ClassMethods
14
+ # create or overwrite class methods...
15
+ def class_method_name
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,4 +1,4 @@
1
- <!-- insert_before 'div:contains("title_action")' -->
2
- <%= title_actions "<h2>ForemanProxmox</h2>" %>
3
-
4
- <!-- vim: set ft=eruby : -->
1
+ <!-- insert_before 'div:contains("title_action")' -->
2
+ <%= title_actions "<h2>ForemanProxmox</h2>" %>
3
+
4
+ <!-- vim: set ft=eruby : -->
@@ -1,2 +1,2 @@
1
- <h4 class="header ca"><%= _('ForemanProxmox') %></h4>
2
- <%= _('Testing') %>
1
+ <h4 class="header ca"><%= _('ForemanProxmox') %></h4>
2
+ <%= _('Widget content') %>
@@ -1 +1 @@
1
- Welcome to <b>Testing</b>
1
+ Welcome to <b>ForemanProxmox</b>
@@ -1,14 +1 @@
1
- Welcome to <b>ForemanProxmox</b>
2
- Connect to your Proxmox-server here.
3
- <%= form_tag("hosts/intializeProxmox", method: "post") do %>
4
- <%= label_tag(:proxmoxip, "Proxmox-server IP:") %>
5
- <%= text_field_tag(:proxmoxip) %>
6
- <%= label_tag(:proxmoxuser, "Proxmox-username:") %>
7
- <%= text_field_tag(:proxmoxuser) %>
8
- <%= label_tag(:proxmoxpassword, "Proxmox-password:") %>
9
- <%= password_field_tag(:proxmoxpassword) %>
10
- <%= submit_tag("Connect") %>
11
- <% end %>
12
- <%= label_tag(:response) %>
13
-
14
-
1
+ Welcome to <b>ForemanProxmox</b>
data/config/routes.rb CHANGED
@@ -1,3 +1,3 @@
1
- Rails.application.routes.draw do
2
- match 'new_action', to: 'foreman_proxmox/hosts#new_action'
3
- end
1
+ Rails.application.routes.draw do
2
+ get 'proxmox/:id' => 'proxmox#create_vm'
3
+ end
@@ -1,79 +1,79 @@
1
- require 'deface'
2
-
3
- module ForemanProxmox
4
- class Engine < ::Rails::Engine
5
- engine_name 'foreman_proxmox'
6
-
7
- config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
8
- config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
9
- config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
10
- config.autoload_paths += Dir["#{config.root}/app/overrides"]
11
-
12
- # Add any db migrations
13
- initializer 'foreman_proxmox.load_app_instance_data' do |app|
14
- app.config.paths['db/migrate'] += ForemanProxmox::Engine.paths['db/migrate'].existent
15
- end
16
-
17
- initializer 'foreman_proxmox.register_plugin', after: :finisher_hook do |_app|
18
- Foreman::Plugin.register :foreman_proxmox do
19
- requires_foreman '>= 1.6'
20
-
21
- # Add permissions
22
- security_block :foreman_proxmox do
23
- permission :view_foreman_proxmox, :'foreman_proxmox/hosts' => [:new_action]
24
- end
25
-
26
- # Add a new role called 'Discovery' if it doesn't exist
27
- role 'ForemanProxmox', [:view_foreman_proxmox]
28
-
29
- # add menu entry
30
- menu :top_menu, :template,
31
- url_hash: { controller: :'foreman_proxmox/hosts', action: :new_action },
32
- caption: 'ForemanProxmox',
33
- parent: :hosts_menu,
34
- after: :hosts
35
-
36
- # add dashboard widget
37
- widget 'foreman_proxmox_widget', name: N_('Foreman Proxmox widget'), sizex: 4, sizey: 1
38
- end
39
- end
40
-
41
- # Precompile any JS or CSS files under app/assets/
42
- # If requiring files from each other, list them explicitly here to avoid precompiling the same
43
- # content twice.
44
- assets_to_precompile =
45
- Dir.chdir(root) do
46
- Dir['app/assets/javascripts/**/*', 'app/assets/stylesheets/**/*'].map do |f|
47
- f.split(File::SEPARATOR, 4).last
48
- end
49
- end
50
- initializer 'foreman_proxmox.assets.precompile' do |app|
51
- app.config.assets.precompile += assets_to_precompile
52
- end
53
- initializer 'foreman_proxmox.configure_assets', group: :assets do
54
- SETTINGS[:foreman_proxmox] = { assets: { precompile: assets_to_precompile } }
55
- end
56
-
57
- # Include concerns in this config.to_prepare block
58
- config.to_prepare do
59
- begin
60
- Host::Managed.send(:include, ForemanProxmox::HostExtensions)
61
- HostsHelper.send(:include, ForemanProxmox::HostsHelperExtensions)
62
- rescue => e
63
- Rails.logger.warn "ForemanProxmox: skipping engine hook (#{e})"
64
- end
65
- end
66
-
67
- rake_tasks do
68
- Rake::Task['db:seed'].enhance do
69
- ForemanProxmox::Engine.load_seed
70
- end
71
- end
72
-
73
- initializer 'foreman_proxmox.register_gettext', after: :load_config_initializers do |_app|
74
- locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
75
- locale_domain = 'foreman_proxmox'
76
- Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
77
- end
78
- end
79
- end
1
+ require 'deface'
2
+
3
+ module ForemanProxmox
4
+ class Engine < ::Rails::Engine
5
+ engine_name 'foreman_proxmox'
6
+
7
+ config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
8
+ config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
9
+ config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
10
+ config.autoload_paths += Dir["#{config.root}/app/overrides"]
11
+
12
+ # Add any db migrations
13
+ initializer 'foreman_proxmox.load_app_instance_data' do |app|
14
+ app.config.paths['db/migrate'] += ForemanProxmox::Engine.paths['db/migrate'].existent
15
+ end
16
+
17
+ initializer 'foreman_proxmox.register_plugin', after: :finisher_hook do |_app|
18
+ Foreman::Plugin.register :foreman_proxmox do
19
+ requires_foreman '>= 1.4'
20
+
21
+ # Add permissions
22
+ security_block :foreman_proxmox do
23
+ permission :view_foreman_proxmox, :'foreman_proxmox/hosts' => [:new_action]
24
+ end
25
+
26
+ # Add a new role called 'Discovery' if it doesn't exist
27
+ role 'ForemanProxmox', [:view_foreman_proxmox]
28
+
29
+ # add menu entry
30
+ menu :top_menu, :template,
31
+ url_hash: { controller: :'foreman_proxmox/hosts', action: :new_action },
32
+ caption: 'ForemanProxmox',
33
+ parent: :hosts_menu,
34
+ after: :hosts
35
+
36
+ # add dashboard widget
37
+ widget 'foreman_proxmox_widget', name: N_('Foreman plugin template widget'), sizex: 4, sizey: 1
38
+ end
39
+ end
40
+
41
+ # Precompile any JS or CSS files under app/assets/
42
+ # If requiring files from each other, list them explicitly here to avoid precompiling the same
43
+ # content twice.
44
+ assets_to_precompile =
45
+ Dir.chdir(root) do
46
+ Dir['app/assets/javascripts/**/*', 'app/assets/stylesheets/**/*'].map do |f|
47
+ f.split(File::SEPARATOR, 4).last
48
+ end
49
+ end
50
+ initializer 'foreman_proxmox.assets.precompile' do |app|
51
+ app.config.assets.precompile += assets_to_precompile
52
+ end
53
+ initializer 'foreman_proxmox.configure_assets', group: :assets do
54
+ SETTINGS[:foreman_proxmox] = { assets: { precompile: assets_to_precompile } }
55
+ end
56
+
57
+ # Include concerns in this config.to_prepare block
58
+ config.to_prepare do
59
+ begin
60
+ Host::Managed.send(:include, ForemanProxmox::HostExtensions)
61
+ HostsHelper.send(:include, ForemanProxmox::HostsHelperExtensions)
62
+ rescue => e
63
+ Rails.logger.warn "ForemanProxmox: skipping engine hook (#{e})"
64
+ end
65
+ end
66
+
67
+ rake_tasks do
68
+ Rake::Task['db:seed'].enhance do
69
+ ForemanProxmox::Engine.load_seed
70
+ end
71
+ end
72
+
73
+ initializer 'foreman_proxmox.register_gettext', after: :load_config_initializers do |_app|
74
+ locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
75
+ locale_domain = 'foreman_proxmox'
76
+ Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
77
+ end
78
+ end
79
+ end
@@ -1,3 +1,3 @@
1
- module ForemanProxmox
2
- VERSION = '0.0.9'
3
- end
1
+ module ForemanProxmox
2
+ VERSION = '0.0.10'
3
+ end
@@ -1,4 +1,4 @@
1
- require 'foreman_proxmox/engine'
2
-
3
- module ForemanProxmox
4
- end
1
+ require 'foreman_proxmox/engine'
2
+
3
+ module ForemanProxmox
4
+ end
@@ -1,49 +1,49 @@
1
- # Tasks
2
- namespace :foreman_proxmox do
3
- namespace :example do
4
- desc 'Example Task'
5
- task task: :environment do
6
- # Task goes here
7
- end
8
- end
9
- end
10
-
11
- # Tests
12
- namespace :test do
13
- desc 'Test ForemanProxmox'
14
- Rake::TestTask.new(:foreman_proxmox) do |t|
15
- test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
16
- t.libs << ['test', test_dir]
17
- t.pattern = "#{test_dir}/**/*_test.rb"
18
- t.verbose = true
19
- end
20
- end
21
-
22
- namespace :foreman_proxmox do
23
- task :rubocop do
24
- begin
25
- require 'rubocop/rake_task'
26
- RuboCop::RakeTask.new(:rubocop_foreman_proxmox) do |task|
27
- task.patterns = ["#{ForemanProxmox::Engine.root}/app/**/*.rb",
28
- "#{ForemanProxmox::Engine.root}/lib/**/*.rb",
29
- "#{ForemanProxmox::Engine.root}/test/**/*.rb"]
30
- end
31
- rescue
32
- puts 'Rubocop not loaded.'
33
- end
34
-
35
- Rake::Task['rubocop_foreman_proxmox'].invoke
36
- end
37
- end
38
-
39
- Rake::Task[:test].enhance do
40
- Rake::Task['test:foreman_proxmox'].invoke
41
- end
42
-
43
- load 'tasks/jenkins.rake'
44
- if Rake::Task.task_defined?(:'jenkins:unit')
45
- Rake::Task['jenkins:unit'].enhance do
46
- Rake::Task['test:foreman_proxmox'].invoke
47
- Rake::Task['foreman_proxmox:rubocop'].invoke
48
- end
49
- end
1
+ # Tasks
2
+ namespace :foreman_proxmox do
3
+ namespace :example do
4
+ desc 'Example Task'
5
+ task task: :environment do
6
+ # Task goes here
7
+ end
8
+ end
9
+ end
10
+
11
+ # Tests
12
+ namespace :test do
13
+ desc 'Test ForemanProxmox'
14
+ Rake::TestTask.new(:foreman_proxmox) do |t|
15
+ test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
16
+ t.libs << ['test', test_dir]
17
+ t.pattern = "#{test_dir}/**/*_test.rb"
18
+ t.verbose = true
19
+ end
20
+ end
21
+
22
+ namespace :foreman_proxmox do
23
+ task :rubocop do
24
+ begin
25
+ require 'rubocop/rake_task'
26
+ RuboCop::RakeTask.new(:rubocop_foreman_proxmox) do |task|
27
+ task.patterns = ["#{ForemanProxmox::Engine.root}/app/**/*.rb",
28
+ "#{ForemanProxmox::Engine.root}/lib/**/*.rb",
29
+ "#{ForemanProxmox::Engine.root}/test/**/*.rb"]
30
+ end
31
+ rescue
32
+ puts 'Rubocop not loaded.'
33
+ end
34
+
35
+ Rake::Task['rubocop_foreman_proxmox'].invoke
36
+ end
37
+ end
38
+
39
+ Rake::Task[:test].enhance do
40
+ Rake::Task['test:foreman_proxmox'].invoke
41
+ end
42
+
43
+ load 'tasks/jenkins.rake'
44
+ if Rake::Task.task_defined?(:'jenkins:unit')
45
+ Rake::Task['jenkins:unit'].enhance do
46
+ Rake::Task['test:foreman_proxmox'].invoke
47
+ Rake::Task['foreman_proxmox:rubocop'].invoke
48
+ end
49
+ end