fog/fog-vsphere

View on GitHub

Showing 128 of 128 total issues

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

        def list_virtual_machines(options = {})
          if options['instance_uuid']
            server = data[:servers][options['instance_uuid']]
            server.nil? ? [] : [server]
          elsif options['mo_ref']
Severity: Minor
Found in lib/fog/vsphere/requests/compute/list_virtual_machines.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

Avoid deeply nested control flow statements.
Open

                raise ArgumentError, "Unsupported autoMode, supported modes are : 'perSeat' or 'perServer'" unless %w[perSeat perServer].include? identity['Sysprep']['licenseFilePrintData']['autoMode']
Severity: Major
Found in lib/fog/vsphere/requests/compute/vm_clone.rb - About 45 mins to fix

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

                    new_vm = nil
                    Fog.wait_for(150, 15) do
                      begin
                        (new_vm = dest_folder.find(options['name'], RbVmomi::VIM::VirtualMachine)) || raise(Fog::Vsphere::Errors::NotFound)
                      rescue Fog::Vsphere::Errors::NotFound
    Severity: Minor
    Found in lib/fog/vsphere/requests/compute/vm_clone.rb and 1 other location - About 45 mins to fix
    lib/fog/vsphere/requests/compute/vm_clone.rb on lines 730..738

    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 39.

    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

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

                  new_vm = nil
                  Fog.wait_for(150, 15) do
                    begin
                      (new_vm = dest_folder.find(options['name'], RbVmomi::VIM::VirtualMachine)) || raise(Fog::Vsphere::Errors::NotFound)
                    rescue Fog::Vsphere::Errors::NotFound
    Severity: Minor
    Found in lib/fog/vsphere/requests/compute/vm_clone.rb and 1 other location - About 45 mins to fix
    lib/fog/vsphere/requests/compute/vm_clone.rb on lines 684..692

    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 39.

    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

    Consider simplifying this complex logical expression.
    Open

              if options.is_a? Fog::Vsphere::Compute::Interface
                options
    
              else
                raise ArgumentError, "Either key or name is a required parameter. options: #{options}" unless options.key?(:key) || options.key?(:mac) || options.key?(:name)
    Severity: Major
    Found in lib/fog/vsphere/requests/compute/list_vm_interfaces.rb - About 40 mins to fix

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

            class Real
              def vm_reconfig_cpus(options = {})
                raise ArgumentError, 'cpus is a required parameter' unless options.key? 'cpus'
                raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
                hardware_spec = { 'numCPUs' => options['cpus'], 'numCoresPerSocket' => options['corespersocket'] }
      Severity: Minor
      Found in lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb and 1 other location - About 40 mins to fix
      lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb on lines 13..18

      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 37.

      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

            class Mock
              def vm_reconfig_cpus(options = {})
                raise ArgumentError, 'cpus is a required parameter' unless options.key? 'cpus'
                raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
                hardware_spec = { 'numCPUs' => options['cpus'], 'numCoresPerSocket' => options['corespersocket'] }
      Severity: Minor
      Found in lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb and 1 other location - About 40 mins to fix
      lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb on lines 4..9

      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 37.

      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

      Method host_start_maintenance has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              def host_start_maintenance(name, cluster_name, datacenter_name, timeout = 0, evacuate_powered_off_vms = false)
      Severity: Minor
      Found in lib/fog/vsphere/requests/compute/host_start_maintenance.rb - About 35 mins to fix

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

                def connect
                  # This is a state variable to allow digest validation of the SSL cert
                  bad_cert = false
                  loop do
                    begin
        Severity: Minor
        Found in lib/fog/vsphere/compute.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 list_datastores has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def list_datastores(filters = {})
                  datacenter_name = filters[:datacenter]
                  cluster_name = filters.fetch(:cluster, nil)
                  # default to show all datastores
                  only_active = filters[:accessible] || false
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/list_datastores.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 save has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def save
                  raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted?
                  requires :server_id, :type, :network
        
                  # Our approach of finding the newly created interface is rough.  We assume that the :key value always increments
        Severity: Minor
        Found in lib/fog/vsphere/models/compute/interface.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 create_controller has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def create_controller(controller = nil, index = 0)
                  options = if controller
                              controller_default_options.merge(controller.attributes)
                            else
                              controller_default_options
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/create_vm.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 class_from_string has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.class_from_string(name, default_path = '')
              const = default_path.empty? ? name.to_s : "#{default_path}::#{name}"
              klass = const.split('::').inject(Object) { |m, c| m.const_get(c) }
              return klass unless klass == Object
            rescue NameError
        Severity: Minor
        Found in lib/fog/vsphere.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 upload_iso_check_options has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def upload_iso_check_options(options)
                  default_options = {
                    'upload_directory' => 'isos'
                  }
                  options = default_options.merge(options)
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/upload_iso.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_vm_interfaces_specs has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def update_vm_interfaces_specs(vm_mob_ref, fog_interfaces, datacenter)
                  vm_nics = vm_mob_ref.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard)
                  modified_nics = fog_interfaces.to_a.take(vm_nics.size)
                  new_nics = fog_interfaces.to_a.drop(vm_nics.size)
        
        
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/update_vm.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 create_disk has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def create_disk(disk, operation = :add, options = {})
                  # If we deploy the vm on a storage pod, datastore has to be an empty string
                  datastore = if options[:storage_pod]
                                ''
                              else
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/create_vm.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

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

              class Real
                def add_vm_cdrom(cdrom)
                  vm_reconfig_hardware('instance_uuid' => cdrom.server.instance_uuid, 'hardware_spec' => { 'deviceChange' => [create_cdrom(cdrom, cdrom.unit_number, :add)] })
                end
        
        
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb and 1 other location - About 35 mins to fix
        lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb on lines 14..20

        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 35.

        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

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

                def modify_template_volumes_specs(vm_mob_ref, volumes)
                  template_volumes = vm_mob_ref.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
        
                  specs = []
                  template_volumes.zip(modified_volumes(vm_mob_ref, volumes)).each do |template_volume, new_volume|
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/vm_clone.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

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

              class Mock
                def add_vm_cdrom(cdrom)
                  vm_reconfig_hardware('instance_uuid' => cdrom.server.instance_uuid, 'hardware_spec' => { 'deviceChange' => [create_cdrom(cdrom, cdrom.unit_number, :add)] })
                end
        
        
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb and 1 other location - About 35 mins to fix
        lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb on lines 4..10

        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 35.

        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

              class Real
                def vm_reconfig_memory(options = {})
                  raise ArgumentError, 'memory is a required parameter' unless options.key? 'memory'
                  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
                  hardware_spec = { 'memoryMB' => options['memory'] }
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb and 1 other location - About 30 mins to fix
        lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb on lines 13..18

        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 33.

        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

        Severity
        Category
        Status
        Source
        Language