theforeman/foreman-xen

View on GitHub
app/models/foreman_xen/xenserver.rb

Summary

Maintainability
F
4 days
Test Coverage

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

  class Xenserver < ComputeResource
    validates :url, :user, :password, :presence => true

    GB_BYTES = 1_073_741_824 # 1gb in bytes

Severity: Major
Found in app/models/foreman_xen/xenserver.rb - About 1 day to fix

    File xenserver.rb has 546 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module ForemanXen
      class Xenserver < ComputeResource
        validates :url, :user, :password, :presence => true
    
        GB_BYTES = 1_073_741_824 # 1gb in bytes
    Severity: Major
    Found in app/models/foreman_xen/xenserver.rb - About 1 day to fix

      Method host_network_data has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          def host_network_data(host)
            p_if = host.primary_interface
            network_data = { links: [], networks: [], services: [] }
            network = { id: 'network0', routes: [] }
            if p_if.subnet
      Severity: Minor
      Found in app/models/foreman_xen/xenserver.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 create_vm has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def create_vm(args = {})
            args = args.deep_symbolize_keys
            logger.debug('create_vm args:')
            logger.debug(args)
            begin
      Severity: Minor
      Found in app/models/foreman_xen/xenserver.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 create_vm has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def create_vm(args = {})
            args = args.deep_symbolize_keys
            logger.debug('create_vm args:')
            logger.debug(args)
            begin
      Severity: Minor
      Found in app/models/foreman_xen/xenserver.rb - About 1 hr to fix

        Method host_network_data has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def host_network_data(host)
              p_if = host.primary_interface
              network_data = { links: [], networks: [], services: [] }
              network = { id: 'network0', routes: [] }
              if p_if.subnet
        Severity: Minor
        Found in app/models/foreman_xen/xenserver.rb - About 1 hr to fix

          Method host_xenstore_data has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def host_xenstore_data(host)
                p_if = host.primary_interface
                subnet = p_if.subnet || p_if.subnet6
                { 'vm-data'     => { 'ifs' => { '0' =>
                                                       { 'ip'      => p_if.ip.empty? ? p_if.ip6 : p_if.ip,
          Severity: Minor
          Found in app/models/foreman_xen/xenserver.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 generate_configdrive has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def generate_configdrive(vm_uuid, meta_data, network_data, user_data, dst_dir)
          Severity: Minor
          Found in app/models/foreman_xen/xenserver.rb - About 35 mins to fix

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

                def find_vm_by_uuid(uuid)
                  return client.servers.find { |s| s.reference == uuid } if uuid.start_with? 'OpaqueRef:'
            
                  client.servers.find_by_uuid(uuid)
                rescue Fog::XenServer::RequestFailed => e
            Severity: Minor
            Found in app/models/foreman_xen/xenserver.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 console has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def console(uuid)
                  vm = find_vm_by_uuid(uuid)
                  raise 'VM is not running!' unless vm.ready?
            
                  console = vm.service.consoles.find { |c| c.vm && c.vm.reference == vm.reference && c.protocol == 'rfb' }
            Severity: Minor
            Found in app/models/foreman_xen/xenserver.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 attach_iso has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def attach_iso(vm, iso_vdi)
                  cd_drive = client.vbds.find { |v| v.vm == vm && v.type == 'CD' }
                  if cd_drive&.empty
                    client.insert_vbd cd_drive.reference, iso_vdi.reference
                  else
            Severity: Minor
            Found in app/models/foreman_xen/xenserver.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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                  if p_if.subnet6
                    sn = p_if.subnet6
                    network[:ip_address] = p_if.ip6 unless p_if.ip6.empty?
                    network[:type] = sn.boot_mode == 'DHCP' ? 'ipv6_dhcp' : 'ipv6'
                  end
            Severity: Minor
            Found in app/models/foreman_xen/xenserver.rb and 1 other location - About 15 mins to fix
            app/models/foreman_xen/xenserver.rb on lines 571..575

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 26.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                  if p_if.subnet
                    sn = p_if.subnet
                    network[:ip_address] = p_if.ip unless p_if.ip.empty?
                    network[:type] = sn.boot_mode == 'DHCP' ? 'ipv4_dhcp' : 'ipv4'
                  end
            Severity: Minor
            Found in app/models/foreman_xen/xenserver.rb and 1 other location - About 15 mins to fix
            app/models/foreman_xen/xenserver.rb on lines 576..580

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 26.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status