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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c50ccd826ef2ecbcf80ba0e0a30d20386b1866c2
4
- data.tar.gz: 4b917f127777166ba7f1811815c5d31efc840df5
3
+ metadata.gz: 6c7609ff160f6ad5aa47e600a462ec5ce27c875a
4
+ data.tar.gz: d944bb014e7db5a5341c079177c2d05d81aa79c5
5
5
  SHA512:
6
- metadata.gz: eef516f319dd09e05b4741d6e87be4d88fd18f258889cbeeb5b5b3fd0a7cb5b7e34194634d6ee90c39b307b3aedc1636356c7d28a07f65698a0f0228d5b4bb36
7
- data.tar.gz: 3f53be8b059ff013e13660db23774cb215534aac874a760133a0ca7b33cd81e661d73c6ef44f2c804320a9d4b4492ca49f1da33805cb6a34825eeeb4f46f45a7
6
+ metadata.gz: 71f45a60fa45467ee1d782b520625e66aec7d2753d9d6d28052ee8f5869e95b73975bd120b4eaf3aeeefa7bc77b26d78e19371a4a69a182c44c5f433caca2549
7
+ data.tar.gz: c2266c7ccd6a59dac205ffd12dd6a8bae3b5ba085ad5568e7ab2078f5458b01213e3baa04254c485ad163fd3f1be6243720019f7d22285c915c5f0f7c867a14b
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
3
3
  begin
4
4
  require 'bundler/setup'
@@ -1,155 +1,164 @@
1
1
  module ForemanXen
2
2
  class SnapshotsController < ::ApplicationController
3
3
  helper :all
4
- skip_before_filter :verify_authenticity_token
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 = params[:id]
9
- if id != nil && id != ""
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
- if !@compute_resource.nil?
12
+ unless @compute_resource.nil?
16
13
  vm = @compute_resource.find_vm_by_uuid(@host.uuid)
17
14
  if !vm.nil?
18
- @snapshots = @compute_resource.get_snapshots_for_vm(vm)
15
+ @snapshots = @compute_resource.find_snapshots_for_vm(vm)
19
16
  else
20
- process_error({:error_msg => "Error retrieving compute resource #{@host.compute_resource_id} from provider."})
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({:error_msg => "No host found with ID: #{id}."})
22
+ process_error(:error_msg => "No host found with ID: #{id}.")
26
23
  return
27
24
  else
28
- process_error({:error_msg => "No compute resource found for host with ID: #{id}."})
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 = params[:id]
36
- ref = params[:ref]
37
- @host = get_host_by_id(id)
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({:success_msg => "Succesfully reverted and powered on #{@host.name}", :success_redirect => "/foreman_xen/snapshots/#{id}"})
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({:error_msg => "Error retrieving host information for #{@host.name}" })
47
+ process_error(:error_msg => "Error retrieving host information for #{@host.name}")
48
48
  return
49
49
  end
50
50
  else
51
- process_error({:error_msg => "Error retrieving compute resource information for #{@host.name}" })
51
+ process_error(:error_msg => "Error retrieving compute resource information for #{@host.name}")
52
52
  return
53
53
  end
54
- process_success({:success_msg => ("Succesfully reverted #{@host.name}"), :success_redirect => "/foreman_xen/snapshots/#{id}"})
55
- return
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 = params[:ref]
61
- id = params[:id]
62
- @host = get_host_by_id(id)
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 = nil
67
+ name = nil
65
68
  if @compute_resource
66
69
  if @host
67
- snapshots = @compute_resource.get_snapshots
68
- snapshots.each do | snapshot |
69
- if snapshot.reference == ref
70
- name = snapshot.name
71
- snapshot.destroy
72
- notice ("Succesfully deleted snapshot #{snapshot.name}")
73
- break
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({:error_msg => ("Error retrieving host information for host id: #{id}")})
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({:error_msg => ("Error retrieving compute resource information for host id: #{id}")})
83
+ process_error(:error_msg => ("Error retrieving compute resource information for host id: #{id}"))
82
84
  return
83
85
  end
84
- process_success({:success_msg => ("Succesfully deleted snapshot: #{name}"), :success_redirect => "/foreman_xen/snapshots/#{id}"})
85
- return
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 = params[: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({:error_msg => "Error retrieving compute information for compute resource id: #{@host.compute_resource_id}"})
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({:error_msg => "Error retrieving host information for host id: #{id}"})
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 = params[:id]
112
+ id = params[:id]
107
113
  name = params[:name]
108
- if name.nil? || name == ""
109
- process_error({:error_msg => "You must supply a name."})
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({:error_msg => "Error retrieving host information for host id #{id}"})
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({:success_msg => "Succesfully created snapshot #{name} for #{@host.name}", :success_redirect => "/foreman_xen/snapshots/#{id}"})
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({:error_msg => "Error retrieving compute resource information for #{@host.name}"})
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({:error_msg => "Error retrieving compute provider information for #{@host.name}"})
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
- when 'show'
146
+ when 'show'
147
+ return '/'
148
+ when 'new'
149
+ id = params[:id]
150
+ if id.nil?
138
151
  return '/'
139
- when 'new'
140
- id = params[:id]
141
- if id.nil?
142
- return '/'
143
- else
144
- return "/foreman_xen/snapshots/#{id}"
145
- end
146
- when 'create'
147
- id = params[:id]
148
- if id.nil?
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 = { :ifs =>
13
- { '0' => {
14
- :ip => '',
15
- :gateway => '',
16
- :netmask => ''
17
- }
18
- },
19
- :nameserver1 => '',
20
- :nameserver2 => '',
21
- :environment => ''
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] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
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] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
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] = compute_attributes['vcpus_max'] ? compute_attributes['vcpus_max'] : nil
41
- attribute_map[:memory_min] = compute_attributes['memory_min'] ? compute_attributes['memory_min'] : nil
42
- attribute_map[:memory_max] = compute_attributes['memory_max'] ? compute_attributes['memory_max'] : nil
43
- attribute_map[:power_on] = compute_attributes['start'] ? compute_attributes['start'] : nil
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] = new.vcpus_max ? new.vcpus_max : nil
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] = vdi.virtual_size ? (vdi.virtual_size.to_i / 1073741824).to_s : nil
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] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
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] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
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] = compute_attributes['vcpus_max'] ? compute_attributes['vcpus_max'] : nil
80
- attribute_map[:memory_min] = compute_attributes['memory_min'] ? compute_attributes['memory_min'] : nil
81
- attribute_map[:memory_max] = compute_attributes['memory_max'] ? compute_attributes['memory_max'] : nil
82
- attribute_map[:power_on] = compute_attributes['start'] ? compute_attributes['start'] : nil
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 => nil,
89
- :volume_selected => nil,
90
- :network_selected => nil,
91
- :template_selected_custom => nil,
92
- :template_selected_builtin => nil,
93
- :cpu_count => nil,
94
- :memory_min => nil,
95
- :memory_max => nil,
96
- :power_on => nil}
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
- attr_accessor :memory_min, :memory_max, :custom_template_name, :builtin_template_name, :hypervisor_host
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); end
15
+ def nics_attributes=(attrs)
16
+ end
16
17
 
17
- def volumes_attributes=(attrs); end
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
- _("%{cpus} CPUs and %{memory} memory") % {:cpus => vcpus_max, :memory => number_to_human_size(memory_max.to_i)}
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
- return fog_nics[0]
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
- def xen_host_title_actions(host)
6
- title_actions(
7
- button_group(
8
- link_to_if_authorized(_("Edit"), hash_for_edit_host_path(:id => host).merge(:auth_object => host),
9
- :title => _("Edit your host"), :id => "edit-button"),
10
- if not host.compute_resource.nil? and host.compute_resource.type =="ForemanXen::Xenserver"
11
- link_to(_("Snapshots"), "../foreman_xen/snapshots/#{@host.id}/",
12
- :title => _("Manage machine snapshots"))
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
- link_to(_("Loading power state ..."), '#', :disabled => true, :id => :loading_power_state)
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