saltstack/salt

View on GitHub
salt/modules/netbox.py

Summary

Maintainability
F
5 days
Test Coverage

File netbox.py has 914 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
NetBox
======

Severity: Major
Found in salt/modules/netbox.py - About 2 days to fix

    Function openconfig_interfaces has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def openconfig_interfaces(device_name=None):
        '''
        .. versionadded:: 2019.2.0
    
        Return a dictionary structured as standardised in the
    Severity: Minor
    Found in salt/modules/netbox.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 create_interface has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_interface(device_name,
                         interface_name,
                         mac_address=None,
                         description=None,
                         enabled=None,
    Severity: Minor
    Found in salt/modules/netbox.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 create_circuit_provider has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_circuit_provider(name, asn=None):
        '''
        .. versionadded:: 2019.2.0
    
        Create a new Netbox circuit provider
    Severity: Minor
    Found in salt/modules/netbox.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 create_ipaddress has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_ipaddress(ip_address, family, device=None, interface=None):
        '''
        .. versionadded:: 2019.2.0
    
        Add an IP address, and optionally attach it to an interface.
    Severity: Minor
    Found in salt/modules/netbox.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 create_circuit has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_circuit(name, provider_id, circuit_type, description=None):
        '''
        .. versionadded:: 2019.2.0
    
        Create a new Netbox circuit
    Severity: Minor
    Found in salt/modules/netbox.py - About 55 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 create_circuit_termination has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_circuit_termination(circuit, interface, device, speed, xconnect_id=None, term_side='A'):
        '''
        .. versionadded:: 2019.2.0
    
        Terminate a circuit on an interface
    Severity: Minor
    Found in salt/modules/netbox.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 create_inventory_item has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_inventory_item(device_name,
                              item_name,
                              manufacturer_name=None,
                              serial='',
                              part_id='',
    Severity: Minor
    Found in salt/modules/netbox.py - 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

    Function update_interface has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def update_interface(device_name, interface_name, **kwargs):
        '''
        .. versionadded:: 2019.2.0
    
        Update an existing interface with new attributes.
    Severity: Minor
    Found in salt/modules/netbox.py - 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

    Avoid too many return statements within this function.
    Open

            return False
    Severity: Major
    Found in salt/modules/netbox.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return {'dcim': {'devices': payload}}
      Severity: Major
      Found in salt/modules/netbox.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return ipaddr
        Severity: Major
        Found in salt/modules/netbox.py - About 30 mins to fix

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

          def create_device(name,
                            role,
                            model,
                            manufacturer,
                            site):
          Severity: Minor
          Found in salt/modules/netbox.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_site(site):
              '''
              .. versionadded:: 2019.2.0
          
              Create a new device site
          Severity: Major
          Found in salt/modules/netbox.py and 1 other location - About 3 hrs to fix
          salt/modules/netbox.py on lines 197..221

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

          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_manufacturer(name):
              '''
              .. versionadded:: 2019.2.0
          
              Create a device manufacturer.
          Severity: Major
          Found in salt/modules/netbox.py and 1 other location - About 3 hrs to fix
          salt/modules/netbox.py on lines 313..337

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

          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 get_ipaddresses(device_name=None, **kwargs):
              '''
              .. versionadded:: 2019.2.0
          
              Filters for an IP address using specified filters
          Severity: Major
          Found in salt/modules/netbox.py and 1 other location - About 2 hrs to fix
          salt/modules/netbox.py on lines 522..545

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

          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 get_interfaces(device_name=None, **kwargs):
              '''
              .. versionadded:: 2019.2.0
          
              Returns interfaces for a specific device using arbitrary netbox filters
          Severity: Major
          Found in salt/modules/netbox.py and 1 other location - About 2 hrs to fix
          salt/modules/netbox.py on lines 881..903

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

          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