Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
fix errors introduced by linting; fix vm import
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels Baumgartner authored and mmoll committed Jul 1, 2019
1 parent f8aa0f8 commit a94e376
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/models/concerns/fog_extensions/xenserver/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def id
uuid
end

def identity
uuid
end

def to_s
name
end
Expand Down
12 changes: 10 additions & 2 deletions app/models/foreman_xen/xenserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ 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')
raise(ActiveRecord::RecordNotFound) if e.message.include?('VM.get_record: ["SESSION_INVALID"')

raise e
end
# rubocop:enable Rails/DynamicFindBy

# we default to destroy the VM's storage as well.
def destroy_vm(ref, args = {})
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/views/compute_resources_vms/index/_xenserver.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<tbody>
<% @vms.each do |vm| -%>
<tr>
<td><%= link_to_if_authorized vm.name, hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity) %></td>
<td><%= link_to_if_authorized vm.name, hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.uuid) %></td>
<td><%= vm.vcpus_max %></td>
<td><%= (vm.memory_static_max.to_i / 1073741824).to_s %> GB</td>
<td><%= vm.power_state %> </td>
Expand Down

0 comments on commit a94e376

Please sign in to comment.