diff --git a/app/models/concerns/fog_extensions/xenserver/network.rb b/app/models/concerns/fog_extensions/xenserver/network.rb new file mode 100644 index 0000000..eee12c9 --- /dev/null +++ b/app/models/concerns/fog_extensions/xenserver/network.rb @@ -0,0 +1,11 @@ +module FogExtensions + module Xenserver + module Network + extend ActiveSupport::Concern + + def id + uuid + end + end + end +end diff --git a/app/models/concerns/fog_extensions/xenserver/server.rb b/app/models/concerns/fog_extensions/xenserver/server.rb index 570af14..9af8690 100644 --- a/app/models/concerns/fog_extensions/xenserver/server.rb +++ b/app/models/concerns/fog_extensions/xenserver/server.rb @@ -57,6 +57,7 @@ def vm_description end def interfaces + @interfaces ||= [] (vifs + @interfaces).uniq end diff --git a/app/models/concerns/fog_extensions/xenserver/storage_repository.rb b/app/models/concerns/fog_extensions/xenserver/storage_repository.rb index a29c010..71b6b0d 100644 --- a/app/models/concerns/fog_extensions/xenserver/storage_repository.rb +++ b/app/models/concerns/fog_extensions/xenserver/storage_repository.rb @@ -8,6 +8,10 @@ module StorageRepository prepend FogExtensions::Xenserver::StorageRepository end + def id + uuid + end + def initialize(new_attributes = {}) super(new_attributes) attributes[:display_name] = init_display_name @@ -29,6 +33,14 @@ def physical_utilisation_gb physical_utilisation.to_i / 1024 / 1024 / 1024 end + def capacity + physical_size_gb + end + + def freespace + free_space + end + def init_display_name srname = name unless shared diff --git a/app/models/concerns/foreman_xen/host_extensions.rb b/app/models/concerns/foreman_xen/host_extensions.rb index 49f768e..692ea6a 100644 --- a/app/models/concerns/foreman_xen/host_extensions.rb +++ b/app/models/concerns/foreman_xen/host_extensions.rb @@ -3,7 +3,10 @@ module HostExtensions extend ActiveSupport::Concern def built(installed = true) - compute_resource.cleanup_configdrive(uuid) if compute_resource && compute_resource.type == 'ForemanXen::Xenserver' + if compute_resource && compute_resource.type == 'ForemanXen::Xenserver' + compute_resource.detach_cdrom(uuid) + compute_resource.cleanup_configdrive(uuid) + end super(installed) end diff --git a/app/models/foreman_xen/xenserver.rb b/app/models/foreman_xen/xenserver.rb index df4236c..868d353 100644 --- a/app/models/foreman_xen/xenserver.rb +++ b/app/models/foreman_xen/xenserver.rb @@ -39,6 +39,15 @@ def iso_library_mountpoint=(path) attrs[:iso_library_mountpoint] = mountpoint end + def detach_cdrom(uuid) + begin + vm = find_vm_by_uuid(uuid) + detach_cdrom_vbd(vm) if vm + rescue => e + logger.error "unable to detach cdrom:#{e}" + end + end + def cleanup_configdrive(uuid) iso_file_name = "foreman-configdrive-#{uuid}.iso" begin @@ -110,6 +119,14 @@ def available_images custom_templates! end + def available_storage_domains(*) + storage_pools + end + + def available_networks(*) + networks + end + def available_hypervisors hypervisors.select(&:enabled) end @@ -273,8 +290,8 @@ def vm_attr_from_args(args) { name: args[:name], name_description: args[:comment], - vcpus_max: args[:vcpus_max], - vcpus_at_startup: args[:vcpus_max], + VCPUs_max: args[:vcpus_max], + VCPUs_at_startup: args[:vcpus_max], memory_static_max: args[:memory_max], memory_dynamic_max: args[:memory_max], memory_dynamic_min: args[:memory_min], @@ -374,9 +391,9 @@ def set_vm_profile_attributes(vm, attr) mem = %w[memory_static_max memory_dynamic_max memory_dynamic_min memory_static_min] mem.reverse! if vm.memory_static_max.to_i > attr[:memory_static_max].to_i - # VCPU values must satisfy: 0 < vcpus_at_startup <= vcpus_max - cpu = %w[vcpus_max vcpus_at_startup] - cpu.reverse! if vm.vcpus_at_startup > attr[:vcpus_at_startup] + # VCPU values must satisfy: 0 < VCPUs_at_startup <= VCPUs_max + cpu = %w[VCPUs_max VCPUs_at_startup] + cpu.reverse! if vm.vcpus_at_startup > attr[:VCPUs_at_startup] (mem + cpu).each { |e| vm.set_attribute e, attr[e.to_sym] } end @@ -489,6 +506,13 @@ def attach_iso(vm, iso_vdi) true end + def detach_cdrom_vbd(vm) + cd_drive = client.vbds.find { |v| v.vm == vm && v.type == 'CD' } + unless cd_drive&.empty + client.eject_vbd cd_drive.reference + end + end + def find_free_userdevice(vm) # Find next free userdevice id for vbd # vm.vbds is not current, vm.reload not working. @@ -518,7 +542,7 @@ def host_xenstore_data(host) 'netmask' => subnet.nil? ? '' : subnet.mask } } }, 'nameserver1' => subnet.nil? ? '' : subnet.dns_primary, 'nameserver2' => subnet.nil? ? '' : subnet.dns_secondary, - 'environment' => host.environment.to_s } + 'environment' => !host.respond_to?("environment") ? '' : host.environment.to_s } end def xenstore_hash_flatten(nested_hash, _key = nil, keychain = nil, out_hash = {}) @@ -539,7 +563,7 @@ def set_vm_affinity(vm, hypervisor) if hypervisor.empty? vm.set_attribute('affinity', '') else - vm.set_attribute('affinity', client.hosts.find_by_uuid(hypervisor)) + vm.set_attribute('affinity', hypervisor) end end # rubocop:enable Rails/DynamicFindBy diff --git a/app/views/compute_resources_vms/form/_network_provisioning.html.erb b/app/views/compute_resources_vms/form/_network_provisioning.html.erb index da8976a..04c4845 100644 --- a/app/views/compute_resources_vms/form/_network_provisioning.html.erb +++ b/app/views/compute_resources_vms/form/_network_provisioning.html.erb @@ -1,5 +1,5 @@ -