foreman_xen 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fda121c7e0ffccfdf645234f204aa10604e6d9cb
4
- data.tar.gz: a54ea22b53e3c11206fa23941f874c4d88a9366f
3
+ metadata.gz: 2df01d8a9f3e43bd910e4597a70b24e38f6dd7d9
4
+ data.tar.gz: b6707ccb696495513f969f8168e27f7dd8a3456a
5
5
  SHA512:
6
- metadata.gz: 785cd3011b69a36e24c0ff17dc04fadb7bea6130b6909d5390b54e62683d6a377fbdcedfacb2aa4c87bc53960a597fa313688b22542ddfc4d00d21922fcece18
7
- data.tar.gz: 5b0b6ef197c7cb627fa9bdf88c741704a4628e939fa91f3d0dc70bc0bb06197645d71deae9ba6dafd6b23c9a35a998965831e1a1d3d73cfc2a154a16f33396c0
6
+ metadata.gz: 7a9bf52e332b9413d0b2502b4d41c921ebaa20af439f5257afcbcadbdb8bc40433d61b76db6ef31279d8fc0ce3aea7fc4aad46ff5f1e0d3b3ffa9931e036d9c0
7
+ data.tar.gz: 2138939601ccad3c2950061173ee665e416c89c651f0a47ad1b07d8b18a0e74d958b5ea9893f4084df2658a8a908ef2f298e71a2113049783a09d52a6a87d4bb
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,164 +1,155 @@
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
- @host = get_host_by_id(id) if !id.nil? && id != ''
8
+ id = params[:id]
9
+ if id != nil && id != ""
10
+ @host = get_host_by_id(id)
11
+ end
12
+ puts @host.inspect
10
13
  if !@host.nil? && @host.compute_resource_id
11
14
  @compute_resource = get_compute_resource_for_host(@host)
12
- unless @compute_resource.nil?
15
+ if !@compute_resource.nil?
13
16
  vm = @compute_resource.find_vm_by_uuid(@host.uuid)
14
17
  if !vm.nil?
15
- @snapshots = @compute_resource.find_snapshots_for_vm(vm)
18
+ @snapshots = @compute_resource.get_snapshots_for_vm(vm)
16
19
  else
17
- process_error(:error_msg => "Error retrieving compute resource #{@host.compute_resource_id} from provider.")
20
+ process_error({:error_msg => "Error retrieving compute resource #{@host.compute_resource_id} from provider."})
18
21
  return
19
22
  end
20
23
  end
21
24
  elsif @host.nil?
22
- process_error(:error_msg => "No host found with ID: #{id}.")
25
+ process_error({:error_msg => "No host found with ID: #{id}."})
23
26
  return
24
27
  else
25
- process_error(:error_msg => "No compute resource found for host with ID: #{id}.")
28
+ process_error({:error_msg => "No compute resource found for host with ID: #{id}."})
26
29
  return
27
30
  end
28
31
  end
29
32
 
30
- # GET = foreman_xen/snapshots/revert
33
+ #GET = foreman_xen/snapshots/revert
31
34
  def revert
32
- id = params[:id]
33
- ref = params[:ref]
34
- @host = get_host_by_id(id)
35
+ id = params[:id]
36
+ ref = params[:ref]
37
+ @host = get_host_by_id(id)
35
38
  @compute_resource = get_compute_resource_by_host_id(id)
36
39
  if @compute_resource
37
40
  if @host
38
41
  vm = @compute_resource.find_vm_by_uuid(@host.uuid)
39
42
  vm.revert(ref)
40
43
  vm.start
41
- process_success(
42
- :success_msg => "Succesfully reverted and powered on #{@host.name}",
43
- :success_redirect => "/foreman_xen/snapshots/#{id}"
44
- )
44
+ process_success({:success_msg => "Succesfully reverted and powered on #{@host.name}", :success_redirect => "/foreman_xen/snapshots/#{id}"})
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(
55
- :success_msg => ("Succesfully reverted #{@host.name}"),
56
- :success_redirect => "/foreman_xen/snapshots/#{id}"
57
- )
58
- nil
54
+ process_success({:success_msg => ("Succesfully reverted #{@host.name}"), :success_redirect => "/foreman_xen/snapshots/#{id}"})
55
+ return
59
56
  end
60
57
 
61
- # GET = foreman_xen/snapshots/delete
58
+ #GET = foreman_xen/snapshots/delete
62
59
  def destroy
63
- ref = params[:ref]
64
- id = params[:id]
65
- @host = get_host_by_id(id)
60
+ ref = params[:ref]
61
+ id = params[:id]
62
+ @host = get_host_by_id(id)
66
63
  @compute_resource = get_compute_resource_by_host_id(id)
67
- name = nil
64
+ name = nil
68
65
  if @compute_resource
69
66
  if @host
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
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
77
75
  end
78
76
  else
79
- process_error(:error_msg => ("Error retrieving host information for host id: #{id}"))
77
+ process_error({:error_msg => ("Error retrieving host information for host id: #{id}")})
80
78
  return
81
79
  end
82
80
  else
83
- process_error(:error_msg => ("Error retrieving compute resource information for host id: #{id}"))
81
+ process_error({:error_msg => ("Error retrieving compute resource information for host id: #{id}")})
84
82
  return
85
83
  end
86
- process_success(
87
- :success_msg => ("Succesfully deleted snapshot: #{name}"),
88
- :success_redirect => "/foreman_xen/snapshots/#{id}"
89
- )
90
- nil
84
+ process_success({:success_msg => ("Succesfully deleted snapshot: #{name}"), :success_redirect => "/foreman_xen/snapshots/#{id}"})
85
+ return
91
86
  end
92
87
 
93
- # GET = foreman_xen/snapshots/:id/new
88
+ #GET = foreman_xen/snapshots/:id/new
94
89
  def new
95
- id = params[:id]
90
+ id = params[:id]
96
91
  @host = get_host_by_id(id)
97
92
  if !@host.nil?
98
93
  @compute_resource = get_compute_resource_by_host_id(id)
99
94
  if @compute_resource.nil?
100
- process_error(
101
- :error_msg => "Error retrieving compute information for compute resource id: #{@host.compute_resource_id}"
102
- )
95
+ process_error({:error_msg => "Error retrieving compute information for compute resource id: #{@host.compute_resource_id}"})
103
96
  return
104
97
  end
105
98
  else
106
- process_error(:error_msg => "Error retrieving host information for host id: #{id}")
99
+ process_error({:error_msg => "Error retrieving host information for host id: #{id}"})
100
+ return
107
101
  end
108
102
  end
109
103
 
110
- # POST = foreman_xen/snapshots/:id/create
104
+ #POST = foreman_xen/snapshots/:id/create
111
105
  def create
112
- id = params[:id]
106
+ id = params[:id]
113
107
  name = params[:name]
114
- if name.nil? || name == ''
115
- process_error(:error_msg => 'You must supply a name.')
108
+ if name.nil? || name == ""
109
+ process_error({:error_msg => "You must supply a name."})
116
110
  return
117
111
  end
118
112
  @host = get_host_by_id(id)
119
113
  if !@host.nil?
120
114
  @compute_resource = get_compute_resource_by_host_id(id)
121
115
  else
122
- process_error(:error_msg => "Error retrieving host information for host id #{id}")
116
+ process_error({:error_msg => "Error retrieving host information for host id #{id}"})
123
117
  return
124
118
  end
125
119
  if !@compute_resource.nil?
126
120
  vm = @compute_resource.find_vm_by_uuid(@host.uuid)
127
121
  if !vm.nil?
128
122
  vm.snapshot(name)
129
- process_success(
130
- :success_msg => "Succesfully created snapshot #{name} for #{@host.name}",
131
- :success_redirect => "/foreman_xen/snapshots/#{id}"
132
- )
123
+ process_success({:success_msg => "Succesfully created snapshot #{name} for #{@host.name}", :success_redirect => "/foreman_xen/snapshots/#{id}"})
133
124
  return
134
125
  else
135
- process_error(:error_msg => "Error retrieving compute resource information for #{@host.name}")
126
+ process_error({:error_msg => "Error retrieving compute resource information for #{@host.name}"})
136
127
  return
137
128
  end
138
129
  else
139
- process_error(:error_msg => "Error retrieving compute provider information for #{@host.name}")
130
+ process_error({:error_msg => "Error retrieving compute provider information for #{@host.name}"})
140
131
  return
141
132
  end
142
133
  end
143
134
 
144
135
  def snapshots_url
145
136
  case params[:action]
146
- when 'show'
147
- return '/'
148
- when 'new'
149
- id = params[:id]
150
- if id.nil?
137
+ when 'show'
151
138
  return '/'
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
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
162
153
  end
163
154
  end
164
155
 
@@ -170,11 +161,16 @@ module ForemanXen
170
161
 
171
162
  def get_compute_resource_by_host_id(host_id)
172
163
  host = get_host_by_id(host_id)
173
- ComputeResource.where(:id => host.compute_resource_id).to_a[0] if host
164
+ if host
165
+ ComputeResource.where(:id => host.compute_resource_id).to_a[0]
166
+ end
174
167
  end
175
168
 
176
169
  def get_compute_resource_for_host(host)
177
- ComputeResource.where(:id => host.compute_resource_id).to_a[0] if host
170
+ if host
171
+ ComputeResource.where(:id => host.compute_resource_id).to_a[0]
172
+ end
178
173
  end
174
+
179
175
  end
180
- end
176
+ end
@@ -8,18 +8,17 @@ module XenComputeHelper
8
8
  attribute_map
9
9
  end
10
10
 
11
- def init_vmdata
12
- vmdata = {
13
- :ifs => {
14
- '0' => {
15
- :ip => '',
16
- :gateway => '',
17
- :netmask => ''
18
- }
19
- },
20
- :nameserver1 => '',
21
- :nameserver2 => '',
22
- :environment => ''
11
+ def init_vmdata()
12
+ vmdata = { :ifs =>
13
+ { '0' => {
14
+ :ip => '',
15
+ :gateway => '',
16
+ :netmask => ''
17
+ }
18
+ },
19
+ :nameserver1 => '',
20
+ :nameserver2 => '',
21
+ :environment => ''
23
22
  }
24
23
  end
25
24
 
@@ -30,31 +29,35 @@ module XenComputeHelper
30
29
  if new_host?(new)
31
30
  compute_attributes = compute_resource.compute_profile_attributes_for(params['host']['compute_profile_id'])
32
31
  if compute_attributes['VBDs']
33
- attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
32
+ attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
34
33
  attribute_map[:volume_selected] = compute_attributes['VBDs']['sr_uuid'] ? compute_attributes['VBDs']['sr_uuid'] : nil
35
34
  end
36
35
  if compute_attributes['VIFs']
37
36
  attribute_map[:network_selected] = compute_attributes['VIFs']['print'] ? compute_attributes['VIFs']['print'] : nil
38
37
  end
39
- attribute_map[:template_selected_custom] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
38
+ attribute_map[:template_selected_custom] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
40
39
  attribute_map[:template_selected_builtin] = compute_attributes['builtin_template_name'] ? compute_attributes['custom_template_name'] : 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
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
44
+ elsif params && params['host'] && params['host']['compute_attributes']
45
+ if params['host']['compute_attributes']['VBDs']
46
+ attribute_map[:volume_size] = (params['host']['compute_attributes']['VBDs']['physical_size']) ? params['host']['compute_attributes']['VBDs']['physical_size'] : nil
47
+ attribute_map[:volume_selected] = (params['host']['compute_attributes']['VBDs']['sr_uuid']) ? params['host']['compute_attributes']['VBDs']['sr_uuid'] : nil
48
+ end
49
+ if params['host']['compute_attributes']['VIFs']
50
+ attribute_map[:network_selected] = params['host']['compute_attributes']['VIFs']['print'] ? params['host']['compute_attributes']['VIFs']['print'] : nil
51
+ end
52
+ attribute_map[:template_selected_custom] = params['host']['compute_attributes']['custom_template_name'] ? params['host']['compute_attributes']['custom_template_name'] : nil
53
+ attribute_map[:template_selected_builtin] = params['host']['compute_attributes']['builtin_template_name'] ? params['host']['compute_attributes']['builtin_template_name'] : nil
45
54
  elsif new
46
- attribute_map[:cpu_count] = new.vcpus_max ? new.vcpus_max : nil
47
- attribute_map[:memory_min] = new.memory_static_min ? new.memory_static_min : nil
48
- attribute_map[:memory_max] = new.memory_static_max ? new.memory_static_max : nil
49
55
  if new.__vbds
50
- vdi = new.vbds.first.vdi
51
- if vdi
52
- attribute_map[:volume_selected] = vdi.sr.uuid ? vdi.sr.uuid : nil
53
- attribute_map[:volume_size] = vdi.virtual_size ? (vdi.virtual_size.to_i / 1_073_741_824).to_s : nil
54
- end
56
+ attribute_map[:volume_selected] = new.__vbds['sr_uuid'] ? new.__vbds['sr_uuid'] : nil
57
+ attribute_map[:volume_size] = new.__vbds['physical_size'] ? new.__vbds['physical_size'] : nil
55
58
  end
56
59
  if new.__vifs
57
- attribute_map[:network_selected] = new.networks.first.name ? new.networks.first.name : nil
60
+ attribute_map[:network_selected] = new.__vifs['print'] ? new.__vifs['print'] : nil
58
61
  end
59
62
  end
60
63
  attribute_map
@@ -69,31 +72,31 @@ module XenComputeHelper
69
72
  end
70
73
  if compute_attributes
71
74
  if compute_attributes['VBDs']
72
- attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
75
+ attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
73
76
  attribute_map[:volume_selected] = compute_attributes['VBDs']['sr_uuid'] ? compute_attributes['VBDs']['sr_uuid'] : nil
74
77
  end
75
78
  if compute_attributes['VIFs']
76
79
  attribute_map[:network_selected] = compute_attributes['VIFs']['print'] ? compute_attributes['VIFs']['print'] : nil
77
80
  end
78
- attribute_map[:template_selected_custom] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
81
+ attribute_map[:template_selected_custom] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
79
82
  attribute_map[:template_selected_builtin] = compute_attributes['builtin_template_name'] ? compute_attributes['builtin_template_name'] : 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
+ attribute_map[:cpu_count] = compute_attributes['vcpus_max'] ? compute_attributes['vcpus_max'] : nil
84
+ attribute_map[:memory_min] = compute_attributes['memory_min'] ? compute_attributes['memory_min'] : nil
85
+ attribute_map[:memory_max] = compute_attributes['memory_max'] ? compute_attributes['memory_max'] : nil
86
+ attribute_map[:power_on] = compute_attributes['start'] ? compute_attributes['start'] : nil
84
87
  end
85
88
  attribute_map
86
89
  end
87
90
 
88
91
  def empty_attribute_map
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 }
92
+ {:volume_size => nil,
93
+ :volume_selected => nil,
94
+ :network_selected => nil,
95
+ :template_selected_custom => nil,
96
+ :template_selected_builtin => nil,
97
+ :cpu_count => nil,
98
+ :memory_min => nil,
99
+ :memory_max => nil,
100
+ :power_on => nil}
98
101
  end
99
102
  end
@@ -6,17 +6,15 @@ 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)
16
- end
15
+ def nics_attributes=(attrs); end
17
16
 
18
- def volumes_attributes=(attrs)
19
- end
17
+ def volumes_attributes=(attrs); end
20
18
 
21
19
  def memory
22
20
  memory_static_max.to_i
@@ -39,7 +37,7 @@ module FogExtensions
39
37
  end
40
38
 
41
39
  def vm_description
42
- _('%{cpus} CPUs and %{ram} memory') % { :cpus => vcpus_max, :ram => number_to_human_size(memory_max.to_i) }
40
+ _("%{cpus} CPUs and %{memory} memory") % {:cpus => vcpus_max, :memory => number_to_human_size(memory_max.to_i)}
43
41
  end
44
42
 
45
43
  def interfaces
@@ -47,8 +45,9 @@ module FogExtensions
47
45
  end
48
46
 
49
47
  def select_nic(fog_nics, nic)
50
- fog_nics[0]
48
+ return fog_nics[0]
51
49
  end
50
+
52
51
  end
53
52
  end
54
53
  end
@@ -2,26 +2,49 @@ module ForemanXen
2
2
  module HostHelperExtensions
3
3
  extend ActiveSupport::Concern
4
4
 
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(
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?
13
32
  button_group(
14
- link_to(
15
- _('Xen Snapshots'),
16
- "../foreman_xen/snapshots/#{@host.id}/",
17
- :title => _('Manage machine snapshots'),
18
- :id => :xen_snap_button
19
- )
33
+ link_to(_("Loading power state ..."), '#', :disabled => true, :id => :loading_power_state)
20
34
  )
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)
21
46
  )
22
- end
23
- end
24
- host_title_actions_without_xen_snap_button(*args)
47
+ )
25
48
  end
26
49
  end
27
50
  end