foreman_fog_proxmox 0.8.0 → 0.8.2

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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -1
  3. data/Rakefile +3 -1
  4. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +2 -2
  5. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +2 -2
  6. data/app/helpers/node_dashboard_helper.rb +13 -14
  7. data/app/helpers/proxmox_compute_selectors_helper.rb +49 -50
  8. data/app/helpers/proxmox_container_helper.rb +42 -36
  9. data/app/helpers/proxmox_form_helper.rb +38 -40
  10. data/app/helpers/proxmox_server_helper.rb +39 -41
  11. data/app/helpers/proxmox_vm_helper.rb +21 -25
  12. data/app/models/concerns/fog_extensions/proxmox/disk.rb +8 -8
  13. data/app/models/concerns/fog_extensions/proxmox/interface.rb +8 -8
  14. data/app/models/concerns/fog_extensions/proxmox/node.rb +24 -22
  15. data/app/models/concerns/fog_extensions/proxmox/server.rb +71 -59
  16. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +47 -39
  17. data/app/models/concerns/fog_extensions/proxmox/volume.rb +8 -8
  18. data/app/models/concerns/host_ext/proxmox/interfaces.rb +21 -13
  19. data/app/models/concerns/orchestration/proxmox/compute.rb +14 -10
  20. data/app/models/foreman_fog_proxmox/options_select.rb +14 -14
  21. data/app/models/foreman_fog_proxmox/proxmox.rb +30 -466
  22. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +54 -0
  23. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +67 -0
  24. data/app/models/foreman_fog_proxmox/proxmox_console.rb +41 -0
  25. data/app/models/foreman_fog_proxmox/proxmox_images.rb +53 -0
  26. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +60 -0
  27. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -0
  28. data/app/models/foreman_fog_proxmox/proxmox_token_expiration.rb +30 -0
  29. data/app/models/foreman_fog_proxmox/proxmox_version.rb +36 -0
  30. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +108 -0
  31. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +162 -0
  32. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +74 -0
  33. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +85 -0
  34. data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +7 -6
  35. data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +13 -11
  36. data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +13 -11
  37. data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +8 -7
  38. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +7 -6
  39. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +7 -6
  40. data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +7 -6
  41. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +16 -16
  42. data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -1
  43. data/app/views/compute_resources/form/_proxmox.html.erb +3 -0
  44. data/app/views/compute_resources/show/_proxmox.html.erb +8 -0
  45. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +5 -0
  46. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +6 -1
  47. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +6 -0
  48. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +6 -2
  49. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +8 -2
  50. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +6 -0
  51. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +15 -1
  52. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +2 -2
  53. data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +1 -1
  54. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +6 -1
  55. data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +1 -1
  56. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +1 -1
  57. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +1 -1
  58. data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +2 -2
  59. data/config/routes.rb +4 -4
  60. data/lib/foreman_fog_proxmox/engine.rb +14 -14
  61. data/lib/foreman_fog_proxmox/semver.rb +78 -78
  62. data/lib/foreman_fog_proxmox/value.rb +5 -3
  63. data/lib/foreman_fog_proxmox/version.rb +1 -1
  64. data/lib/tasks/foreman_fog_proxmox_tasks.rake +3 -13
  65. data/locale/en/foreman_fog_proxmox.edit.po +472 -0
  66. data/locale/en/foreman_fog_proxmox.po +48 -24
  67. data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
  68. data/locale/foreman_fog_proxmox.pot +140 -102
  69. data/locale/fr/foreman_fog_proxmox.edit.po +472 -0
  70. data/locale/fr/foreman_fog_proxmox.po +52 -28
  71. data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
  72. data/locale/gemspec.rb +2 -0
  73. data/test/{unit/foreman_fog_proxmox/proxmox_test_helpers.rb → factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb} +4 -140
  74. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +61 -0
  75. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
  76. data/test/factories/proxmox_factory.rb +15 -15
  77. data/test/functional/compute_resources_controller_test.rb +12 -10
  78. data/test/test_plugin_helper.rb +2 -0
  79. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +178 -182
  80. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +122 -126
  81. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +180 -187
  82. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +116 -0
  83. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +71 -0
  84. data/test/unit/foreman_fog_proxmox/proxmox_test.rb +9 -479
  85. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +82 -0
  86. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +207 -0
  87. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +92 -0
  88. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +324 -0
  89. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb +43 -0
  90. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +71 -0
  91. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +63 -0
  92. data/test/unit/foreman_fog_proxmox/semver_test.rb +67 -53
  93. metadata +52 -14
@@ -22,39 +22,35 @@ require 'fog/proxmox/helpers/nic_helper'
22
22
  require 'foreman_fog_proxmox/value'
23
23
 
24
24
  module ProxmoxServerHelper
25
-
26
- KILO = 1024
27
- MEGA = KILO * KILO
28
- GIGA = KILO * MEGA
29
-
30
25
  def parse_server_vm(args)
31
26
  logger.debug("parse_server_vm args=#{args}")
32
27
  args = ActiveSupport::HashWithIndifferentAccess.new(args)
33
28
  return {} unless args
34
29
  return {} if args.empty?
35
30
  return {} unless args['type'] == 'qemu'
31
+
36
32
  config = args['config_attributes']
37
- main_a = %w[name type node_id vmid interfaces mount_points disks]
38
- config = args.reject { |key,_value| main_a.include? key } unless config
39
- cdrom_a = %w[cdrom cdrom_storage cdrom_iso]
40
- cdrom = parse_server_cdrom(config.select { |key,_value| cdrom_a.include? key })
33
+ main_a = ['name', 'type', 'node_id', 'vmid', 'interfaces', 'mount_points', 'disks']
34
+ config ||= args.reject { |key, _value| main_a.include? key }
35
+ cdrom_a = ['cdrom', 'cdrom_storage', 'cdrom_iso']
36
+ cdrom = parse_server_cdrom(config.select { |key, _value| cdrom_a.include? key })
41
37
  vols = args['volumes_attributes']
42
38
  volumes = parse_server_volumes(vols)
43
- cpu_a = %w[cpu_type spectre pcid]
44
- cpu = parse_server_cpu(config.select { |key,_value| cpu_a.include? key })
45
- memory_a = %w[memory min_memory balloon shares]
46
- memory = parse_server_memory(config.select { |key,_value| memory_a.include? key })
39
+ cpu_a = ['cpu_type', 'spectre', 'pcid']
40
+ cpu = parse_server_cpu(config.select { |key, _value| cpu_a.include? key })
41
+ memory_a = ['memory', 'min_memory', 'balloon', 'shares']
42
+ memory = parse_server_memory(config.select { |key, _value| memory_a.include? key })
47
43
  interfaces_attributes = args['interfaces_attributes']
48
44
  interfaces_to_add, interfaces_to_delete = parse_server_interfaces(interfaces_attributes)
49
- general_a = %w[node_id type config_attributes volumes_attributes interfaces_attributes firmware_type provision_method container_volumes server_volumes]
45
+ general_a = ['node_id', 'type', 'config_attributes', 'volumes_attributes', 'interfaces_attributes', 'firmware_type', 'provision_method', 'container_volumes', 'server_volumes']
50
46
  logger.debug("general_a: #{general_a}")
51
- parsed_vm = args.reject { |key,value| general_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
47
+ parsed_vm = args.reject { |key, value| general_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
52
48
  config_a = []
53
49
  config_a += cpu_a
54
50
  config_a += cdrom_a
55
51
  config_a += memory_a
56
52
  config_a += general_a
57
- parsed_config = config.reject { |key,value| config_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
53
+ parsed_config = config.reject { |key, value| config_a.include?(key) || ForemanFogProxmox::Value.empty?(value) }
58
54
  logger.debug("parse_server_config(): #{parsed_config}")
59
55
  parsed_vm = parsed_vm.merge(parsed_config).merge(cpu).merge(memory).merge(cdrom)
60
56
  interfaces_to_add.each { |interface| parsed_vm = parsed_vm.merge(interface) }
@@ -65,29 +61,30 @@ module ProxmoxServerHelper
65
61
  end
66
62
 
67
63
  def parse_server_memory(args)
68
- memory = { }
69
- memory.store(:memory,args['memory'].to_i) if args['memory']
64
+ memory = {}
65
+ memory.store(:memory, args['memory'].to_i) if args['memory']
70
66
  ballooned = args['balloon'].to_i == 1
71
67
  if ballooned
72
- memory.store(:shares,args['shares'].to_i) if args['shares']
73
- memory.store(:min_memory,args['min_memory'].to_i) if args['min_memory']
68
+ memory.store(:shares, args['shares'].to_i) if args['shares']
69
+ memory.store(:min_memory, args['min_memory'].to_i) if args['min_memory']
74
70
  end
75
- memory.store(:balloon,args['balloon'].to_i) if args['balloon']
71
+ memory.store(:balloon, args['balloon'].to_i) if args['balloon']
76
72
  logger.debug("parse_server_memory(): #{memory}")
77
73
  memory
78
74
  end
79
75
 
80
76
  def parse_server_cpu(args)
81
77
  return {} unless args['cpu_type']
78
+
82
79
  cpu = "cputype=#{args['cpu_type']}"
83
80
  spectre = args['spectre'].to_i == 1
84
81
  pcid = args['pcid'].to_i == 1
85
- cpu += ",flags=" if spectre || pcid
86
- cpu += "+spec-ctrl" if spectre
87
- cpu += ";" if spectre && pcid
88
- cpu += "+pcid" if pcid
89
- args.delete_if { |key,value| %w[cpu_type spectre pcid].include?(key) || ForemanFogProxmox::Value.empty?(value) }
90
- args.each_value { |value| value.to_i }
82
+ cpu += ',flags=' if spectre || pcid
83
+ cpu += '+spec-ctrl' if spectre
84
+ cpu += ';' if spectre && pcid
85
+ cpu += '+pcid' if pcid
86
+ args.delete_if { |key, value| ['cpu_type', 'spectre', 'pcid'].include?(key) || ForemanFogProxmox::Value.empty?(value) }
87
+ args.each_value(&:to_i)
91
88
  parsed_cpu = { cpu: cpu }.merge(args)
92
89
  logger.debug("parse_server_cpu(): #{parsed_cpu}")
93
90
  parsed_cpu
@@ -98,22 +95,24 @@ module ProxmoxServerHelper
98
95
  cdrom_image = args['cdrom_iso']
99
96
  volid = cdrom_image.empty? ? cdrom : cdrom_image
100
97
  return {} unless volid
98
+
101
99
  cdrom = "#{volid},media=cdrom"
102
- {ide2: cdrom}
100
+ { ide2: cdrom }
103
101
  end
104
102
 
105
103
  def parse_server_volume(args)
106
104
  disk = {}
107
- id = args['id']
108
- id = "#{args['controller']}#{args['device']}" if args.has_key?('controller') && args.has_key?('device') && !id
105
+ volid = args['volid'] if args.key?('volid')
106
+ id = args['id'] if volid
107
+ id = "#{args['controller']}#{args['device']}" if args.key?('controller') && args.key?('device') && !id
109
108
  return args if ForemanFogProxmox::Value.empty?(id) || id == 'rootfs'
110
- delete = args['_delete'].to_i == 1
111
- args.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
109
+
110
+ args.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
112
111
  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}
112
+ disk.store(:volid, args['volid']) if args.key?('volid')
113
+ disk.store(:storage, args['storage'].to_s) if args.key?('storage')
114
+ disk.store(:size, args['size'].to_i) if args.key?('size')
115
+ options = args.reject { |key, _value| ['id', 'volid', 'controller', 'device', 'storage', 'size', '_delete'].include? key }
117
116
  disk.store(:options, options)
118
117
  logger.debug("parse_server_volume(): disk=#{disk}")
119
118
  Fog::Proxmox::DiskHelper.flatten(disk)
@@ -121,7 +120,7 @@ module ProxmoxServerHelper
121
120
 
122
121
  def parse_server_volumes(args)
123
122
  volumes = []
124
- args.each_value { |value| volumes.push(parse_server_volume(value))} if args
123
+ args&.each_value { |value| volumes.push(parse_server_volume(value)) }
125
124
  logger.debug("parse_server_volumes(): volumes=#{volumes}")
126
125
  volumes
127
126
  end
@@ -129,13 +128,13 @@ module ProxmoxServerHelper
129
128
  def parse_server_interfaces(interfaces_attributes)
130
129
  interfaces_to_add = []
131
130
  interfaces_to_delete = []
132
- interfaces_attributes.each_value { |value| add_server_interface(value,interfaces_to_delete,interfaces_to_add)} if interfaces_attributes
131
+ interfaces_attributes&.each_value { |value| add_server_interface(value, interfaces_to_delete, interfaces_to_add) }
133
132
  logger.debug("parse_server_interfaces(): interfaces_to_delete=#{interfaces_to_delete} interfaces_to_add=#{interfaces_to_add}")
134
133
  [interfaces_to_add, interfaces_to_delete]
135
134
  end
136
135
 
137
136
  def add_server_interface(interface_attributes, interfaces_to_delete, interfaces_to_add)
138
- interface_attributes.delete_if { |_key,value| ForemanFogProxmox::Value.empty?(value) }
137
+ interface_attributes.delete_if { |_key, value| ForemanFogProxmox::Value.empty?(value) }
139
138
  nic = {}
140
139
  id = interface_attributes['id']
141
140
  logger.debug("add_server_interface(): id=#{id}")
@@ -156,5 +155,4 @@ module ProxmoxServerHelper
156
155
  interfaces_to_add.push(Fog::Proxmox::NicHelper.flatten(nic))
157
156
  end
158
157
  end
159
-
160
- end
158
+ end
@@ -22,54 +22,51 @@ require 'fog/proxmox/helpers/nic_helper'
22
22
  require 'foreman_fog_proxmox/value'
23
23
 
24
24
  module ProxmoxVmHelper
25
-
26
25
  KILO = 1024
27
26
  MEGA = KILO * KILO
28
27
  GIGA = KILO * MEGA
29
28
 
30
- def object_to_config_hash(vm,type)
29
+ def object_to_config_hash(vm)
31
30
  vm_h = ActiveSupport::HashWithIndifferentAccess.new
32
- main_a = %w[hostname name vmid]
33
- type = vm.config.attributes['type']
34
- type = vm.type unless type
35
- main = vm.attributes.select { |key,_value| main_a.include? key }
36
- main_a += %w[templated]
37
- config = vm.config.attributes.reject { |key,_value| main_a.include?(key) || Fog::Proxmox::DiskHelper.disk?(key) || Fog::Proxmox::NicHelper.nic?(key) }
31
+ main_a = ['hostname', 'name', 'vmid']
32
+ main = vm.attributes.select { |key, _value| main_a.include? key }
33
+ main_a += ['templated']
34
+ config = vm.config.attributes.reject { |key, _value| main_a.include?(key) || Fog::Proxmox::DiskHelper.disk?(key) || Fog::Proxmox::NicHelper.nic?(key) }
38
35
  vm_h = vm_h.merge(main)
39
- vm_h = vm_h.merge({'config_attributes': config})
36
+ vm_h = vm_h.merge('config_attributes': config)
40
37
  vm_h
41
38
  end
42
39
 
43
- def add_cdrom_to_config_server(vm,config)
40
+ def add_cdrom_to_config_server(vm, config)
44
41
  cd_disks = vm.config.disks.select { |disk| disk.id == 'ide2' }
45
42
  cdrom = {}
46
- disk_to_cdrom(cd_disks.first,cdrom)
43
+ disk_to_cdrom(cd_disks.first, cdrom)
47
44
  config = config.merge(cdrom)
48
45
  config
49
46
  end
50
47
 
51
- def disk_to_cdrom(disk,cdrom)
52
- volid = disk.volid
53
- cdrom_a = %w[none cdrom]
48
+ def disk_to_cdrom(disk, cdrom)
49
+ volid = disk.volid
50
+ cdrom_a = ['none', 'cdrom']
54
51
  if cdrom_a.include? volid
55
- cdrom.store('cdrom',volid)
52
+ cdrom.store('cdrom', volid)
56
53
  else
57
- cdrom.store('cdrom','image')
58
- cdrom.store('cdrom_iso',volid)
59
- cdrom.store('cdrom_storage',disk.storage)
54
+ cdrom.store('cdrom', 'image')
55
+ cdrom.store('cdrom_iso', volid)
56
+ cdrom.store('cdrom_storage', disk.storage)
60
57
  end
61
58
  end
62
59
 
63
60
  def convert_sizes(args)
64
- convert_memory_size(args['config_attributes'],'memory')
65
- convert_memory_size(args['config_attributes'],'min_memory')
66
- convert_memory_size(args['config_attributes'],'shares')
67
- convert_memory_size(args['config_attributes'],'swap')
61
+ convert_memory_size(args['config_attributes'], 'memory')
62
+ convert_memory_size(args['config_attributes'], 'min_memory')
63
+ convert_memory_size(args['config_attributes'], 'shares')
64
+ convert_memory_size(args['config_attributes'], 'swap')
68
65
  args['volumes_attributes'].each_value { |value| value['size'] = (value['size'].to_i / GIGA).to_s unless ForemanFogProxmox::Value.empty?(value['size']) }
69
66
  end
70
67
 
71
68
  def remove_deletes(args)
72
- args['volumes_attributes'].delete_if { |_key,value| value.has_key? '_delete' } if args['volumes_attributes']
69
+ args['volumes_attributes']&.delete_if { |_key, value| value.key? '_delete' }
73
70
  end
74
71
 
75
72
  def convert_memory_size(config_hash, key)
@@ -77,5 +74,4 @@ module ProxmoxVmHelper
77
74
  memory = (config_hash[key].to_i / MEGA).to_s == '0' ? config_hash[key] : (config_hash[key].to_i / MEGA).to_s
78
75
  config_hash.store(key, memory)
79
76
  end
80
-
81
- end
77
+ end
@@ -18,12 +18,12 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module FogExtensions
21
- module Proxmox
22
- module Disk
23
- extend ActiveSupport::Concern
24
- def templated?
25
- volid ? volid.match(/^([\w-]+)[:]base-(\d+)-disk-(\d+)/) : false
26
- end
27
- end
21
+ module Proxmox
22
+ module Disk
23
+ extend ActiveSupport::Concern
24
+ def templated?
25
+ volid ? volid.match(/^([\w-]+)[:]base-(\d+)-disk-(\d+)/) : false
26
+ end
28
27
  end
29
- end
28
+ end
29
+ end
@@ -18,12 +18,12 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module FogExtensions
21
- module Proxmox
22
- module Interface
23
- extend ActiveSupport::Concern
24
- def mac
25
- macaddr
26
- end
27
- end
21
+ module Proxmox
22
+ module Interface
23
+ extend ActiveSupport::Concern
24
+ def mac
25
+ macaddr
26
+ end
28
27
  end
29
- end
28
+ end
29
+ end
@@ -18,27 +18,29 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module FogExtensions
21
- module Proxmox
22
- module Node
23
- extend ActiveSupport::Concern
24
- def all(options = {})
25
- vms = servers.all
26
- vms += containers.all
27
- vms
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
21
+ module Proxmox
22
+ module Node
23
+ extend ActiveSupport::Concern
24
+ def all(_options = {})
25
+ vms = servers.all
26
+ vms += containers.all
27
+ vms
28
+ end
29
+
30
+ def each(collection_filters = {})
31
+ if block_given?
32
+ Kernel.loop do
33
+ break unless collection_filters[:marker]
34
+
35
+ page = all(collection_filters)
36
+ # We need to explicitly use the base 'each' method here on the page,
37
+ # otherwise we get infinite recursion
38
+ base_each = Fog::Collection.instance_method(:each)
39
+ base_each.bind(page).call { |item| yield item }
40
+ end
42
41
  end
42
+ self
43
+ end
43
44
  end
44
- end
45
+ end
46
+ end
@@ -18,63 +18,75 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module FogExtensions
21
- module Proxmox
22
- module Server
23
- extend ActiveSupport::Concern
24
- attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password
25
-
26
- def start
27
- action('start')
28
- end
29
- def stop
30
- action('stop')
31
- end
32
- def reboot
33
- stop
34
- start
35
- end
36
- def reset
37
- reboot
38
- end
39
- def mac
40
- config.mac_addresses.first
41
- end
42
- def memory
43
- maxmem.to_i
44
- end
45
- def state
46
- qmpstatus
47
- end
48
- def description
49
- config.description
50
- end
51
- def vm_description
52
- "Name=#{name}, vmid=#{vmid}"
53
- end
54
- def select_nic(fog_nics, nic)
55
- fog_nics.find {|fog_nic| fog_nic.identity.to_s == nic.identifier}
56
- end
57
- def interfaces
58
- config.interfaces
59
- end
60
- def nics
61
- config.interfaces.collect { |nic| nic.to_s }
62
- end
63
- def volumes
64
- config.disks.reject { |disk| disk.cdrom? }
65
- end
66
- def disks
67
- config.disks.collect { |disk| disk.to_s }
68
- end
69
- def vga
70
- config.vga
71
- end
72
- def interfaces_attributes=(attrs); end
73
- def volumes_attributes=(attrs); end
74
- def config_attributes=(attrs); end
75
- def templated?
76
- volumes.any? { |volume| volume.templated? }
77
- end
78
- end
21
+ module Proxmox
22
+ module Server
23
+ extend ActiveSupport::Concern
24
+ attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password
25
+
26
+ def start
27
+ action('start')
28
+ end
29
+
30
+ def stop
31
+ action('stop')
32
+ end
33
+
34
+ def reboot
35
+ stop
36
+ start
37
+ end
38
+
39
+ def reset
40
+ reboot
41
+ end
42
+
43
+ def mac
44
+ config.mac_addresses.first
45
+ end
46
+
47
+ def memory
48
+ maxmem.to_i
49
+ end
50
+
51
+ def state
52
+ qmpstatus
53
+ end
54
+
55
+ delegate :description, to: :config
56
+
57
+ def vm_description
58
+ "Name=#{name}, vmid=#{vmid}"
59
+ end
60
+
61
+ def select_nic(fog_nics, nic)
62
+ fog_nics.find { |fog_nic| fog_nic.identity.to_s == nic.identifier }
63
+ end
64
+
65
+ delegate :interfaces, to: :config
66
+
67
+ def nics
68
+ config.interfaces.collect(&:to_s)
69
+ end
70
+
71
+ def volumes
72
+ config.disks.reject(&:cdrom?)
73
+ end
74
+
75
+ def disks
76
+ config.disks.collect(&:to_s)
77
+ end
78
+
79
+ delegate :vga, to: :config
80
+
81
+ def interfaces_attributes=(attrs); end
82
+
83
+ def volumes_attributes=(attrs); end
84
+
85
+ def config_attributes=(attrs); end
86
+
87
+ def templated?
88
+ volumes.any?(&:templated?)
89
+ end
79
90
  end
80
- end
91
+ end
92
+ end