foreman_fog_proxmox 0.12.2 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -5
  3. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +36 -2
  4. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +134 -60
  5. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +2 -50
  6. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume.js +39 -0
  7. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cdrom.js +63 -0
  8. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cloudinit.js +25 -0
  9. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
  10. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +23 -25
  11. data/app/helpers/proxmox_compute_controllers_helper.rb +39 -0
  12. data/app/helpers/proxmox_compute_resources_helper.rb +49 -0
  13. data/app/helpers/proxmox_compute_selectors_helper.rb +6 -44
  14. data/app/helpers/proxmox_form_helper.rb +12 -4
  15. data/app/{models/concerns/fog_extensions/proxmox/volume.rb → helpers/proxmox_storages_helper.rb} +5 -8
  16. data/app/helpers/proxmox_vm_cdrom_helper.rb +35 -0
  17. data/app/helpers/proxmox_vm_cloudinit_helper.rb +43 -0
  18. data/app/helpers/proxmox_vm_config_helper.rb +160 -0
  19. data/app/helpers/proxmox_vm_helper.rb +24 -62
  20. data/app/helpers/proxmox_vm_interfaces_helper.rb +85 -0
  21. data/app/helpers/proxmox_vm_os_template_helper.rb +47 -0
  22. data/app/{models/foreman_fog_proxmox/proxmox_token_expiration.rb → helpers/proxmox_vm_uuid_helper.rb} +14 -10
  23. data/app/helpers/proxmox_vm_volumes_helper.rb +105 -0
  24. data/app/models/concerns/fog_extensions/proxmox/disk.rb +17 -2
  25. data/app/models/concerns/fog_extensions/proxmox/interface.rb +19 -4
  26. data/app/models/concerns/fog_extensions/proxmox/server.rb +12 -3
  27. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +8 -30
  28. data/app/models/concerns/host_ext/proxmox/interfaces.rb +7 -2
  29. data/app/models/concerns/orchestration/proxmox/compute.rb +49 -0
  30. data/app/models/foreman_fog_proxmox/proxmox.rb +58 -15
  31. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +14 -18
  32. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +14 -9
  33. data/app/models/foreman_fog_proxmox/proxmox_images.rb +2 -1
  34. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +53 -28
  35. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
  36. data/app/models/foreman_fog_proxmox/proxmox_version.rb +7 -2
  37. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +19 -31
  38. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +108 -94
  39. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +9 -6
  40. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +79 -22
  41. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +6 -2
  42. data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
  43. data/app/views/compute_resources/form/_proxmox.html.erb +23 -10
  44. data/app/views/compute_resources/show/_proxmox.html.erb +6 -6
  45. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +3 -1
  46. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +46 -29
  47. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +3 -3
  48. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +2 -1
  49. data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +8 -7
  50. data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +0 -2
  51. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +15 -14
  52. data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +2 -2
  53. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb +34 -0
  54. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cloud_init.html.erb +29 -0
  55. data/app/views/compute_resources_vms/form/proxmox/server/{_volume.html.erb → _volume_hard_disk.html.erb} +7 -3
  56. data/app/views/compute_resources_vms/show/_proxmox.html.erb +2 -0
  57. data/config/routes.rb +7 -7
  58. data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +29 -0
  59. data/lib/foreman_fog_proxmox/engine.rb +15 -10
  60. data/lib/foreman_fog_proxmox/hash_collection.rb +69 -0
  61. data/lib/foreman_fog_proxmox/version.rb +1 -1
  62. data/lib/tasks/foreman_fog_proxmox_tasks.rake +0 -3
  63. data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +20 -8
  64. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +5 -5
  65. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +17 -7
  66. data/test/factories/proxmox_factory.rb +4 -4
  67. data/test/functional/compute_resources_controller_test.rb +4 -4
  68. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +53 -32
  69. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +56 -31
  70. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +22 -20
  71. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb +38 -0
  72. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb +50 -0
  73. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +10 -11
  74. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +38 -10
  75. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +10 -10
  76. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +34 -24
  77. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +8 -8
  78. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb +181 -0
  79. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb +131 -0
  80. data/test/unit/foreman_fog_proxmox/{proxmox_vm_commands_server_update_volumes_test.rb → proxmox_vm_commands_server_update_hard_disk_test.rb} +45 -19
  81. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +21 -21
  82. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +3 -3
  83. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +3 -3
  84. metadata +44 -23
  85. data/app/helpers/proxmox_container_helper.rb +0 -163
  86. data/app/helpers/proxmox_server_helper.rb +0 -155
@@ -20,6 +20,7 @@
20
20
  module ForemanFogProxmox
21
21
  module ProxmoxVmQueries
22
22
  include ProxmoxPools
23
+ include ProxmoxVmUuidHelper
23
24
 
24
25
  def nodes
25
26
  nodes = client.nodes.all if client
@@ -30,6 +31,7 @@ module ForemanFogProxmox
30
31
  node = client.nodes.get node_id
31
32
  node ||= default_node
32
33
  storages = node.storages.list_by_content_type type
34
+ logger.debug(format(_('storages(): node_id %<node_id>s type %<type>s'), node_id: node_id, type: type))
33
35
  storages.sort_by(&:storage)
34
36
  end
35
37
 
@@ -50,25 +52,26 @@ module ForemanFogProxmox
50
52
  def find_vm_by_uuid(uuid)
51
53
  # look for the uuid on all known nodes
52
54
  vm = nil
55
+ vmid = extract_vmid(uuid)
53
56
  nodes.each do |node|
54
- vm = find_vm_in_servers_by_uuid(node.servers, uuid)
55
- vm ||= find_vm_in_servers_by_uuid(node.containers, uuid)
57
+ vm = find_vm_in_servers_by_vmid(node.servers, vmid)
58
+ vm ||= find_vm_in_servers_by_vmid(node.containers, vmid)
56
59
  unless vm.nil?
57
- logger.debug("found vm #{uuid} on node #{node.node}")
60
+ logger.debug("found vm #{vmid} on node #{node.node}")
58
61
  break
59
62
  end
60
63
  end
61
64
  vm
62
65
  end
63
66
 
64
- def find_vm_in_servers_by_uuid(servers, uuid)
65
- vm = servers.get(uuid) if !uuid.nil? && !uuid.to_s.empty?
67
+ def find_vm_in_servers_by_vmid(servers, vmid)
68
+ vm = servers.get(vmid) unless ForemanFogProxmox::Value.empty?(vmid)
66
69
  pool_owner(vm) if vm
67
70
  vm
68
71
  rescue Fog::Errors::NotFound
69
72
  nil
70
73
  rescue StandardError => e
71
- Foreman::Logging.exception(format(_('Failed retrieving proxmox server vm by vmid=%<vmid>s'), vmid: uuid), e)
74
+ Foreman::Logging.exception(format(_('Failed retrieving proxmox server vm by vmid=%<vmid>s'), vmid: vmid), e)
72
75
  raise(ActiveRecord::RecordNotFound, e)
73
76
  end
74
77
  end
@@ -18,13 +18,17 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  require 'fog/proxmox/helpers/disk_helper'
21
+ require 'foreman_fog_proxmox/hash_collection'
21
22
 
22
23
  module ForemanFogProxmox
23
24
  module ProxmoxVolumes
24
25
  include ProxmoxVmHelper
25
26
 
26
- def delete_volume(vm, id)
27
+ def delete_volume(vm, id, volume_attributes)
28
+ logger.info(format(_('vm %<vmid>s delete volume %<volume_id>s'), vmid: vm.identity, volume_id: id))
27
29
  vm.detach(id)
30
+ return unless volume_type?(volume_attributes, 'hard_disk')
31
+
28
32
  device = Fog::Proxmox::DiskHelper.extract_device(id)
29
33
  vm.detach('unused' + device.to_s)
30
34
  end
@@ -36,25 +40,65 @@ module ForemanFogProxmox
36
40
  options
37
41
  end
38
42
 
39
- def update_volume(vm, id, volume_attributes)
40
- disk = vm.config.disks.get(id)
41
- diff_size = volume_attributes['size'].to_i - disk.size
42
- raise ::Foreman::Exception, format(_('Unable to shrink %<id>s size. Proxmox allows only increasing size.'), id: id) unless diff_size >= 0
43
+ def update_volume_required?(old_volume_attributes, new_volume_attributes)
44
+ old_h = ForemanFogProxmox::HashCollection.new_hash_reject_empty_values(old_volume_attributes)
45
+ new_h = ForemanFogProxmox::HashCollection.new_hash_reject_empty_values(new_volume_attributes)
46
+ new_h = ForemanFogProxmox::HashCollection.new_hash_reject_keys(new_h, ['cdrom', 'cloudinit', 'storage_type'])
47
+ !ForemanFogProxmox::HashCollection.equals?(old_h.with_indifferent_access, new_h.with_indifferent_access)
48
+ end
43
49
 
44
- if diff_size > 0
45
- extension = '+' + (diff_size / GIGA).to_s + 'G'
46
- vm.extend(id, extension)
47
- elsif disk.storage != volume_attributes['storage']
48
- vm.move(id, volume_attributes['storage'])
50
+ def update_cdrom(vm, disk, volume_attributes)
51
+ new_disk = { id: disk.id }
52
+ if ['none', 'cdrom'].include?(volume_attributes[:cdrom])
53
+ new_disk[:volid] = volume_attributes[:cdrom]
49
54
  else
50
- options = volume_options(vm, id, volume_attributes)
51
- vm.attach({ :id => disk.id, :volid => disk.volid, :size => disk.size }, options)
55
+ new_disk[:storage] = volume_attributes[:storage]
56
+ new_disk[:volid] = volume_attributes[:volid]
57
+ end
58
+ vm.attach(new_disk, {})
59
+ end
60
+
61
+ def extend_volume(vm, id, diff_size)
62
+ extension = '+' + (diff_size / GIGA).to_s + 'G'
63
+ logger.info(format(_('vm %<vmid>s extend volume %<volume_id>s to %<extension>s'), vmid: vm.identity, volume_id: id, extension: extension))
64
+ vm.extend(id, extension)
65
+ end
66
+
67
+ def move_volume(id, vm, new_storage)
68
+ logger.info(format(_('vm %<vmid>s move volume %<volume_id>s into %<new_storage>s'), vmid: vm.identity, volume_id: id, new_storage: new_storage))
69
+ vm.move(id, new_storage)
70
+ end
71
+
72
+ def update_options(disk, vm, volume_attributes)
73
+ options = volume_options(vm, disk.id, volume_attributes) if volume_type?(volume_attributes, 'hard_disk')
74
+ logger.info(format(_('vm %<vmid>s update volume %<volume_id>s to %<options>s'), vmid: vm.identity, volume_id: disk.id, options: options))
75
+ new_disk = { id: disk.id }
76
+ new_disk[:volid] = disk.volid
77
+ vm.attach(new_disk, options)
78
+ end
79
+
80
+ def update_volume(vm, disk, volume_attributes)
81
+ id = disk.id
82
+ if volume_type?(volume_attributes, 'cdrom')
83
+ update_cdrom(vm, disk, volume_attributes)
84
+ elsif volume_type?(volume_attributes, 'hard_disk')
85
+ diff_size = volume_attributes['size'].to_i - disk.size if volume_attributes['size'] && disk.size
86
+ raise ::Foreman::Exception, format(_('Unable to shrink %<id>s size. Proxmox allows only increasing size.'), id: id) unless diff_size >= 0
87
+
88
+ new_storage = volume_attributes['storage']
89
+
90
+ if diff_size > 0
91
+ extend_volume(vm, id, diff_size)
92
+ elsif disk.storage != new_storage
93
+ move_volume(id, vm, new_storage)
94
+ else
95
+ update_options(disk, vm, volume_attributes)
96
+ end
52
97
  end
53
98
  end
54
99
 
55
- def volume_exists?(volume_attributes)
56
- volid = volume_attributes.key?('volid') ? volume_attributes['volid'] : ''
57
- volid.present?
100
+ def volume_exists?(vm, volume_attributes)
101
+ vm.attributes.key?(volume_attributes['id'])
58
102
  end
59
103
 
60
104
  def volume_to_delete?(volume_attributes)
@@ -63,28 +107,41 @@ module ForemanFogProxmox
63
107
 
64
108
  def extract_id(vm, volume_attributes)
65
109
  id = ''
66
- if volume_exists?(volume_attributes)
110
+ if volume_exists?(vm, volume_attributes)
67
111
  id = volume_attributes['id']
68
112
  else
69
113
  device = vm.container? ? 'mp' : volume_attributes['controller']
70
- id = device + volume_attributes['device']
114
+ id = volume_type?(volume_attributes, 'cdrom') ? 'ide2' : device + volume_attributes['device']
71
115
  end
72
116
  id
73
117
  end
74
118
 
75
119
  def add_volume(vm, id, volume_attributes)
76
- options = volume_options(vm, id, volume_attributes)
77
- disk_attributes = { id: id, storage: volume_attributes['storage'], size: (volume_attributes['size'].to_i / GIGA).to_s }
120
+ disk_attributes = { id: id }
121
+ if volume_type?(volume_attributes, 'hard_disk')
122
+ options = volume_options(vm, id, volume_attributes)
123
+ disk_attributes[:storage] = volume_attributes['storage']
124
+ disk_attributes[:size] = (volume_attributes['size'].to_i / GIGA).to_s
125
+ elsif volume_type?(volume_attributes, 'cdrom')
126
+ disk_attributes[:volid] = volume_attributes[:iso]
127
+ elsif volume_type?(volume_attributes, 'cloud_init')
128
+ disk_attributes[:storage] = volume_attributes['storage']
129
+ disk_attributes[:volid] = "#{volume_attributes['storage']}:cloudinit"
130
+ end
131
+ logger.info(format(_('vm %<vmid>s add volume %<volume_id>s'), vmid: vm.identity, volume_id: id))
132
+ logger.debug(format(_('add_volume(%<vmid>s) disk_attributes=%<disk_attributes>s'), vmid: vm.identity, disk_attributes: disk_attributes))
78
133
  vm.attach(disk_attributes, options)
79
134
  end
80
135
 
81
136
  def save_volume(vm, volume_attributes)
137
+ logger.debug(format(_('save_volume(%<vmid>s) volume_attributes=%<volume_attributes>s'), vmid: vm.identity, volume_attributes: volume_attributes))
82
138
  id = extract_id(vm, volume_attributes)
83
- if volume_exists?(volume_attributes)
139
+ if volume_exists?(vm, volume_attributes)
84
140
  if volume_to_delete?(volume_attributes)
85
- delete_volume(vm, id)
141
+ delete_volume(vm, id, volume_attributes)
86
142
  else
87
- update_volume(vm, id, volume_attributes)
143
+ disk = vm.config.disks.get(id)
144
+ update_volume(vm, disk, volume_attributes) if update_volume_required?(disk.attributes, volume_attributes)
88
145
  end
89
146
  else
90
147
  add_volume(vm, id, volume_attributes)
@@ -24,9 +24,13 @@ module ForemanFogProxmox
24
24
  @filter = filter
25
25
  end
26
26
 
27
+ def node
28
+ @compute_resource = ComputeResource.where(type: 'ForemanFogProxmox::Proxmox').first
29
+ @compute_resource.nodes.first
30
+ end
31
+
27
32
  def node_id
28
- @compute_resource = ComputeResource.find_by(type: 'ForemanFogProxmox::Proxmox')
29
- @compute_resource&.node_id
33
+ node&.identity
30
34
  end
31
35
 
32
36
  def statistics
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- attributes :url, :user, :password, :ssl_verify_peer, :ssl_certs, :renew
3
+ attributes :url, :user, :ssl_verify_peer, :ssl_certs, :renew
@@ -17,13 +17,26 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
17
17
 
18
18
  <%= javascript_include_tag 'foreman_fog_proxmox/proxmox_compute_resource', "data-turbolinks-track" => true %>
19
19
 
20
- <% nodes = f.object.nodes rescue nil %>
21
- <% token_expired = f.object.token_expired? %>
22
- <% token_deadline = f.object.token_deadline %>
23
- <%= checkbox_f f, :renew, :label => _("Renew expired token ?"), :checked_value => '1', :label_help => _("Token expires on #{token_deadline}") %>
24
- <%= text_f f, :url, :help_block => _("e.g. https://127.0.0.1:8006/api2/json"), :help_inline_permanent => load_button_f(f, !!nodes, _("Test failed")) %>
25
- <%= text_f f, :user , :help_block => _("e.g. root@pam") %>
26
- <%= password_f f, :password, :keep_value => true, :unset => unset_password? %>
27
- <%= checkbox_f f, :ssl_verify_peer, :label => _("SSL verify peer"), :checked_value => '1', :onchange => "sslVerifyPeerSelected()" %>
28
- <%= textarea_f f, :ssl_certs, :label => _("X509 Certification Authorities"), :size => "col-md-4",
29
- :placeholder => _("Optionally provide a CA, or a correctly ordered CA chain. If left blank, disable ssl_verify_peer.") %>
20
+ <% user_token = f.object.auth_method == 'user_token' %>
21
+ <% access_ticket = f.object.auth_method == 'access_ticket' %>
22
+ <% ssl_verify_peer = f.object.ssl_verify_peer == '1' %>
23
+ <%= select_f f, :auth_method, proxmox_auth_methods_map, :id, :name, { }, :label_help => _("Click Test connection button before changing it"), :label => _('Authentication method'), :label_size => "col-md-2", :required => true, :onchange => 'authMethodSelected();' %>
24
+ <%= field_set_tag _("Common fields"), :id => "compute_ressource_common_field_set" do %>
25
+ <%= text_f f, :url, :help_block => _("e.g. https://127.0.0.1:8006/api2/json") %>
26
+ <%= text_f f, :user , :help_block => _("e.g. root@pam") %>
27
+ <% end %>
28
+ <%= field_set_tag _("User token fields"), :id => "compute_ressource_user_token_field_set", :class => ('hide' unless user_token), :disabled => !user_token do %>
29
+ <%= text_f f, :token_id, :label => _('User token id'), :required => user_token %>
30
+ <%= text_f f, :token, :label => _('User token value'), :required => user_token, :label_help => _("Click Test connection button to check token") %>
31
+ <% end %>
32
+ <%= field_set_tag _("Access ticket fields"), :id => "compute_ressource_access_ticket_field_set", :class => ('hide' unless access_ticket), :disabled => !access_ticket do %>
33
+ <%= password_f f, :password, :keep_value => true, :unset => unset_password?, :required => access_ticket %>
34
+ <% end %>
35
+ <%= field_set_tag _("SSL fields"), :id => "compute_ressource_ssl_field_set" do %>
36
+ <%= checkbox_f f, :ssl_verify_peer, :label => _("SSL verify peer"), :label_help => _("Click Test connection button before changing it"), :checked_value => '1', :onchange => 'sslVerifyPeerSelected();' %>
37
+ <%= textarea_f f, :ssl_certs, :label => _("X509 Certification Authorities"), :size => "col-md-4",
38
+ :placeholder => _("Optionally provide a CA, or a correctly ordered CA chain. If left blank, disable ssl_verify_peer.") %>
39
+ <% end %>
40
+ <div class="col-md-offset-2">
41
+ <%= test_connection_button_f(f, (f.object.nodes rescue false)) %>
42
+ </div>
@@ -21,17 +21,17 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
21
21
  </tr>
22
22
  <tr>
23
23
  <td><%= _("Version") %></td>
24
- <td><%= @compute_resource.version%></td>
24
+ <td><%= @compute_resource.version %></td>
25
25
  </tr>
26
26
  <tr>
27
- <td><%= _("Token has expired?") %></td>
28
- <td><%= @compute_resource.token_expired?%></td>
27
+ <td><%= _("Authentication method") %></td>
28
+ <td><%= @compute_resource.auth_method %></td>
29
29
  </tr>
30
30
  <tr>
31
- <td><%= _("Token expires on") %></td>
32
- <td><%= @compute_resource.token_deadline%></td>
31
+ <td><%= _("User token expires") %></td>
32
+ <td><%= user_token_expiration_date(@compute_resource) %></td>
33
33
  </tr>
34
34
  <tr>
35
35
  <td><%= _("Cluster nodes") %></td>
36
- <td><%= @compute_resource.nodes.collect { |node| node.node }%></td>
36
+ <td><%= cluster_nodes(@compute_resource) %></td>
37
37
  </tr>
@@ -16,10 +16,12 @@ 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
  <% if @host.compute_resource.class == ForemanFogProxmox::Proxmox %>
18
18
  <% compute_attributes = f.object.compute_attributes %>
19
- <% vm_type = f.object.respond_to?('type') ? f.object.type : nil %>
19
+ <% logger.debug("_add_vm_type_to_nic_provider_specific_form.html compute_attributes=#{compute_attributes}") %>
20
20
  <% node_id = f.object.respond_to?('node_id') ? f.object.node_id : nil %>
21
21
 
22
22
  <%= f.fields_for 'compute_attributes', OpenStruct.new(f.object.compute_attributes) do |f| %>
23
+ <% vm_type = compute_attributes.respond_to?('type') ? compute_attributes.type : 'qemu' %>
24
+ <% logger.debug("_add_vm_type_to_nic_provider_specific_form.html vm_type=#{vm_type}") %>
23
25
  <%= render provider_partial(@host.compute_resource, 'network'), :f => f, :vm_type => vm_type, :node_id => node_id, :disabled => f.object.persisted?, :compute_resource => @host.compute_resource, :new_host => new_vm, :new_vm => new_vm %>
24
26
  <% end %>
25
27
  <% else %>
@@ -14,45 +14,63 @@ GNU General Public License for more details.
14
14
 
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
- <% if compute_resource.class == ForemanFogProxmox::Proxmox %>
18
- <% type = f.object.type %>
19
- <% node_id = f.object.node_id %>
20
- <% server = type == 'qemu' %>
21
- <% container = type == 'lxc' %>
22
-
23
- <%= new_child_fields_template_typed(f, :volumes, {
24
- :type => 'server',
25
- :object => compute_resource.new_volume_server,
26
- :partial => provider_partial(compute_resource, 'server/volume'),
27
- :form_builder_attrs => { :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove storage volume') },
28
- :layout => "compute_resources_vms/form/#{item_layout}_layout" }) %>
29
- <%= new_child_fields_template_typed(f, :volumes, {
30
- :type => 'container',
31
- :object => compute_resource.new_volume_container(id: 'mp0'),
32
- :partial => provider_partial(compute_resource, 'container/volume_mp'),
33
- :form_builder_attrs => { :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove storage volume') },
34
- :layout => "compute_resources_vms/form/#{item_layout}_layout" }) %>
35
17
 
18
+ <% if compute_resource.class == ForemanFogProxmox::Proxmox %>
19
+ <%= javascript_include_tag 'foreman_fog_proxmox/proxmox_volume', "data-turbolinks-track" => true %>
20
+ <% type = f.object.type %>
21
+ <% node_id = f.object.node_id %>
22
+ <% server = type == 'qemu' %>
23
+ <% container = type == 'lxc' %>
24
+ <% cdrom = f.object.cdrom? %>
25
+ <% logger.debug("_add_vm_type_to_volumes_edit.html cdrom=#{cdrom}") %>
26
+ <% cloud_init = f.object.cloud_init? %>
27
+ <% logger.debug("_add_vm_type_to_volumes_edit.html cloud_init=#{cloud_init}") %>
28
+ <% container = type == 'lxc' %>
36
29
 
30
+ <%= add_child_link_typed '+ ' + _("Add Hard Disk"), :volumes, 'hard_disk', { :class => "info #{'hide' unless server }", :title => _('add new hard disk') } %>
31
+ <%= add_child_link_typed '+ ' + _("Add CD-ROM"), :volumes, 'cdrom', { :class => "info #{'hide' if cdrom }", :title => _('add new cd-rom') } %>
32
+ <%= add_child_link_typed '+ ' + _("Add Cloud-init"), :volumes, 'cloud_init', { :class => "info #{'hide' if cloud_init }", :title => _('add new cloud-init') } %>
33
+ <%= add_child_link_typed '+ ' + _("Add Mount Point"), :volumes, 'mp', { :class => "info #{'hide' unless container}", :title => _('add new mount point') } %>
34
+
35
+ <%= new_child_fields_template_typed(f, :volumes, {
36
+ :type => 'hard_disk',
37
+ :object => compute_resource.new_typed_volume({},'qemu','hard_disk'),
38
+ :partial => provider_partial(compute_resource, 'server/volume_hard_disk'),
39
+ :form_builder_attrs => { :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove Hard disk') },
40
+ :layout => "compute_resources_vms/form/#{item_layout}_layout" }) %>
41
+ <%= new_child_fields_template_typed(f, :volumes, {
42
+ :type => 'cdrom',
43
+ :object => compute_resource.new_typed_volume({},'qemu','cdrom'),
44
+ :partial => provider_partial(compute_resource, 'server/volume_cdrom'),
45
+ :form_builder_attrs => { :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove CDROM') },
46
+ :layout => "compute_resources_vms/form/#{item_layout}_layout" }) %>
47
+ <%= new_child_fields_template_typed(f, :volumes, {
48
+ :type => 'cloud_init',
49
+ :object => compute_resource.new_typed_volume({},'qemu','cloud_init'),
50
+ :partial => provider_partial(compute_resource, 'server/volume_cloud_init'),
51
+ :form_builder_attrs => { :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove Cloud-init') },
52
+ :layout => "compute_resources_vms/form/#{item_layout}_layout" }) %>
53
+ <%= new_child_fields_template_typed(f, :volumes, {
54
+ :type => 'mp',
55
+ :object => compute_resource.new_typed_volume({ id: 'mp0' }, 'lxc','mp'),
56
+ :partial => provider_partial(compute_resource, 'container/volume_mp'),
57
+ :form_builder_attrs => { :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove mount point') },
58
+ :layout => "compute_resources_vms/form/#{item_layout}_layout" }) %>
37
59
 
38
60
  <%= f.fields_for :volumes do |i| %>
39
61
  <% if i.object.rootfs? %>
40
- <div id="container_volumes_rootfs" style="<%= 'display: ' + (container ? 'block' : 'none') + ';' %>">
41
62
  <%= render :partial => provider_partial(compute_resource, 'container/volume_rootfs'), :locals => { :f => i, :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove storage volume'), :disabled => !container }, :layout => "compute_resources_vms/form/#{item_layout}_layout" %>
42
- </div>
43
63
  <% elsif i.object.mount_point? %>
44
- <div id="container_volumes_mp" style="<%= 'display: ' + (container ? 'block' : 'none') + ';' %>">
45
64
  <%= render :partial => provider_partial(compute_resource, 'container/volume_mp'), :locals => { :f => i, :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove storage volume'), :disabled => !container }, :layout => "compute_resources_vms/form/#{item_layout}_layout" %>
46
- </div>
47
- <% elsif i.object.controller? %>
48
- <div id="server_volumes" style="<%= 'display: ' + (server ? 'block' : 'none') + ';' %>">
49
- <%= render :partial => provider_partial(compute_resource, 'server/volume'), :locals => { :f => i, :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove storage volume'), :disabled => !server }, :layout => "compute_resources_vms/form/#{item_layout}_layout" %>
50
- </div>
65
+ <% elsif i.object.hard_disk? %>
66
+ <%= render :partial => provider_partial(compute_resource, 'server/volume_hard_disk'), :locals => { :f => i, :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove storage volume'), :disabled => !server }, :layout => "compute_resources_vms/form/#{item_layout}_layout" %>
67
+ <% elsif i.object.cdrom? %>
68
+ <%= render :partial => provider_partial(compute_resource, 'server/volume_cdrom'), :locals => { :f => i, :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove storage volume'), :disabled => !server }, :layout => "compute_resources_vms/form/#{item_layout}_layout" %>
69
+ <% elsif i.object.cloud_init? %>
70
+ <%= render :partial => provider_partial(compute_resource, 'server/volume_cloud_init'), :locals => { :f => i, :type => type, :node_id => node_id, :compute_resource => compute_resource, :new_host => new_vm, :new_vm => new_vm, :remove_title => _('remove storage volume'), :disabled => !server }, :layout => "compute_resources_vms/form/#{item_layout}_layout" %>
51
71
  <% end %>
52
72
  <% end %>
53
73
 
54
- <%= add_child_link_typed '+ ' + _("Add Volume"), :volumes, 'server', { :class => "info #{'hide' unless server}", :title => _('add new storage volume') } %>
55
- <%= add_child_link_typed '+ ' + _("Add Volume"), :volumes, 'container', { :class => "info #{'hide' unless container}", :title => _('add new storage volume') } %>
56
74
  <% else %>
57
75
  <%= new_child_fields_template(f, :volumes, {
58
76
  :object => volume,
@@ -68,4 +86,3 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
68
86
  <%= add_child_link '+ ' + _("Add Volume"), :volumes, { :class => "info", :title => _('add new storage volume') } %>
69
87
  <% end %>
70
88
  <% end %>
71
-
@@ -31,9 +31,9 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
31
31
  <%= render :partial => "compute_resources_vms/form/proxmox/container/advanced", :locals => { :f => f, :compute_resource => compute_resource, :new_vm => new_vm } %>
32
32
 
33
33
  <!-- Config Options Settings-->
34
- <%= f.fields_for :config, compute_resource.new_server_vm(object_to_config_hash(f.object)).config, include_id: false do |server_config|%>
35
- <%= render :partial => "compute_resources_vms/form/proxmox/server/config", :locals => { :f => server_config, :compute_resource => compute_resource, :host => @host, :new_vm => new_vm, :item_layout => 'removable', :type => f.object.type, :node_id => f.object.node_id } %>
34
+ <%= f.fields_for :config, compute_resource.new_typed_vm(object_to_config_hash(f.object, 'qemu'), 'qemu').config, include_id: false do |server_config|%>
35
+ <%= render :partial => "compute_resources_vms/form/proxmox/server/config", :locals => { :f => server_config, :cloudinit => f.object.cloud_init?, :compute_resource => compute_resource, :host => @host, :new_vm => new_vm, :item_layout => 'removable', :type => f.object.type, :node_id => f.object.node_id } %>
36
36
  <% end %>
37
- <%= f.fields_for :config, compute_resource.new_container_vm(object_to_config_hash(f.object)).config, include_id: false do |container_config|%>
37
+ <%= f.fields_for :config, compute_resource.new_typed_vm(object_to_config_hash(f.object, 'lxc'), 'lxc').config, include_id: false do |container_config|%>
38
38
  <%= render :partial => "compute_resources_vms/form/proxmox/container/config", :locals => { :f => container_config, :compute_resource => compute_resource, :host => @host, :new_vm => new_vm, :item_layout => 'removable', :type => f.object.type, :node_id => f.object.node_id } %>
39
39
  <% end %>
@@ -16,9 +16,10 @@ 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
  <% if compute_resource.class == ForemanFogProxmox::Proxmox %>
18
18
  <% volume_rootfs = f.object.respond_to?(:rootfs?) && f.object.rootfs? %>
19
+ <% type = f.object.respond_to?(:storage_type) && f.object.storage_type %>
19
20
 
20
21
  <% unless volume_rootfs %>
21
- <%= remove_child_link('X', f, { :method => :'_delete', :title => local_assigns[:remove_title], :class => 'label label-danger' }) %>
22
+ <%= remove_child_link_typed('X', f, type, { :method => :'_delete', :title => local_assigns[:remove_title], :class => 'label label-danger' }) %>
22
23
  <% end %>
23
24
  <% else %>
24
25
  <% if new_vm %>
@@ -20,14 +20,15 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
20
20
 
21
21
  <%= field_set_tag _("Nic"), :id => "container_network_#{index}", :style => ('display: none;' unless container), :disabled => !container do %>
22
22
  <%= f.hidden_field :id if !new_vm %>
23
- <%= text_f f, :name, :label => _('Name'), :label_size => "col-md-2" %>
24
- <%= checkbox_f f, :dhcpv4, :label => _('DHCP IPv4') %>
25
- <%= text_f f, :cidrv4_prefix, :label => _('CIDR IPv4 prefix'), :label_size => "col-md-2" %>
26
- <%= text_f f, :gwv4, :label => _('Gateway IPv4'), :label_size => "col-md-2" %>
27
- <%= checkbox_f f, :dhcpv6, :label => _('DHCP IPv6') %>
28
- <%= text_f f, :cidrv6_prefix, :label => _('CIDR IPv6 prefix'), :label_size => "col-md-2" %>
29
- <%= text_f f, :gwv6, :label => _('Gateway IPv6'), :label_size => "col-md-2" %>
23
+ <%= text_f f, :name, :label => _('Name'), :label_size => "col-md-2", :required => true, :label_help => _("eth[n] with n integer >= 0, e.g. eth0") %>
24
+ <%= checkbox_f f, :dhcp, :label => _('DHCP IPv4') %>
25
+ <%= text_f f, :cidr, :label => _('CIDR IPv4'), :label_size => "col-md-2", :label_help => _("integer within [0..32]") %>
26
+ <%= text_f f, :gw, :label => _('Gateway IPv4'), :label_size => "col-md-2" %>
27
+ <%= checkbox_f f, :dhcp6, :label => _('DHCP IPv6') %>
28
+ <%= text_f f, :cidr6, :label => _('CIDR IPv6'), :label_size => "col-md-2", :label_help => _("integer within [0..128]")%>
29
+ <%= text_f f, :gw6, :label => _('Gateway IPv6'), :label_size => "col-md-2" %>
30
30
  <%= counter_f f, :tag, :class => "input-mini", :label => _('VLAN tag'), :label_size => "col-md-2" %>
31
31
  <%= counter_f f, :rate, :class => "input-mini", :label => _('Rate limit'), :label_size => "col-md-2" %>
32
+ <%= checkbox_f f, :firewall, :label => _('Firewall') %>
32
33
  <%= select_f f, :bridge, compute_resource.bridges(node_id), :iface, :iface, { }, :label => _('Bridge'), :label_size => "col-md-2" %>
33
34
  <% end %>
@@ -24,8 +24,6 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
24
24
  <%= check_box_tag 'show_server_config_cpu', '1', false, :onclick => "$('#server_config_cpu').toggle()" %>
25
25
  <%= label_tag 'show_server_config_memory', _("Memory") %>
26
26
  <%= check_box_tag 'show_server_config_memory', '1', false, :onclick => "$('#server_config_memory').toggle()" %>
27
- <%= label_tag 'show_server_config_cdrom', _("CDROM") %>
28
- <%= check_box_tag 'show_server_config_cdrom', '1', false, :onclick => "$('#server_config_cdrom').toggle()" %>
29
27
  <%= label_tag 'show_server_config_os', _("OS") %>
30
28
  <%= check_box_tag 'show_server_config_os', '1', false, :onclick => "$('#server_config_os').toggle()" %>
31
29
  <% end %>