saltstack/salt

View on GitHub
salt/cloud/clouds/libvirt.py

Summary

Maintainability
F
5 days
Test Coverage

File libvirt.py has 506 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Libvirt Cloud Module
====================

Severity: Major
Found in salt/cloud/clouds/libvirt.py - About 1 day to fix

    Function create has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
    Open

    def create(vm_):
        '''
        Provision a single machine
        '''
        clone_strategy = vm_.get('clone_strategy') or 'full'
    Severity: Minor
    Found in salt/cloud/clouds/libvirt.py - About 7 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

    Cyclomatic complexity is too high in function create. (30)
    Open

    def create(vm_):
        '''
        Provision a single machine
        '''
        clone_strategy = vm_.get('clone_strategy') or 'full'
    Severity: Minor
    Found in salt/cloud/clouds/libvirt.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function do_cleanup has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def do_cleanup(cleanup):
        '''
        Clean up clone domain leftovers as much as possible.
    
        Extra robust clean up in order to deal with some small changes in libvirt
    Severity: Minor
    Found in salt/cloud/clouds/libvirt.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 get_domain_ips has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_domain_ips(domain, ip_source):
        ips = []
        state = domain.state(0)
        if state[0] != libvirt.VIR_DOMAIN_RUNNING:
            return ips
    Severity: Minor
    Found in salt/cloud/clouds/libvirt.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 destroy has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def destroy(name, call=None):
        """
        This function irreversibly destroys a virtual machine on the cloud provider.
        Before doing so, it should fire an event on the Salt event bus.
    
    
    Severity: Minor
    Found in salt/cloud/clouds/libvirt.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

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

    def get_domain_volumes(conn, domain):
        volumes = []
        xml = ElementTree.fromstring(domain.XMLDesc(0))
        for disk in xml.findall("""./devices/disk[@device='disk'][@type='file']"""):
            if disk.find("./driver[@name='qemu'][@type='qcow2']") is not None:
    Severity: Minor
    Found in salt/cloud/clouds/libvirt.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

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

    def find_pool_and_volume(conn, path):
        # active and persistent storage pools
        # TODO: should we filter on type?
        for sp in conn.listAllStoragePools(2+4):
            for v in sp.listAllVolumes():
    Severity: Minor
    Found in salt/cloud/clouds/libvirt.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 create_volume_with_backing_store_xml(volume):
        template = """<volume>
                        <name>n</name>
                        <capacity>c</capacity>
                        <allocation>0</allocation>
    Severity: Major
    Found in salt/cloud/clouds/libvirt.py and 1 other location - About 1 day to fix
    salt/cloud/clouds/libvirt.py on lines 602..622

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

    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 create_volume_xml(volume):
        template = """<volume>
                        <name>n</name>
                        <capacity>c</capacity>
                        <allocation>0</allocation>
    Severity: Major
    Found in salt/cloud/clouds/libvirt.py and 1 other location - About 1 day to fix
    salt/cloud/clouds/libvirt.py on lines 625..648

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

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

                __utils__['cloud.fire_event'](
                    'event',
                    'requesting instance',
                    'salt/cloud/{0}/requesting'.format(name),
                    args={
    Severity: Major
    Found in salt/cloud/clouds/libvirt.py and 2 other locations - About 3 hrs to fix
    salt/cloud/clouds/softlayer.py on lines 401..409
    salt/cloud/clouds/softlayer_hw.py on lines 324..332

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

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

            __utils__['cloud.fire_event'](
                'event',
                'created instance',
                'salt/cloud/{0}/created'.format(name),
                args=__utils__['cloud.filter_event']('created', vm_, ['name', 'profile', 'provider', 'driver']),
    Severity: Major
    Found in salt/cloud/clouds/libvirt.py and 10 other locations - About 2 hrs to fix
    salt/cloud/clouds/libvirt.py on lines 309..315
    salt/cloud/clouds/linode.py on lines 341..347
    salt/cloud/clouds/linode.py on lines 430..436
    salt/cloud/clouds/linode.py on lines 528..534
    salt/cloud/clouds/packet.py on lines 334..340
    salt/cloud/clouds/packet.py on lines 426..432
    salt/cloud/clouds/softlayer.py on lines 272..278
    salt/cloud/clouds/softlayer.py on lines 514..520
    salt/cloud/clouds/softlayer_hw.py on lines 240..246
    salt/cloud/clouds/softlayer_hw.py on lines 416..422

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

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

        __utils__['cloud.fire_event'](
            'event',
            'starting create',
            'salt/cloud/{0}/creating'.format(name),
            args=__utils__['cloud.filter_event']('creating', vm_, ['name', 'profile', 'provider', 'driver']),
    Severity: Major
    Found in salt/cloud/clouds/libvirt.py and 10 other locations - About 2 hrs to fix
    salt/cloud/clouds/libvirt.py on lines 459..465
    salt/cloud/clouds/linode.py on lines 341..347
    salt/cloud/clouds/linode.py on lines 430..436
    salt/cloud/clouds/linode.py on lines 528..534
    salt/cloud/clouds/packet.py on lines 334..340
    salt/cloud/clouds/packet.py on lines 426..432
    salt/cloud/clouds/softlayer.py on lines 272..278
    salt/cloud/clouds/softlayer.py on lines 514..520
    salt/cloud/clouds/softlayer_hw.py on lines 240..246
    salt/cloud/clouds/softlayer_hw.py on lines 416..422

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

    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

        try:
            # Check for required profile parameters before sending any API calls.
            if vm_['profile'] and config.is_profile_configured(__opts__,
                                                               __active_provider_name__ or 'libvirt',
                                                               vm_['profile']) is False:
    Severity: Major
    Found in salt/cloud/clouds/libvirt.py and 5 other locations - About 1 hr to fix
    salt/cloud/clouds/dimensiondata.py on lines 197..204
    salt/cloud/clouds/oneandone.py on lines 745..753
    salt/cloud/clouds/opennebula.py on lines 997..1003
    salt/cloud/clouds/profitbricks.py on lines 821..829
    salt/cloud/clouds/virtualbox.py on lines 144..152

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

    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 __virtual__():
        '''
        This function determines whether or not
        to make this cloud module available upon execution.
        Most often, it uses get_configured_provider() to determine
    Severity: Minor
    Found in salt/cloud/clouds/libvirt.py and 1 other location - About 40 mins to fix
    salt/cloud/clouds/virtualbox.py on lines 56..77

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

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

        if key_filename is not None and not os.path.isfile(key_filename):
            raise SaltCloudConfigError(
                'The defined key_filename \'{0}\' does not exist'.format(
    Severity: Major
    Found in salt/cloud/clouds/libvirt.py and 7 other locations - About 30 mins to fix
    salt/cloud/clouds/digitalocean.py on lines 327..329
    salt/cloud/clouds/nova.py on lines 952..954
    salt/cloud/clouds/opennebula.py on lines 1125..1127
    salt/cloud/clouds/openstack.py on lines 675..677
    salt/cloud/clouds/scaleway.py on lines 223..225
    salt/utils/cloud.py on lines 414..416
    salt/utils/cloud.py on lines 1463..1465

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

    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