fog/fog-vsphere

View on GitHub

Showing 128 of 128 total issues

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

      class Real
        def vm_reboot(options = {})
          options = { 'force' => false }.merge(options)
          raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'

Severity: Major
Found in lib/fog/vsphere/requests/compute/vm_reboot.rb and 1 other location - About 1 hr to fix
lib/fog/vsphere/requests/compute/vm_power_off.rb on lines 4..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 59.

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_power_off(options = {})
          options = { 'force' => false }.merge(options)
          raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'

Severity: Major
Found in lib/fog/vsphere/requests/compute/vm_power_off.rb and 1 other location - About 1 hr to fix
lib/fog/vsphere/requests/compute/vm_reboot.rb on lines 4..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 59.

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 list_networks has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def list_networks(filters = {})
          datacenter_name = filters[:datacenter]
          cluster_name = filters.fetch(:cluster, nil)
          # default to show all networks
          only_active = filters[:accessible] || false
Severity: Minor
Found in lib/fog/vsphere/requests/compute/list_networks.rb - About 1 hr to fix

    Method create_vm has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def create_vm(attributes = {})
              # build up vm configuration
              cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter])
              raise Fog::Vsphere::Compute::NotFound, "Cluster #{attributes[:cluster]} Doesn't Exist in the DC!" unless cluster
    
    
    Severity: Minor
    Found in lib/fog/vsphere/requests/compute/create_vm.rb - About 1 hr to fix

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

            class Mock
              def list_datastores(filters)
                datacenter_name = filters[:datacenter]
                cluster_name = filters.fetch(:cluster, nil)
                if cluster_name.nil?
      Severity: Major
      Found in lib/fog/vsphere/requests/compute/list_datastores.rb and 1 other location - About 1 hr to fix
      lib/fog/vsphere/requests/compute/list_networks.rb on lines 109..119

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

      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 list_networks(filters)
                datacenter_name = filters[:datacenter]
                cluster_name = filters.fetch(:cluster, nil)
                if cluster_name.nil?
      Severity: Major
      Found in lib/fog/vsphere/requests/compute/list_networks.rb and 1 other location - About 1 hr to fix
      lib/fog/vsphere/requests/compute/list_datastores.rb on lines 83..93

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

      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_nics_specs has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def modify_template_nics_specs(vm_mob_ref, nics, datacenter)
                specs = []
                template_nics = vm_mob_ref.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard)
                modified_nics = nics.take(template_nics.size)
                new_nics      = nics.drop(template_nics.size)
      Severity: Minor
      Found in lib/fog/vsphere/requests/compute/vm_clone.rb - About 1 hr to fix

        Method list_folders has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

                def list_folders(filters = {})
                  path            = filters[:path] || filters['path'] || ''
                  datacenter_name = filters[:datacenter]
        
                  # if we don't need to display folders for a specific path
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/list_folders.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 get_vm_by_name has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

                def get_vm_by_name(name, dc, folder, recursive)
                  vms = if folder
                          # This returns an Enumerator, which when called with .find will
                          # search only until it finds the VM we're looking for
                          raw_list_all_virtual_machines_in_folder(folder, dc, recursive)
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/get_virtual_machine.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 vm_relocate has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def vm_relocate(options = {})
                  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
        
                  # Find the VM Object
                  search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
        Severity: Minor
        Found in lib/fog/vsphere/requests/compute/vm_relocate.rb - About 1 hr to fix

          Method connect has 30 lines of code (exceeds 25 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 1 hr to fix

            Method vm_clone_check_options has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def vm_clone_check_options(options)
                      default_options = {
                        'force'        => false,
                        'linked_clone' => false,
                        'nic_type' => 'VirtualE1000'
            Severity: Minor
            Found in lib/fog/vsphere/requests/compute/vm_clone.rb - About 1 hr to fix

              Method list_hosts has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      def list_hosts(filters = {})
                        cluster = get_raw_cluster(filters[:cluster], filters[:datacenter])
              
                        results = property_collector_results(host_system_filter_spec(cluster))
              
              
              Severity: Minor
              Found in lib/fog/vsphere/requests/compute/list_hosts.rb - About 1 hr to fix

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

                        def get_raw_folder(path, datacenter_name_or_obj, type)
                          # The required path syntax - 'topfolder/subfolder
                
                          # Clean up path to be relative since we're providing datacenter name
                          dc = if datacenter_name_or_obj.is_a?(String)
                Severity: Minor
                Found in lib/fog/vsphere/requests/compute/get_folder.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 modify_template_nics_simple_spec has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        def modify_template_nics_simple_spec(network_label, nic_type, network_adapter_device_key, datacenter)
                          config_spec_operation = RbVmomi::VIM::VirtualDeviceConfigSpecOperation('edit')
                          # Get the portgroup and handle it from there.
                          network = get_raw_network(network_label, datacenter)
                          nic_backing_info = if network.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
                Severity: Minor
                Found in lib/fog/vsphere/requests/compute/vm_clone.rb - About 1 hr to fix

                  Method create_disk has 27 lines of code (exceeds 25 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 1 hr to fix

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

                            def boot_order(attributes, vm_cfg)
                              # attributes[:boot_order] may be an array like this ['network', 'disk']
                              # stating, that we want to prefer network boots over disk boots
                              boot_order = []
                              attributes[:boot_order].each do |boot_device|
                    Severity: Minor
                    Found in lib/fog/vsphere/requests/compute/create_vm.rb - About 1 hr to fix

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

                              def list_vm_volumes(vm_id)
                                get_vm_ref(vm_id).disks.map do |vol|
                                  {
                                    id: vol.backing.uuid,
                                    thin: (begin
                      Severity: Minor
                      Found in lib/fog/vsphere/requests/compute/list_vm_volumes.rb - About 1 hr to fix

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

                                def list_vm_snapshots(vm_id, _opts = {})
                                  [
                                    {
                                      name: 'clean',
                                      quiesced: false,
                        Severity: Minor
                        Found in lib/fog/vsphere/requests/compute/list_vm_snapshots.rb - About 1 hr to fix

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

                                  def vm_reconfig_cdrom(options = {})
                                    raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
                                    if options.key?('iso')
                                      raise ArgumentError, 'datastore is a required parameter' unless options.key? 'datastore'
                                      backing = {
                          Severity: Minor
                          Found in lib/fog/vsphere/requests/compute/vm_reconfig_cdrom.rb - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language