From 6d092364551bb244ae88ab8c09813657c3aa2070 Mon Sep 17 00:00:00 2001 From: jaisejose1123 Date: Mon, 8 Apr 2024 16:25:38 +0530 Subject: [PATCH] API for vm_infras in reconfigure form from manageiq-API --- app/controllers/api/base_controller.rb | 1 - .../api/base_controller/generic.rb | 1 + .../api/base_controller/renderer.rb | 32 ++++++++----------- app/controllers/api/vm_infras_controller.rb | 5 +++ config/api.yml | 2 +- 5 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 app/controllers/api/vm_infras_controller.rb diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 76a0713a28..40f00c7676 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -88,7 +88,6 @@ def show :expand_actions => true, :expand_custom_actions => true } - byebug render_resource(@req.subject, resource_search(@req.subject_id, @req.subject), opts) end diff --git a/app/controllers/api/base_controller/generic.rb b/app/controllers/api/base_controller/generic.rb index 1f85dd32b0..9b7bb713ff 100644 --- a/app/controllers/api/base_controller/generic.rb +++ b/app/controllers/api/base_controller/generic.rb @@ -251,6 +251,7 @@ def validate_id(id, key_id, klass) raise BadRequestError, "Invalid #{klass} #{key_id} #{id || "nil"} specified" end end + id.split(/\s*,\s*/) end end end diff --git a/app/controllers/api/base_controller/renderer.rb b/app/controllers/api/base_controller/renderer.rb index d9f7496161..95cb87a15e 100644 --- a/app/controllers/api/base_controller/renderer.rb +++ b/app/controllers/api/base_controller/renderer.rb @@ -15,17 +15,13 @@ def render_collection(type, resources, opts = {}) # Helper proc to render a single resource # def render_resource(type, resource, opts = {}) - byebug - puts"=====type===="+type.inspect - puts"=====resource===="+resource.inspect - render :json => resource_to_jbuilder(type, gen_reftype(type, opts), resource, opts).target!, :status => status_from_resource(resource) + render :json => resource_to_jbuilder(type, gen_reftype(type, opts), resource, opts).target!, :status => status_from_resource(resource) end # # We want reftype to reflect subcollection if targeting as such. # def gen_reftype(type, opts) - byebug opts[:is_subcollection] ? "#{@req.collection}/#{@req.collection_id}/#{type}" : type end @@ -134,7 +130,6 @@ def resource_search(id, type, klass = nil, key_id = nil) klass ||= collection_class(type) key_id ||= collection_config.resource_identifier(type) validate_id(id, key_id, klass) - puts"====type====="+type.inspect target = if respond_to?("find_#{type}") public_send("find_#{type}", id) @@ -144,7 +139,6 @@ def resource_search(id, type, klass = nil, key_id = nil) else find_resource(klass, key_id, id) end - puts"======tagget======"+target.inspect raise NotFoundError, "Couldn't find #{klass} with '#{key_id}'=#{id}" unless target filter_resource(target, type, klass) end @@ -162,14 +156,14 @@ def filter_resource(target, type, klass) def vm_infra_reconfigure_form(type, klass, id) @request_id = "new" request_data = id - reconfigure_ids = request_data.split(/\s*,\s*/) + reconfigure_ids = request_data.split(/\s*,\s*/).map(&:to_i) request_hash = build_reconfigure_hash(reconfigure_ids) + return request_hash end def build_reconfigure_hash(reconfigure_ids) - puts"=====1========" - @req = nil - @reconfig_values = {} + #@req = nil + @reconfig_values = {} if @request_id == 'new' @reconfig_values = get_reconfig_info(reconfigure_ids) else @@ -198,7 +192,7 @@ def build_reconfigure_hash(reconfigure_ids) :cb_bootable => disk[:bootable], :add_remove => 'add'} end - + reconfig_item = Vm.find(reconfigure_ids) if reconfig_item reconfig_item.first.hardware.disks.each do |disk| @@ -233,9 +227,9 @@ def build_reconfigure_hash(reconfigure_ids) @reconfig_values[:disks] = vmdisks @reconfig_values[:cdroms] = vmcdroms end - - @reconfig_values[:cb_memory] = !!(@req && @req.options[:vm_memory]) # default for checkbox is false for new request - @reconfig_values[:cb_cpu] = !!(@req && (@req.options[:number_of_sockets] || @req.options[:cores_per_socket])) # default for checkbox is false for new request + + @reconfig_values[:cb_memory] = false #if @request_id != new we need to change false + @reconfig_values[:cb_cpu] = false #if @request_id != new we need to change false @reconfig_values end @@ -251,7 +245,6 @@ def get_reconfig_info(reconfigure_ids) cores_per_socket = @reconfigureitems.first.cpu_cores_per_socket cores_per_socket = '' unless @reconfigureitems.all? { |vm| vm.cpu_cores_per_socket == cores_per_socket } memory, memory_type = reconfigure_calculations(memory) - # if only one vm that supports disk reconfiguration is selected, get the disks information vmdisks = [] @reconfigureitems.first.hardware.disks.order(:filename).each do |disk| @@ -264,9 +257,10 @@ def get_reconfig_info(reconfigure_ids) :hdSize => dsize, :hdUnit => dunit, :add_remove => '', - :cb_bootable => disk.bootable} + :cb_bootable => disk.bootable, + :vm => @reconfigureitems} end - + # reconfiguring network adapters is only supported when one vm was selected network_adapters = [] vmcdroms = [] @@ -282,7 +276,7 @@ def get_reconfig_info(reconfigure_ids) vmcdroms = build_vmcdrom_list(vm) end end - + {:objectIds => reconfigure_ids, :memory => memory, :memory_type => memory_type, diff --git a/app/controllers/api/vm_infras_controller.rb b/app/controllers/api/vm_infras_controller.rb new file mode 100644 index 0000000000..502584585c --- /dev/null +++ b/app/controllers/api/vm_infras_controller.rb @@ -0,0 +1,5 @@ +module Api + class VmInfrasController < BaseProviderController + end + + end \ No newline at end of file diff --git a/config/api.yml b/config/api.yml index 2062951839..81c1a0dbb2 100644 --- a/config/api.yml +++ b/config/api.yml @@ -803,7 +803,7 @@ :identifier: cloud_volume_snapshot_delete :vm_infras: :description: Vm Infras - :identifier: vm_infra, + :identifier: vm_infra :options: - :collection :verbs: *gpppd