From 5ae1b481611d8fd1c7678286efaaa7fe1216e756 Mon Sep 17 00:00:00 2001 From: Hans-Georg Winkler Date: Thu, 5 Sep 2024 10:24:12 +0200 Subject: [PATCH] feat(compute): remove old bare metal filter for flavor (#1399) --- .../app/helpers/compute/instances_helper.rb | 33 +++++++++++-------- .../app/views/compute/instances/new.html.haml | 14 ++------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/plugins/compute/app/helpers/compute/instances_helper.rb b/plugins/compute/app/helpers/compute/instances_helper.rb index e64da30d67..d047abec85 100644 --- a/plugins/compute/app/helpers/compute/instances_helper.rb +++ b/plugins/compute/app/helpers/compute/instances_helper.rb @@ -131,13 +131,13 @@ def js_images_data(images) js_data = [] unless images.empty? js_data = - images.map do |flavor| + images.map do |image| { - flavor.id => { - "name" => flavor.name, - "ram" => flavor.ram, - "vcpus" => flavor.vcpus, - "disk" => flavor.disk, + image.id => { + "name" => image.name, + "ram" => image.ram, + "vcpus" => image.vcpus, + "disk" => image.disk, }, } end @@ -193,7 +193,7 @@ def grouped_flavors(flavors) private_flavors = [] flavors.each do |flavor| if flavor.public? - if flavor.name =~ /^(baremetal|zg|zh|bg_|bm_)/ + if flavor.extra_specs["capabilities:hypervisor_type"] == "ironic" public_flavors_baremetal << flavor else public_flavors_vmware << flavor @@ -269,21 +269,28 @@ def js_flavor_data(flavors) flavors.map do |flavor| { flavor.id => { - "name" => flavor.name, - "ram" => flavor.ram, - "vcpus" => flavor.vcpus, - "disk" => flavor.disk, + "name" => flavor.name, + "ram" => flavor.ram, + "vcpus" => flavor.vcpus, + "disk" => flavor.disk, + "hypervisor_type" => flavor.extra_specs["capabilities:hypervisor_type"], }, } end end - js_data.to_json end # flavor label in dropdown def flavor_label_for_select(flavor) - "#{flavor.name} (RAM: #{Core::DataType.new(:bytes, :mega).format(flavor.ram)}, VCPUs: #{flavor.vcpus}, Disk: #{Core::DataType.new(:bytes, :giga).format(flavor.disk)} )" + + label = "#{flavor.name} (RAM: #{Core::DataType.new(:bytes, :mega).format(flavor.ram)}, VCPUs: #{flavor.vcpus}, Disk: #{Core::DataType.new(:bytes, :giga).format(flavor.disk)} )" + + if flavor.extra_specs["capabilities:hypervisor_type"] == "ironic" + label = "#{flavor.name} ironic (RAM: #{Core::DataType.new(:bytes, :mega).format(flavor.ram)}, VCPUs: #{flavor.vcpus}, Disk: #{Core::DataType.new(:bytes, :giga).format(flavor.disk)} )" + end + + return label end ######################################################################## diff --git a/plugins/compute/app/views/compute/instances/new.html.haml b/plugins/compute/app/views/compute/instances/new.html.haml index 7b7133f6ee..f52afee2eb 100644 --- a/plugins/compute/app/views/compute/instances/new.html.haml +++ b/plugins/compute/app/views/compute/instances/new.html.haml @@ -88,12 +88,7 @@ :javascript $(document).ready(function(){ if ($('#server_flavor_id option:selected').text() != "Choose flavor") { - if ($('#server_flavor_id option:selected').text().match(/^baremetal/) || - $('#server_flavor_id option:selected').text().match(/^hv/) || - $('#server_flavor_id option:selected').text().match(/^zh/) || - $('#server_flavor_id option:selected').text().match(/^bm_/) || - $('#server_flavor_id option:selected').text().match(/^bg_/) || - $('#server_flavor_id option:selected').text().match(/^zg/)) { + if ($('#server_flavor_id option:selected').text().match(/ironic/)) { // baremetal $('#baremetal_image_id_wrapper').removeClass('hidden'); @@ -146,12 +141,7 @@ //flavors = JSON.parse(flavors.replace(/"/g,'"')); $('#server_flavor_id').change(function(){ //console.log($( this ).val()) - if ($('#server_flavor_id option:selected').text().match(/^baremetal/) || - $('#server_flavor_id option:selected').text().match(/^hv/) || - $('#server_flavor_id option:selected').text().match(/^zh/) || - $('#server_flavor_id option:selected').text().match(/^bm_/) || - $('#server_flavor_id option:selected').text().match(/^bg_/) || - $('#server_flavor_id option:selected').text().match(/^zg/)) { + if ($('#server_flavor_id option:selected').text().match(/ironic/)) { // baremetal $('#baremetal_image_id_wrapper').removeClass('hidden'); $('#vmware_image_id_wrapper').addClass('hidden');