diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8dc61ca..297cf08 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-05-05 02:13:49 +0200 using RuboCop version 0.54.0. +# on 2018-11-11 15:08:09 +0100 using RuboCop version 0.60.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -41,7 +41,7 @@ Lint/UselessAssignment: Metrics/AbcSize: Max: 67 -# Offense count: 2 +# Offense count: 1 # Configuration parameters: CountBlocks. Metrics/BlockNesting: Max: 4 @@ -49,21 +49,21 @@ Metrics/BlockNesting: # Offense count: 2 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 368 + Max: 367 # Offense count: 3 Metrics/CyclomaticComplexity: Max: 12 # Offense count: 21 -# Configuration parameters: CountComments. +# Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 52 # Offense count: 1 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 113 + Max: 111 # Offense count: 1 # Configuration parameters: CountKeywordArgs. @@ -76,7 +76,7 @@ Metrics/PerceivedComplexity: # Offense count: 4 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: io, id, to +# AllowedNames: io, id, to, by, on, in, at, ip, db Naming/UncommunicativeMethodParamName: Exclude: - 'app/helpers/xen_compute_helper.rb' diff --git a/Gemfile b/Gemfile index 3d57dd7..ffa7165 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,4 @@ source 'https://rubygems.org' gemspec -gem 'rubocop', '~> 0.54.0', require: false +gem 'rubocop', '~> 0.60.0', require: false diff --git a/app/controllers/foreman_xen/snapshots_controller.rb b/app/controllers/foreman_xen/snapshots_controller.rb index c0ab7d6..567dbfd 100644 --- a/app/controllers/foreman_xen/snapshots_controller.rb +++ b/app/controllers/foreman_xen/snapshots_controller.rb @@ -59,6 +59,7 @@ def destroy snapshots = @compute_resource.find_snapshots snapshots.each do |snapshot| next unless snapshot.reference == ref + name = snapshot.name snapshot.destroy notice "Successfully deleted snapshot #{snapshot.name}" diff --git a/app/helpers/xen_compute_helper.rb b/app/helpers/xen_compute_helper.rb index 7d62ad2..e51f65f 100644 --- a/app/helpers/xen_compute_helper.rb +++ b/app/helpers/xen_compute_helper.rb @@ -31,19 +31,17 @@ def hosts_controller_compute_attribute_map(params, compute_resource, new) compute_attributes = compute_resource.compute_profile_attributes_for(params['host']['compute_profile_id']) attribute_map = filter_compute_attributes(attribute_map, compute_attributes) elsif new - attribute_map[:cpu_count] = new.vcpus_max ? new.vcpus_max : nil - attribute_map[:memory_min] = new.memory_static_min ? new.memory_static_min : nil - attribute_map[:memory_max] = new.memory_static_max ? new.memory_static_max : nil + attribute_map[:cpu_count] = new.vcpus_max || nil + attribute_map[:memory_min] = new.memory_static_min || nil + attribute_map[:memory_max] = new.memory_static_max || nil if new.vbds vdi = new.vbds.first.vdi if vdi - attribute_map[:volume_selected] = vdi.sr.uuid ? vdi.sr.uuid : nil + attribute_map[:volume_selected] = vdi.sr.uuid || nil attribute_map[:volume_size] = vdi.virtual_size ? (vdi.virtual_size.to_i / 1_073_741_824).to_s : nil end end - if new.vifs - attribute_map[:network_selected] = new.vifs.first.network.name ? new.vifs.first.network.name : nil - end + attribute_map[:network_selected] = new.vifs.first.network.name || nil if new.vifs end attribute_map end diff --git a/app/models/foreman_xen/xenserver.rb b/app/models/foreman_xen/xenserver.rb index dd979d6..5cb4b00 100644 --- a/app/models/foreman_xen/xenserver.rb +++ b/app/models/foreman_xen/xenserver.rb @@ -19,6 +19,7 @@ def find_vm_by_uuid(uuid) 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 @@ -92,6 +93,7 @@ def storage_pools! available_hypervisors.each do |host| next unless sr.reference == host.suspend_image_sr + found = true subresults[:name] = sr.name subresults[:display_name] = sr.name + '(' + host.hostname + ')' @@ -161,10 +163,11 @@ def associated_host(vm) def find_snapshots_for_vm(vm) return [] if vm.snapshots.empty? + tmps = begin client.servers.templates.select(&:is_a_snapshot) - rescue - [] + rescue + [] end retval = [] tmps.each do |snapshot| @@ -176,8 +179,8 @@ def find_snapshots_for_vm(vm) def find_snapshots tmps = begin client.servers.templates.select(&:is_a_snapshot) - rescue - [] + rescue + [] end tmps.sort_by(&:name) end @@ -185,6 +188,7 @@ def find_snapshots def new_vm(attr = {}) test_connection return unless errors.empty? + opts = vm_instance_defaults.merge(attr.to_hash).symbolize_keys %i[networks volumes].each do |collection| @@ -422,6 +426,7 @@ def get_templates(templates) def get_hypervisor_host(args) return client.hosts.first unless args[:hypervisor_host] != '' + client.hosts.find { |host| host.name == args[:hypervisor_host] } end diff --git a/lib/foreman_xen/vnc_tunnel.rb b/lib/foreman_xen/vnc_tunnel.rb index 6102bd2..498aff7 100644 --- a/lib/foreman_xen/vnc_tunnel.rb +++ b/lib/foreman_xen/vnc_tunnel.rb @@ -51,6 +51,7 @@ def listen(client_srv) begin data = @client_socket.read_nonblock(1024) break if data.nil? + @srv_socket.write(data) rescue IO::WaitReadable => e IO.select([@client_socket])