foreman_fog_proxmox 0.22.0 → 0.23.0

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
  SHA256:
3
- metadata.gz: 5ea8c8bfb4c244c6b8de14bc2119c03bd737d44d3ebfac7f57ee6b4b836bffe4
4
- data.tar.gz: 8588badabb959ac81107d258a4c05e3c06ccb7c109c94ddfe91281dd3507bdea
3
+ metadata.gz: a437699869ae38137e94761791e2a01d741e9dd36f924c286bfaa9afc139f9e7
4
+ data.tar.gz: 5698645c6f2a3a3278959989e5214357263f3ba7c0091830d1f41205033582ea
5
5
  SHA512:
6
- metadata.gz: 360e58e7b7efc5cc25dbc6fd473fb869c44329527aa1bdb96b0f98c3049928ae5ee5246632c83f900aa245d9fb3d023b3f4c58e405e12898e75da110f9057936
7
- data.tar.gz: 8bcd614b6e3ff837e2e3524c1da9ec54d43ef93869034208634208d8cee66c418db38030ac2bf62829aa3ac1d17f8c3954b6d37f920428a557887181650b2139
6
+ metadata.gz: 1d29712272ab785a33e4bdc70f345b0da96ff22d020820bbefc27c14302c24c1207d198d6ec742562a4d30a84083b1e081b43bb6a855c432e5a67ce60ca8a5b9
7
+ data.tar.gz: 9f3c39bbeca9d7364f4ee92cef02cc6fc7c398692cbc12f03a7c581324a9c21ca65ef1af33fcc892b1da02e3378f3f7c214fad2fb79bded7cfb028d55f5e5827
@@ -21,12 +21,18 @@ module FogExtensions
21
21
  module Proxmox
22
22
  module Server
23
23
  extend ActiveSupport::Concern
24
- attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password, :start_after_create
24
+ attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password, :start_after_create, :compute_resource_id
25
25
 
26
26
  def unique_cluster_identity(compute_resource)
27
27
  compute_resource.id.to_s + '_' + identity.to_s
28
28
  end
29
29
 
30
+ def foreman_uuid
31
+ return identity.to_s if compute_resource_id.nil?
32
+
33
+ compute_resource_id.to_s + '_' + identity.to_s
34
+ end
35
+
30
36
  def start
31
37
  action('start')
32
38
  end
@@ -45,6 +45,7 @@ module ForemanFogProxmox
45
45
 
46
46
  def provided_attributes
47
47
  super.merge(
48
+ :uuid => :foreman_uuid,
48
49
  :mac => :mac
49
50
  )
50
51
  end
@@ -62,10 +63,11 @@ module ForemanFogProxmox
62
63
  end
63
64
 
64
65
  def associated_host(vm)
65
- associate_by('mac', vm.mac)
66
+ associate_by('mac', vm&.mac)
66
67
  end
67
68
 
68
69
  def associate_by(name, attributes)
70
+ return nil if attributes.blank?
69
71
  Host.authorized(:view_hosts,
70
72
  Host).joins(:primary_interface).where(:nics => { :primary => true }).where("nics.#{name}".downcase => attributes.downcase).readonly(false).first
71
73
  end
@@ -19,8 +19,13 @@
19
19
 
20
20
  module ForemanFogProxmox
21
21
  module ProxmoxComputeAttributes
22
+ FOREMAN_INTERFACE_ATTRIBUTES = [:id, :mac, :ip, :ip6].freeze
23
+ PROXMOX_MAC_ATTRIBUTES = [:macaddr, :hwaddr].freeze
24
+ PROXMOX_INTERFACE_METADATA = [:identifier, :compute_attributes].freeze
25
+
22
26
  def host_compute_attrs(host)
23
- ostype = host.compute_attributes['config_attributes']['ostype']
27
+ config = host.compute_attributes['config_attributes'] || {}
28
+ ostype = config['ostype']
24
29
  type = host.compute_attributes['type']
25
30
  case type
26
31
  when 'lxc'
@@ -41,9 +46,21 @@ module ForemanFogProxmox
41
46
  end
42
47
 
43
48
  def interface_compute_attributes(interface_attributes)
44
- vm_attrs = ForemanFogProxmox::HashCollection.new_hash_reject_keys(interface_attributes, [:identifier, :macaddr, :hwaddr])
45
- vm_attrs[:dhcp] = (interface_attributes[:ip] == 'dhcp') ? '1' : '0'
46
- vm_attrs[:dhcp6] = (interface_attributes[:ip6] == 'dhcp') ? '1' : '0'
49
+ attrs = interface_attributes.with_indifferent_access
50
+ provider_attrs = attrs[:compute_attributes].present? ? attrs[:compute_attributes].with_indifferent_access : ActiveSupport::HashWithIndifferentAccess.new
51
+
52
+ vm_attrs = FOREMAN_INTERFACE_ATTRIBUTES.index_with do |key|
53
+ attrs[key] || provider_attrs.delete(key)
54
+ end.compact
55
+ vm_attrs[:mac] ||= attrs[:macaddr] || attrs[:hwaddr] || provider_attrs.delete(:macaddr) || provider_attrs.delete(:hwaddr)
56
+
57
+ attrs.except(*FOREMAN_INTERFACE_ATTRIBUTES, *PROXMOX_MAC_ATTRIBUTES, *PROXMOX_INTERFACE_METADATA).each do |key, value|
58
+ provider_attrs[key] = value
59
+ end
60
+
61
+ provider_attrs[:dhcp] = (vm_attrs[:ip] == 'dhcp') ? '1' : '0'
62
+ provider_attrs[:dhcp6] = (vm_attrs[:ip6] == 'dhcp') ? '1' : '0'
63
+ vm_attrs[:compute_attributes] = provider_attrs
47
64
  vm_attrs
48
65
  end
49
66
 
@@ -20,16 +20,20 @@
20
20
  module ForemanFogProxmox
21
21
  module ProxmoxOperatingSystems
22
22
  def compute_os_types(host)
23
- os_linux_types_mapping(host).empty? ? os_windows_types_mapping(host) : os_linux_types_mapping(host)
23
+ [os_linux_types_mapping(host), os_windows_types_mapping(host), os_other_types_mapping(host)].find(&:any?) || []
24
24
  end
25
25
 
26
26
  def available_operating_systems
27
- operating_systems = ['other', 'solaris']
27
+ operating_systems = available_other_operating_systems
28
28
  operating_systems += available_linux_operating_systems
29
29
  operating_systems += available_windows_operating_systems
30
30
  operating_systems
31
31
  end
32
32
 
33
+ def available_other_operating_systems
34
+ ['other', 'solaris']
35
+ end
36
+
33
37
  def available_linux_operating_systems
34
38
  ['l24', 'l26', 'debian', 'ubuntu', 'centos', 'fedora', 'opensuse', 'archlinux', 'gentoo', 'alpine']
35
39
  end
@@ -50,5 +54,12 @@ module ForemanFogProxmox
50
54
  def os_windows_types_mapping(host)
51
55
  ['Windows'].include?(host.operatingsystem.type) ? available_windows_operating_systems : []
52
56
  end
57
+
58
+ def os_other_types_mapping(host)
59
+ {
60
+ 'Freebsd' => ['other'],
61
+ 'Solaris' => ['solaris'],
62
+ }.fetch(host.operatingsystem.type, [])
63
+ end
53
64
  end
54
65
  end
@@ -46,9 +46,10 @@ module ForemanFogProxmox
46
46
  def vms(opts = {})
47
47
  vms = []
48
48
  nodes.each { |node| vms += node.servers.all + node.containers.all }
49
+ vms.each { |vm| attach_compute_resource_id(vm) }
49
50
  if opts.key?(:eager_loading) && opts[:eager_loading]
50
51
  vms_eager = []
51
- vms.each { |vm| vms_eager << vm.collection.get(vm.identity) }
52
+ vms.each { |vm| vms_eager << attach_compute_resource_id(vm.collection.get(vm.identity)) }
52
53
  vms = vms_eager
53
54
  end
54
55
  ForemanFogProxmox::Vms.new(vms)
@@ -71,12 +72,21 @@ module ForemanFogProxmox
71
72
  def find_vm_in_servers_by_vmid(servers, vmid)
72
73
  vm = servers.get(vmid) unless ForemanFogProxmox::Value.empty?(vmid)
73
74
  pool_owner(vm) if vm
74
- vm
75
+ attach_compute_resource_id(vm)
75
76
  rescue Fog::Errors::NotFound
76
77
  nil
77
78
  rescue StandardError => e
78
79
  Foreman::Logging.exception(format(_('Failed retrieving proxmox server vm by vmid=%<vmid>s'), vmid: vmid), e)
79
80
  raise(ActiveRecord::RecordNotFound, e)
80
81
  end
82
+
83
+ private
84
+
85
+ def attach_compute_resource_id(virtual_machine)
86
+ return virtual_machine if virtual_machine.nil?
87
+
88
+ virtual_machine.compute_resource_id = id if virtual_machine.respond_to?(:compute_resource_id=)
89
+ virtual_machine
90
+ end
81
91
  end
82
92
  end
@@ -42,6 +42,7 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
42
42
  <%= action_buttons(
43
43
  vm_power_action(vm, authorizer),
44
44
  vm_associate_link(vm),
45
+ vm_import_action(vm),
45
46
  display_delete_if_authorized(hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.unique_cluster_identity(@compute_resource)).merge(:auth_object => @compute_resource, :authorizer => authorizer))) %>
46
47
  </td>
47
48
  </tr>
@@ -18,5 +18,5 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ForemanFogProxmox
21
- VERSION = '0.22.0'
21
+ VERSION = '0.23.0'
22
22
  end
@@ -60,6 +60,52 @@ module ForemanFogProxmox
60
60
  assert err.message.end_with?('Operating system family Solaris is not consistent with l26')
61
61
  end
62
62
 
63
+ it 'accepts proxmox linux ostype for linux servers' do
64
+ operatingsystem = FactoryBot.build(:debian7_1)
65
+ physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true)
66
+ host = FactoryBot.build(
67
+ :host_empty,
68
+ :interfaces => [physical_nic],
69
+ :operatingsystem => operatingsystem,
70
+ :compute_attributes => {
71
+ 'type' => 'qemu',
72
+ 'config_attributes' => {
73
+ 'ostype' => 'l26',
74
+ },
75
+ 'interfaces_attributes' => {
76
+ '0' => physical_nic,
77
+ },
78
+ }
79
+ )
80
+
81
+ @cr.host_compute_attrs(host)
82
+
83
+ assert_equal host.name, host.compute_attributes['config_attributes']['name']
84
+ end
85
+
86
+ it 'accepts proxmox other ostype for FreeBSD servers' do
87
+ operatingsystem = FactoryBot.build(:freebsd)
88
+ physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true)
89
+ host = FactoryBot.build(
90
+ :host_empty,
91
+ :interfaces => [physical_nic],
92
+ :operatingsystem => operatingsystem,
93
+ :compute_attributes => {
94
+ 'type' => 'qemu',
95
+ 'config_attributes' => {
96
+ 'ostype' => 'other',
97
+ },
98
+ 'interfaces_attributes' => {
99
+ '0' => physical_nic,
100
+ },
101
+ }
102
+ )
103
+
104
+ @cr.host_compute_attrs(host)
105
+
106
+ assert_equal host.name, host.compute_attributes['config_attributes']['name']
107
+ end
108
+
63
109
  it 'sets container hostname with host name' do
64
110
  physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true,
65
111
  :compute_attributes => { 'dhcp' => '1', 'dhcp6' => '1' })
@@ -87,6 +133,23 @@ module ForemanFogProxmox
87
133
  end
88
134
  excluded_keys = [:vmid, :disks, :interfaces]
89
135
 
136
+ it 'maps flat interface attributes into foreman nic structure' do
137
+ vm_attrs = @cr.interface_compute_attributes(
138
+ id: 'net0',
139
+ macaddr: '36:25:8C:53:0C:50',
140
+ model: 'virtio',
141
+ bridge: 'vmbr0'
142
+ )
143
+
144
+ assert_equal 'net0', vm_attrs[:id]
145
+ assert_equal '36:25:8C:53:0C:50', vm_attrs[:mac]
146
+ assert_equal 'virtio', vm_attrs[:compute_attributes][:model]
147
+ assert_equal 'vmbr0', vm_attrs[:compute_attributes][:bridge]
148
+ assert_equal '0', vm_attrs[:compute_attributes][:dhcp]
149
+ assert_equal '0', vm_attrs[:compute_attributes][:dhcp6]
150
+ assert_not vm_attrs[:compute_attributes].key?(:macaddr)
151
+ end
152
+
90
153
  it 'converts a server to hash' do
91
154
  vm, config_attributes, volume_attributes, interface_attributes = mock_server_vm
92
155
  vm_attrs = @cr.vm_compute_attributes(vm)
@@ -101,11 +164,13 @@ module ForemanFogProxmox
101
164
  assert_not vm_attrs[:config_attributes].key?(:interfaces)
102
165
  assert vm_attrs.key?(:interfaces_attributes)
103
166
  assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
104
- assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:macaddr]
167
+ assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:mac]
105
168
  assert_equal interface_attributes[:compute_attributes][:model],
106
169
  vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:model]
107
170
  assert_equal interface_attributes[:compute_attributes][:bridge],
108
171
  vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
172
+ assert_equal '0', vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:dhcp]
173
+ assert_equal '0', vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:dhcp6]
109
174
  end
110
175
 
111
176
  it 'converts a container to hash' do
@@ -121,11 +186,13 @@ module ForemanFogProxmox
121
186
  assert_equal volume_attributes.merge(_delete: '0'), vm_attrs[:volumes_attributes]['0']
122
187
  assert vm_attrs.key?(:interfaces_attributes)
123
188
  assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
189
+ assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:mac]
124
190
  assert_equal interface_attributes[:compute_attributes][:name],
125
191
  vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:name]
126
- assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:hwaddr]
127
192
  assert_equal interface_attributes[:compute_attributes][:bridge],
128
193
  vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
194
+ assert_equal '0', vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:dhcp]
195
+ assert_equal '0', vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:dhcp6]
129
196
  end
130
197
  end
131
198
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of ForemanFogProxmox.
4
+
5
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'test_plugin_helper'
19
+
20
+ module ForemanFogProxmox
21
+ class ProxmoxOperatingSystemsTest < ActiveSupport::TestCase
22
+ def setup
23
+ @cr = FactoryBot.build_stubbed(:proxmox_cr)
24
+ end
25
+
26
+ test '#compute_os_types returns linux os types for linux families' do
27
+ assert_equal @cr.available_linux_operating_systems, @cr.compute_os_types(host_with_os_type('Debian'))
28
+ end
29
+
30
+ test '#compute_os_types returns windows os types for windows family' do
31
+ assert_equal @cr.available_windows_operating_systems, @cr.compute_os_types(host_with_os_type('Windows'))
32
+ end
33
+
34
+ test '#compute_os_types returns other os type for Freebsd family' do
35
+ assert_equal ['other'], @cr.compute_os_types(host_with_os_type('Freebsd'))
36
+ end
37
+
38
+ test '#compute_os_types returns solaris os type for Solaris family' do
39
+ assert_equal ['solaris'], @cr.compute_os_types(host_with_os_type('Solaris'))
40
+ end
41
+
42
+ private
43
+
44
+ def host_with_os_type(type)
45
+ stub(operatingsystem: stub(type: type))
46
+ end
47
+ end
48
+ end
@@ -48,6 +48,12 @@ module ForemanFogProxmox
48
48
  assert_equal host, (as_admin { cr.associated_host(vm) })
49
49
  end
50
50
 
51
+ test '#provided_attributes maps uuid to foreman_uuid' do
52
+ cr = FactoryBot.build_stubbed(:proxmox_cr)
53
+
54
+ assert_equal :foreman_uuid, cr.provided_attributes[:uuid]
55
+ end
56
+
51
57
  test '#node' do
52
58
  node = mock('node')
53
59
  cr = FactoryBot.build_stubbed(:proxmox_cr)
@@ -117,13 +117,12 @@ const ProxmoxContainerStorage = ({
117
117
  const newMountPoint = {
118
118
  id: newNextId,
119
119
  data: initMP,
120
- storagesMap,
121
120
  };
122
121
  setMountPoints(prev => [...prev, newMountPoint]);
123
122
  return newNextId;
124
123
  });
125
124
  },
126
- [nextId, paramScope, storagesMap]
125
+ [nextId, paramScope]
127
126
  );
128
127
 
129
128
  const removeMountPoint = idToRemove => {
@@ -221,7 +220,7 @@ const ProxmoxContainerStorage = ({
221
220
  key={mountPoint.id}
222
221
  id={mountPoint.id}
223
222
  data={mountPoint.data}
224
- storagesMap={mountPoint.storagesMap}
223
+ storagesMap={storagesMap}
225
224
  />
226
225
  </div>
227
226
  ))}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_fog_proxmox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Robert
@@ -261,6 +261,7 @@ files:
261
261
  - test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb
262
262
  - test/unit/foreman_fog_proxmox/proxmox_images_test.rb
263
263
  - test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb
264
+ - test/unit/foreman_fog_proxmox/proxmox_operating_systems_test.rb
264
265
  - test/unit/foreman_fog_proxmox/proxmox_test.rb
265
266
  - test/unit/foreman_fog_proxmox/proxmox_version_test.rb
266
267
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb
@@ -321,7 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
322
  - !ruby/object:Gem::Version
322
323
  version: '0'
323
324
  requirements: []
324
- rubygems_version: 4.0.6
325
+ rubygems_version: 4.0.10
325
326
  specification_version: 4
326
327
  summary: Foreman plugin that adds Proxmox VE compute resource using fog-proxmox
327
328
  test_files:
@@ -339,6 +340,7 @@ test_files:
339
340
  - test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb
340
341
  - test/unit/foreman_fog_proxmox/proxmox_images_test.rb
341
342
  - test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb
343
+ - test/unit/foreman_fog_proxmox/proxmox_operating_systems_test.rb
342
344
  - test/unit/foreman_fog_proxmox/proxmox_test.rb
343
345
  - test/unit/foreman_fog_proxmox/proxmox_version_test.rb
344
346
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb