CiscoUcs/imcsdk

View on GitHub
imcsdk/apis/v2/admin/snmp.py

Summary

Maintainability
F
1 wk
Test Coverage

File snmp.py has 723 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2017 Cisco Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Major
Found in imcsdk/apis/v2/admin/snmp.py - About 1 day to fix

    Function snmp_user_add has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def snmp_user_add(handle, name, security_level,
                      auth=None, auth_pwd=None, change_auth_pwd=False,
                      privacy=None, privacy_pwd=None, change_privacy_pwd=False,
                      **kwargs):
        """
    Severity: Minor
    Found in imcsdk/apis/v2/admin/snmp.py - About 2 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 snmp_trap_add_all has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def snmp_trap_add_all(handle, traps=None):
        """
        Adds snmp trap.
    
        Args:
    Severity: Minor
    Found in imcsdk/apis/v2/admin/snmp.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 snmp_user_add has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def snmp_user_add(handle, name, security_level,
    Severity: Major
    Found in imcsdk/apis/v2/admin/snmp.py - About 1 hr to fix

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

      def snmp_user_add_all(handle, users=None):
          """
          Adds snmp user.
      
          Args:
      Severity: Minor
      Found in imcsdk/apis/v2/admin/snmp.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 snmp_enable has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def snmp_enable(handle, port=None, community=None,
      Severity: Major
      Found in imcsdk/apis/v2/admin/snmp.py - About 1 hr to fix

        Function snmp_trap_add has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def snmp_trap_add(handle, hostname, version, notification_type,
        Severity: Major
        Found in imcsdk/apis/v2/admin/snmp.py - About 1 hr to fix

          Function snmp_user_exists has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def snmp_user_exists(handle, name, security_level, change_auth_pwd=False,
          Severity: Minor
          Found in imcsdk/apis/v2/admin/snmp.py - About 45 mins to fix

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

            def _set_snmp(handle, mo, timeout=90):
                start = datetime.datetime.now()
                while True:
                    try:
                        handle.set_mo(mo)
            Severity: Minor
            Found in imcsdk/apis/v2/admin/snmp.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 _validate_api_prop has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def _validate_api_prop(prop, value, api, validate_value=False,
            Severity: Minor
            Found in imcsdk/apis/v2/admin/snmp.py - About 35 mins to fix

              Function _reset has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              def _reset(handle, local_mo, community, trap_community, engine_id_key):
              Severity: Minor
              Found in imcsdk/apis/v2/admin/snmp.py - About 35 mins to fix

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

                    if response:
                        ret = process_conf_mos_response(response, api, False,
                                                        'Create SNMP users failed',
                                                        snmp_users_callback,
                                                        dn_to_user_dict)
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 3 other locations - About 7 hrs to fix
                imcsdk/apis/v2/admin/snmp.py on lines 449..462
                imcsdk/apis/v2/server/vmedia.py on lines 255..266
                imcsdk/apis/v2/storage/sdcard.py on lines 383..396

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

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

                    if response:
                        ret = process_conf_mos_response(response, api, False,
                                                        'Create SNMP traps failed',
                                                        snmp_traps_callback,
                                                        dn_to_trap_dict)
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 3 other locations - About 7 hrs to fix
                imcsdk/apis/v2/admin/snmp.py on lines 868..881
                imcsdk/apis/v2/server/vmedia.py on lines 255..266
                imcsdk/apis/v2/storage/sdcard.py on lines 383..396

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

                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

                def _validate_api_prop(prop, value, api, validate_value=False,
                                       valid_values=None):
                    if value is None:
                        raise ImcOperationError(api, "Required property '%s' missing." % (
                           api, prop))
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 1 other location - About 4 hrs to fix
                imcsdk/apis/v2/utils.py on lines 45..53

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

                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

                    if security_level in auth_type:
                        if mo.auth and mo.auth == auth:
                            params['auth_pwd'] = auth_pwd if change_auth_pwd else None
                        else:
                            params['auth'] = auth
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 1 other location - About 3 hrs to fix
                imcsdk/apis/v2/admin/snmp.py on lines 650..655

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

                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

                    if security_level in priv_type:
                        if mo.privacy and mo.privacy == privacy:
                            params['privacy_pwd'] = privacy_pwd if change_privacy_pwd else None
                        else:
                            params['privacy'] = privacy
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 1 other location - About 3 hrs to fix
                imcsdk/apis/v2/admin/snmp.py on lines 643..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 69.

                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 snmp_trap_modify(handle, hostname, **kwargs):
                    """
                    Modifies snmp trap referred to by id
                
                    Args:
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 1 other location - About 2 hrs to fix
                imcsdk/apis/v2/admin/snmp.py on lines 707..733

                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

                def snmp_user_modify(handle, name, **kwargs):
                    """
                    Modifies snmp user. Use this after getting the id from snmp_user_exists
                
                    Args:
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 1 other location - About 2 hrs to fix
                imcsdk/apis/v2/admin/snmp.py on lines 306..333

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

                def snmp_disable(handle):
                    """
                    Disables SNMP.
                
                    Args:
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 2 other locations - About 1 hr to fix
                imcsdk/apis/admin/snmp.py on lines 73..96
                imcsdk/apis/v2/admin/ssh.py on lines 60..81

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

                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 trap in traps:
                        if trap.hostname == "0.0.0.0":
                            continue
                        trap.admin_state = CommSnmpTrapConsts.ADMIN_STATE_DISABLED
                        trap.admin_action = CommSnmpTrapConsts.ADMIN_ACTION_CLEAR
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 1 other location - About 1 hr to fix
                imcsdk/apis/v2/admin/user.py on lines 622..627

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

                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 snmp_user_exists_any(handle):
                    """
                    Checks if any snmp user exists.
                
                    Args:
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 1 other location - About 1 hr to fix
                imcsdk/apis/v2/admin/snmp.py on lines 526..546

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

                def snmp_trap_exists_any(handle):
                    """
                    Checks if any snmp trap exists.
                
                    Args:
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 1 other location - About 1 hr to fix
                imcsdk/apis/v2/admin/snmp.py on lines 945..966

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

                def snmp_trap_get(handle, hostname):
                    traps = _get_snmp_traps(handle)
                    for trap in traps:
                        if trap.hostname == hostname:
                            return trap
                Severity: Major
                Found in imcsdk/apis/v2/admin/snmp.py and 2 other locations - About 1 hr to fix
                imcsdk/apis/admin/user.py on lines 158..163
                imcsdk/apis/v2/admin/user.py on lines 284..289

                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