foreman_proxmox 0.0.12 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +10 -20
  3. data/app/controllers/foreman_proxmox/proxmoxservers_controller.rb +62 -0
  4. data/app/controllers/foreman_proxmox/virtualmachines_controller.rb +76 -0
  5. data/app/helpers/concerns/foreman_proxmox/hosts_helper_extensions.rb +13 -3
  6. data/app/helpers/foreman_proxmox/proxmoxservers_helper.rb +26 -0
  7. data/app/helpers/foreman_proxmox/virtualmachines_helper.rb +9 -0
  8. data/app/models/concerns/foreman_proxmox/host_extensions.rb +43 -0
  9. data/app/models/foreman_proxmox/proxmoxserver.rb +204 -0
  10. data/app/models/foreman_proxmox/virtualmachine.rb +42 -0
  11. data/app/views/foreman_proxmox/{hosts/proxmox.html.erb → proxmoxservers/_form.html.erb} +1 -4
  12. data/app/views/foreman_proxmox/proxmoxservers/edit.html.erb +12 -0
  13. data/app/views/foreman_proxmox/proxmoxservers/index.html.erb +36 -0
  14. data/app/views/foreman_proxmox/proxmoxservers/new.html.erb +12 -0
  15. data/app/views/foreman_proxmox/proxmoxservers/show.html.erb +50 -0
  16. data/app/views/foreman_proxmox/virtualmachines/show.html.erb +33 -0
  17. data/app/views/layouts/foreman_proxmox/application.html.erb +14 -0
  18. data/config/routes.rb +16 -8
  19. data/db/migrate/20151021104305_create_foreman_proxmox_proxmoxservers.rb +12 -0
  20. data/db/migrate/20151030104550_create_foreman_proxmox_virtualmachines.rb +15 -0
  21. data/lib/foreman_proxmox/engine.rb +6 -3
  22. data/lib/foreman_proxmox/version.rb +1 -1
  23. data/test/controllers/foreman_proxmox/{creations_controller_test.rb → proxmoxservers_controller_test.rb} +1 -1
  24. data/test/controllers/foreman_proxmox/{hosts_controller_test.rb → virtualmachines_controller_test.rb} +1 -1
  25. data/test/dummy/config/secrets.yml +2 -2
  26. data/test/fixtures/foreman_proxmox/{proxmox_connections.yml → proxmoxservers.yml} +0 -0
  27. data/test/fixtures/foreman_proxmox/virtualmachines.yml +17 -0
  28. data/test/models/foreman_proxmox/{proxmox_connection_test.rb → proxmoxserver_test.rb} +1 -1
  29. data/test/models/foreman_proxmox/virtualmachine_test.rb +9 -0
  30. metadata +71 -42
  31. data/app/controllers/foreman_proxmox/creations_controller.rb +0 -17
  32. data/app/controllers/foreman_proxmox/hosts_controller.rb +0 -18
  33. data/app/models/foreman_proxmox/proxmox_connection.rb +0 -4
  34. data/db/migrate/20151006132039_create_foreman_proxmox_proxmox_connections.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0800d3ce318e244809442420b40d30aeabb50d9c
4
- data.tar.gz: 783e91d35f3ad3dafb49542a415d7ae75040491c
3
+ metadata.gz: 95bfb36adea1b34da0acc5a573e321bd3811e729
4
+ data.tar.gz: 4d32901d852bc5be08e39d40ed91be52c73947d8
5
5
  SHA512:
6
- metadata.gz: 0f507e5db2f4ae5466752f87365c85af50c729c5b2e3c2d76357bbea54f672e962ce8f6a5c2a0a267517a60426de5cbb796d2b8ca97124747c7874cd376fb375
7
- data.tar.gz: 1b154d8cc5fb78052a067db01366f159fe24933f2bffe8c1bb0843995a573ff0f21c9885d5b1ed85e13c209eb2d6065ef1db99b4d034adcc98344f53bc3d65dd
6
+ metadata.gz: 1b27a1001c580c4a6db22132eb2d9e347528c7bd1c377fb8563f4556bcbd6402ebe57bd531be0f196d91484d6b47afbe22e87f956f130df2f631de9b3e2613b3
7
+ data.tar.gz: 64aad54ca6b7485becfc312451019a0a8b4f856971172e7c5619b9465a769c0640f9f219b34aedeb4fc07a841eaa74c22554d92e5b634718cffe57b04fe9e4a0
data/Rakefile CHANGED
@@ -1,16 +1,10 @@
1
- #!/usr/bin/env rake
2
1
  begin
3
2
  require 'bundler/setup'
4
3
  rescue LoadError
5
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
5
  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
6
+
7
+ require 'rdoc/task'
14
8
 
15
9
  RDoc::Task.new(:rdoc) do |rdoc|
16
10
  rdoc.rdoc_dir = 'rdoc'
@@ -20,7 +14,13 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
14
  rdoc.rdoc_files.include('lib/**/*.rb')
21
15
  end
22
16
 
23
- APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
24
 
25
25
  Bundler::GemHelper.install_tasks
26
26
 
@@ -33,15 +33,5 @@ Rake::TestTask.new(:test) do |t|
33
33
  t.verbose = false
34
34
  end
35
35
 
36
- task default: :test
37
36
 
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
37
+ task default: :test
@@ -0,0 +1,62 @@
1
+ module ForemanProxmox
2
+ class ProxmoxserversController < ApplicationController
3
+
4
+ def index
5
+ @proxmoxservers = Proxmoxserver.all
6
+ end
7
+
8
+ def show
9
+ @proxmox = Proxmoxserver.find(params[:id])
10
+ end
11
+
12
+
13
+ def new
14
+ @proxmox = Proxmoxserver.new
15
+ end
16
+
17
+ def create
18
+ Proxmoxserver.create(params[:proxmoxserver])
19
+ redirect_to '/proxmox'
20
+ end
21
+
22
+ def edit
23
+ @proxmox = Proxmoxserver.find(params[:id])
24
+ end
25
+
26
+ def update
27
+ end
28
+
29
+ def destroy
30
+ end
31
+
32
+ def setcurrent
33
+ oldcurrent = Proxmoxserver.where("current = 'true'").first
34
+ if oldcurrent != nil then
35
+ oldcurrent.current = false
36
+ end
37
+ newcurrent = Proxmoxserver.find(params[:id])
38
+ newcurrent.current= true
39
+ if newcurrent.save then
40
+ flash[:notice] = newcurrent.current
41
+ end
42
+ redirect_to :back
43
+ end
44
+
45
+ def start_all_vms
46
+ redirect_to :back
47
+ end
48
+
49
+ def stop_all_vms
50
+ redirect_to :back
51
+ end
52
+
53
+ def reboot_node
54
+ redirect_to :back
55
+ end
56
+
57
+ def shutdown_node
58
+ redirect_to :back
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,76 @@
1
+ require 'logger'
2
+ module ForemanProxmox
3
+ class VirtualmachinesController < ApplicationController
4
+
5
+ def create_vm
6
+ host = Host.find(params[:id])
7
+ $LOG= Logger.new("/tmp/proxmox_debug.log")
8
+
9
+ if Virtualmachine.where("host_id = '#{host.id}'").first == nil then
10
+ new_vm = Virtualmachine.new
11
+
12
+ $LOG.error("creating vm")
13
+
14
+ if host.params['vmid'] == nil then
15
+ $LOG.error("searching vmid")
16
+ new_vm.get_free_vmid
17
+ else
18
+ new_vm.vmid = host.params['vmid']
19
+ end
20
+
21
+ $LOG.error(new_vm.vmid)
22
+ new_vm.sockets = host.params['sockets']
23
+ new_vm.cores = host.params['cores']
24
+ new_vm.memory = host.params['memory']
25
+ new_vm.size = host.params['size']
26
+ new_vm.mac = host.mac
27
+ new_vm.host_id = host.id
28
+
29
+ if new_vm.save then
30
+ flash[:notice] = "VM saved in DB"
31
+ else
32
+ flash[:error] = _('Fail')
33
+ end
34
+ end
35
+
36
+ new_vm = Virtualmachine.where("host_id = '#{host.id}'").first
37
+
38
+ new_vm.create_harddisk
39
+ new_vm.create_virtualmachine
40
+ new_vm.start
41
+
42
+ redirect_to :back
43
+ end
44
+
45
+ def start_vm
46
+ vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
47
+ vm.start
48
+ redirect_to :back
49
+ end
50
+
51
+ def stop_vm
52
+ vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
53
+ vm.stop
54
+ redirect_to :back
55
+ end
56
+
57
+ def reboot_vm
58
+ vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
59
+ vm.reboot
60
+ redirect_to :back
61
+ end
62
+
63
+ def delete_vm
64
+ vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
65
+ vm.delete_virtualmachine
66
+ redirect_to :back
67
+ end
68
+
69
+
70
+
71
+ def show
72
+ @vm = Virtualmachine.where("host_id = '#{params[:id]}'").first
73
+ end
74
+
75
+ end
76
+ end
@@ -10,10 +10,19 @@ module ForemanProxmox
10
10
 
11
11
  def host_title_actions_with_proxmox(*args)
12
12
  title_actions(
13
- button_group(
14
- display_proxmox_if_authorized(_("Create VM"), {:controller => 'foreman_proxmox/creations', :action => 'create_vm', :id => @host}, :class => 'btn')
13
+ if Virtualmachine.where("host_id = '#{@host.id}'").first != nil
14
+ button_group(
15
+ display_proxmox_if_authorized(_("VM details"), {:controller => 'foreman_proxmox/virtualmachines', :action => 'show', :id => @host.id}, :class => 'btn')
15
16
  )
16
- )
17
+ end,
18
+ button_group(
19
+ select_action_button(_('Power Control'),{},
20
+ display_proxmox_if_authorized(_('Start VM'), {:controller => 'foreman_proxmox/virtualmachines', :action => 'start_vm', :id => @host.id}, :class => 'btn'),
21
+ display_proxmox_if_authorized(_('Stop VM'), {:controller => 'foreman_proxmox/virtualmachines', :action => 'stop_vm', :id => @host.id}, :class => 'btn'),
22
+ display_proxmox_if_authorized(_('Reboot VM'), {:controller => 'foreman_proxmox/virtualmachines', :action => 'reboot_vm', :id => @host.id}, :class => 'btn')
23
+ )
24
+ )
25
+ )
17
26
  host_title_actions_without_proxmox(*args)
18
27
  end
19
28
 
@@ -34,3 +43,4 @@ module ForemanProxmox
34
43
  end
35
44
  end
36
45
  end
46
+
@@ -0,0 +1,26 @@
1
+ module ForemanProxmox
2
+ module ProxmoxserversHelper
3
+
4
+ def show_appropriate_connection_button(proxmox)
5
+ if proxmox == nil then
6
+ link_to(_("New"), new_proxmoxserver_path, :class => 'btn')
7
+ else
8
+ link_to(_("Edit"), edit_proxmoxserver_path, :class => 'btn')
9
+ end
10
+ end
11
+
12
+
13
+
14
+ def show_node_controlls(proxmox)
15
+ [ link_to(_("Start all VMs"), startall_path, :class => 'btn'),
16
+ link_to(_("Stop all VMs"), stopall_path, :class => 'btn'),
17
+ link_to(_("Reboot"), reboot_path, :class => 'btn'),
18
+ link_to(_("Shutdown"), shutdown_path, :class => 'btn')
19
+ ].compact
20
+ end
21
+
22
+ # def set_options(options={})
23
+ # ForemanProxmox::Engine.routes.url_for(options.merge(:only_path => true, :controller => 'proxmoxserver'))
24
+ # end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ require 'httpclient'
2
+ require 'json'
3
+ module ForemanProxmox
4
+ module VirtualmachinesHelper
5
+ # def get_next_free_vmid
6
+
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,43 @@
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 destroy
11
+ vm = Virtualmachine.where("host_id = #{self.id}").first
12
+ vm.delete_virtualmachine
13
+ super
14
+ end
15
+
16
+ def create
17
+ super
18
+ new_vm = Virtualmachine.new
19
+ if self.params['vmid'] == nil then
20
+ new_vm.get_free_vmid
21
+ else
22
+ new_vm.vmid = self.params['vmid']
23
+ end
24
+ new_vm.sockets = self.params['sockets']
25
+ new_vm.cores = self.params['cores']
26
+ new_vm.memory = self.params['memory']
27
+ new_vm.size = self.params['size']
28
+ new_vm.mac = self.mac
29
+ new_vm.host_id = self.id
30
+ new_vm.save
31
+
32
+ new_vm.create_harddisk
33
+ new_vm.create_virtualmachine
34
+ new_vm.start
35
+
36
+ end
37
+
38
+ module ClassMethods
39
+ # create or overwrite class methods...
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,204 @@
1
+ require 'httpclient'
2
+ require 'json'
3
+ require 'logger'
4
+ module ForemanProxmox
5
+ class Proxmoxserver < ActiveRecord::Base
6
+ $LOG= Logger.new("/tmp/proxmox_debug.log")
7
+
8
+ def setup_httpclient
9
+ @client= HTTPClient.new
10
+ @client.ssl_config.verify_mode= OpenSSL::SSL::VERIFY_NONE
11
+ @node = get_first_node_in_cluster
12
+
13
+ $LOG.error("Created HttpClient")
14
+ end
15
+
16
+ def check_ip_connectivity
17
+ $LOG.error("checking connect")
18
+ if @client == nil then setup_httpclient end
19
+ code_response = @client.get("https://#{self.ip}:8006/api2/json/access/ticket")
20
+ $LOG.error(code_response)
21
+ if code_response.code != 200 then
22
+ $LOG.error("connection fail")
23
+ flash[:error] = "Proxmoxserver seems down, try again or change Server"
24
+ return false
25
+ else
26
+ $LOG.error("connection there")
27
+ return true
28
+ end
29
+ end
30
+
31
+ def authenticate_client
32
+ if !check_ip_connectivity then
33
+ return nil
34
+ end
35
+ $LOG.error("authenticating")
36
+ domain= "https://#{self.ip}:8006/"
37
+ url= URI.parse(domain)
38
+ credentials= {:username => "#{self.username}@pam", :password => self.password}
39
+ auth_response= @client.post("https://#{self.ip}:8006/api2/json/access/ticket", credentials)
40
+ $LOG.error(auth_response.body)
41
+ auth= JSON.parse(auth_response.body)
42
+ ticket= auth["data"]["ticket"]
43
+ token= auth["data"]["CSRFPreventionToken"]
44
+ @header= {:CSRFPreventionToken => token}
45
+ $LOG.error("#{ticket} #{token}")
46
+ cookie_ticket= WebAgent::Cookie.new
47
+ cookie_ticket.name= 'PVEAuthCookie'
48
+ cookie_ticket.value= ticket
49
+ cookie_ticket.url= url
50
+ @client.cookie_manager.add(cookie_ticket)
51
+ $LOG.error("authenticated")
52
+ end
53
+
54
+ def get_first_node_in_cluster
55
+ if !check_ip_connectivity then
56
+ return nil
57
+ end
58
+ authenticate_client
59
+ nodes_response = @client.get("https://#{self.ip}:8006/api2/json/nodes")
60
+ nodes = JSON.parse(nodes_response.body)
61
+ return nodes["data"][0]["node"]
62
+ end
63
+
64
+ def find_node_for_vmid(vmid)
65
+ authenticate_client
66
+ nodes_response = @client.get("https://#{self.ip}:8006/api2/json/nodes")
67
+ nodes = JSON.parse(nodes_response.body)
68
+ current_node_id = 0
69
+ current_node = nodes["data"][current_node_id]
70
+ while current_node != nil
71
+ node_name = nodes["data"][current_node_id]["node"]
72
+ current_vm_id = 0
73
+ vms_response = @client.get("https://#{self.ip}:8006/api2/json/nodes/#{node_name}/qemu")
74
+ vms = JSON.parse(vms_response.body)
75
+ current_vm = vms["data"][current_vm_id]
76
+ while current_vm != nil do
77
+ if vms["data"][current_vm_id]["vmid"] == vmid
78
+ @node = node_name
79
+ end
80
+ current_vm_id+=1
81
+ current_vm = vms["data"][current_vm_id]
82
+ end
83
+ current_node_id+=1
84
+ current_node = nodes["data"][current_node_id]
85
+ end
86
+ end
87
+
88
+ def get_next_free_vmid
89
+ $LOG= Logger.new("/tmp/proxmox_debug.log")
90
+ $LOG.error("start here")
91
+ authenticate_client
92
+ nodes_response = @client.get("https://#{self.ip}:8006/api2/json/nodes")
93
+ nodes = JSON.parse(nodes_response.body)
94
+ $LOG.error(nodes)
95
+ current_node_id = 0
96
+ highest_vmid = 0
97
+ current_node = nodes["data"][current_node_id]
98
+ $LOG.error(current_node)
99
+ while current_node != nil
100
+ node_name = nodes["data"][current_node_id]["node"]
101
+ $LOG.error(node_name)
102
+ current_vm_id = 0
103
+ vms_response = @client.get("https://#{self.ip}:8006/api2/json/nodes/#{node_name}/qemu")
104
+ vms = JSON.parse(vms_response.body)
105
+ $LOG.error(vms)
106
+ current_vm = vms["data"][current_vm_id]
107
+ while current_vm != nil do
108
+ if vms["data"][current_vm_id]["vmid"].to_i > highest_vmid
109
+ highest_vmid = vms["data"][current_vm_id]["vmid"].to_i
110
+ $LOG.error(highest_vmid)
111
+ end
112
+ current_vm_id+=1
113
+ current_vm = vms["data"][current_vm_id]
114
+ end
115
+ current_node_id+=1
116
+ current_node = nodes["data"][current_node_id]
117
+ end
118
+ $LOG.error(highest_vmid+1).to_s
119
+ return highest_vmid+1
120
+ end
121
+
122
+
123
+ #manage kvms
124
+ def create_ide(vmid, size)
125
+ if !check_ip_connectivity then
126
+ return nil
127
+ end
128
+ authenticate_client
129
+ body= { :filename => "vm-#{vmid}-disk-0.qcow2", :format => "qcow2", :size => size, :vmid => vmid}
130
+ testres= @client.post("https://#{self.ip}:8006/api2/json/nodes/#{@node}/storage/local/content",body,@header)
131
+ $LOG.error("Body: #{testres.body}")
132
+ $LOG.error("Header: #{testres.header}")
133
+ end
134
+
135
+ def create_kvm(vmid, sockets, cores ,memory,mac)
136
+ if !check_ip_connectivity then
137
+ return nil
138
+ end
139
+ authenticate_client
140
+ body= { :vmid => vmid, :sockets => sockets, :cores => cores, :memory => memory, :net0 => "e1000=#{mac},bridge=vmbr1", :ide0 => "volume=local:#{vmid}/vm-#{vmid}-disk-0.qcow2,media=disk"}
141
+ testres= @client.post("https://#{self.ip}:8006/api2/json/nodes/#{@node}/qemu",body,@header)
142
+ $LOG.error("Body: #{testres.body}")
143
+ $LOG.error("Header: #{testres.header}")
144
+ end
145
+
146
+ def edit_kvm(vmid)
147
+ end
148
+
149
+ def delete_kvm(vmid)
150
+ if !check_ip_connectivity then
151
+ return nil
152
+ end
153
+ find_node_for_vmid(vmid)
154
+ testres= @client.delete("https://#{self.ip}:8006/api2/json/nodes/proxmox/qemu/#{vmid}",{},@header)
155
+ $LOG.error("Body: #{testres.body}")
156
+ $LOG.error("Header: #{testres.header}")
157
+ end
158
+
159
+ def start_kvm(vmid)
160
+ if !check_ip_connectivity then
161
+ return nil
162
+ end
163
+ find_node_for_vmid(vmid)
164
+ testres= @client.post("https://#{self.ip}:8006/api2/json/nodes/proxmox/qemu/#{vmid}/status/start",{},@header)
165
+ $LOG.error("Body: #{testres.body}")
166
+ $LOG.error("Header: #{testres.header}")
167
+ end
168
+
169
+ def stop_kvm(vmid)
170
+ if !check_ip_connectivity then
171
+ return nil
172
+ end
173
+ find_node_for_vmid(vmid)
174
+ testres= @client.post("https://#{self.ip}:8006/api2/json/nodes/proxmox/qemu/#{vmid}/status/stop",{},@header)
175
+ $LOG.error("Body: #{testres.body}")
176
+ $LOG.error("Header: #{testres.header}")
177
+ end
178
+
179
+ def reboot_kvm(vmid)
180
+ if !check_ip_connectivity then
181
+ return nil
182
+ end
183
+ find_node_for_vmid(vmid)
184
+ testres= @client.post("https://#{self.ip}:8006/api2/json/nodes/proxmox/qemu/#{vmid}/status/reset",{},@header)
185
+ $LOG.error("Body: #{testres.body}")
186
+ $LOG.error("Header: #{testres.header}")
187
+ end
188
+
189
+
190
+ #manage node
191
+ def reboot
192
+ end
193
+
194
+ def shutdown
195
+ end
196
+
197
+ def start_all_vms
198
+ end
199
+
200
+ def stop_all_vms
201
+ end
202
+
203
+ end
204
+ end
@@ -0,0 +1,42 @@
1
+ module ForemanProxmox
2
+ class Virtualmachine < ActiveRecord::Base
3
+ belongs_to :host
4
+
5
+ def create_harddisk
6
+ proxmoxserver = Proxmoxserver.where("current = 'true'").first
7
+ proxmoxserver.create_ide(self.vmid,self.size)
8
+ end
9
+
10
+ def create_virtualmachine
11
+ proxmoxserver = Proxmoxserver.where("current = 'true'").first
12
+ proxmoxserver.create_kvm(self.vmid,self.sockets,self.cores,self.memory,self.mac)
13
+ end
14
+
15
+ def start
16
+ proxmoxserver = Proxmoxserver.where("current = 'true'").first
17
+ proxmoxserver.start_kvm(self.vmid)
18
+ end
19
+
20
+ def stop
21
+ proxmoxserver = Proxmoxserver.where("current = 'true'").first
22
+ proxmoxserver.stop_kvm(self.vmid)
23
+ end
24
+
25
+ def reboot
26
+ proxmoxserver = Proxmoxserver.where("current = 'true'").first
27
+ proxmoxserver.reboot_kvm(self.vmid)
28
+ end
29
+
30
+ def delete_virtualmachine
31
+ proxmoxserver = Proxmoxserver.where("current = 'true'").first
32
+ self.stop
33
+ proxmoxserver.delete_kvm(self.vmid)
34
+ self.destroy
35
+ end
36
+
37
+ def get_free_vmid
38
+ proxmoxserver = Proxmoxserver.where("current = 'true'").first
39
+ self.vmid = proxmoxserver.get_next_free_vmid
40
+ end
41
+ end
42
+ end
@@ -1,4 +1,4 @@
1
- <%= form_for @proxmoxconnection, url: {action: 'create'} do |f| %>
1
+ <%= form_for @proxmox, url: proxmoxserver_path do |f| %>
2
2
  <%= f.label :ip %>
3
3
  <%= f.text_field :ip %>
4
4
  <br>
@@ -10,6 +10,3 @@
10
10
  <br>
11
11
  <%= f.submit 'Create' %>
12
12
  <% end %>
13
- <%= @proxmoxconnection.ip %>
14
- <%= @proxmoxconnection.username %>
15
- <%= @proxmoxconnection.password %>
@@ -0,0 +1,12 @@
1
+ <%= form_for @proxmox do |f| %>
2
+ <%= f.label :ip %>
3
+ <%= f.text_field :ip %>
4
+ <br>
5
+ <%= f.label :username %>
6
+ <%= f.text_field :username %>
7
+ <br>
8
+ <%= f.label :password %>
9
+ <%= f.text_field :password %>
10
+ <br>
11
+ <%= f.submit 'Submit' %>
12
+ <% end %>
@@ -0,0 +1,36 @@
1
+ <table id="proxmoxservers_overview" class="table table-bordered table-striped">
2
+ <thead>
3
+ <tr>
4
+ <th>Proxmox Servers</th>
5
+ </tr>
6
+ </thead>
7
+ <tbody>
8
+ <tr>
9
+ <td>Server ID</td>
10
+ <td>Server IP</td>
11
+ <td>Username</td>
12
+ <td>Is Current?</td>
13
+ </tr>
14
+ <% @proxmoxservers.each do |server| %>
15
+ <tr>
16
+ <td><%= server.id%></td>
17
+ <td><%= server.ip%></td>
18
+ <td><%= server.username%></td>
19
+ <td>
20
+ <% if server.current == true then%>
21
+ <%= _('Yes') %>
22
+ <% end %>
23
+ </td>
24
+ <td>
25
+ <%= action_buttons(
26
+ link_to(_('Edit'),edit_proxmoxserver_path(:id => server.id)),
27
+ link_to(_('Show'),proxmoxserver_path(:id => server.id)),
28
+ link_to(_('Set Current'),setcurrent_path(:id => server.id)),
29
+ link_to(_('Delete'),{:controller => 'proxmoxservers', :action => 'destroy', :id => server.id})
30
+ ) %>
31
+ </td>
32
+ </tr>
33
+ <% end %>
34
+ </tbody>
35
+ </table>
36
+ <%= link_to(_('New Server'),new_proxmoxserver_path) %>
@@ -0,0 +1,12 @@
1
+ <%= form_for @proxmox do |f| %>
2
+ <%= f.label :ip %>
3
+ <%= f.text_field :ip %>
4
+ <br>
5
+ <%= f.label :username %>
6
+ <%= f.text_field :username %>
7
+ <br>
8
+ <%= f.label :password %>
9
+ <%= f.text_field :password %>
10
+ <br>
11
+ <%= f.submit 'Create' %>
12
+ <% end %>
@@ -0,0 +1,50 @@
1
+ <div class="col-md-6">
2
+ <table id="nodecontrolls" class="table table-bordered table-striped">
3
+ <thead>
4
+ <tr>
5
+ <th><%= _('Node Controlls') %></th>
6
+ </tr>
7
+ </thead>
8
+ <tbody>
9
+ <tr>
10
+ <td>
11
+ <% show_node_controlls(@proxmox).each do |btn| %>
12
+ <%= btn %>
13
+ <% end %>
14
+ </td>
15
+ </tr>
16
+ </tbody>
17
+ </table>
18
+ </div>
19
+ <div class="col-md-6">
20
+ <table id="connectioncontrolls" class="table table-bordered table-striped">
21
+ <thead>
22
+ <tr>
23
+ <th><%= _('Connection Controlls') %></th>
24
+ </tr>
25
+ </thead>
26
+ <tbody>
27
+ <tr>
28
+ <td>IP-adress</td>
29
+ <td>Username</td>
30
+ <td>Password</td>
31
+ </tr>
32
+ <% if @proxmox == nil then %>
33
+ <tr>
34
+ <td><%= 'nil' %></td>
35
+ <td><%= 'nil' %></td>
36
+ <td><%= 'nil' %></td>
37
+ </tr>
38
+ <% else %>
39
+ <tr>
40
+ <td><%= @proxmox.ip %></td>
41
+ <td><%= @proxmox.username %></td>
42
+ <td><%= @proxmox.password %></td>
43
+ </tr>
44
+ <% end %>
45
+ <tr>
46
+ <td><%= show_appropriate_connection_button(@proxmox) %></td>
47
+ </tr>
48
+ </tbody>
49
+ </table>
50
+ </div>
@@ -0,0 +1,33 @@
1
+ <div>
2
+ <table id="properties" class="table table-bordered table-striped">
3
+ <thead>
4
+ <tr>
5
+ <th>VMID</th>
6
+ <th>Sockets</th>
7
+ <th>Cores</th>
8
+ <th>Memory</th>
9
+ <th>Size</th>
10
+ <th>Host ID</th>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <tr>
15
+ <td><%= @vm.vmid %></td>
16
+ <td><%= @vm.sockets %></td>
17
+ <td><%= @vm.cores %></td>
18
+ <td><%= @vm.memory %></td>
19
+ <th><%= @vm.size %></th>
20
+ <td><%= @vm.host_id %></td>
21
+ </tr>
22
+ </tbody>
23
+ </table>
24
+ </div>
25
+ <div>
26
+ <table id="harddrives" class="table table-bordered table-striped">
27
+ <thead>
28
+ <tr>
29
+
30
+ </tr>
31
+ </thead>
32
+ </table>
33
+ </div>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>ForemanProxmox</title>
5
+ <%= stylesheet_link_tag "foreman_proxmox/application", media: "all" %>
6
+ <%= javascript_include_tag "foreman_proxmox/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -1,17 +1,25 @@
1
1
  Rails.application.routes.draw do
2
- match 'proxmox', to: 'foreman_proxmox/hosts#proxmox'
3
-
4
- resource :hosts
2
+ match 'proxmox', to: 'foreman_proxmox/proxmoxservers#index'
5
3
 
6
4
  end
7
5
 
8
6
  ForemanProxmox::Engine.routes.draw do
9
7
 
10
- resource :hosts
11
-
12
- resources :creations, :only => [] do
8
+ get 'proxmoxservers/:id/start_all_vms' => 'proxmoxservers#start_all_vms', as: 'startall'
9
+ get 'proxmoxservers/:id/stop_all_vms' => 'proxmoxservers#stop_all_vms', as: 'stopall'
10
+ get 'proxmoxservers/:id/reboot' => 'proxmoxservers#reboot', as: 'reboot'
11
+ get 'proxmoxservers/:id/shutdown' => 'proxmoxservers#shutdown', as: 'shutdown'
12
+ get 'proxmoxservers/:id/setcurrent' => 'proxmoxservers#setcurrent', as: 'setcurrent'
13
+
14
+ resources :proxmoxservers
15
+
16
+ resources :virtualmachines, :only => [:show] do
13
17
  constraints(:id => /[^\/]+/) do
14
- get 'hosts/:id', :on => :collection, :to => 'creations#create_vm'
18
+ get 'create_vm/:id', :on => :collection, :to => 'virtualmachines#create_vm'
19
+ get 'delete_vm/:id', :on => :collection, :to => 'virtualmachines#delete_vm'
20
+ get 'start/:id', :on => :collection, :to => 'virtualmachines#start_vm'
21
+ get 'stop/:id', :on => :collection, :to => 'virtualmachines#stop_vm'
22
+ get 'reboot/:id', :on => :collection, :to => 'virtualmachines#reboot_vm'
15
23
  end
16
24
  end
17
- end
25
+ end
@@ -0,0 +1,12 @@
1
+ class CreateForemanProxmoxProxmoxservers < ActiveRecord::Migration
2
+ def change
3
+ create_table :foreman_proxmox_proxmoxservers do |t|
4
+ t.string :ip
5
+ t.string :username
6
+ t.string :password
7
+ t.boolean :current
8
+
9
+ t.timestamps null: false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ class CreateForemanProxmoxVirtualmachines < ActiveRecord::Migration
2
+ def change
3
+ create_table :foreman_proxmox_virtualmachines, id: false do |t|
4
+ t.primary_key :vmid
5
+ t.string :sockets
6
+ t.string :cores
7
+ t.string :memory
8
+ t.string :size
9
+ t.string :mac
10
+ t.belongs_to :host
11
+
12
+ t.timestamps null: false
13
+ end
14
+ end
15
+ end
@@ -24,15 +24,18 @@ module ForemanProxmox
24
24
 
25
25
  # Add permissions
26
26
  security_block :foreman_proxmox do
27
- permission :view_foreman_proxmox, :'foreman_proxmox/hosts' => [:proxmoxn]
27
+ permission :view_foreman_proxmox, {:'foreman_proxmox/proxmoxservers' => [:index]}
28
+ permission :manage_proxmoxserver, {:'foreman_proxmox/proxmoxservers' => [:new, :create, :stop_all_vms, :start_all_vms, :reboot_node, :shutdown_node]}
29
+ permission :proxmoxservers_crud, {:'foreman_proxmox/proxmoxservers' => [:edit, :update, :show, :delete, :setcurrent]}
30
+ permission :manage_vm, {:'foreman_proxmox/virtualmachines' => [:create_vm, :start_vm, :stop_vm, :reboot_vm, :delete_vm, :show]}
28
31
  end
29
32
 
30
33
  # Add a new role called 'Discovery' if it doesn't exist
31
- role 'ForemanProxmox', [:view_foreman_proxmox]
34
+ role 'ForemanProxmox', [:view_foreman_proxmox, :manage_proxmoxserver, :proxmoxservers_crud, :manage_vm]
32
35
 
33
36
  #add menu entry
34
37
  menu :top_menu, :template,
35
- url_hash: { controller: :'foreman_proxmox/hosts', action: :proxmox },
38
+ url_hash: { controller: :'foreman_proxmox/proxmoxservers', action: :index },
36
39
  caption: 'ForemanProxmox',
37
40
  parent: :hosts_menu,
38
41
  after: :hosts
@@ -1,3 +1,3 @@
1
1
  module ForemanProxmox
2
- VERSION = "0.0.12"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module ForemanProxmox
4
- class CreationsControllerTest < ActionController::TestCase
4
+ class ProxmoxserversControllerTest < ActionController::TestCase
5
5
  setup do
6
6
  @routes = Engine.routes
7
7
  end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module ForemanProxmox
4
- class HostsControllerTest < ActionController::TestCase
4
+ class VirtualmachinesControllerTest < ActionController::TestCase
5
5
  setup do
6
6
  @routes = Engine.routes
7
7
  end
@@ -11,10 +11,10 @@
11
11
  # if you're sharing your code publicly.
12
12
 
13
13
  development:
14
- secret_key_base: 3da2ff5a981b7bf7cd3a94bac41fdc533080a81677a9c006e336604d7de92965a09e273630e4ad2feefda2187d95252906b99371a40e0a23d194910627bb638b
14
+ secret_key_base: f95bc37aefe825f29c4f142e610a6020820a49f1291978045986f2d67314e9a36f6cebfbc7b8d83b65cca2c7323c4c9fbee10e22c085d66fcce438a3a3f93fea
15
15
 
16
16
  test:
17
- secret_key_base: 9fe5bdee53a20baded69ae214b0e0b7f777b5e92a07f1e42fc3b213375e840a67687f3f2cb41ca044d5d8fa8bdb6d59328fd84cb8a69078b685a3d3154351957
17
+ secret_key_base: e0f2e06c080e1e9a7f985a8f5fcd95bc53a0171414b48e9cf9d4b7692abff0f75ac8699d0c0d9d8cdc0e8935e4f66cacdc2ceffdc6fd6c04a38088f5ba6a49ca
18
18
 
19
19
  # Do not keep production secrets in the repository,
20
20
  # instead read values from the environment.
@@ -0,0 +1,17 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ vmid: MyString
5
+ sockets: MyString
6
+ cores: MyString
7
+ size: MyString
8
+ memory: MyString
9
+ proxmoxserver_id: 1
10
+
11
+ two:
12
+ vmid: MyString
13
+ sockets: MyString
14
+ cores: MyString
15
+ size: MyString
16
+ memory: MyString
17
+ proxmoxserver_id: 1
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module ForemanProxmox
4
- class ProxmoxConnectionTest < ActiveSupport::TestCase
4
+ class ProxmoxserverTest < ActiveSupport::TestCase
5
5
  # test "the truth" do
6
6
  # assert true
7
7
  # end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module ForemanProxmox
4
+ class VirtualmachineTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_proxmox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Isensee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-06 00:00:00.000000000 Z
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -62,14 +76,25 @@ files:
62
76
  - LICENSE
63
77
  - README.md
64
78
  - Rakefile
65
- - app/controllers/foreman_proxmox/creations_controller.rb
66
- - app/controllers/foreman_proxmox/hosts_controller.rb
79
+ - app/controllers/foreman_proxmox/proxmoxservers_controller.rb
80
+ - app/controllers/foreman_proxmox/virtualmachines_controller.rb
67
81
  - app/helpers/concerns/foreman_proxmox/hosts_helper_extensions.rb
68
- - app/models/foreman_proxmox/proxmox_connection.rb
69
- - app/views/foreman_proxmox/hosts/proxmox.html.erb
82
+ - app/helpers/foreman_proxmox/proxmoxservers_helper.rb
83
+ - app/helpers/foreman_proxmox/virtualmachines_helper.rb
84
+ - app/models/concerns/foreman_proxmox/host_extensions.rb
85
+ - app/models/foreman_proxmox/proxmoxserver.rb
86
+ - app/models/foreman_proxmox/virtualmachine.rb
87
+ - app/views/foreman_proxmox/proxmoxservers/_form.html.erb
88
+ - app/views/foreman_proxmox/proxmoxservers/edit.html.erb
89
+ - app/views/foreman_proxmox/proxmoxservers/index.html.erb
90
+ - app/views/foreman_proxmox/proxmoxservers/new.html.erb
91
+ - app/views/foreman_proxmox/proxmoxservers/show.html.erb
92
+ - app/views/foreman_proxmox/virtualmachines/show.html.erb
93
+ - app/views/layouts/foreman_proxmox/application.html.erb
70
94
  - config/routes.rb
71
95
  - config/routes/mount_engine.rb
72
- - db/migrate/20151006132039_create_foreman_proxmox_proxmox_connections.rb
96
+ - db/migrate/20151021104305_create_foreman_proxmox_proxmoxservers.rb
97
+ - db/migrate/20151030104550_create_foreman_proxmox_virtualmachines.rb
73
98
  - lib/foreman_proxmox.rb
74
99
  - lib/foreman_proxmox/engine.rb
75
100
  - lib/foreman_proxmox/version.rb
@@ -78,8 +103,8 @@ files:
78
103
  - locale/en/foreman_proxmox.po
79
104
  - locale/foreman_proxmox.pot
80
105
  - locale/gemspec.rb
81
- - test/controllers/foreman_proxmox/creations_controller_test.rb
82
- - test/controllers/foreman_proxmox/hosts_controller_test.rb
106
+ - test/controllers/foreman_proxmox/proxmoxservers_controller_test.rb
107
+ - test/controllers/foreman_proxmox/virtualmachines_controller_test.rb
83
108
  - test/dummy/README.rdoc
84
109
  - test/dummy/Rakefile
85
110
  - test/dummy/app/assets/javascripts/application.js
@@ -114,10 +139,12 @@ files:
114
139
  - test/dummy/public/422.html
115
140
  - test/dummy/public/500.html
116
141
  - test/dummy/public/favicon.ico
117
- - test/fixtures/foreman_proxmox/proxmox_connections.yml
142
+ - test/fixtures/foreman_proxmox/proxmoxservers.yml
143
+ - test/fixtures/foreman_proxmox/virtualmachines.yml
118
144
  - test/foreman_proxmox_test.rb
119
145
  - test/integration/navigation_test.rb
120
- - test/models/foreman_proxmox/proxmox_connection_test.rb
146
+ - test/models/foreman_proxmox/proxmoxserver_test.rb
147
+ - test/models/foreman_proxmox/virtualmachine_test.rb
121
148
  - test/test_helper.rb
122
149
  homepage: http://github.com/fiesensee/foreman_proxmox
123
150
  licenses: []
@@ -138,49 +165,51 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
165
  version: '0'
139
166
  requirements: []
140
167
  rubyforge_project:
141
- rubygems_version: 2.4.8
168
+ rubygems_version: 2.4.6
142
169
  signing_key:
143
170
  specification_version: 4
144
171
  summary: Proxmox support for foreman
145
172
  test_files:
146
173
  - test/integration/navigation_test.rb
147
- - test/fixtures/foreman_proxmox/proxmox_connections.yml
148
- - test/models/foreman_proxmox/proxmox_connection_test.rb
149
- - test/dummy/app/assets/stylesheets/application.css
150
- - test/dummy/app/assets/javascripts/application.js
151
- - test/dummy/app/controllers/application_controller.rb
152
- - test/dummy/app/views/layouts/application.html.erb
153
- - test/dummy/app/helpers/application_helper.rb
154
- - test/dummy/bin/bundle
155
- - test/dummy/bin/setup
156
- - test/dummy/bin/rails
157
- - test/dummy/bin/rake
158
- - test/dummy/config.ru
159
174
  - test/dummy/README.rdoc
160
- - test/dummy/public/422.html
161
175
  - test/dummy/public/500.html
176
+ - test/dummy/public/422.html
162
177
  - test/dummy/public/favicon.ico
163
178
  - test/dummy/public/404.html
164
- - test/dummy/config/secrets.yml
165
- - test/dummy/config/locales/en.yml
166
- - test/dummy/config/environments/development.rb
179
+ - test/dummy/config.ru
180
+ - test/dummy/config/initializers/backtrace_silencers.rb
181
+ - test/dummy/config/initializers/assets.rb
182
+ - test/dummy/config/initializers/filter_parameter_logging.rb
183
+ - test/dummy/config/initializers/mime_types.rb
184
+ - test/dummy/config/initializers/wrap_parameters.rb
185
+ - test/dummy/config/initializers/cookies_serializer.rb
186
+ - test/dummy/config/initializers/inflections.rb
187
+ - test/dummy/config/initializers/session_store.rb
167
188
  - test/dummy/config/environments/test.rb
189
+ - test/dummy/config/environments/development.rb
168
190
  - test/dummy/config/environments/production.rb
169
- - test/dummy/config/routes.rb
191
+ - test/dummy/config/secrets.yml
170
192
  - test/dummy/config/database.yml
171
- - test/dummy/config/application.rb
193
+ - test/dummy/config/routes.rb
172
194
  - test/dummy/config/boot.rb
173
195
  - test/dummy/config/environment.rb
174
- - test/dummy/config/initializers/filter_parameter_logging.rb
175
- - test/dummy/config/initializers/inflections.rb
176
- - test/dummy/config/initializers/wrap_parameters.rb
177
- - test/dummy/config/initializers/assets.rb
178
- - test/dummy/config/initializers/mime_types.rb
179
- - test/dummy/config/initializers/backtrace_silencers.rb
180
- - test/dummy/config/initializers/cookies_serializer.rb
181
- - test/dummy/config/initializers/session_store.rb
196
+ - test/dummy/config/application.rb
197
+ - test/dummy/config/locales/en.yml
182
198
  - test/dummy/Rakefile
183
- - test/test_helper.rb
184
- - test/controllers/foreman_proxmox/creations_controller_test.rb
185
- - test/controllers/foreman_proxmox/hosts_controller_test.rb
199
+ - test/dummy/bin/bundle
200
+ - test/dummy/bin/setup
201
+ - test/dummy/bin/rails
202
+ - test/dummy/bin/rake
203
+ - test/dummy/app/helpers/application_helper.rb
204
+ - test/dummy/app/views/layouts/application.html.erb
205
+ - test/dummy/app/controllers/application_controller.rb
206
+ - test/dummy/app/assets/javascripts/application.js
207
+ - test/dummy/app/assets/stylesheets/application.css
208
+ - test/models/foreman_proxmox/virtualmachine_test.rb
209
+ - test/models/foreman_proxmox/proxmoxserver_test.rb
210
+ - test/controllers/foreman_proxmox/proxmoxservers_controller_test.rb
211
+ - test/controllers/foreman_proxmox/virtualmachines_controller_test.rb
186
212
  - test/foreman_proxmox_test.rb
213
+ - test/fixtures/foreman_proxmox/proxmoxservers.yml
214
+ - test/fixtures/foreman_proxmox/virtualmachines.yml
215
+ - test/test_helper.rb
@@ -1,17 +0,0 @@
1
- require 'rest-client'
2
- module ForemanProxmox
3
- class CreationsController < ::ApplicationController
4
- before_filter :find_resource, :only => %w[host]
5
-
6
- def create_vm
7
-
8
- redirect_to :back
9
- end
10
-
11
- private
12
-
13
- def resource_scope(controller = controller_name)
14
- Host::Managed.authorized(:view_hosts)
15
- end
16
- end
17
- end
@@ -1,18 +0,0 @@
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 proxmox
8
- @proxmoxconnection = ProxmoxConnection.new
9
- end
10
-
11
- def create
12
- @proxmoxconnection.ip = params[:ip]
13
- @proxmoxconnection.username = params[:username]
14
- @proxmoxconnection.password = params[:username]
15
- redirect_to :back
16
- end
17
- end
18
- end
@@ -1,4 +0,0 @@
1
- module ForemanProxmox
2
- class ProxmoxConnection < ActiveRecord::Base
3
- end
4
- end
@@ -1,11 +0,0 @@
1
- class CreateForemanProxmoxProxmoxConnections < ActiveRecord::Migration
2
- def change
3
- create_table :foreman_proxmox_proxmox_connections do |t|
4
- t.string :ip
5
- t.string :username
6
- t.string :password
7
-
8
- t.timestamps null: false
9
- end
10
- end
11
- end