foreman_fog_proxmox 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of foreman_fog_proxmox might be problematic. Click here for more details.

Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -4
  3. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +12 -5
  4. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +33 -14
  5. data/app/helpers/proxmox_container_helper.rb +32 -38
  6. data/app/helpers/proxmox_server_helper.rb +34 -39
  7. data/app/helpers/proxmox_vm_helper.rb +1 -20
  8. data/app/models/concerns/fog_extensions/proxmox/interface.rb +29 -0
  9. data/app/models/concerns/fog_extensions/proxmox/node.rb +13 -0
  10. data/app/models/concerns/fog_extensions/proxmox/server.rb +4 -1
  11. data/app/models/concerns/host_ext/proxmox/interfaces.rb +37 -0
  12. data/app/models/concerns/orchestration/proxmox/compute.rb +38 -0
  13. data/app/models/foreman_fog_proxmox/proxmox.rb +71 -36
  14. data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +24 -0
  15. data/app/views/compute_resources/form/_proxmox.html.erb +1 -1
  16. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +0 -1
  17. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +0 -1
  18. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +0 -1
  19. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +3 -6
  20. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +22 -0
  21. data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +2 -1
  22. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +6 -5
  23. data/app/views/compute_resources_vms/form/proxmox/container/_volume_rootfs.html.erb +3 -3
  24. data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +2 -1
  25. data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +5 -4
  26. data/app/views/compute_resources_vms/show/_proxmox.html.erb +1 -1
  27. data/lib/foreman_fog_proxmox/engine.rb +4 -0
  28. data/lib/foreman_fog_proxmox/version.rb +1 -1
  29. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +28 -29
  30. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +28 -27
  31. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +0 -25
  32. data/test/unit/foreman_fog_proxmox/proxmox_test.rb +215 -5
  33. data/test/unit/foreman_fog_proxmox/proxmox_test_helpers.rb +10 -2
  34. metadata +9 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67b90e9d6ff96226f14cddbef179252562e82abbdb1796e0c13d5f69cfc8a3c6
4
- data.tar.gz: c845f7e54a242b0aa0615c799e49632ee6eb65a611238deec9d1647ba938d311
3
+ metadata.gz: 481cace7d30a49fb40a61fe50041ff10a278d674fd0420eca29c6bb756dfff9d
4
+ data.tar.gz: ff60cb1dd7b8793c19146431ed0c41b7f15a9e7a2379474f7b6ef80f6c8ee213
5
5
  SHA512:
6
- metadata.gz: 4e8cda3b7436b46cd4f64ff2d676b810943ce382d53fd6da58bfdaf3faabe310b429c1fb076bed47ee10b00386d505d4531190361e1b7bf943863f45794072de
7
- data.tar.gz: 01a69e1955953ac427add329d4883f5b8bde2df97aae11db1972d746d9f93dd0d8a010f107cf80f804265a595ea0aa2c130a407b091546e8fe21070e27e852d1
6
+ metadata.gz: e6eb265bcc6d768b55d10df5987bd3fa003960f7adbb54072d54edb46a84e5f5bb51b16565665f497ef2848ae996a80f58132ebe8c2be8370ce044cb945a9ff6
7
+ data.tar.gz: ccc4f415b32b1ef39a628a2d30048464612c35707c5be757248e0e69dddf2c314f5dbbf066c0f219506a164e61610935af7794f76bdf26864f4897e42b7ac139
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  It is intended to satisfy this [feature](http://projects.theforeman.org/issues/2186).
12
12
 
13
- If you like it and need more features you can [support](SUPPORT.md) it.
13
+ If you like it and need more features you can [support](.github/SUPPORT.md) it.
14
14
 
15
15
  ## Compatibility versions
16
16
 
@@ -18,7 +18,7 @@ If you like it and need more features you can [support](SUPPORT.md) it.
18
18
  |--|--|--|--|--|
19
19
  |<0.6|<5.3|<0.6|<=1.20|>=2.3|
20
20
  |=0.6|=5.3|=0.6|=1.21|>=2.3|
21
- |=0.7|=5.4|=0.7|=1.22|>=2.3|
21
+ |>=0.7|=5.4|>=0.7|>=1.22|>=2.3|
22
22
 
23
23
  ## Installation
24
24
 
@@ -142,6 +142,7 @@ cp config/settings.yaml.test config/settings.yaml
142
142
  ```shell
143
143
  cp config/model.mappings.example config/model.mappings
144
144
  cp config/database.yml.example config/database.yml
145
+ cp config/ignored_environments.yml.sample config/ignored_environments.yml
145
146
  bundle exec bin/rake db:migrate
146
147
  bundle exec bin/rake db:seed
147
148
  ```
@@ -202,10 +203,10 @@ See details in [foreman plugin development](https://projects.theforeman.org/proj
202
203
 
203
204
  ## Contributing
204
205
 
205
- You can reach the [contributors](CONTRIBUTORS.md).
206
+ You can reach the [contributors](.github/CONTRIBUTORS.md).
206
207
  Bug reports and pull requests are welcome on GitHub at [ForemanFogProxmox](https://github.com/theforeman/foreman_fog_proxmox).
207
208
 
208
- Please read more information about [how to contribute](CONTRIBUTING.md).
209
+ Please read more information about [how to contribute](.github/CONTRIBUTING.md).
209
210
 
210
211
  ## License
211
212
 
@@ -15,12 +15,19 @@
15
15
  // You should have received a copy of the GNU General Public License
16
16
  // along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
- function sslVerifyPeerSelected(item){
19
- var selected = $(item).is(':checked');
20
- var ssl_certs_form = $('#compute_resource_ssl_certs').parents('.clearfix');
18
+ $(document).on('ContentLoad', tfm.numFields.initAll);
19
+ $(document).ready(sslVerifyPeerSelected);
20
+
21
+ function sslVerifyPeerSelected(){
22
+ var selected = $("#compute_resource_ssl_verify_peer").is(':checked');
23
+ var ssl_certs_block = $('#compute_resource_ssl_certs').parents('.clearfix');
24
+ var ssl_certs_textarea = $('#compute_resource_ssl_certs');
21
25
  if (selected) {
22
- ssl_certs_form.show();
26
+ ssl_certs_block.show();
27
+ ssl_certs_textarea.show();
23
28
  } else {
24
- ssl_certs_form.hide();
29
+ ssl_certs_block.hide();
30
+ ssl_certs_textarea.text('');
31
+ ssl_certs_textarea.hide();
25
32
  }
26
33
  }
@@ -79,36 +79,55 @@ function storageIsoSelected(item) {
79
79
  }
80
80
  }
81
81
 
82
+ function attributesPrefixSelector(profile, type) {
83
+ return profile ? '#compute_attribute_vm_attrs_' + type + '_attributes_': '#host_compute_attributes_' + type + '_attributes_';
84
+ }
85
+
86
+ function volumesAttributesSelector(profile,index,selector) {
87
+ return attributesPrefixSelector(profile,'volumes') + index + '_' + selector;
88
+ }
89
+
90
+ function getIndex(item) {
91
+ var id = $(item).attr('id');
92
+ var pattern = /(host_compute_attributes_volumes_attributes_||compute_attribute_vm_attrs_volumes_attributes_)(\d+)[_](.*)/i;
93
+ pattern_a = pattern.exec(id);
94
+ var index = pattern_a[2];
95
+ console.log("index=" + index);
96
+ return index;
97
+ }
98
+
99
+ function isProfile() {
100
+ return $(volumesAttributesSelector(true,0,'id')) !== undefined;
101
+ }
102
+
82
103
  function controllerSelected(item) {
83
104
  var controller = $(item).val();
84
105
  var index = getIndex(item);
85
106
  var max = computeControllerMaxDevice(controller);
86
- var device_selector = '#host_compute_attributes_volumes_attributes_' + index + '_device';
107
+ var profile = isProfile();
108
+ console.log("profile="+profile);
109
+ var device_selector = volumesAttributesSelector(profile,index,'device');
110
+ var id_selector = volumesAttributesSelector(profile,index,'id');
87
111
  $(device_selector).attr('data-soft-max', max);
88
112
  var device = $(device_selector).limitedSpinner('value');
89
- $('#host_compute_attributes_volumes_attributes_' + index + '_id').val(controller + device);
113
+ var id = controller + device;
114
+ $(id_selector).val(id);
90
115
  tfm.numFields.initAll();
91
116
  }
92
117
 
93
118
  function deviceSelected(item) {
94
119
  var device = $(item).limitedSpinner('value');
95
- console.log("device=" + device);
96
120
  var index = getIndex(item);
97
- var controller_selector = '#host_compute_attributes_volumes_attributes_' + index + '_controller';
121
+ var profile = isProfile();
122
+ console.log("profile="+profile);
123
+ var controller_selector = volumesAttributesSelector(profile,index,'controller');
124
+ var id_selector = volumesAttributesSelector(profile,index,'id');
98
125
  var controller = $(controller_selector).val();
99
- $('#host_compute_attributes_volumes_attributes_' + index + '_id').val(controller + device);
126
+ var id = controller + device;
127
+ $(id_selector).val(id);
100
128
  tfm.numFields.initAll();
101
129
  }
102
130
 
103
- function getIndex(item) {
104
- var id = $(item).attr('id');
105
- var pattern = /(host_compute_attributes_volumes_attributes_)(\d+)[_](.*)/i;
106
- pattern_a = pattern.exec(id);
107
- var index = pattern_a[2];
108
- console.log("index=" + index);
109
- return index;
110
- }
111
-
112
131
  function computeControllerMaxDevice(controller) {
113
132
  switch (controller) {
114
133
  case 'ide':
@@ -45,7 +45,7 @@ module ProxmoxContainerHelper
45
45
  memory_a = %w[memory swap]
46
46
  memory = parse_container_memory(config.select { |key,_value| memory_a.include? key })
47
47
  interfaces_attributes = args['interfaces_attributes']
48
- networks = parse_container_interfaces(interfaces_attributes)
48
+ interfaces_to_add, interfaces_to_delete = parse_container_interfaces(interfaces_attributes)
49
49
  general_a = %w[node_id name type config_attributes volumes_attributes interfaces_attributes firmware_type provision_method container_volumes server_volumes]
50
50
  logger.debug("general_a: #{general_a}")
51
51
  parsed_vm = args.reject { |key,value| general_a.include?(key) || ostemplate_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
@@ -57,7 +57,8 @@ module ProxmoxContainerHelper
57
57
  parsed_config = config.reject { |key,value| config_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
58
58
  logger.debug("parse_container_config(): #{parsed_config}")
59
59
  parsed_vm = parsed_vm.merge(parsed_config).merge(cpu).merge(memory).merge(ostemplate)
60
- networks.each { |network| parsed_vm = parsed_vm.merge(network) }
60
+ interfaces_to_add.each { |interface| parsed_vm = parsed_vm.merge(interface) }
61
+ parsed_vm = parsed_vm.merge(delete: interfaces_to_delete.join(',')) unless interfaces_to_delete.empty?
61
62
  volumes.each { |volume| parsed_vm = parsed_vm.merge(volume) }
62
63
  logger.debug("parse_container_vm(): #{parsed_vm}")
63
64
  parsed_vm
@@ -98,24 +99,17 @@ module ProxmoxContainerHelper
98
99
  disk = {}
99
100
  id = args['id']
100
101
  id = "mp#{args['device']}" if args.has_key?('device')
101
- delete = args['_delete'].to_i == 1
102
102
  logger.debug("parse_container_volume() args=#{args}")
103
- return args if ForemanFogProxmox::Value.empty?(id) || server_disk?(id)
103
+ return args if ForemanFogProxmox::Value.empty?(id) || Fog::Proxmox::DiskHelper.server_disk?(id)
104
104
  args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
105
- if delete
106
- logger.debug("parse_container_volume(): delete id=#{id}")
107
- disk.store(:delete, id)
108
- disk
109
- else
110
- disk.store(:id, id)
111
- disk.store(:volid, args['volid'])
112
- disk.store(:storage, args['storage'].to_s)
113
- disk.store(:size, args['size'].to_i)
114
- options = args.reject { |key,_value| %w[id volid device storage size _delete].include? key}
115
- disk.store(:options, options)
116
- logger.debug("parse_container_volume(): add disk=#{disk}")
117
- Fog::Proxmox::DiskHelper.flatten(disk)
118
- end
105
+ disk.store(:id, id)
106
+ disk.store(:volid, args['volid'])
107
+ disk.store(:storage, args['storage'].to_s)
108
+ disk.store(:size, args['size'].to_i)
109
+ options = args.reject { |key,_value| %w[id volid device storage size _delete].include? key}
110
+ disk.store(:options, options)
111
+ logger.debug("parse_container_volume(): disk=#{disk}")
112
+ Fog::Proxmox::DiskHelper.flatten(disk)
119
113
  end
120
114
 
121
115
  def parse_container_volumes(args)
@@ -126,34 +120,34 @@ module ProxmoxContainerHelper
126
120
  volumes
127
121
  end
128
122
 
129
- def parse_container_interfaces(args)
130
- nics = []
131
- args.each_value { |value| nics.push(parse_container_interface(value))} if args
132
- logger.debug("parse_container_interfaces(): nics=#{nics}")
133
- nics
123
+ def parse_container_interfaces(interfaces_attributes)
124
+ interfaces_to_add = []
125
+ interfaces_to_delete = []
126
+ interfaces_attributes.each_value { |value| add_container_interface(value,interfaces_to_delete,interfaces_to_add) } if interfaces_attributes
127
+ logger.debug("parse_container_interfaces(): interfaces_to_add=#{interfaces_to_add}, interfaces_to_delete=#{interfaces_to_delete}")
128
+ [interfaces_to_add, interfaces_to_delete]
134
129
  end
135
130
 
136
- def parse_container_interface(args)
137
- args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
131
+ def add_container_interface(interface_attributes, interfaces_to_delete, interfaces_to_add)
132
+ interface_attributes.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
138
133
  nic = {}
139
- id = args['id']
134
+ id = interface_attributes['id']
140
135
  logger.debug("parse_container_interface(): id=#{id}")
141
- delete = args['_delete'].to_i == 1
136
+ delete = interface_attributes['_delete'].to_i == 1
142
137
  if delete
143
- logger.debug("parse_container_interface(): delete id=#{id}")
144
- nic.store(:delete, id)
145
- nic
138
+ interfaces_to_delete.push(id.to_s)
146
139
  else
147
140
  nic.store(:id, id)
148
- nic.store(:name, args['name'].to_s)
149
- nic.store(:bridge, args['bridge'].to_s) if args['bridge']
150
- nic.store(:ip, args['ip'].to_s) if args['ip']
151
- nic.store(:ip6, args['ip6'].to_s) if args['ip6']
152
- nic.store(:rate, args['rate'].to_i) if args['rate']
153
- nic.store(:tag, args['tag'].to_i) if args['tag']
141
+ nic.store(:macaddr, interface_attributes['macaddr']) if interface_attributes['macaddr']
142
+ nic.store(:name, interface_attributes['name'].to_s)
143
+ nic.store(:bridge, interface_attributes['bridge'].to_s) if interface_attributes['bridge']
144
+ nic.store(:ip, interface_attributes['ip'].to_s) if interface_attributes['ip']
145
+ nic.store(:ip6, interface_attributes['ip6'].to_s) if interface_attributes['ip6']
146
+ nic.store(:rate, interface_attributes['rate'].to_i) if interface_attributes['rate']
147
+ nic.store(:tag, interface_attributes['tag'].to_i) if interface_attributes['tag']
154
148
  logger.debug("parse_container_interface(): add nic=#{nic}")
155
- Fog::Proxmox::NicHelper.flatten(nic)
156
- end
149
+ interfaces_to_add.push(Fog::Proxmox::NicHelper.flatten(nic))
150
+ end
157
151
  end
158
152
 
159
153
  end
@@ -45,7 +45,7 @@ module ProxmoxServerHelper
45
45
  memory_a = %w[memory min_memory balloon shares]
46
46
  memory = parse_server_memory(config.select { |key,_value| memory_a.include? key })
47
47
  interfaces_attributes = args['interfaces_attributes']
48
- networks = parse_server_interfaces(interfaces_attributes)
48
+ interfaces_to_add, interfaces_to_delete = parse_server_interfaces(interfaces_attributes)
49
49
  general_a = %w[node_id type config_attributes volumes_attributes interfaces_attributes firmware_type provision_method container_volumes server_volumes]
50
50
  logger.debug("general_a: #{general_a}")
51
51
  parsed_vm = args.reject { |key,value| general_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
@@ -57,7 +57,8 @@ module ProxmoxServerHelper
57
57
  parsed_config = config.reject { |key,value| config_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
58
58
  logger.debug("parse_server_config(): #{parsed_config}")
59
59
  parsed_vm = parsed_vm.merge(parsed_config).merge(cpu).merge(memory).merge(cdrom)
60
- networks.each { |network| parsed_vm = parsed_vm.merge(network) }
60
+ interfaces_to_add.each { |interface| parsed_vm = parsed_vm.merge(interface) }
61
+ parsed_vm = parsed_vm.merge(delete: interfaces_to_delete.join(',')) unless interfaces_to_delete.empty?
61
62
  volumes.each { |volume| parsed_vm = parsed_vm.merge(volume) }
62
63
  logger.debug("parse_server_vm(): #{parsed_vm}")
63
64
  parsed_vm
@@ -108,20 +109,14 @@ module ProxmoxServerHelper
108
109
  return args if ForemanFogProxmox::Value.empty?(id) || id == 'rootfs'
109
110
  delete = args['_delete'].to_i == 1
110
111
  args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
111
- if delete
112
- logger.debug("parse_server_volume(): delete id=#{id}")
113
- disk.store(:delete, id)
114
- disk
115
- else
116
- disk.store(:id, id)
117
- disk.store(:volid, args['volid']) if args.has_key?('volid')
118
- disk.store(:storage, args['storage'].to_s) if args.has_key?('storage')
119
- disk.store(:size, args['size'].to_i) if args.has_key?('size')
120
- options = args.reject { |key,_value| %w[id volid controller device storage size _delete].include? key}
121
- disk.store(:options, options)
122
- logger.debug("parse_server_volume(): add disk=#{disk}")
123
- Fog::Proxmox::DiskHelper.flatten(disk)
124
- end
112
+ disk.store(:id, id)
113
+ disk.store(:volid, args['volid']) if args.has_key?('volid')
114
+ disk.store(:storage, args['storage'].to_s) if args.has_key?('storage')
115
+ disk.store(:size, args['size'].to_i) if args.has_key?('size')
116
+ options = args.reject { |key,_value| %w[id volid controller device storage size _delete].include? key}
117
+ disk.store(:options, options)
118
+ logger.debug("parse_server_volume(): disk=#{disk}")
119
+ Fog::Proxmox::DiskHelper.flatten(disk)
125
120
  end
126
121
 
127
122
  def parse_server_volumes(args)
@@ -131,35 +126,35 @@ module ProxmoxServerHelper
131
126
  volumes
132
127
  end
133
128
 
134
- def parse_server_interfaces(args)
135
- nics = []
136
- args.each_value { |value| nics.push(parse_server_interface(value))} if args
137
- logger.debug("parse_server_interfaces(): nics=#{nics}")
138
- nics
129
+ def parse_server_interfaces(interfaces_attributes)
130
+ interfaces_to_add = []
131
+ interfaces_to_delete = []
132
+ interfaces_attributes.each_value { |value| add_server_interface(value,interfaces_to_delete,interfaces_to_add)} if interfaces_attributes
133
+ logger.debug("parse_server_interfaces(): interfaces_to_delete=#{interfaces_to_delete} interfaces_to_add=#{interfaces_to_add}")
134
+ [interfaces_to_add, interfaces_to_delete]
139
135
  end
140
136
 
141
- def parse_server_interface(args)
142
- args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
137
+ def add_server_interface(interface_attributes, interfaces_to_delete, interfaces_to_add)
138
+ interface_attributes.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
143
139
  nic = {}
144
- id = args['id']
145
- logger.debug("parse_server_interface(): id=#{id}")
146
- delete = args['_delete'].to_i == 1
140
+ id = interface_attributes['id']
141
+ logger.debug("add_server_interface(): id=#{id}")
142
+ delete = interface_attributes['_delete'].to_i == 1
147
143
  if delete
148
- logger.debug("parse_server_interface(): delete id=#{id}")
149
- nic.store(:delete, id)
150
- nic
144
+ interfaces_to_delete.push(id.to_s)
151
145
  else
152
146
  nic.store(:id, id)
153
- nic.store(:tag, args['tag'].to_i) if args['tag']
154
- nic.store(:model, args['model'].to_s)
155
- nic.store(:bridge, args['bridge'].to_s) if args['bridge']
156
- nic.store(:firewall, args['firewall'].to_i) if args['firewall']
157
- nic.store(:rate, args['rate'].to_i) if args['rate']
158
- nic.store(:link_down, args['link_down'].to_i) if args['link_down']
159
- nic.store(:queues, args['queues'].to_i) if args['queues']
160
- logger.debug("parse_server_interface(): add nic=#{nic}")
161
- Fog::Proxmox::NicHelper.flatten(nic)
162
- end
147
+ nic.store(:macaddr, interface_attributes['macaddr']) if interface_attributes['macaddr']
148
+ nic.store(:tag, interface_attributes['tag'].to_i) if interface_attributes['tag']
149
+ nic.store(:model, interface_attributes['model'].to_s)
150
+ nic.store(:bridge, interface_attributes['bridge'].to_s) if interface_attributes['bridge']
151
+ nic.store(:firewall, interface_attributes['firewall'].to_i) if interface_attributes['firewall']
152
+ nic.store(:rate, interface_attributes['rate'].to_i) if interface_attributes['rate']
153
+ nic.store(:link_down, interface_attributes['link_down'].to_i) if interface_attributes['link_down']
154
+ nic.store(:queues, interface_attributes['queues'].to_i) if interface_attributes['queues']
155
+ logger.debug("add_server_interface(): add nic=#{nic}")
156
+ interfaces_to_add.push(Fog::Proxmox::NicHelper.flatten(nic))
157
+ end
163
158
  end
164
159
 
165
160
  end
@@ -33,10 +33,8 @@ module ProxmoxVmHelper
33
33
  type = vm.config.attributes['type']
34
34
  type = vm.type unless type
35
35
  main = vm.attributes.select { |key,_value| main_a.include? key }
36
- disks_regexp = /^(scsi|sata|mp|rootfs|virtio|ide)(\d+){0,1}$/
37
- nics_regexp = /^(net)(\d+)/
38
36
  main_a += %w[templated]
39
- config = vm.config.attributes.reject { |key,_value| main_a.include?(key) || disks_regexp.match(key) || nics_regexp.match(key) }
37
+ config = vm.config.attributes.reject { |key,_value| main_a.include?(key) || Fog::Proxmox::DiskHelper.disk?(key) || Fog::Proxmox::NicHelper.nic?(key) }
40
38
  vm_h = vm_h.merge(main)
41
39
  vm_h = vm_h.merge({'config_attributes': config})
42
40
  vm_h
@@ -80,21 +78,4 @@ module ProxmoxVmHelper
80
78
  config_hash.store(key, memory)
81
79
  end
82
80
 
83
- def parse_type_and_vmid(uuid)
84
- uuid_regexp = /^(lxc|qemu)\_(\d+)$/
85
- raise ::Foreman::Exception.new _("Invalid uuid=[%{uuid}]." % { uuid: uuid }) unless uuid.match(uuid_regexp)
86
- id_a = uuid.scan(uuid_regexp).first
87
- type = id_a[0]
88
- vmid = id_a[1]
89
- return type, vmid
90
- end
91
-
92
- def mount_point_disk?(id)
93
- /^(mp)(\d+)$/.match?(id)
94
- end
95
-
96
- def server_disk?(id)
97
- /^(scsi|sata|virtio|ide)(\d+)$/.match?(id)
98
- end
99
-
100
81
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module FogExtensions
21
+ module Proxmox
22
+ module Interface
23
+ extend ActiveSupport::Concern
24
+ def mac
25
+ macaddr
26
+ end
27
+ end
28
+ end
29
+ end
@@ -26,6 +26,19 @@ module FogExtensions
26
26
  vms += containers.all
27
27
  vms
28
28
  end
29
+ def each(collection_filters = {})
30
+ if block_given?
31
+ Kernel.loop do
32
+ break unless collection_filters[:marker]
33
+ page = all(collection_filters)
34
+ # We need to explicitly use the base 'each' method here on the page,
35
+ # otherwise we get infinite recursion
36
+ base_each = Fog::Collection.instance_method(:each)
37
+ base_each.bind(page).call { |item| yield item }
38
+ end
39
+ end
40
+ self
41
+ end
29
42
  end
30
43
  end
31
44
  end
@@ -57,11 +57,14 @@ module FogExtensions
57
57
  def interfaces
58
58
  config.interfaces
59
59
  end
60
+ def nics
61
+ config.interfaces.collect { |nic| nic.to_s }
62
+ end
60
63
  def volumes
61
64
  config.disks.reject { |disk| disk.cdrom? }
62
65
  end
63
66
  def disks
64
- config.disks.collect { |disk| disk.id+': '+disk.volid }
67
+ config.disks.collect { |disk| disk.to_s }
65
68
  end
66
69
  def vga
67
70
  config.vga