Skip to content

Commit

Permalink
add container and remove old ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Manisha15 committed May 15, 2024
1 parent 3ed7dc1 commit f86264c
Show file tree
Hide file tree
Showing 21 changed files with 15,119 additions and 27,353 deletions.
58 changes: 35 additions & 23 deletions app/helpers/proxmox_vm_attrs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,44 @@
require 'fog/proxmox/helpers/cpu_helper'
require 'foreman_fog_proxmox/value'
require 'foreman_fog_proxmox/hash_collection'

include ForemanFogProxmox::ProxmoxComputeAttributes
# Convert a foreman form server hash into a fog-proxmox server attributes hash
module ProxmoxVmAttrsHelper
def object_to_attributes_hash(vm)
def object_to_attributes_hash(vm, from_profile, cr)
paramScope = from_profile ? "compute_attribute[vm_attrs]" : "host[compute_attributes]"
vm_h = ActiveSupport::HashWithIndifferentAccess.new
keys = [ :vmid, :node_id, :type]
keys = [ :vmid, :node_id, :type, :pool]
extra_keys = [:cpu_type]
main = vm.attributes.select { |key, _value| keys.include? key }
config = vm.config.all_attributes
general = [:pool, :description]
main.merge!(config.select {|key, _value| general.include? key})
opts = [:boot, :vga, :bios, :scsihw, :kvm, :agent, :ostype, :onboot]
options = config.select {|key, _value| opts.include? key}
cpu = [:cpu_type, :cpulimit, :cpuunits, :vcpus, :cores, :sockets, :numa]
cpu_opts = config.select {|key, _value| cpu.include? key}
memory = [:memory, :balloon, :shares]
mem_opts = config.select {|key, _value| memory.include? key}
hw = {'cpus': cpu_opts, 'memory': mem_opts}
cloudinit_opts = [:volid, :storage_type, :storage, :controller, :device]
cloudinit = config.select {|key, _value| [:ciuser, :cipassword, :searchdomain, :nameserver, :sshkeys].include? key}
hdd_opts = [:volid, :storage_type, :storage, :controller, :device, :cache, :size]
cdrom_opts = [:storage_type, :cdrom, :storage, :volid]
storage = {'hdd': hdd_opts, 'cdrom': cdrom_opts, 'cloudinitVal': cloudinit, 'cloudinit': cloudinit_opts, 'disks': config[:disks] }
network = [:id, :model, :bridge, :tag, :rate, :queues, :firewall, :link_down]
nics = {'nic': network, 'interfaces': config[:interfaces]}
attributes = {'general': main, 'options': options, 'hw': hw, 'storage': storage, 'network': nics }
logger
vm_h = vm_h.merge(attributes)
disks = Hash[vm.config.disks.each_with_index.map do |disk, idx|
[idx.to_s, disk.attributes]
end ]
interfaces = Hash[vm.config.interfaces.each_with_index.map do |interface, idx|
[idx.to_s, interface_compute_attributes(interface.attributes)]
end ]
#server = cr.new_typed_vm(vm.attributes, 'qemu')
vm.config.all_attributes.each do |key, value|
if key == :interfaces
vm_h.merge!({key => {:name => "#{paramScope}[interfaces_attributes]", :value => interfaces }})
elsif key == :disks
vm_h.merge!({ key => {:name => "#{paramScope}[volumes_attributes]", :value => disks}})
elsif !keys.include? key
vm_h.merge!({key => {:name => "#{paramScope}[config_attributes][#{key}]", :value => value}})
end
end
main.each do |key, value|
vm_h.merge!({key => {:name => "#{paramScope}[#{key}]", :value => value}})
end
vm_h.merge!({:pool => {:name => "#{paramScope}[pool]", :value => vm.pool}})
vm_h.merge!({:cpu_type => {:name => "#{paramScope}[config_attributes][cpu_type]", :value => ""}})
vm_h.merge(cpu_flags_attrs(paramScope, config))
end

def cpu_flags_attrs(paramScope, config)
flag_attrs = ActiveSupport::HashWithIndifferentAccess.new
Fog::Proxmox::CpuHelper.flags.each do |key, _val|
flag_attrs.merge!({key => {:name => "#{paramScope}[config_attributes][#{key}]", :value => config[key]}})
end
flag_attrs
end
end
1 change: 1 addition & 0 deletions app/helpers/proxmox_vm_volumes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def parsed_typed_volumes(args, type, parsed_vm)
end
volumes = parse_typed_volumes(volumes_attributes, type)
volumes.each { |volume| parsed_vm = parsed_vm.merge(volume) }
logger.warn("**************************** parse_typed_volumes #{volumes} ......... #{parsed_vm}")
parsed_vm
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
# You should have received a copy of the GNU General Public License
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.

Deface::Override.new(
virtual_path: 'compute_attributes/_compute_form',
name: 'remove_networks_and_volumes_partial',
remove: "erb[loud]:contains('compute_resources_vms/form/networks'), erb[loud]:contains('compute_resources_vms/form/volumes')"
)

Deface::Override.new(
:virtual_path => 'compute_attributes/_form',
:name => 'add_from_profile_to_compute_attributes_form',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Deface::Override.new(
:virtual_path => 'hosts/_unattended',
:name => 'add_react_js_to_host_form',
:replace_contents => "div#compute_resource",
:text => "<%= render('compute_resources_vms/form/proxmox/add_react_js_to_host_form', host: @host, vm: @vm, compute_resource: @host.compute_resource) if @host.compute_resource %>",
:original => 'ce6211df4eac241538eb3844e2ba5fb911a98772',
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deface::Override.new(
virtual_path: 'compute_attributes/_compute_form',
name: 'remove_networks_and_volumes_partial',
remove: "erb[loud]:contains('render :partial => \"compute_resources_vms/form/networks\"'), erb[loud]:contains('render :partial => \"compute_resources_vms/form/volumes\"')"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<% content_for(:javascripts) do %>
<%= webpacked_plugins_js_for :foreman_fog_proxmox %>
<%= javascript_include_tag 'foreman_fog_proxmox/proxmox_vm', "data-turbolinks-track" => true %>

<% end %>
<%= compute_resource %>
<%= fields_for "#{type}[compute_attributes]", @vm || host.compute_object do |compute| %>
<%= f.object_name%>
<%= "this page is loaded"%>
<% if compute.object %>
<%= alert(:header => _('Notice'),
:class => 'alert-info hide',
:id => 'update_not_supported',
:text => _('Virtual machine settings cannot be edited on an existing machine in %s') %
compute_resource.provider_friendly_name) %>
<%= render partial: provider_partial(compute_resource, 'base'),
locals: { f: f, host: host, compute_resource: compute_resource, new_host: host.new_record?, new_vm: !compute.object.persisted?,
arch: host.architecture_id, os: host.operatingsystem_id } %>
<% else %>
<% if host.new_record? %>
<%= alert(:class => 'alert-danger',
:header => _("Failed connecting to %s") % compute_resource,
:text => _("Errors: %s") % compute_resource.errors.full_messages.to_sentence) %>
<% else %>
<%= alert(:class => 'alert-danger',
:header => _("'%{host}' not found on '%{resource}'") % { :host => host.name, :resource => compute_resource },
:text => _("'%{host}' could be deleted or '%{resource}' is not responding.") % { host: host.name, resource: compute_resource}) %>
<% end %>
<% end%>
<%= hidden_field_tag 'capabilities', compute_resource.capabilities, :disabled => true %>
<%= hidden_field_tag 'provider', compute_resource.provider, :disabled => true %>
<%= content_tag(:div,'', :id => :'supports_update', :data=> { :'supports-update'=> compute_resource.supports_update? || (host && host.new_record?) }) %>
<% end if compute_resource %>
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
<%= webpacked_plugins_js_for :foreman_fog_proxmox %>
<%= webpacked_plugins_css_for :foreman_fog_proxmox %>


<% if compute_resource.class == ForemanFogProxmox::Proxmox %>
<%= javascript_include_tag 'foreman_fog_proxmox/proxmox_volume', "data-turbolinks-track" => true %>
Expand Down
9 changes: 4 additions & 5 deletions app/views/compute_resources_vms/form/proxmox/_base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
<%= webpacked_plugins_js_for :foreman_fog_proxmox %>
<%= webpacked_plugins_css_for :foreman_fog_proxmox %>
<% nodes = compute_resource.nodes %>
<% unless local_assigns[:hide_image] && !new_vm %>
<%
arch ||= nil ; os ||= nil
images = possible_images(compute_resource, arch, os)
-%>
<% end %>
<% content_for(:javascripts) do %>
<%= webpacked_plugins_js_for :foreman_fog_proxmox %>
<%= javascript_include_tag 'foreman_fog_proxmox/proxmox_vm', "data-turbolinks-track" => true %>
<%= f.object %>
<% logger.debug("************** the base obj is #{f.object.config} #{object_to_attributes_hash(f.object)}") %>
<%= react_component('ProxmoxVmType', { vm_attributes: object_to_attributes_hash(f.object), nodes: nodes, images: images, pools: compute_resource.pools, from_profile: true, new_vm: new_vm, paramsScope: "#{f.object_name}"}) %>
<% end %>
<%= react_component('ProxmoxVmType', { vm_attributes: object_to_attributes_hash(f.object, from_profile, compute_resource), nodes: nodes, images: images, pools: compute_resource.pools, storages: compute_resource.storages(f.object.node_id), from_profile: true, new_vm: new_vm}) %>
Loading

0 comments on commit f86264c

Please sign in to comment.