From a94e376d82272aacb47a3e8057b1f6d73a6fd632 Mon Sep 17 00:00:00 2001 From: Niels Baumgartner Date: Mon, 1 Jul 2019 09:58:01 +0200 Subject: [PATCH] fix errors introduced by linting; fix vm import --- .../concerns/fog_extensions/xenserver/server.rb | 4 ++++ app/models/foreman_xen/xenserver.rb | 12 ++++++++++-- .../compute_resources_vms/index/_xenserver.html.erb | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/fog_extensions/xenserver/server.rb b/app/models/concerns/fog_extensions/xenserver/server.rb index 570af14..5559b1e 100644 --- a/app/models/concerns/fog_extensions/xenserver/server.rb +++ b/app/models/concerns/fog_extensions/xenserver/server.rb @@ -13,6 +13,10 @@ def id uuid end + def identity + uuid + end + def to_s name end diff --git a/app/models/foreman_xen/xenserver.rb b/app/models/foreman_xen/xenserver.rb index 1ddd56f..1808159 100644 --- a/app/models/foreman_xen/xenserver.rb +++ b/app/models/foreman_xen/xenserver.rb @@ -52,8 +52,11 @@ def cleanup_configdrive(uuid) end end + # rubocop:disable Rails/DynamicFindBy + # Fog::XenServer::Compute (client) isn't an ActiveRecord model which + # supports find_by() def find_vm_by_uuid(uuid) - client.servers.find_by(uuid: uuid) + client.servers.find_by_uuid(uuid) rescue Fog::XenServer::RequestFailed => e Foreman::Logging.exception("Failed retrieving xenserver vm by uuid #{uuid}", e) raise(ActiveRecord::RecordNotFound) if e.message.include?('HANDLE_INVALID') @@ -61,6 +64,7 @@ def find_vm_by_uuid(uuid) raise e end + # rubocop:enable Rails/DynamicFindBy # we default to destroy the VM's storage as well. def destroy_vm(ref, args = {}) @@ -526,13 +530,17 @@ def xenstore_hash_flatten(nested_hash, _key = nil, keychain = nil, out_hash = {} out_hash end + # rubocop:disable Rails/DynamicFindBy + # Fog::XenServer::Compute (client) isn't an ActiveRecord model which + # supports find_by() 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', client.hosts.find_by_uuid(hypervisor)) end end + # rubocop:enable Rails/DynamicFindBy def create_and_attach_configdrive(vm, attr) network_data = add_mac_to_network_data(attr[:network_data], vm) diff --git a/app/views/compute_resources_vms/index/_xenserver.html.erb b/app/views/compute_resources_vms/index/_xenserver.html.erb index bb90731..3c3bbf3 100644 --- a/app/views/compute_resources_vms/index/_xenserver.html.erb +++ b/app/views/compute_resources_vms/index/_xenserver.html.erb @@ -11,7 +11,7 @@ <% @vms.each do |vm| -%> - <%= link_to_if_authorized vm.name, hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity) %> + <%= link_to_if_authorized vm.name, hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.uuid) %> <%= vm.vcpus_max %> <%= (vm.memory_static_max.to_i / 1073741824).to_s %> GB <%= vm.power_state %>