cloudfoundry-community/bosh-cloudstack-cpi

View on GitHub
bosh_aws_cpi/lib/cloud/aws/cloud.rb

Summary

Maintainability
D
1 day
Test Coverage

File cloud.rb has 399 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'cloud/aws/stemcell_finder'

module Bosh::AwsCloud

  class Cloud < Bosh::Cloud
Severity: Minor
Found in bosh_aws_cpi/lib/cloud/aws/cloud.rb - About 5 hrs to fix

    Class Cloud has 35 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Cloud < Bosh::Cloud
        include Helpers
    
        # default maximum number of times to retry an AWS API call
        DEFAULT_MAX_RETRIES = 2
    Severity: Minor
    Found in bosh_aws_cpi/lib/cloud/aws/cloud.rb - About 4 hrs to fix

      Method create_vm has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def create_vm(agent_id, stemcell_id, resource_pool, network_spec, disk_locality = nil, environment = nil)
      Severity: Minor
      Found in bosh_aws_cpi/lib/cloud/aws/cloud.rb - About 45 mins to fix

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

            def create_stemcell(image_path, stemcell_properties)
              with_thread_name("create_stemcell(#{image_path}...)") do
                creator = StemcellCreator.new(region, stemcell_properties)
        
                return creator.fake.id if creator.fake?
        Severity: Minor
        Found in bosh_aws_cpi/lib/cloud/aws/cloud.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 current_vm_id has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def current_vm_id
              @metadata_lock.synchronize do
                return @current_vm_id if @current_vm_id
        
                client = HTTPClient.new
        Severity: Minor
        Found in bosh_aws_cpi/lib/cloud/aws/cloud.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 delete_disk has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def delete_disk(disk_id)
              with_thread_name("delete_disk(#{disk_id})") do
                volume = @ec2.volumes[disk_id]
        
                logger.info("Deleting volume `#{volume.id}'")
        Severity: Minor
        Found in bosh_aws_cpi/lib/cloud/aws/cloud.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 set_vm_metadata has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def set_vm_metadata(vm, metadata)
              instance = @ec2.instances[vm]
        
              metadata.each_pair do |key, value|
                TagManager.tag(instance, key, value)
        Severity: Minor
        Found in bosh_aws_cpi/lib/cloud/aws/cloud.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_vm has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def create_vm(agent_id, stemcell_id, resource_pool, network_spec, disk_locality = nil, environment = nil)
              with_thread_name("create_vm(#{agent_id}, ...)") do
                # do this early to fail fast
                stemcell = StemcellFinder.find_by_region_and_id(region, stemcell_id)
        
        
        Severity: Minor
        Found in bosh_aws_cpi/lib/cloud/aws/cloud.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

        Method validate_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_options
              required_keys = {
                  "aws" => ["access_key_id", "secret_access_key", "region", "default_key_name"],
                  "registry" => ["endpoint", "user", "password"],
              }
        Severity: Minor
        Found in bosh_aws_cpi/lib/cloud/aws/cloud.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

        Method snapshot_disk has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def snapshot_disk(disk_id, metadata)
              with_thread_name("snapshot_disk(#{disk_id})") do
                volume = @ec2.volumes[disk_id]
                devices = []
                volume.attachments.each {|attachment| devices << attachment.device}
        Severity: Minor
        Found in bosh_aws_cpi/lib/cloud/aws/cloud.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

            def find_ebs_device(sd_name)
              xvd_name = sd_name.gsub(/^\/dev\/sd/, "/dev/xvd")
        
              DEVICE_POLL_TIMEOUT.times do
                if File.blockdev?(sd_name)
        Severity: Minor
        Found in bosh_aws_cpi/lib/cloud/aws/cloud.rb and 1 other location - About 20 mins to fix
        bosh_cloudstack_cpi/lib/cloud/cloudstack/cloud.rb on lines 626..639

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

        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