foreman_xen 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/app/controllers/foreman_xen/snapshots_controller.rb +10 -38
- data/app/models/foreman_xen/xenserver.rb +25 -28
- data/app/views/compute_resources/form/_xenserver.html.erb +1 -3
- data/lib/foreman_xen/engine.rb +2 -2
- data/lib/foreman_xen/version.rb +1 -1
- data/lib/foreman_xen/vnc_tunnel.rb +2 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f1adce9377bfddcc90e390be4aa635db21f6c60
|
4
|
+
data.tar.gz: 7c2030f9848d832fc4cdffa24b498f4f10ecc748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 524c2b085d36a462d32c8c7d6ec3105739da12881a17a6ec8fe8ff9e6a1d906e9fbe7630211b5d5912380bbdf26aa205ec4d4153d7b3abf680bf10681639ba44
|
7
|
+
data.tar.gz: 8618ce64c4381cb460af72b5443efb079b88014a37547f4c53b211705106015291c014bf7682417f01dcdb03a664ec3cc18586999c1bbe56a8c56cb97d7e51a5
|
data/README.md
CHANGED
@@ -12,11 +12,12 @@ Please see the Foreman manual for further instructions:
|
|
12
12
|
|
13
13
|
## Compatibility
|
14
14
|
|
15
|
-
| Foreman Version | Plugin Version
|
16
|
-
|:---------------
|
17
|
-
| >=1.5, <1.8 | 0.0.x
|
18
|
-
| >=1.8.1, <1.10 | 0.1.x
|
19
|
-
| >=1.10
|
15
|
+
| Foreman Version | Plugin Version |
|
16
|
+
|:--------------- |:--------------------- |
|
17
|
+
| >=1.5, <1.8 | 0.0.x (unmaintained) |
|
18
|
+
| >=1.8.1, <1.10 | 0.1.x (unmaintained) |
|
19
|
+
| >=1.10, <1.11 | 0.2.x |
|
20
|
+
| >=1.11 | 0.3.x |
|
20
21
|
|
21
22
|
## Support
|
22
23
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ForemanXen
|
2
2
|
class SnapshotsController < ::ApplicationController
|
3
3
|
helper :all
|
4
|
-
|
4
|
+
skip_before_action :verify_authenticity_token
|
5
5
|
|
6
6
|
# GET - foreman_xen/snapshots/:host_id
|
7
7
|
def show
|
@@ -15,15 +15,12 @@ module ForemanXen
|
|
15
15
|
@snapshots = @compute_resource.find_snapshots_for_vm(vm)
|
16
16
|
else
|
17
17
|
process_error(:error_msg => "Error retrieving compute resource #{@host.compute_resource_id} from provider.")
|
18
|
-
return
|
19
18
|
end
|
20
19
|
end
|
21
20
|
elsif @host.nil?
|
22
21
|
process_error(:error_msg => "No host found with ID: #{id}.")
|
23
|
-
return
|
24
22
|
else
|
25
23
|
process_error(:error_msg => "No compute resource found for host with ID: #{id}.")
|
26
|
-
return
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
@@ -39,23 +36,15 @@ module ForemanXen
|
|
39
36
|
vm.revert(ref)
|
40
37
|
vm.start
|
41
38
|
process_success(
|
42
|
-
:success_msg => "
|
39
|
+
:success_msg => "Successfully reverted and powered on #{@host.name}",
|
43
40
|
:success_redirect => "/foreman_xen/snapshots/#{id}"
|
44
41
|
)
|
45
|
-
return
|
46
42
|
else
|
47
43
|
process_error(:error_msg => "Error retrieving host information for #{@host.name}")
|
48
|
-
return
|
49
44
|
end
|
50
45
|
else
|
51
46
|
process_error(:error_msg => "Error retrieving compute resource information for #{@host.name}")
|
52
|
-
return
|
53
47
|
end
|
54
|
-
process_success(
|
55
|
-
:success_msg => ("Succesfully reverted #{@host.name}"),
|
56
|
-
:success_redirect => "/foreman_xen/snapshots/#{id}"
|
57
|
-
)
|
58
|
-
nil
|
59
48
|
end
|
60
49
|
|
61
50
|
# GET = foreman_xen/snapshots/delete
|
@@ -72,22 +61,19 @@ module ForemanXen
|
|
72
61
|
next unless snapshot.reference == ref
|
73
62
|
name = snapshot.name
|
74
63
|
snapshot.destroy
|
75
|
-
notice "
|
64
|
+
notice "Successfully deleted snapshot #{snapshot.name}"
|
76
65
|
break
|
77
66
|
end
|
78
67
|
else
|
79
|
-
process_error(:error_msg =>
|
80
|
-
return
|
68
|
+
process_error(:error_msg => "Error retrieving host information for host id: #{id}")
|
81
69
|
end
|
82
70
|
else
|
83
|
-
process_error(:error_msg =>
|
84
|
-
return
|
71
|
+
process_error(:error_msg => "Error retrieving compute resource information for host id: #{id}")
|
85
72
|
end
|
86
73
|
process_success(
|
87
|
-
:success_msg =>
|
74
|
+
:success_msg => "Successfully deleted snapshot: #{name}",
|
88
75
|
:success_redirect => "/foreman_xen/snapshots/#{id}"
|
89
76
|
)
|
90
|
-
nil
|
91
77
|
end
|
92
78
|
|
93
79
|
# GET = foreman_xen/snapshots/:id/new
|
@@ -100,7 +86,6 @@ module ForemanXen
|
|
100
86
|
process_error(
|
101
87
|
:error_msg => "Error retrieving compute information for compute resource id: #{@host.compute_resource_id}"
|
102
88
|
)
|
103
|
-
return
|
104
89
|
end
|
105
90
|
else
|
106
91
|
process_error(:error_msg => "Error retrieving host information for host id: #{id}")
|
@@ -113,52 +98,39 @@ module ForemanXen
|
|
113
98
|
name = params[:name]
|
114
99
|
if name.nil? || name == ''
|
115
100
|
process_error(:error_msg => 'You must supply a name.')
|
116
|
-
return
|
117
101
|
end
|
118
102
|
@host = get_host_by_id(id)
|
119
103
|
if !@host.nil?
|
120
104
|
@compute_resource = get_compute_resource_by_host_id(id)
|
121
105
|
else
|
122
106
|
process_error(:error_msg => "Error retrieving host information for host id #{id}")
|
123
|
-
return
|
124
107
|
end
|
125
108
|
if !@compute_resource.nil?
|
126
109
|
vm = @compute_resource.find_vm_by_uuid(@host.uuid)
|
127
110
|
if !vm.nil?
|
128
111
|
vm.snapshot(name)
|
129
112
|
process_success(
|
130
|
-
:success_msg => "
|
113
|
+
:success_msg => "Successfully created snapshot #{name} for #{@host.name}",
|
131
114
|
:success_redirect => "/foreman_xen/snapshots/#{id}"
|
132
115
|
)
|
133
|
-
return
|
134
116
|
else
|
135
117
|
process_error(:error_msg => "Error retrieving compute resource information for #{@host.name}")
|
136
|
-
return
|
137
118
|
end
|
138
119
|
else
|
139
120
|
process_error(:error_msg => "Error retrieving compute provider information for #{@host.name}")
|
140
|
-
return
|
141
121
|
end
|
142
122
|
end
|
143
123
|
|
144
124
|
def snapshots_url
|
145
125
|
case params[:action]
|
146
126
|
when 'show'
|
147
|
-
|
127
|
+
'/'
|
148
128
|
when 'new'
|
149
129
|
id = params[:id]
|
150
|
-
|
151
|
-
return '/'
|
152
|
-
else
|
153
|
-
return "/foreman_xen/snapshots/#{id}"
|
154
|
-
end
|
130
|
+
id.nil? ? '/' : "/foreman_xen/snapshots/#{id}"
|
155
131
|
when 'create'
|
156
132
|
id = params[:id]
|
157
|
-
|
158
|
-
return '/'
|
159
|
-
else
|
160
|
-
return "/foreman_xen/snapshots/#{id}/new"
|
161
|
-
end
|
133
|
+
id.nil? ? '/' : "/foreman_xen/snapshots/#{id}/new"
|
162
134
|
end
|
163
135
|
end
|
164
136
|
|
@@ -155,7 +155,7 @@ module ForemanXen
|
|
155
155
|
|
156
156
|
def find_snapshots_for_vm(vm)
|
157
157
|
return [] if vm.snapshots.empty?
|
158
|
-
tmps
|
158
|
+
tmps = begin
|
159
159
|
client.servers.templates.select(&:is_a_snapshot)
|
160
160
|
rescue
|
161
161
|
[]
|
@@ -198,17 +198,13 @@ module ForemanXen
|
|
198
198
|
if builtin_template_name != '' && custom_template_name != ''
|
199
199
|
logger.info "custom_template_name: #{custom_template_name}"
|
200
200
|
logger.info "builtin_template_name: #{builtin_template_name}"
|
201
|
-
|
201
|
+
raise 'you can select at most one template type'
|
202
202
|
end
|
203
203
|
begin
|
204
204
|
vm = nil
|
205
205
|
logger.info "create_vm(): custom_template_name: #{custom_template_name}"
|
206
206
|
logger.info "create_vm(): builtin_template_name: #{builtin_template_name}"
|
207
|
-
|
208
|
-
vm = create_vm_from_custom args
|
209
|
-
else
|
210
|
-
vm = create_vm_from_builtin args
|
211
|
-
end
|
207
|
+
vm = (custom_template_name != '') ? create_vm_from_custom(args) : create_vm_from_builtin(args)
|
212
208
|
vm.set_attribute('name_description', 'Provisioned by Foreman')
|
213
209
|
cpus = args[:vcpus_max]
|
214
210
|
if vm.vcpus_max.to_i < cpus.to_i
|
@@ -231,15 +227,15 @@ module ForemanXen
|
|
231
227
|
mem_max = args[:memory_max]
|
232
228
|
mem_min = args[:memory_min]
|
233
229
|
|
234
|
-
if args[:hypervisor_host] != ''
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
230
|
+
host = if args[:hypervisor_host] != ''
|
231
|
+
client.hosts.find { |host| host.name == args[:hypervisor_host] }
|
232
|
+
else
|
233
|
+
client.hosts.first
|
234
|
+
end
|
235
|
+
|
236
|
+
logger.info "create_vm_from_builtin: host : #{host.name}"
|
241
237
|
|
242
|
-
|
238
|
+
raise 'Memory max cannot be lower than Memory min' if mem_min.to_i > mem_max.to_i
|
243
239
|
vm = client.servers.new :name => args[:name],
|
244
240
|
:affinity => host,
|
245
241
|
:template_name => args[:custom_template_name]
|
@@ -283,18 +279,21 @@ module ForemanXen
|
|
283
279
|
end
|
284
280
|
|
285
281
|
def create_vm_from_builtin(args)
|
282
|
+
mem_max = args[:memory_max]
|
283
|
+
mem_min = args[:memory_min]
|
284
|
+
|
285
|
+
host = if args[:hypervisor_host] != ''
|
286
|
+
client.hosts.find { |host| host.name == args[:hypervisor_host] }
|
287
|
+
else
|
288
|
+
client.hosts.first
|
289
|
+
end
|
290
|
+
|
291
|
+
logger.info "create_vm_from_builtin: host : #{host.name}"
|
292
|
+
|
286
293
|
builtin_template_name = args[:builtin_template_name]
|
287
294
|
builtin_template_name = builtin_template_name.to_s
|
288
295
|
|
289
|
-
|
290
|
-
host = client.hosts.find { |host| host.name == args[:hypervisor_host] }
|
291
|
-
logger.info "create_vm_from_builtin: host : #{host.name}"
|
292
|
-
else
|
293
|
-
host = client.hosts.first
|
294
|
-
logger.info "create_vm_from_builtin: host : #{host.name}"
|
295
|
-
end
|
296
|
-
|
297
|
-
storage_repository = client.storage_repositories.find { |sr| sr.uuid == "#{args[:VBDs][:sr_uuid]}" }
|
296
|
+
storage_repository = client.storage_repositories.find { |sr| sr.uuid == (args[:VBDs][:sr_uuid]).to_s }
|
298
297
|
|
299
298
|
gb = 1_073_741_824 # 1gb in bytes
|
300
299
|
size = args[:VBDs][:physical_size].to_i * gb
|
@@ -303,8 +302,6 @@ module ForemanXen
|
|
303
302
|
:description => "#{args[:name]}-disk_1",
|
304
303
|
:virtual_size => size.to_s
|
305
304
|
|
306
|
-
mem_max = args[:memory_max]
|
307
|
-
mem_min = args[:memory_min]
|
308
305
|
other_config = {}
|
309
306
|
if builtin_template_name != ''
|
310
307
|
template = client.servers.builtin_templates.find { |tmp| tmp.name == args[:builtin_template_name] }
|
@@ -336,10 +333,10 @@ module ForemanXen
|
|
336
333
|
|
337
334
|
def console(uuid)
|
338
335
|
vm = find_vm_by_uuid(uuid)
|
339
|
-
|
336
|
+
raise 'VM is not running!' unless vm.ready?
|
340
337
|
|
341
338
|
console = vm.service.consoles.find { |c| c.__vm == vm.reference && c.protocol == 'rfb' }
|
342
|
-
|
339
|
+
raise "No console for vm #{vm.name}" if console.nil?
|
343
340
|
|
344
341
|
session_ref = (vm.service.instance_variable_get :@connection).instance_variable_get :@credentials
|
345
342
|
full_url = "#{console.location}&session_id=#{session_ref}"
|
@@ -8,6 +8,4 @@
|
|
8
8
|
<% end -%>
|
9
9
|
<%= link_to_function _("Test Connection"), "testConnection(this)", :class => "btn + #{hypervisor.nil? ? "btn-default" : "btn-success"}", :'data-url' => test_connection_compute_resources_path %>
|
10
10
|
|
11
|
-
<%=
|
12
|
-
|
13
|
-
|
11
|
+
<%= hidden_spinner('', :id => 'test_connection_indicator') %>
|
data/lib/foreman_xen/engine.rb
CHANGED
@@ -15,7 +15,7 @@ module ForemanXen
|
|
15
15
|
|
16
16
|
initializer 'foreman_xen.register_plugin', :after => :finisher_hook do |app|
|
17
17
|
Foreman::Plugin.register :foreman_xen do
|
18
|
-
requires_foreman '>= 1.
|
18
|
+
requires_foreman '>= 1.11'
|
19
19
|
# Register xen compute resource in foreman
|
20
20
|
compute_resource ForemanXen::Xenserver
|
21
21
|
end
|
@@ -24,7 +24,7 @@ module ForemanXen
|
|
24
24
|
config.to_prepare do
|
25
25
|
begin
|
26
26
|
# extend fog xen server and image models.
|
27
|
-
require 'fog/
|
27
|
+
require 'fog/compute/xen_server/models/server'
|
28
28
|
require File.expand_path('../../../app/models/concerns/fog_extensions/xenserver/server', __FILE__)
|
29
29
|
require File.expand_path('../../../app/models/concerns/foreman_xen/host_helper_extensions', __FILE__)
|
30
30
|
|
data/lib/foreman_xen/version.rb
CHANGED
@@ -29,7 +29,7 @@ class VNCTunnel
|
|
29
29
|
listen client_srv
|
30
30
|
else
|
31
31
|
logger.error "Cannot connect to the conosle located at #{uri} reason: #{header}"
|
32
|
-
|
32
|
+
raise "Cannot connect to the console located at #{uri} reason: #{header}"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -76,7 +76,7 @@ class VNCTunnel
|
|
76
76
|
data = @srv_socket.read_nonblock(1024)
|
77
77
|
@client_socket.write(data)
|
78
78
|
rescue IO::WaitReadable => e
|
79
|
-
retry unless
|
79
|
+
retry unless IO.select([@srv_socket], nil, nil, 60).nil?
|
80
80
|
end
|
81
81
|
end
|
82
82
|
rescue EOFError
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_xen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Nemirovsky
|
@@ -10,8 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fog-xenserver
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0.2'
|
15
29
|
- !ruby/object:Gem::Dependency
|
16
30
|
name: rake
|
17
31
|
requirement: !ruby/object:Gem::Requirement
|