cloudfoundry-community/bosh-cloudstack-cpi

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

Summary

Maintainability
F
6 days
Test Coverage

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

require 'json'
require 'membrane'
require 'ruby_vim_sdk'
require 'cloud'
require 'cloud/vsphere/retry_block'
Severity: Major
Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 1 day to fix

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

      class Cloud < Bosh::Cloud
        include VimSdk
        include RetryBlock
    
        class TimeoutException < StandardError;
    Severity: Minor
    Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 5 hrs to fix

      Method attach_disk has 72 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def attach_disk(vm_cid, disk_cid)
            with_thread_name("attach_disk(#{vm_cid}, #{disk_cid})") do
              @logger.info("Attaching disk: #{disk_cid} on vm: #{vm_cid}")
              disk = Models::Disk.first(uuid: disk_cid)
              raise "Disk not found: #{disk_cid}" if disk.nil?
      Severity: Major
      Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 2 hrs to fix

        Method configure_networks has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def configure_networks(vm_cid, networks)
              with_thread_name("configure_networks(#{vm_cid}, ...)") do
                vm = get_vm_by_cid(vm_cid)
        
                @logger.debug('Waiting for the VM to shutdown')
        Severity: Major
        Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 2 hrs to fix

          Method delete_vm has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def delete_vm(vm_cid)
                with_thread_name("delete_vm(#{vm_cid})") do
                  @logger.info("Deleting vm: #{vm_cid}")
          
                  vm = get_vm_by_cid(vm_cid)
          Severity: Major
          Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 2 hrs to fix

            Method attach_disk has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                def attach_disk(vm_cid, disk_cid)
                  with_thread_name("attach_disk(#{vm_cid}, #{disk_cid})") do
                    @logger.info("Attaching disk: #{disk_cid} on vm: #{vm_cid}")
                    disk = Models::Disk.first(uuid: disk_cid)
                    raise "Disk not found: #{disk_cid}" if disk.nil?
            Severity: Minor
            Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.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 replicate_stemcell has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def replicate_stemcell(cluster, datastore, stemcell)
                  stemcell_vm = client.find_by_inventory_path([cluster.datacenter.name, 'vm',
                                                               cluster.datacenter.template_folder.name, stemcell])
                  raise "Could not find stemcell: #{stemcell}" if stemcell_vm.nil?
                  stemcell_datastore = client.get_property(stemcell_vm, Vim::VirtualMachine, 'datastore', ensure_all: true)
            Severity: Minor
            Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 1 hr to fix

              Method delete_vm has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  def delete_vm(vm_cid)
                    with_thread_name("delete_vm(#{vm_cid})") do
                      @logger.info("Deleting vm: #{vm_cid}")
              
                      vm = get_vm_by_cid(vm_cid)
              Severity: Minor
              Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.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 replicate_stemcell has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  def replicate_stemcell(cluster, datastore, stemcell)
                    stemcell_vm = client.find_by_inventory_path([cluster.datacenter.name, 'vm',
                                                                 cluster.datacenter.template_folder.name, stemcell])
                    raise "Could not find stemcell: #{stemcell}" if stemcell_vm.nil?
                    stemcell_datastore = client.get_property(stemcell_vm, Vim::VirtualMachine, 'datastore', ensure_all: true)
              Severity: Minor
              Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.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 set_vm_metadata has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  def set_vm_metadata(vm_cid, metadata)
                    with_thread_name("set_vm_metadata(#{vm_cid}, ...)") do
                      begin
                        fields_manager = client.service_content.custom_fields_manager
                        custom_fields = fields_manager.field
              Severity: Minor
              Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.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 create_stemcell has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def create_stemcell(image, _)
                    with_thread_name("create_stemcell(#{image}, _)") do
                      result = nil
                      Dir.mktmpdir do |temp_dir|
                        @logger.info("Extracting stemcell to: #{temp_dir}")
              Severity: Minor
              Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 1 hr to fix

                Method detach_disk has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def detach_disk(vm_cid, disk_cid)
                      with_thread_name("detach_disk(#{vm_cid}, #{disk_cid})") do
                        @logger.info("Detaching disk: #{disk_cid} from vm: #{vm_cid}")
                        disk = Models::Disk.first(uuid: disk_cid)
                        raise "Disk not found: #{disk_cid}" if disk.nil?
                Severity: Minor
                Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 1 hr to fix

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

                      def detach_disk(vm_cid, disk_cid)
                        with_thread_name("detach_disk(#{vm_cid}, #{disk_cid})") do
                          @logger.info("Detaching disk: #{disk_cid} from vm: #{vm_cid}")
                          disk = Models::Disk.first(uuid: disk_cid)
                          raise "Disk not found: #{disk_cid}" if disk.nil?
                  Severity: Minor
                  Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.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 upload_ovf has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def upload_ovf(ovf, lease, file_items)
                        info = client.get_property(lease, Vim::HttpNfcLease, 'info', ensure_all: true)
                        lease_updater = LeaseUpdater.new(client, lease)
                  
                        info.device_url.each do |device_url|
                  Severity: Minor
                  Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 1 hr to fix

                    Method delete_disk has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def delete_disk(disk_cid)
                          with_thread_name("delete_disk(#{disk_cid})") do
                            @logger.info("Deleting disk: #{disk_cid}")
                            disk = Models::Disk.first(uuid: disk_cid)
                            if disk
                    Severity: Minor
                    Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.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 configure_networks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def configure_networks(vm_cid, networks)
                          with_thread_name("configure_networks(#{vm_cid}, ...)") do
                            vm = get_vm_by_cid(vm_cid)
                    
                            @logger.debug('Waiting for the VM to shutdown')
                    Severity: Minor
                    Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.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 create_nic_config_spec has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def create_nic_config_spec(v_network_name, network, controller_key, dvs_index)
                          raise "Can't find network: #{v_network_name}" if network.nil?
                          if network.class == Vim::Dvs::DistributedVirtualPortgroup
                            portgroup_properties = client.get_properties(network,
                                                                         Vim::Dvs::DistributedVirtualPortgroup,
                    Severity: Minor
                    Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 1 hr to fix

                      Method set_vm_metadata has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          def set_vm_metadata(vm_cid, metadata)
                            with_thread_name("set_vm_metadata(#{vm_cid}, ...)") do
                              begin
                                fields_manager = client.service_content.custom_fields_manager
                                custom_fields = fields_manager.field
                      Severity: Minor
                      Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 1 hr to fix

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

                            def get_primary_datastore(devices)
                              ephemeral_disks = devices.select { |device| device.kind_of?(Vim::Vm::Device::VirtualDisk) &&
                                device.backing.disk_mode != Vim::Vm::Device::VirtualDiskOption::DiskMode::INDEPENDENT_PERSISTENT }
                        
                              datastore = nil
                        Severity: Minor
                        Found in bosh_vsphere_cpi/lib/cloud/vsphere/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 create_vm has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            def create_vm(agent_id, stemcell, cloud_properties, networks, disk_locality = nil, environment = nil)
                        Severity: Minor
                        Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 45 mins to fix

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

                              def fix_device_unit_numbers(devices, device_changes)
                                controllers_available_unit_numbers = Hash.new { |h,k| h[k] = (0..15).to_a }
                                devices.each do |device|
                                  if device.controller_key
                                    available_unit_numbers = controllers_available_unit_numbers[device.controller_key]
                          Severity: Minor
                          Found in bosh_vsphere_cpi/lib/cloud/vsphere/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 create_disk_config_spec has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              def create_disk_config_spec(datastore, file_name, controller_key, space, options = {})
                          Severity: Minor
                          Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 35 mins to fix

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

                                def generate_agent_env(name, vm, agent_id, networking_env, disk_env)
                            Severity: Minor
                            Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 35 mins to fix

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

                                  def clone_vm(vm, name, folder, resource_pool, options={})
                              Severity: Minor
                              Found in bosh_vsphere_cpi/lib/cloud/vsphere/cloud.rb - About 35 mins to fix

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

                                    def get_vm_location(vm, options = {})
                                      datacenter_name = options[:datacenter]
                                      datastore_name = options[:datastore]
                                      vm_name = options[:vm]
                                
                                
                                Severity: Minor
                                Found in bosh_vsphere_cpi/lib/cloud/vsphere/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 generate_network_env has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    def generate_network_env(devices, networks, dvs_index)
                                      nics = {}
                                
                                      devices.each do |device|
                                        if device.kind_of?(Vim::Vm::Device::VirtualEthernetCard)
                                Severity: Minor
                                Found in bosh_vsphere_cpi/lib/cloud/vsphere/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 reboot_vm has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    def reboot_vm(vm_cid)
                                      with_thread_name("reboot_vm(#{vm_cid})") do
                                        vm = get_vm_by_cid(vm_cid)
                                        datacenter = client.find_parent(vm, Vim::Datacenter)
                                        power_state = client.get_property(vm, Vim::VirtualMachine, 'runtime.powerState')
                                Severity: Minor
                                Found in bosh_vsphere_cpi/lib/cloud/vsphere/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_stemcell has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    def create_stemcell(image, _)
                                      with_thread_name("create_stemcell(#{image}, _)") do
                                        result = nil
                                        Dir.mktmpdir do |temp_dir|
                                          @logger.info("Extracting stemcell to: #{temp_dir}")
                                Severity: Minor
                                Found in bosh_vsphere_cpi/lib/cloud/vsphere/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 clone_vm has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    def clone_vm(vm, name, folder, resource_pool, options={})
                                      relocation_spec = Vim::Vm::RelocateSpec.new
                                      relocation_spec.datastore = options[:datastore] if options[:datastore]
                                      if options[:linked]
                                        relocation_spec.disk_move_type = Vim::Vm::RelocateSpec::DiskMoveOptions::CREATE_NEW_CHILD_DISK_BACKING
                                Severity: Minor
                                Found in bosh_vsphere_cpi/lib/cloud/vsphere/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

                                There are no issues that match your filters.

                                Category
                                Status