theforeman/foreman-xen

View on GitHub

Showing 21 of 23 total issues

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 show has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def show
              id    = params[:id]
              @host = get_host_by_id(id) if !id.nil? && id != ''
              if !@host.nil? && @host.compute_resource_id
                @compute_resource = get_compute_resource_for_host(@host)
        Severity: Minor
        Found in app/controllers/foreman_xen/snapshots_controller.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 destroy has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def destroy
              ref               = params[:ref]
              id                = params[:id]
              @host             = get_host_by_id(id)
              @compute_resource = get_compute_resource_by_host_id(id)
        Severity: Minor
        Found in app/controllers/foreman_xen/snapshots_controller.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 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

          Function refreshCache has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function refreshCache(item) {
            tfm.tools.showSpinner();
            attribute_name = $(item).data('attribute');
            sel = $(item).closest('.input-group').children('select')
            data = {
          Severity: Minor
          Found in app/assets/javascripts/foreman_xen/xenserver/cache_refresh.js - About 1 hr to fix

            Function refreshCache has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            function refreshCache(item) {
              tfm.tools.showSpinner();
              attribute_name = $(item).data('attribute');
              sel = $(item).closest('.input-group').children('select')
              data = {
            Severity: Minor
            Found in app/assets/javascripts/foreman_xen/xenserver/cache_refresh.js - 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 has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def create
                  id   = params[:id]
                  name = params[:name]
                  process_error(:error_msg => 'You must supply a name.') if name.nil? || name == ''
                  @host = get_host_by_id(id)
            Severity: Minor
            Found in app/controllers/foreman_xen/snapshots_controller.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 listen_from_server has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def listen_from_server
                logger.debug 'VNCTunnel Server is listening'
                begin
                  while @read_from_server
                    begin
            Severity: Minor
            Found in lib/foreman_xen/vnc_tunnel.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 start has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def start
                client_srv = TCPServer.new('127.0.0.1', port)
                thr        = Thread.new do
                  req         = "CONNECT #{@uri.path}?#{@uri.query} HTTP/1.1\r\n\r\n"
                  @srv_socket = TCPSocket.open(@uri.host, 80)
            Severity: Minor
            Found in lib/foreman_xen/vnc_tunnel.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 selectable_f_with_cache_invalidation has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def selectable_f_with_cache_invalidation(f, attr, array,
                                                       select_options = {}, html_options = {}, input_group_options = {})
            Severity: Minor
            Found in app/helpers/xen_compute_helper.rb - About 45 mins to fix

              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 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 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 listen has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def listen(client_srv)
                    @client_socket = client_srv.accept
                    logger.debug 'VNCTunnel Client: client accepted'
                    server_listen_thr = Thread.new do
                      listen_from_server
                Severity: Minor
                Found in lib/foreman_xen/vnc_tunnel.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 snapshots_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def snapshots_url
                      case params[:action]
                      when 'show'
                        '/'
                      when 'new'
                Severity: Minor
                Found in app/controllers/foreman_xen/snapshots_controller.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

                Severity
                Category
                Status
                Source
                Language