Skip to content

Commit

Permalink
Merge pull request #151 from ATIX-AG/fix_vm_type_error
Browse files Browse the repository at this point in the history
Fixes ActionView::Template::Error vm_type Error
  • Loading branch information
tristanrobert authored Jul 22, 2020
2 parents 38f985f + c13557a commit 39265d3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
8 changes: 0 additions & 8 deletions app/helpers/proxmox_vm_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,4 @@ def convert_memory_size(config_hash, key)
memory = (config_hash[key].to_i / MEGA).to_s == '0' ? config_hash[key] : (config_hash[key].to_i / MEGA).to_s
config_hash.store(key, memory)
end

def vm_type(host)
host.compute_object.type
end

def node_id(host)
host.compute_object.node_id
end
end
6 changes: 4 additions & 2 deletions app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def interface_compute_attributes(interface_attributes)
vm_attrs.store(:identifier, interface_attributes[:id])
vm_attrs.store(:ip, interface_attributes[:ip])
vm_attrs.store(:ip6, interface_attributes[:ip6])
vm_attrs[:compute_attributes] = interface_attributes.reject { |k,v| [:macaddr, :id].include?(k) }
vm_attrs[:compute_attributes] = interface_attributes.reject { |k, _v| [:macaddr, :id].include?(k) }
vm_attrs
end

Expand All @@ -54,7 +54,9 @@ def vm_compute_attributes(vm)
if vm.respond_to?(:config)
vm_attrs = vm_attrs.merge(vmid: vm.identity, node_id: vm.node_id, type: vm.type)
vm_attrs[:volumes_attributes] = Hash[vm.config.disks.each_with_index.map { |disk, idx| [idx.to_s, disk.attributes] }] if vm.config.respond_to?(:disks)
vm_attrs[:interfaces_attributes] = Hash[vm.config.interfaces.each_with_index.map { |interface, idx| [idx.to_s, interface_compute_attributes(interface.attributes)] }] if vm.config.respond_to?(:interfaces)
if vm.config.respond_to?(:interfaces)
vm_attrs[:interfaces_attributes] = Hash[vm.config.interfaces.each_with_index.map { |interface, idx| [idx.to_s, interface_compute_attributes(interface.attributes)] }]
end
vm_attrs[:config_attributes] = vm.config.attributes.reject do |key, value|
not_config_key?(vm, key) || ForemanFogProxmox::Value.empty?(value.to_s) || Fog::Proxmox::DiskHelper.disk?(key.to_s) || Fog::Proxmox::NicHelper.nic?(key.to_s)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ You should have received a copy of the GNU General Public License
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
<% if @host.compute_resource.class == ForemanFogProxmox::Proxmox %>
<% compute_attributes = f.object.compute_attributes %>
<% vm_type = vm_type(@host) %>
<% node_id = node_id(@host) %>
<% vm_type = f.object.respond_to?('type') ? f.object.type : nil %>
<% node_id = f.object.respond_to?('node_id') ? f.object.node_id : nil %>
<%= f.fields_for 'compute_attributes', OpenStruct.new(f.object.compute_attributes) do |f| %>
<%= 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 %>
Expand Down

0 comments on commit 39265d3

Please sign in to comment.