QualiSystems/vCenterShell

View on GitHub
package/cloudshell/cp/vcenter/commands/connect_orchestrator.py

Summary

Maintainability
D
2 days
Test Coverage

File connect_orchestrator.py has 363 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import traceback
from multiprocessing.pool import ThreadPool

import jsonpickle

Severity: Minor
Found in package/cloudshell/cp/vcenter/commands/connect_orchestrator.py - About 4 hrs to fix

    ConnectionCommandOrchestrator has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ConnectionCommandOrchestrator(object):
        def __init__(self, connector, disconnector, resource_model_parser):
            """
    
            :param connector:
    Severity: Minor
    Found in package/cloudshell/cp/vcenter/commands/connect_orchestrator.py - About 3 hrs to fix

      Function _remove_vlan has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def _remove_vlan(self, action_mappings, si, vm_uuid, logger):
              final_res = []
              mode_to_actions = action_mappings.action_tree[ACTION_TYPE_REMOVE_VLAN]
              try:
                  self.logger.info('disconnecting vm({0})'.format(vm_uuid))
      Severity: Minor
      Found in package/cloudshell/cp/vcenter/commands/connect_orchestrator.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_set_mappings has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_set_mappings(self, req_to_modes):
              set_mappings = []
              if ACTION_TYPE_SET_VLAN in req_to_modes:
                  set_requests = req_to_modes[ACTION_TYPE_SET_VLAN]
                  for mode, actions in set_requests.items():
      Severity: Minor
      Found in package/cloudshell/cp/vcenter/commands/connect_orchestrator.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_set_vlan_result_suc has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_set_vlan_result_suc(self, act_by_mode_by_vlan_by_nic, connection_res_map):
              results = []
              for mode, vlans_to_nics in act_by_mode_by_vlan_by_nic.items():
                  for vlan_id, nics_to_actions in vlans_to_nics.items():
                      for nic_name, actions in nics_to_actions.items():
      Severity: Minor
      Found in package/cloudshell/cp/vcenter/commands/connect_orchestrator.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_remove_mappings has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_remove_mappings(self, req_to_modes, vm):
              remove_mappings = []
              if ACTION_TYPE_REMOVE_VLAN in req_to_modes:
                  for mode, actions in req_to_modes[ACTION_TYPE_REMOVE_VLAN].items():
                      for action in actions:
      Severity: Minor
      Found in package/cloudshell/cp/vcenter/commands/connect_orchestrator.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 _group_actions_by_vlan_by_vnic has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _group_actions_by_vlan_by_vnic(self, set_actions_grouped_by_vlan_id):
              set_act_group_by_mode_by_vlan_by_requsted_vnic = dict()
              for mode, vlan_to_action in set_actions_grouped_by_vlan_id.items():
                  set_act_group_by_mode_by_vlan_by_requsted_vnic[mode] = dict()
                  for vlan_id, actions in vlan_to_action.items():
      Severity: Minor
      Found in package/cloudshell/cp/vcenter/commands/connect_orchestrator.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 _set_vlan has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def _set_vlan(self, action_mappings, si, vm_uuid, logger):
              results = []
              set_vlan_actions = action_mappings.action_tree[ACTION_TYPE_SET_VLAN]
              try:
                  self.logger.info('connecting vm({0})'.format(vm_uuid))
      Severity: Minor
      Found in package/cloudshell/cp/vcenter/commands/connect_orchestrator.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 _group_vm_action_type_by_mode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def _group_vm_action_type_by_mode(self, grouped_by_vm_by_requset):
              grouped_by_vm_by_requset_by_mode = dict()
              for machine, req_to_actions in grouped_by_vm_by_requset.items():
                  grouped_by_vm_by_requset_by_mode[machine] = dict()
                  for req_type, actions in req_to_actions.items():
      Severity: Minor
      Found in package/cloudshell/cp/vcenter/commands/connect_orchestrator.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

                  for mode, actions in set_vlan_actions.items():
                      for action in actions:
                          error_result = self._create_error_action_res(action, e)
                          results.append(error_result)
      package/cloudshell/cp/vcenter/commands/connect_orchestrator.py on lines 353..356

      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

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

                  for mode, actions in mode_to_actions.items():
                      for action in actions:
                          error_result = self._create_error_action_res(action, e)
                          final_res.append(error_result)
      package/cloudshell/cp/vcenter/commands/connect_orchestrator.py on lines 231..234

      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