Skip to content

Commit

Permalink
API for vm_infras in reconfigure form from manageiq-API
Browse files Browse the repository at this point in the history
  • Loading branch information
jaisejose1123 committed Apr 8, 2024
1 parent dd606ab commit 6d09236
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
1 change: 0 additions & 1 deletion app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions app/controllers/api/base_controller/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 13 additions & 19 deletions app/controllers/api/base_controller/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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

Expand All @@ -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|
Expand All @@ -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 = []
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/api/vm_infras_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Api
class VmInfrasController < BaseProviderController
end

end
2 changes: 1 addition & 1 deletion config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@
:identifier: cloud_volume_snapshot_delete
:vm_infras:
:description: Vm Infras
:identifier: vm_infra,
:identifier: vm_infra
:options:
- :collection
:verbs: *gpppd
Expand Down

0 comments on commit 6d09236

Please sign in to comment.