saltstack/salt

View on GitHub
salt/modules/xapi_virt.py

Summary

Maintainability
F
6 days
Test Coverage

File xapi_virt.py has 692 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
This module (mostly) uses the XenAPI to manage Xen virtual machines.

Big fat warning: the XenAPI used in this file is the one bundled with
Severity: Major
Found in salt/modules/xapi_virt.py - About 1 day to fix

    Function vcpu_pin has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def vcpu_pin(vm_, vcpu, cpus):
        '''
        Set which CPUs a VCPU can use.
    
        CLI Example:
    Severity: Minor
    Found in salt/modules/xapi_virt.py - About 3 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

    Function vm_info has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def vm_info(vm_=None):
        '''
        Return detailed information about the vms.
    
        If you pass a VM name in as an argument then it will return info
    Severity: Minor
    Found in salt/modules/xapi_virt.py - 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

    Function node_info has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def node_info():
        '''
        Return a dict with information about this node
    
        CLI Example:
    Severity: Minor
    Found in salt/modules/xapi_virt.py - 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

    Function vm_diskstats has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def vm_diskstats(vm_=None):
        '''
        Return disk usage counters used by the vms on this hyper in a
        list of dicts:
    
    
    Severity: Minor
    Found in salt/modules/xapi_virt.py - 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

    Function _check_xenapi has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def _check_xenapi():
        if __grains__.get('os') == 'Debian':
            debian_xen_version = '/usr/lib/xen-common/bin/xen-version'
            if os.path.isfile(debian_xen_version):
                # __salt__ is not available in __virtual__
    Severity: Minor
    Found in salt/modules/xapi_virt.py - 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

    Function vm_netstats has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def vm_netstats(vm_=None):
        '''
        Return combined network counters used by the vms on this hyper in a
        list of dicts:
    
    
    Severity: Minor
    Found in salt/modules/xapi_virt.py - 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 too many return statements within this function.
    Open

        return 'xenstore' in __salt__['cmd.run'](__grains__['ps'])
    Severity: Major
    Found in salt/modules/xapi_virt.py - About 30 mins to fix

      Function vm_cputime has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def vm_cputime(vm_=None):
          '''
          Return cputime used by the vms on this hyper in a
          list of dicts:
      
      
      Severity: Minor
      Found in salt/modules/xapi_virt.py - 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 is_hyper():
          '''
          Returns a bool whether or not this node is a hypervisor of any kind
      
          CLI Example:
      Severity: Major
      Found in salt/modules/xapi_virt.py and 1 other location - About 6 hrs to fix
      salt/modules/virt.py on lines 3573..3590

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

      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 6 locations. Consider refactoring.
      Open

      def resume(vm_):
          '''
          Resume the named vm
      
          CLI Example:
      Severity: Major
      Found in salt/modules/xapi_virt.py and 5 other locations - About 2 hrs to fix
      salt/modules/xapi_virt.py on lines 576..594
      salt/modules/xapi_virt.py on lines 597..615
      salt/modules/xapi_virt.py on lines 656..674
      salt/modules/xapi_virt.py on lines 677..695
      salt/modules/xapi_virt.py on lines 739..758

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

      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 6 locations. Consider refactoring.
      Open

      def reboot(vm_):
          '''
          Reboot a domain via ACPI request
      
          CLI Example:
      Severity: Major
      Found in salt/modules/xapi_virt.py and 5 other locations - About 2 hrs to fix
      salt/modules/xapi_virt.py on lines 576..594
      salt/modules/xapi_virt.py on lines 597..615
      salt/modules/xapi_virt.py on lines 618..636
      salt/modules/xapi_virt.py on lines 677..695
      salt/modules/xapi_virt.py on lines 739..758

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

      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 6 locations. Consider refactoring.
      Open

      def stop(vm_):
          '''
          Hard power down the virtual machine, this is equivalent to pulling the
          power
      
      
      Severity: Major
      Found in salt/modules/xapi_virt.py and 5 other locations - About 2 hrs to fix
      salt/modules/xapi_virt.py on lines 576..594
      salt/modules/xapi_virt.py on lines 597..615
      salt/modules/xapi_virt.py on lines 618..636
      salt/modules/xapi_virt.py on lines 656..674
      salt/modules/xapi_virt.py on lines 677..695

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

      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 6 locations. Consider refactoring.
      Open

      def pause(vm_):
          '''
          Pause the named vm
      
          CLI Example:
      Severity: Major
      Found in salt/modules/xapi_virt.py and 5 other locations - About 2 hrs to fix
      salt/modules/xapi_virt.py on lines 576..594
      salt/modules/xapi_virt.py on lines 618..636
      salt/modules/xapi_virt.py on lines 656..674
      salt/modules/xapi_virt.py on lines 677..695
      salt/modules/xapi_virt.py on lines 739..758

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

      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 6 locations. Consider refactoring.
      Open

      def shutdown(vm_):
          '''
          Send a soft shutdown signal to the named vm
      
          CLI Example:
      Severity: Major
      Found in salt/modules/xapi_virt.py and 5 other locations - About 2 hrs to fix
      salt/modules/xapi_virt.py on lines 597..615
      salt/modules/xapi_virt.py on lines 618..636
      salt/modules/xapi_virt.py on lines 656..674
      salt/modules/xapi_virt.py on lines 677..695
      salt/modules/xapi_virt.py on lines 739..758

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

      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 6 locations. Consider refactoring.
      Open

      def reset(vm_):
          '''
          Reset a VM by emulating the reset button on a physical machine
      
          CLI Example:
      Severity: Major
      Found in salt/modules/xapi_virt.py and 5 other locations - About 2 hrs to fix
      salt/modules/xapi_virt.py on lines 576..594
      salt/modules/xapi_virt.py on lines 597..615
      salt/modules/xapi_virt.py on lines 618..636
      salt/modules/xapi_virt.py on lines 656..674
      salt/modules/xapi_virt.py on lines 739..758

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

      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

                  for vbd in xapi.VM.get_VBDs(vm_uuid):
                      vbd_rec = _get_record(xapi, 'VBD', vbd)
                      ret[vbd_rec['device']] = _get_metrics_record(xapi, 'VBD',
                                                                   vbd_rec)
                      del ret[vbd_rec['device']]['last_updated']
      Severity: Major
      Found in salt/modules/xapi_virt.py and 1 other location - About 1 hr to fix
      salt/modules/xapi_virt.py on lines 869..873

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

      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

                  for vif in vm_rec['VIFs']:
                      vif_rec = _get_record(xapi, 'VIF', vif)
                      ret[vif_rec['device']] = _get_metrics_record(xapi, 'VIF',
                                                                   vif_rec)
                      del ret[vif_rec['device']]['last_updated']
      Severity: Major
      Found in salt/modules/xapi_virt.py and 1 other location - About 1 hr to fix
      salt/modules/xapi_virt.py on lines 916..920

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

      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

              if vm_:
                  info[vm_] = _info(vm_)
              else:
                  for vm_ in list_domains():
                      info[vm_] = _info(vm_)
      Severity: Major
      Found in salt/modules/xapi_virt.py and 1 other location - About 1 hr to fix
      salt/modules/xapi_virt.py on lines 925..929

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

      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

              if vm_:
                  info[vm_] = _info(vm_)
              else:
                  for vm_ in list_domains():
                      info[vm_] = _info(vm_)
      Severity: Major
      Found in salt/modules/xapi_virt.py and 1 other location - About 1 hr to fix
      salt/modules/xapi_virt.py on lines 878..882

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

      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 3 locations. Consider refactoring.
      Open

                  nic[vif_rec['MAC']] = {
                      'mac': vif_rec['MAC'],
                      'device': vif_rec['device'],
                      'mtu': vif_rec['MTU']
      Severity: Major
      Found in salt/modules/xapi_virt.py and 2 other locations - About 45 mins to fix
      salt/cloud/clouds/softlayer.py on lines 215..218
      salt/cloud/clouds/softlayer_hw.py on lines 131..135

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

      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