theforeman/foreman

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

Summary

Maintainability
F
4 days
Test Coverage

Class Ovirt has 79 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Ovirt < ComputeResource
    ALLOWED_DISPLAY_TYPES = %w(vnc spice)

    validates :url, :format => { :with => URI::DEFAULT_PARSER.make_regexp }, :presence => true,
              :url_schema => ['http', 'https']
Severity: Major
Found in app/models/compute_resources/foreman/model/ovirt.rb - About 1 day to fix

    File ovirt.rb has 613 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'foreman/exception'
    require 'uri'
    
    module Foreman::Model
      class Ovirt < ComputeResource
    Severity: Major
    Found in app/models/compute_resources/foreman/model/ovirt.rb - About 1 day to fix

      Method sanitize_inherited_vm_attributes has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          def sanitize_inherited_vm_attributes(args, template, instance_type)
            # Override memory an cores values if template and/or instance type is/are provided.
            # Take template values if blank values for VM attributes, because oVirt will fail if empty values are present in VM definition
            # Instance type values always take precedence on templates or vm provided values
            if template
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/ovirt.rb - About 3 hrs 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 determine_os_type has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def determine_os_type(host)
            return nil unless host
            return host.params['ovirt_ostype'] if host.params['ovirt_ostype']
            ret = "other_linux"
            return ret unless host.operatingsystem
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/ovirt.rb - About 2 hrs 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 create_interfaces has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def create_interfaces(vm, attrs, cluster_id)
            # first remove all existing interfaces
            vm.interfaces&.each do |interface|
              # The blocking true is a work-around for ovirt bug, it should be removed.
              vm.destroy_interface(:id => interface.id, :blocking => true)
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/ovirt.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 create_vm has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def create_vm(args = {})
            args[:comment] = args[:user_data] if args[:user_data]
            args[:template] = args[:image_id] if args[:image_id]
            template = template(args[:template]) if args[:template]
            instance_type = instance_type(args[:instance_type]) unless args[:instance_type].empty?
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/ovirt.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 determine_os_type has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def determine_os_type(host)
            return nil unless host
            return host.params['ovirt_ostype'] if host.params['ovirt_ostype']
            ret = "other_linux"
            return ret unless host.operatingsystem
      Severity: Minor
      Found in app/models/compute_resources/foreman/model/ovirt.rb - About 1 hr to fix

        Method update_required? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def update_required?(old_attrs, new_attrs)
              return true if super(old_attrs, new_attrs)
        
              new_attrs[:interfaces_attributes]&.each do |key, interface|
                return true if (interface[:id].blank? || interface[:_delete] == '1') && key != 'new_interfaces' # ignore the template
        Severity: Minor
        Found in app/models/compute_resources/foreman/model/ovirt.rb - About 55 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 preallocate_and_clone_disks has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def preallocate_and_clone_disks(args, template)
              volumes_to_change = args[:volumes_attributes].values.select { |x| x[:id].present? }
              return unless volumes_to_change.present?
        
              template_disks = template.volumes
        Severity: Minor
        Found in app/models/compute_resources/foreman/model/ovirt.rb - About 55 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 update_available_operating_systems has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def update_available_operating_systems
              return false if errors.any?
              ovirt_operating_systems = client.operating_systems if client.respond_to?(:operating_systems)
        
              attrs[:available_operating_systems] = ovirt_operating_systems.map do |os|
        Severity: Minor
        Found in app/models/compute_resources/foreman/model/ovirt.rb - About 55 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 supports_operating_systems? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def supports_operating_systems?
              if client.respond_to?(:operating_systems)
                unless attrs.key?(:available_operating_systems)
                  update_available_operating_systems
                  save
        Severity: Minor
        Found in app/models/compute_resources/foreman/model/ovirt.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 update_interfaces has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def update_interfaces(vm, attrs)
              interfaces = nested_attributes_for :interfaces, attrs
              interfaces.each do |interface|
                vm.destroy_interface(:id => interface[:id]) if interface[:_delete] == '1' && interface[:id]
                if interface[:id].blank?
        Severity: Minor
        Found in app/models/compute_resources/foreman/model/ovirt.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 client has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def client
              return @client if @client
              client = ::Fog::Compute.new(
                :provider         => "ovirt",
                :ovirt_username   => user,
        Severity: Minor
        Found in app/models/compute_resources/foreman/model/ovirt.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 connect has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def connect(options = {})
              return unless connection_properties_valid?
        
              update_public_key options
              datacenters && test_https_required
        Severity: Minor
        Found in app/models/compute_resources/foreman/model/ovirt.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 update_public_key has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def update_public_key(options = {})
              return unless public_key.blank? || options[:force]
              client
            rescue Foreman::FingerprintException => e
              self.public_key = e.fingerprint if public_key.blank?
        Severity: Minor
        Found in app/models/compute_resources/foreman/model/ovirt.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