cloudfoundry-community/bosh-cloudstack-cpi

View on GitHub
bosh_vsphere_cpi/lib/cloud/vsphere/client.rb

Summary

Maintainability
D
2 days
Test Coverage

File client.rb has 397 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'ruby_vim_sdk'

module VSphereCloud

  class Client
Severity: Minor
Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb - About 5 hrs to fix

    Method get_search_filter_spec has 97 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def get_search_filter_spec(obj, property_specs)
          resource_pool_traversal_spec = PC::TraversalSpec.new(
              :name => "resourcePoolTraversalSpec",
              :type => Vim::ResourcePool,
              :path => "resourcePool",
    Severity: Major
    Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb - About 3 hrs to fix

      Class Client has 29 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class Client
          include VimSdk
          PC = Vmodl::Query::PropertyCollector
      
          class AlreadyLoggedInException < StandardError; end
      Severity: Minor
      Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb - About 3 hrs to fix

        Method get_properties has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_properties(obj, type, properties, options = {})
              properties = [properties] if properties.kind_of?(String)
              property_specs = [PC::PropertySpec.new(:type => type, :all => false, :path_set => properties)]
        
              if obj.is_a?(Vmodl::ManagedObject)
        Severity: Minor
        Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.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 get_properties has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def get_properties(obj, type, properties, options = {})
              properties = [properties] if properties.kind_of?(String)
              property_specs = [PC::PropertySpec.new(:type => type, :all => false, :path_set => properties)]
        
              if obj.is_a?(Vmodl::ManagedObject)
        Severity: Minor
        Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb - About 1 hr to fix

          Method wait_for_task has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def wait_for_task(task)
                interval = 1.0
                started = Time.now
                loop do
                  properties = get_properties([task], Vim::Task, ["info.progress", "info.state", "info.result", "info.error"],
          Severity: Minor
          Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.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 wait_for_task has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def wait_for_task(task)
                interval = 1.0
                started = Time.now
                loop do
                  properties = get_properties([task], Vim::Task, ["info.progress", "info.state", "info.result", "info.error"],
          Severity: Minor
          Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb - About 1 hr to fix

            Method get_perf_counters has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def get_perf_counters(mobs, names, options = {})
                  metrics = find_perf_metric_names(mobs.first, names)
                  metric_ids = metrics.values
            
                  metric_name_by_id = {}
            Severity: Minor
            Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb - About 1 hr to fix

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

                  def get_managed_objects(type, options={})
                    root = options[:root] || @service_content.root_folder
                    property_specs = [PC::PropertySpec.new(:type => type, :all => false, :path_set => ["name"])]
                    filter_spec = get_search_filter_spec(root, property_specs)
                    object_specs = get_all_properties(filter_spec)
              Severity: Minor
              Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.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

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

                  def copy_disk(source_datacenter, source_path, dest_datacenter, dest_path)
                    tasks = []
                    [".vmdk", "-flat.vmdk"].each do |extension|
                      tasks << @service_content.file_manager.copy_file("#{source_path}#{extension}", source_datacenter,
                                                                       "#{dest_path}#{extension}", dest_datacenter, false)
              Severity: Minor
              Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb and 1 other location - About 35 mins to fix
              bosh_vsphere_cpi/lib/cloud/vsphere/client.rb on lines 199..206

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

              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

                  def move_disk(source_datacenter, source_path, dest_datacenter, dest_path)
                    tasks = []
                    [".vmdk", "-flat.vmdk"].each do |extension|
                      tasks << @service_content.file_manager.move_file("#{source_path}#{extension}", source_datacenter,
                                                                       "#{dest_path}#{extension}", dest_datacenter, false)
              Severity: Minor
              Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb and 1 other location - About 35 mins to fix
              bosh_vsphere_cpi/lib/cloud/vsphere/client.rb on lines 209..216

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

              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

                    resource_pool_traversal_spec = PC::TraversalSpec.new(
                        :name => "resourcePoolTraversalSpec",
                        :type => Vim::ResourcePool,
                        :path => "resourcePool",
                        :skip => false,
              Severity: Minor
              Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb and 1 other location - About 20 mins to fix
              bosh_vsphere_cpi/lib/cloud/vsphere/client.rb on lines 297..306

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

              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

                    compute_resource_rp_traversal_spec = PC::TraversalSpec.new(
                        :name => "computeResourceRpTraversalSpec",
                        :type => Vim::ComputeResource,
                        :path => "resourcePool",
                        :skip => false,
              Severity: Minor
              Found in bosh_vsphere_cpi/lib/cloud/vsphere/client.rb and 1 other location - About 20 mins to fix
              bosh_vsphere_cpi/lib/cloud/vsphere/client.rb on lines 279..288

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

              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