foreman_xen 0.3.0 → 0.3.1

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: 2f1adce9377bfddcc90e390be4aa635db21f6c60
4
- data.tar.gz: 7c2030f9848d832fc4cdffa24b498f4f10ecc748
3
+ metadata.gz: 7970c57af652a76865ce11386d3f96d2ad5cd789
4
+ data.tar.gz: 8b7a10b16676968ce4a50fcb3d3bc59c5f3248c1
5
5
  SHA512:
6
- metadata.gz: 524c2b085d36a462d32c8c7d6ec3105739da12881a17a6ec8fe8ff9e6a1d906e9fbe7630211b5d5912380bbdf26aa205ec4d4153d7b3abf680bf10681639ba44
7
- data.tar.gz: 8618ce64c4381cb460af72b5443efb079b88014a37547f4c53b211705106015291c014bf7682417f01dcdb03a664ec3cc18586999c1bbe56a8c56cb97d7e51a5
6
+ metadata.gz: 1e45718f60595e04ccf5b634df462952bf7494881966b4519c2120ebae45a2f5c3a080f525236fff92f2625eb16146d0e62f1ff4b827692fbfc8d259965ee1d5
7
+ data.tar.gz: c3106ac70bdc20df5c749d63d89dd26234700f3a6e2005645870e5883209408befbbbfcf357bc68b0727e81b69faf18c7e5d2f8987afaf8e0f13001d3d1a0297
@@ -30,31 +30,31 @@ module XenComputeHelper
30
30
  if new_host?(new)
31
31
  compute_attributes = compute_resource.compute_profile_attributes_for(params['host']['compute_profile_id'])
32
32
  if compute_attributes['VBDs']
33
- attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
34
- attribute_map[:volume_selected] = compute_attributes['VBDs']['sr_uuid'] ? compute_attributes['VBDs']['sr_uuid'] : nil
33
+ attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size']
34
+ attribute_map[:volume_selected] = compute_attributes['VBDs']['sr_uuid']
35
35
  end
36
36
  if compute_attributes['VIFs']
37
- attribute_map[:network_selected] = compute_attributes['VIFs']['print'] ? compute_attributes['VIFs']['print'] : nil
37
+ attribute_map[:network_selected] = compute_attributes['VIFs']['print']
38
38
  end
39
- attribute_map[:template_selected_custom] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
40
- 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
39
+ attribute_map[:template_selected_custom] = compute_attributes['custom_template_name']
40
+ attribute_map[:template_selected_builtin] = compute_attributes['builtin_template_name']
41
+ attribute_map[:cpu_count] = compute_attributes['vcpus_max']
42
+ attribute_map[:memory_min] = compute_attributes['memory_min']
43
+ attribute_map[:memory_max] = compute_attributes['memory_max']
44
+ attribute_map[:power_on] = compute_attributes['start']
45
45
  elsif new
46
46
  attribute_map[:cpu_count] = new.vcpus_max ? new.vcpus_max : nil
47
47
  attribute_map[:memory_min] = new.memory_static_min ? new.memory_static_min : nil
48
48
  attribute_map[:memory_max] = new.memory_static_max ? new.memory_static_max : nil
49
- if new.__vbds
49
+ if new.vbds
50
50
  vdi = new.vbds.first.vdi
51
51
  if vdi
52
52
  attribute_map[:volume_selected] = vdi.sr.uuid ? vdi.sr.uuid : nil
53
53
  attribute_map[:volume_size] = vdi.virtual_size ? (vdi.virtual_size.to_i / 1_073_741_824).to_s : nil
54
54
  end
55
55
  end
56
- if new.__vifs
57
- attribute_map[:network_selected] = new.networks.first.name ? new.networks.first.name : nil
56
+ if new.vifs
57
+ attribute_map[:network_selected] = new.vifs.first.network.name ? new.vifs.first.network.name : nil
58
58
  end
59
59
  end
60
60
  attribute_map
@@ -69,18 +69,18 @@ module XenComputeHelper
69
69
  end
70
70
  if compute_attributes
71
71
  if compute_attributes['VBDs']
72
- attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size'] ? compute_attributes['VBDs']['physical_size'] : nil
73
- attribute_map[:volume_selected] = compute_attributes['VBDs']['sr_uuid'] ? compute_attributes['VBDs']['sr_uuid'] : nil
72
+ attribute_map[:volume_size] = compute_attributes['VBDs']['physical_size']
73
+ attribute_map[:volume_selected] = compute_attributes['VBDs']['sr_uuid']
74
74
  end
75
75
  if compute_attributes['VIFs']
76
- attribute_map[:network_selected] = compute_attributes['VIFs']['print'] ? compute_attributes['VIFs']['print'] : nil
76
+ attribute_map[:network_selected] = compute_attributes['VIFs']['print']
77
77
  end
78
- attribute_map[:template_selected_custom] = compute_attributes['custom_template_name'] ? compute_attributes['custom_template_name'] : nil
79
- 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
78
+ attribute_map[:template_selected_custom] = compute_attributes['custom_template_name']
79
+ attribute_map[:template_selected_builtin] = compute_attributes['builtin_template_name']
80
+ attribute_map[:cpu_count] = compute_attributes['vcpus_max']
81
+ attribute_map[:memory_min] = compute_attributes['memory_min']
82
+ attribute_map[:memory_max] = compute_attributes['memory_max']
83
+ attribute_map[:power_on] = compute_attributes['start']
84
84
  end
85
85
  attribute_map
86
86
  end
@@ -2,10 +2,13 @@ module ForemanXen
2
2
  class Xenserver < ComputeResource
3
3
  validates :url, :user, :password, :presence => true
4
4
 
5
+ attr_accessible :uuid
6
+
5
7
  def provided_attributes
6
8
  super.merge(
7
9
  :uuid => :reference,
8
- :mac => :mac)
10
+ :mac => :mac
11
+ )
9
12
  end
10
13
 
11
14
  def capabilities
@@ -89,13 +92,12 @@ module ForemanXen
89
92
  found = 0
90
93
 
91
94
  hosts.each do |host|
92
- if sr.reference == host.suspend_image_sr
93
- found = 1
94
- subresults[:name] = sr.name
95
- subresults[:display_name] = sr.name + '(' + host.hostname + ')'
96
- subresults[:uuid] = sr.uuid
97
- break
98
- end
95
+ next unless sr.reference == host.suspend_image_sr
96
+ found = 1
97
+ subresults[:name] = sr.name
98
+ subresults[:display_name] = sr.name + '(' + host.hostname + ')'
99
+ subresults[:uuid] = sr.uuid
100
+ break
99
101
  end
100
102
 
101
103
  if found == 0
@@ -190,10 +192,8 @@ module ForemanXen
190
192
  end
191
193
 
192
194
  def create_vm(args = {})
193
- custom_template_name = args[:custom_template_name]
194
- builtin_template_name = args[:builtin_template_name]
195
- custom_template_name = custom_template_name.to_s
196
- builtin_template_name = builtin_template_name.to_s
195
+ custom_template_name = args[:custom_template_name].to_s
196
+ builtin_template_name = args[:builtin_template_name].to_s
197
197
 
198
198
  if builtin_template_name != '' && custom_template_name != ''
199
199
  logger.info "custom_template_name: #{custom_template_name}"
@@ -201,20 +201,13 @@ module ForemanXen
201
201
  raise 'you can select at most one template type'
202
202
  end
203
203
  begin
204
- vm = nil
205
204
  logger.info "create_vm(): custom_template_name: #{custom_template_name}"
206
205
  logger.info "create_vm(): builtin_template_name: #{builtin_template_name}"
207
206
  vm = (custom_template_name != '') ? create_vm_from_custom(args) : create_vm_from_builtin(args)
208
207
  vm.set_attribute('name_description', 'Provisioned by Foreman')
209
- cpus = args[:vcpus_max]
210
- if vm.vcpus_max.to_i < cpus.to_i
211
- vm.set_attribute('VCPUs_max', cpus)
212
- vm.set_attribute('VCPUs_at_startup', cpus)
213
- else
214
- vm.set_attribute('VCPUs_at_startup', cpus)
215
- vm.set_attribute('VCPUs_max', cpus)
216
- end
217
- vm.refresh
208
+ vm.set_attribute('VCPUs_at_startup', args[:vcpus_max])
209
+ vm.set_attribute('VCPUs_max', args[:vcpus_max])
210
+ vm.reload
218
211
  return vm
219
212
  rescue => e
220
213
  logger.info e
@@ -321,13 +314,13 @@ module ForemanXen
321
314
  :memory_dynamic_min => mem_min
322
315
 
323
316
  vm.save :auto_start => false
324
- client.vbds.create :server => vm, :vdi => vdi
317
+ client.vbds.create :vm => vm, :vdi => vdi
325
318
 
326
319
  create_network(vm, args)
327
320
 
328
321
  vm.provision
329
322
  vm.set_attribute('HVM_boot_policy', 'BIOS order')
330
- vm.refresh
323
+ vm.reload
331
324
  vm
332
325
  end
333
326
 
@@ -335,7 +328,7 @@ module ForemanXen
335
328
  vm = find_vm_by_uuid(uuid)
336
329
  raise 'VM is not running!' unless vm.ready?
337
330
 
338
- console = vm.service.consoles.find { |c| c.__vm == vm.reference && c.protocol == 'rfb' }
331
+ console = vm.service.consoles.find { |c| c.vm && c.vm.reference == vm.reference && c.protocol == 'rfb' }
339
332
  raise "No console for vm #{vm.name}" if console.nil?
340
333
 
341
334
  session_ref = (vm.service.instance_variable_get :@connection).instance_variable_get :@credentials
@@ -387,17 +380,17 @@ module ForemanXen
387
380
  def create_network(vm, args)
388
381
  net = client.networks.find { |n| n.name == args[:VIFs][:print] }
389
382
  net_config = {
390
- 'MAC_autogenerated' => 'True',
391
- 'VM' => vm.reference,
383
+ 'mac_autogenerated' => 'True',
384
+ 'vm' => vm.reference,
392
385
  'network' => net.reference,
393
- 'MAC' => '',
386
+ 'mac' => '',
394
387
  'device' => '0',
395
- 'MTU' => '0',
388
+ 'mtu' => '0',
396
389
  'other_config' => {},
397
390
  'qos_algorithm_type' => 'ratelimit',
398
391
  'qos_algorithm_params' => {}
399
392
  }
400
- client.create_vif_custom net_config
393
+ vm.vifs = client.vifs.create net_config
401
394
  vm.reload
402
395
  end
403
396
 
@@ -13,7 +13,7 @@ module ForemanXen
13
13
  Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
14
14
  end
15
15
 
16
- initializer 'foreman_xen.register_plugin', :after => :finisher_hook do |app|
16
+ initializer 'foreman_xen.register_plugin', :before => :finisher_hook do |app|
17
17
  Foreman::Plugin.register :foreman_xen do
18
18
  requires_foreman '>= 1.11'
19
19
  # Register xen compute resource in foreman
@@ -1,3 +1,3 @@
1
1
  module ForemanXen
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Nemirovsky
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-02-25 00:00:00.000000000 Z
13
+ date: 2016-08-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fog-xenserver
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.4.5.1
101
+ rubygems_version: 2.5.1
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Provision and manage XEN Server from Foreman