theforeman/foreman

View on GitHub
app/models/compute_resources/foreman/model/libvirt.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Libvirt has 38 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Libvirt < ComputeResource
    include ComputeResourceConsoleCommon

    ALLOWED_DISPLAY_TYPES = %w(vnc spice)

Severity: Minor
Found in app/models/compute_resources/foreman/model/libvirt.rb - About 5 hrs to fix

    File libvirt.rb has 267 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Foreman::Model
      class Libvirt < ComputeResource
        include ComputeResourceConsoleCommon
    
        ALLOWED_DISPLAY_TYPES = %w(vnc spice)
    Severity: Minor
    Found in app/models/compute_resources/foreman/model/libvirt.rb - About 2 hrs to fix

      Method create_volumes has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def create_volumes(args)
            args[:volumes].each { |vol| validate_volume_capacity(vol) }
      
            # if using image creation, the first volume needs a backing disk set
            if args[:backing_id].present?
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/libvirt.rb - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method terminate_connection has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.terminate_connection(url = nil)
            if url
              local_names = ["libvirt_connection_#{url}"]
            else
              local_names = Thread.current.keys
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/libvirt.rb - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method console has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def console(uuid)
            vm = find_vm_by_uuid(uuid)
            raise Foreman::Exception.new(N_("VM is not running!")) unless vm.ready?
            password = random_password(console_password_length(vm.display[:type]))
            # Listen address cannot be updated while the guest is running
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/libvirt.rb - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method client has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def client
            tries ||= 3
            key = "libvirt_connection_#{url}"
            Thread.current[key] ||= begin
              conn = ::Fog::Compute.new(:provider => "Libvirt", :libvirt_uri => url)
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/libvirt.rb - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method new_vm has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def new_vm(attr = { })
            test_connection
            libvirt_connection_error unless errors.empty?
            opts = vm_instance_defaults.merge(attr.to_h).deep_symbolize_keys
      
      
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/libvirt.rb - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      There are no issues that match your filters.

      Category
      Status