theforeman/foreman

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

Summary

Maintainability
F
5 days
Test Coverage

File vmware.rb has 719 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'fog_extensions/vsphere/mini_servers'
require 'foreman/exception'

begin
  require 'rbvmomi'
Severity: Major
Found in app/models/compute_resources/foreman/model/vmware.rb - About 1 day to fix

    Class Vmware has 71 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Vmware < ComputeResource
        include ComputeResourceConsoleCommon
        include ComputeResourceCaching
    
        validates :user, :password, :server, :datacenter, :presence => true
    Severity: Major
    Found in app/models/compute_resources/foreman/model/vmware.rb - About 1 day to fix

      Method guest_types_descriptions has 197 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def guest_types_descriptions
            {
              "almalinux_64Guest" => "AlmaLinux (64-bit)",
              "amazonlinux2_64Guest" => "Amazon Linux 2 (64 bit)",
              "amazonlinux3_64Guest" => "Amazon Linux 3 (64 bit)",
      Severity: Major
      Found in app/models/compute_resources/foreman/model/vmware.rb - About 7 hrs to fix

        Method normalize_vm_attrs has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def normalize_vm_attrs(vm_attrs)
              normalized = slice_vm_attributes(vm_attrs, ['cpus', 'firmware', 'guest_id', 'annotation', 'resource_pool_id', 'image_id'])
        
              normalized['cores_per_socket'] = vm_attrs['corespersocket']
              normalized['memory'] = vm_attrs['memory_mb'].nil? ? nil : (vm_attrs['memory_mb'].to_i * 1024)
        Severity: Minor
        Found in app/models/compute_resources/foreman/model/vmware.rb - About 1 hr to fix

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

              def clone_vm(raw_args)
                args = parse_args(raw_args)
          
                opts = {
                  "datacenter" => datacenter,
          Severity: Minor
          Found in app/models/compute_resources/foreman/model/vmware.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 = { })
                vm = nil
                test_connection
                return unless errors.empty?
          
          
          Severity: Minor
          Found in app/models/compute_resources/foreman/model/vmware.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 clone_vm has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def clone_vm(raw_args)
                args = parse_args(raw_args)
          
                opts = {
                  "datacenter" => datacenter,
          Severity: Minor
          Found in app/models/compute_resources/foreman/model/vmware.rb - About 1 hr to fix

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

                def normalize_vm_attrs(vm_attrs)
                  normalized = slice_vm_attributes(vm_attrs, ['cpus', 'firmware', 'guest_id', 'annotation', 'resource_pool_id', 'image_id'])
            
                  normalized['cores_per_socket'] = vm_attrs['corespersocket']
                  normalized['memory'] = vm_attrs['memory_mb'].nil? ? nil : (vm_attrs['memory_mb'].to_i * 1024)
            Severity: Minor
            Found in app/models/compute_resources/foreman/model/vmware.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 save_vm has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def save_vm(uuid, attr)
                  vm = find_vm_by_uuid(uuid)
                  vm.attributes.merge!(attr.deep_symbolize_keys)
                  # volumes are not part of vm.attributes so we have to set them seperately if needed
                  if attr.has_key?(:volumes_attributes)
            Severity: Minor
            Found in app/models/compute_resources/foreman/model/vmware.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 parse_args has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def parse_args(args)
                  args = args.deep_symbolize_keys
            
                  # convert rails nested_attributes into a plain, symbolized hash
                  [:interfaces, :volumes].each do |collection|
            Severity: Minor
            Found in app/models/compute_resources/foreman/model/vmware.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 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def client
                  @client ||= ::Fog::Compute.new(
                    :provider                     => "vsphere",
                    :vsphere_username             => user,
                    :vsphere_password             => password,
            Severity: Minor
            Found in app/models/compute_resources/foreman/model/vmware.rb - About 25 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