diff --git a/app/controllers/api/vms_controller.rb b/app/controllers/api/vms_controller.rb index b785d7ec88..1b8b204928 100644 --- a/app/controllers/api/vms_controller.rb +++ b/app/controllers/api/vms_controller.rb @@ -1,4 +1,5 @@ module Api + require 'byebug' class VmsController < BaseProviderController extend Api::Mixins::CentralAdmin include Api::Mixins::PolicySimulation @@ -67,13 +68,7 @@ def vm_reconfigure_resource(type, id, data) raise NotFoundError, "Invalid #{type} resource specified - #{data_spec}" end resource = resource_search(id, type) - new_row[:tree_id] = TreeBuilder.build_node_id(resource) if resource - new_row[:cells] << {:is_checkbox => true} - new_row[:cells] << {:name => resource.name} - new_row[:cells] << {:hostname => resource&.host&.name} - new_row[:cells] << {:num_cpu => resource.num_cpu} - new_row[:cells] << {:cpu_cores_per_socket => resource.cpu_cores_per_socket} - new_row[:cells] << {:mem_cpu => "#{(resource.mem_cpu.to_i / 1024.0).to_i}GB"} + new_row = vm_data_collection(new_row,resource) opts = { :name => type.to_s, @@ -85,6 +80,17 @@ def vm_reconfigure_resource(type, id, data) resource_to_jbuilder(type, type, resource, opts).attributes! end + def vm_data_collection(new_row,resource) + new_row[:tree_id] = TreeBuilder.build_node_id(resource) if resource + new_row[:cells] << {:is_checkbox => true} + new_row[:cells] << {:name => resource.name} + new_row[:cells] << {:hostname => resource&.host&.name} + new_row[:cells] << {:num_cpu => resource.num_cpu} + new_row[:cells] << {:cpu_cores_per_socket => resource.cpu_cores_per_socket} + new_row[:cells] << {:mem_cpu => "#{(resource.mem_cpu.to_i / 1024.0).to_i}GB"} + new_row + end + def vm_reconfigure_single_resource(type, id, data) new_row = { :id => id.to_s, @@ -100,13 +106,7 @@ def vm_reconfigure_single_resource(type, id, data) end resource = resource_search(id, type) - new_row[:tree_id] = TreeBuilder.build_node_id(resource) if resource - new_row[:cells] << {:is_checkbox => true} - new_row[:cells] << {:name => resource.name} - new_row[:cells] << {:hostname => resource&.host&.name} - new_row[:cells] << {:num_cpu => resource.num_cpu} - new_row[:cells] << {:cpu_cores_per_socket => resource.cpu_cores_per_socket} - new_row[:cells] << {:mem_cpu => "#{(resource.mem_cpu.to_i / 1024.0).to_i}GB"} + new_row = vm_data_collection(new_row,resource) resource.hardware.guest_devices.order(:device_name => 'asc').each do |guest_device| lan = Lan.find_by(:id => guest_device.lan_id) @@ -126,7 +126,7 @@ def vm_reconfigure_single_resource(type, id, data) end - + opts = { :name => type.to_s, :is_subcollection => false,