foreman_xen 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/controllers/foreman_xen/snapshots_controller.rb +78 -74
- data/app/helpers/xen_compute_helper.rb +35 -34
- data/app/models/concerns/fog_extensions/xenserver/server.rb +7 -6
- data/app/models/concerns/foreman_xen/host_helper_extensions.rb +17 -40
- data/app/models/foreman_xen/xenserver.rb +151 -113
- data/app/views/compute_resources/form/_xenserver.html.erb +2 -2
- data/app/views/compute_resources_vms/form/_hypervisors.html.erb +4 -4
- data/app/views/compute_resources_vms/form/_templates.html.erb +2 -2
- data/app/views/compute_resources_vms/form/_volume.html.erb +1 -1
- data/app/views/compute_resources_vms/form/_xenstore.html.erb +7 -1
- data/app/views/compute_resources_vms/form/xenserver/_base.html.erb +95 -95
- data/app/views/compute_resources_vms/index/_xenserver.html.erb +7 -7
- data/app/views/foreman_xen/snapshots/new.html.erb +14 -14
- data/app/views/foreman_xen/snapshots/show.html.erb +4 -4
- data/config/routes.rb +0 -2
- data/lib/foreman_xen/engine.rb +3 -11
- data/lib/foreman_xen/version.rb +1 -1
- data/lib/foreman_xen/vnc_tunnel.rb +28 -30
- data/test/foreman_xen_test.rb +1 -1
- data/test/test_helper.rb +4 -4
- metadata +5 -19
- data/app/overrides/hosts/show/snapshot_override.html.erb.deface +0 -2
- data/app/overrides/hosts/show/snapshot_override_legacy.html.erb.deface +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c7609ff160f6ad5aa47e600a462ec5ce27c875a
|
4
|
+
data.tar.gz: d944bb014e7db5a5341c079177c2d05d81aa79c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71f45a60fa45467ee1d782b520625e66aec7d2753d9d6d28052ee8f5869e95b73975bd120b4eaf3aeeefa7bc77b26d78e19371a4a69a182c44c5f433caca2549
|
7
|
+
data.tar.gz: c2266c7ccd6a59dac205ffd12dd6a8bae3b5ba085ad5568e7ab2078f5458b01213e3baa04254c485ad163fd3f1be6243720019f7d22285c915c5f0f7c867a14b
|
data/Rakefile
CHANGED
@@ -1,155 +1,164 @@
|
|
1
1
|
module ForemanXen
|
2
2
|
class SnapshotsController < ::ApplicationController
|
3
3
|
helper :all
|
4
|
-
skip_before_filter
|
4
|
+
skip_before_filter :verify_authenticity_token
|
5
5
|
|
6
|
-
#GET - foreman_xen/snapshots/:host_id
|
6
|
+
# GET - foreman_xen/snapshots/:host_id
|
7
7
|
def show
|
8
|
-
id
|
9
|
-
|
10
|
-
@host = get_host_by_id(id)
|
11
|
-
end
|
12
|
-
puts @host.inspect
|
8
|
+
id = params[:id]
|
9
|
+
@host = get_host_by_id(id) if !id.nil? && id != ''
|
13
10
|
if !@host.nil? && @host.compute_resource_id
|
14
11
|
@compute_resource = get_compute_resource_for_host(@host)
|
15
|
-
|
12
|
+
unless @compute_resource.nil?
|
16
13
|
vm = @compute_resource.find_vm_by_uuid(@host.uuid)
|
17
14
|
if !vm.nil?
|
18
|
-
@snapshots =
|
15
|
+
@snapshots = @compute_resource.find_snapshots_for_vm(vm)
|
19
16
|
else
|
20
|
-
process_error(
|
17
|
+
process_error(:error_msg => "Error retrieving compute resource #{@host.compute_resource_id} from provider.")
|
21
18
|
return
|
22
19
|
end
|
23
20
|
end
|
24
21
|
elsif @host.nil?
|
25
|
-
process_error(
|
22
|
+
process_error(:error_msg => "No host found with ID: #{id}.")
|
26
23
|
return
|
27
24
|
else
|
28
|
-
process_error(
|
25
|
+
process_error(:error_msg => "No compute resource found for host with ID: #{id}.")
|
29
26
|
return
|
30
27
|
end
|
31
28
|
end
|
32
29
|
|
33
|
-
#GET = foreman_xen/snapshots/revert
|
30
|
+
# GET = foreman_xen/snapshots/revert
|
34
31
|
def revert
|
35
|
-
id
|
36
|
-
ref
|
37
|
-
@host
|
32
|
+
id = params[:id]
|
33
|
+
ref = params[:ref]
|
34
|
+
@host = get_host_by_id(id)
|
38
35
|
@compute_resource = get_compute_resource_by_host_id(id)
|
39
36
|
if @compute_resource
|
40
37
|
if @host
|
41
38
|
vm = @compute_resource.find_vm_by_uuid(@host.uuid)
|
42
39
|
vm.revert(ref)
|
43
40
|
vm.start
|
44
|
-
process_success(
|
41
|
+
process_success(
|
42
|
+
:success_msg => "Succesfully reverted and powered on #{@host.name}",
|
43
|
+
:success_redirect => "/foreman_xen/snapshots/#{id}"
|
44
|
+
)
|
45
45
|
return
|
46
46
|
else
|
47
|
-
process_error(
|
47
|
+
process_error(:error_msg => "Error retrieving host information for #{@host.name}")
|
48
48
|
return
|
49
49
|
end
|
50
50
|
else
|
51
|
-
process_error(
|
51
|
+
process_error(:error_msg => "Error retrieving compute resource information for #{@host.name}")
|
52
52
|
return
|
53
53
|
end
|
54
|
-
process_success(
|
55
|
-
|
54
|
+
process_success(
|
55
|
+
:success_msg => ("Succesfully reverted #{@host.name}"),
|
56
|
+
:success_redirect => "/foreman_xen/snapshots/#{id}"
|
57
|
+
)
|
58
|
+
nil
|
56
59
|
end
|
57
60
|
|
58
|
-
#GET = foreman_xen/snapshots/delete
|
61
|
+
# GET = foreman_xen/snapshots/delete
|
59
62
|
def destroy
|
60
|
-
ref
|
61
|
-
id
|
62
|
-
@host
|
63
|
+
ref = params[:ref]
|
64
|
+
id = params[:id]
|
65
|
+
@host = get_host_by_id(id)
|
63
66
|
@compute_resource = get_compute_resource_by_host_id(id)
|
64
|
-
name
|
67
|
+
name = nil
|
65
68
|
if @compute_resource
|
66
69
|
if @host
|
67
|
-
snapshots =
|
68
|
-
snapshots.each do |
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
70
|
+
snapshots = @compute_resource.find_snapshots
|
71
|
+
snapshots.each do |snapshot|
|
72
|
+
next unless snapshot.reference == ref
|
73
|
+
name = snapshot.name
|
74
|
+
snapshot.destroy
|
75
|
+
notice "Succesfully deleted snapshot #{snapshot.name}"
|
76
|
+
break
|
75
77
|
end
|
76
78
|
else
|
77
|
-
process_error(
|
79
|
+
process_error(:error_msg => ("Error retrieving host information for host id: #{id}"))
|
78
80
|
return
|
79
81
|
end
|
80
82
|
else
|
81
|
-
process_error(
|
83
|
+
process_error(:error_msg => ("Error retrieving compute resource information for host id: #{id}"))
|
82
84
|
return
|
83
85
|
end
|
84
|
-
process_success(
|
85
|
-
|
86
|
+
process_success(
|
87
|
+
:success_msg => ("Succesfully deleted snapshot: #{name}"),
|
88
|
+
:success_redirect => "/foreman_xen/snapshots/#{id}"
|
89
|
+
)
|
90
|
+
nil
|
86
91
|
end
|
87
92
|
|
88
|
-
#GET = foreman_xen/snapshots/:id/new
|
93
|
+
# GET = foreman_xen/snapshots/:id/new
|
89
94
|
def new
|
90
|
-
id
|
95
|
+
id = params[:id]
|
91
96
|
@host = get_host_by_id(id)
|
92
97
|
if !@host.nil?
|
93
98
|
@compute_resource = get_compute_resource_by_host_id(id)
|
94
99
|
if @compute_resource.nil?
|
95
|
-
process_error(
|
100
|
+
process_error(
|
101
|
+
:error_msg => "Error retrieving compute information for compute resource id: #{@host.compute_resource_id}"
|
102
|
+
)
|
96
103
|
return
|
97
104
|
end
|
98
105
|
else
|
99
|
-
process_error(
|
100
|
-
return
|
106
|
+
process_error(:error_msg => "Error retrieving host information for host id: #{id}")
|
101
107
|
end
|
102
108
|
end
|
103
109
|
|
104
|
-
#POST = foreman_xen/snapshots/:id/create
|
110
|
+
# POST = foreman_xen/snapshots/:id/create
|
105
111
|
def create
|
106
|
-
id
|
112
|
+
id = params[:id]
|
107
113
|
name = params[:name]
|
108
|
-
if name.nil? || name ==
|
109
|
-
process_error(
|
114
|
+
if name.nil? || name == ''
|
115
|
+
process_error(:error_msg => 'You must supply a name.')
|
110
116
|
return
|
111
117
|
end
|
112
118
|
@host = get_host_by_id(id)
|
113
119
|
if !@host.nil?
|
114
120
|
@compute_resource = get_compute_resource_by_host_id(id)
|
115
121
|
else
|
116
|
-
process_error(
|
122
|
+
process_error(:error_msg => "Error retrieving host information for host id #{id}")
|
117
123
|
return
|
118
124
|
end
|
119
125
|
if !@compute_resource.nil?
|
120
126
|
vm = @compute_resource.find_vm_by_uuid(@host.uuid)
|
121
127
|
if !vm.nil?
|
122
128
|
vm.snapshot(name)
|
123
|
-
process_success(
|
129
|
+
process_success(
|
130
|
+
:success_msg => "Succesfully created snapshot #{name} for #{@host.name}",
|
131
|
+
:success_redirect => "/foreman_xen/snapshots/#{id}"
|
132
|
+
)
|
124
133
|
return
|
125
134
|
else
|
126
|
-
process_error(
|
135
|
+
process_error(:error_msg => "Error retrieving compute resource information for #{@host.name}")
|
127
136
|
return
|
128
137
|
end
|
129
138
|
else
|
130
|
-
process_error(
|
139
|
+
process_error(:error_msg => "Error retrieving compute provider information for #{@host.name}")
|
131
140
|
return
|
132
141
|
end
|
133
142
|
end
|
134
143
|
|
135
144
|
def snapshots_url
|
136
145
|
case params[:action]
|
137
|
-
|
146
|
+
when 'show'
|
147
|
+
return '/'
|
148
|
+
when 'new'
|
149
|
+
id = params[:id]
|
150
|
+
if id.nil?
|
138
151
|
return '/'
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
return '/'
|
150
|
-
else
|
151
|
-
return "/foreman_xen/snapshots/#{id}/new"
|
152
|
-
end
|
152
|
+
else
|
153
|
+
return "/foreman_xen/snapshots/#{id}"
|
154
|
+
end
|
155
|
+
when 'create'
|
156
|
+
id = params[:id]
|
157
|
+
if id.nil?
|
158
|
+
return '/'
|
159
|
+
else
|
160
|
+
return "/foreman_xen/snapshots/#{id}/new"
|
161
|
+
end
|
153
162
|
end
|
154
163
|
end
|
155
164
|
|
@@ -161,16 +170,11 @@ module ForemanXen
|
|
161
170
|
|
162
171
|
def get_compute_resource_by_host_id(host_id)
|
163
172
|
host = get_host_by_id(host_id)
|
164
|
-
if host
|
165
|
-
ComputeResource.where(:id => host.compute_resource_id).to_a[0]
|
166
|
-
end
|
173
|
+
ComputeResource.where(:id => host.compute_resource_id).to_a[0] if host
|
167
174
|
end
|
168
175
|
|
169
176
|
def get_compute_resource_for_host(host)
|
170
|
-
if host
|
171
|
-
ComputeResource.where(:id => host.compute_resource_id).to_a[0]
|
172
|
-
end
|
177
|
+
ComputeResource.where(:id => host.compute_resource_id).to_a[0] if host
|
173
178
|
end
|
174
|
-
|
175
179
|
end
|
176
|
-
end
|
180
|
+
end
|
@@ -8,17 +8,18 @@ module XenComputeHelper
|
|
8
8
|
attribute_map
|
9
9
|
end
|
10
10
|
|
11
|
-
def init_vmdata
|
12
|
-
vmdata = {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
def init_vmdata
|
12
|
+
vmdata = {
|
13
|
+
:ifs => {
|
14
|
+
'0' => {
|
15
|
+
:ip => '',
|
16
|
+
:gateway => '',
|
17
|
+
:netmask => ''
|
18
|
+
}
|
19
|
+
},
|
20
|
+
:nameserver1 => '',
|
21
|
+
:nameserver2 => '',
|
22
|
+
:environment => ''
|
22
23
|
}
|
23
24
|
end
|
24
25
|
|
@@ -29,27 +30,27 @@ module XenComputeHelper
|
|
29
30
|
if new_host?(new)
|
30
31
|
compute_attributes = compute_resource.compute_profile_attributes_for(params['host']['compute_profile_id'])
|
31
32
|
if compute_attributes['VBDs']
|
32
|
-
attribute_map[:volume_size]
|
33
|
+
attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
|
33
34
|
attribute_map[:volume_selected] = compute_attributes['VBDs']['sr_uuid'] ? compute_attributes['VBDs']['sr_uuid'] : nil
|
34
35
|
end
|
35
36
|
if compute_attributes['VIFs']
|
36
37
|
attribute_map[:network_selected] = compute_attributes['VIFs']['print'] ? compute_attributes['VIFs']['print'] : nil
|
37
38
|
end
|
38
|
-
attribute_map[:template_selected_custom]
|
39
|
+
attribute_map[:template_selected_custom] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
|
39
40
|
attribute_map[:template_selected_builtin] = compute_attributes['builtin_template_name'] ? compute_attributes['custom_template_name'] : nil
|
40
|
-
attribute_map[:cpu_count]
|
41
|
-
attribute_map[:memory_min]
|
42
|
-
attribute_map[:memory_max]
|
43
|
-
attribute_map[:power_on]
|
41
|
+
attribute_map[:cpu_count] = compute_attributes['vcpus_max'] ? compute_attributes['vcpus_max'] : nil
|
42
|
+
attribute_map[:memory_min] = compute_attributes['memory_min'] ? compute_attributes['memory_min'] : nil
|
43
|
+
attribute_map[:memory_max] = compute_attributes['memory_max'] ? compute_attributes['memory_max'] : nil
|
44
|
+
attribute_map[:power_on] = compute_attributes['start'] ? compute_attributes['start'] : nil
|
44
45
|
elsif new
|
45
|
-
attribute_map[:cpu_count]
|
46
|
+
attribute_map[:cpu_count] = new.vcpus_max ? new.vcpus_max : nil
|
46
47
|
attribute_map[:memory_min] = new.memory_static_min ? new.memory_static_min : nil
|
47
48
|
attribute_map[:memory_max] = new.memory_static_max ? new.memory_static_max : nil
|
48
49
|
if new.__vbds
|
49
50
|
vdi = new.vbds.first.vdi
|
50
51
|
if vdi
|
51
52
|
attribute_map[:volume_selected] = vdi.sr.uuid ? vdi.sr.uuid : nil
|
52
|
-
attribute_map[:volume_size]
|
53
|
+
attribute_map[:volume_size] = vdi.virtual_size ? (vdi.virtual_size.to_i / 1_073_741_824).to_s : nil
|
53
54
|
end
|
54
55
|
end
|
55
56
|
if new.__vifs
|
@@ -68,31 +69,31 @@ module XenComputeHelper
|
|
68
69
|
end
|
69
70
|
if compute_attributes
|
70
71
|
if compute_attributes['VBDs']
|
71
|
-
attribute_map[:volume_size]
|
72
|
+
attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
|
72
73
|
attribute_map[:volume_selected] = compute_attributes['VBDs']['sr_uuid'] ? compute_attributes['VBDs']['sr_uuid'] : nil
|
73
74
|
end
|
74
75
|
if compute_attributes['VIFs']
|
75
76
|
attribute_map[:network_selected] = compute_attributes['VIFs']['print'] ? compute_attributes['VIFs']['print'] : nil
|
76
77
|
end
|
77
|
-
attribute_map[:template_selected_custom]
|
78
|
+
attribute_map[:template_selected_custom] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
|
78
79
|
attribute_map[:template_selected_builtin] = compute_attributes['builtin_template_name'] ? compute_attributes['builtin_template_name'] : nil
|
79
|
-
attribute_map[:cpu_count]
|
80
|
-
attribute_map[:memory_min]
|
81
|
-
attribute_map[:memory_max]
|
82
|
-
attribute_map[:power_on]
|
80
|
+
attribute_map[:cpu_count] = compute_attributes['vcpus_max'] ? compute_attributes['vcpus_max'] : nil
|
81
|
+
attribute_map[:memory_min] = compute_attributes['memory_min'] ? compute_attributes['memory_min'] : nil
|
82
|
+
attribute_map[:memory_max] = compute_attributes['memory_max'] ? compute_attributes['memory_max'] : nil
|
83
|
+
attribute_map[:power_on] = compute_attributes['start'] ? compute_attributes['start'] : nil
|
83
84
|
end
|
84
85
|
attribute_map
|
85
86
|
end
|
86
87
|
|
87
88
|
def empty_attribute_map
|
88
|
-
{:volume_size
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
89
|
+
{ :volume_size => nil,
|
90
|
+
:volume_selected => nil,
|
91
|
+
:network_selected => nil,
|
92
|
+
:template_selected_custom => nil,
|
93
|
+
:template_selected_builtin => nil,
|
94
|
+
:cpu_count => nil,
|
95
|
+
:memory_min => nil,
|
96
|
+
:memory_max => nil,
|
97
|
+
:power_on => nil }
|
97
98
|
end
|
98
99
|
end
|
@@ -6,15 +6,17 @@ module FogExtensions
|
|
6
6
|
include ActionView::Helpers::NumberHelper
|
7
7
|
|
8
8
|
attr_accessor :start
|
9
|
-
|
9
|
+
attr_accessor :memory_min, :memory_max, :custom_template_name, :builtin_template_name, :hypervisor_host
|
10
10
|
|
11
11
|
def to_s
|
12
12
|
name
|
13
13
|
end
|
14
14
|
|
15
|
-
def nics_attributes=(attrs)
|
15
|
+
def nics_attributes=(attrs)
|
16
|
+
end
|
16
17
|
|
17
|
-
def volumes_attributes=(attrs)
|
18
|
+
def volumes_attributes=(attrs)
|
19
|
+
end
|
18
20
|
|
19
21
|
def memory
|
20
22
|
memory_static_max.to_i
|
@@ -37,7 +39,7 @@ module FogExtensions
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def vm_description
|
40
|
-
_(
|
42
|
+
_('%{cpus} CPUs and %{ram} memory') % { :cpus => vcpus_max, :ram => number_to_human_size(memory_max.to_i) }
|
41
43
|
end
|
42
44
|
|
43
45
|
def interfaces
|
@@ -45,9 +47,8 @@ module FogExtensions
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def select_nic(fog_nics, nic)
|
48
|
-
|
50
|
+
fog_nics[0]
|
49
51
|
end
|
50
|
-
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
@@ -2,49 +2,26 @@ module ForemanXen
|
|
2
2
|
module HostHelperExtensions
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end,
|
14
|
-
if host.build
|
15
|
-
link_to_if_authorized(_("Cancel build"), hash_for_cancelBuild_host_path(:id => host).merge(:auth_object => host, :permission => 'build_hosts'),
|
16
|
-
:disabled => host.can_be_built?,
|
17
|
-
:title => _("Cancel build request for this host"), :id => "cancel-build-button")
|
18
|
-
else
|
19
|
-
link_to_if_authorized(_("Build"), hash_for_host_path(:id => host).merge(:auth_object => host, :permission => 'build_hosts', :anchor => "review_before_build"),
|
20
|
-
:disabled => !host.can_be_built?,
|
21
|
-
:title => _("Enable rebuild on next host boot"),
|
22
|
-
:class => "btn",
|
23
|
-
:id => "build-review",
|
24
|
-
:data => { :toggle => 'modal',
|
25
|
-
:target => '#review_before_build',
|
26
|
-
:url => review_before_build_host_path(:id => host)
|
27
|
-
}
|
28
|
-
)
|
29
|
-
end
|
30
|
-
),
|
31
|
-
if host.compute_resource_id || host.bmc_available?
|
5
|
+
included do
|
6
|
+
alias_method_chain :host_title_actions, :xen_snap_button
|
7
|
+
end
|
8
|
+
|
9
|
+
def host_title_actions_with_xen_snap_button(*args)
|
10
|
+
unless @host.compute_resource.nil?
|
11
|
+
if @host.compute_resource.type == 'ForemanXen::Xenserver'
|
12
|
+
title_actions(
|
32
13
|
button_group(
|
33
|
-
|
14
|
+
link_to(
|
15
|
+
_('Xen Snapshots'),
|
16
|
+
"../foreman_xen/snapshots/#{@host.id}/",
|
17
|
+
:title => _('Manage machine snapshots'),
|
18
|
+
:id => :xen_snap_button
|
19
|
+
)
|
34
20
|
)
|
35
|
-
end,
|
36
|
-
button_group(
|
37
|
-
if host.try(:puppet_proxy)
|
38
|
-
link_to_if_authorized(_("Run puppet"), hash_for_puppetrun_host_path(:id => host).merge(:auth_object => host, :permission => 'puppetrun_hosts'),
|
39
|
-
:disabled => !Setting[:puppetrun],
|
40
|
-
:title => _("Trigger a puppetrun on a node; requires that puppet run is enabled"))
|
41
|
-
end
|
42
|
-
),
|
43
|
-
button_group(
|
44
|
-
link_to_if_authorized(_("Delete"), hash_for_host_path(:id => host).merge(:auth_object => host, :permission => 'destroy_hosts'),
|
45
|
-
:class => "btn btn-danger", :id => "delete-button", :data => { :message => _("Are you sure?") }, :method => :delete)
|
46
21
|
)
|
47
|
-
|
22
|
+
end
|
23
|
+
end
|
24
|
+
host_title_actions_without_xen_snap_button(*args)
|
48
25
|
end
|
49
26
|
end
|
50
27
|
end
|