saltstack/salt

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

Summary

Maintainability
F
4 days
Test Coverage

File packet.py has 431 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Packet Cloud Module Using Packet's Python API Client
====================================================

Severity: Minor
Found in salt/cloud/clouds/packet.py - About 6 hrs to fix

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

    def is_profile_configured(vm_):
        try:
            # Check for required profile parameters before sending any API calls.
            if vm_['profile'] and config.is_profile_configured(__opts__,
                                                               __active_provider_name__ or __virtualname__,
    Severity: Minor
    Found in salt/cloud/clouds/packet.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 has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    def create(vm_):
        '''
        Create a single Packet VM.
        '''
        name = vm_['name']
    Severity: Minor
    Found in salt/cloud/clouds/packet.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 destroy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def destroy(name, call=None):
        '''
        Destroys a Packet device by name.
    
        name
    Severity: Minor
    Found in salt/cloud/clouds/packet.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 True
    Severity: Major
    Found in salt/cloud/clouds/packet.py - About 30 mins to fix

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

      def _wait_for_status(status_type, object_id, status=None, timeout=500, quiet=True):
          '''
          Wait for a certain status from Packet.
          status_type
              device or volume
      Severity: Minor
      Found in salt/cloud/clouds/packet.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 3 locations. Consider refactoring.
      Open

      def avail_locations(call=None):
          '''
          Return available Packet datacenter locations.
      
          CLI Example:
      Severity: Major
      Found in salt/cloud/clouds/packet.py and 2 other locations - About 4 hrs to fix
      salt/cloud/clouds/packet.py on lines 174..199
      salt/cloud/clouds/packet.py on lines 202..225

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

      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 avail_projects(call=None):
          '''
          Return available Packet projects.
      
          CLI Example:
      Severity: Major
      Found in salt/cloud/clouds/packet.py and 2 other locations - About 4 hrs to fix
      salt/cloud/clouds/packet.py on lines 147..171
      salt/cloud/clouds/packet.py on lines 174..199

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

      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 avail_sizes(call=None):
          '''
          Return available Packet sizes.
      
          CLI Example:
      Severity: Major
      Found in salt/cloud/clouds/packet.py and 2 other locations - About 4 hrs to fix
      salt/cloud/clouds/packet.py on lines 147..171
      salt/cloud/clouds/packet.py on lines 202..225

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

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

          __utils__['cloud.fire_event'](
              'event',
              'requesting instance',
              'salt/cloud/{0}/requesting'.format(vm_['name']),
              args=__utils__['cloud.filter_event']('requesting', vm_, ['name', 'profile', 'provider', 'driver']),
      Severity: Major
      Found in salt/cloud/clouds/packet.py and 37 other locations - About 2 hrs to fix
      salt/cloud/clouds/aliyun.py on lines 625..631
      salt/cloud/clouds/aliyun.py on lines 732..738
      salt/cloud/clouds/azurearm.py on lines 1349..1359
      salt/cloud/clouds/azurearm.py on lines 1398..1406
      salt/cloud/clouds/azurearm.py on lines 1480..1489
      salt/cloud/clouds/digitalocean.py on lines 287..293
      salt/cloud/clouds/digitalocean.py on lines 537..543
      salt/cloud/clouds/dimensiondata.py on lines 207..213
      salt/cloud/clouds/dimensiondata.py on lines 337..343
      salt/cloud/clouds/ec2.py on lines 2579..2585
      salt/cloud/clouds/gce.py on lines 2461..2467
      salt/cloud/clouds/gce.py on lines 2551..2557
      salt/cloud/clouds/gce.py on lines 2635..2641
      salt/cloud/clouds/gogrid.py on lines 96..102
      salt/cloud/clouds/gogrid.py on lines 180..186
      salt/cloud/clouds/joyent.py on lines 274..280
      salt/cloud/clouds/joyent.py on lines 325..331
      salt/cloud/clouds/lxc.py on lines 440..446
      salt/cloud/clouds/lxc.py on lines 460..466
      salt/cloud/clouds/lxc.py on lines 488..494
      salt/cloud/clouds/msazure.py on lines 429..435
      salt/cloud/clouds/msazure.py on lines 683..689
      salt/cloud/clouds/nova.py on lines 961..967
      salt/cloud/clouds/opennebula.py on lines 1006..1012
      salt/cloud/clouds/openstack.py on lines 684..690
      salt/cloud/clouds/parallels.py on lines 287..293
      salt/cloud/clouds/parallels.py on lines 356..362
      salt/cloud/clouds/proxmox.py on lines 578..585
      salt/cloud/clouds/qingcloud.py on lines 668..674
      salt/cloud/clouds/qingcloud.py on lines 738..744
      salt/cloud/clouds/scaleway.py on lines 200..206
      salt/cloud/clouds/scaleway.py on lines 304..310
      salt/cloud/clouds/virtualbox.py on lines 176..182
      salt/cloud/clouds/vmware.py on lines 2543..2549
      salt/cloud/clouds/vmware.py on lines 3072..3078
      salt/cloud/clouds/vultrpy.py on lines 292..298
      salt/cloud/clouds/vultrpy.py on lines 465..471

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

      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/packet.py and 10 other locations - About 2 hrs to fix
      salt/cloud/clouds/libvirt.py on lines 309..315
      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 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',
              '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/packet.py and 10 other locations - About 2 hrs to fix
      salt/cloud/clouds/libvirt.py on lines 309..315
      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/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 2 locations. Consider refactoring.
      Open

      def list_nodes(call=None):
          '''
          Returns a list of devices, keeping only a brief listing.
          CLI Example:
      
      
      Severity: Major
      Found in salt/cloud/clouds/packet.py and 1 other location - About 2 hrs to fix
      salt/cloud/clouds/packet.py on lines 438..462

      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 list_nodes_full(call=None):
          '''
          List devices, with all available information.
      
          CLI Example:
      Severity: Major
      Found in salt/cloud/clouds/packet.py and 1 other location - About 2 hrs to fix
      salt/cloud/clouds/packet.py on lines 516..539

      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

          if ssh_interface == 'private_ips':
              for ip in device.ip_addresses:
                  if ip['public'] is False:
                      vm_['ssh_host'] = ip['address']
                      break
      Severity: Minor
      Found in salt/cloud/clouds/packet.py and 1 other location - About 40 mins to fix
      salt/cloud/clouds/packet.py on lines 374..383

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

                  for key in required_keys:
                      if profile_data.get(key) is None:
                          log.error(
                              'both storage_size and storage_tier required for '
                              'profile %s. Please check your profile configuration',
      Severity: Minor
      Found in salt/cloud/clouds/packet.py and 1 other location - About 35 mins to fix
      salt/cloud/clouds/packet.py on lines 309..317

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

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

                  for key in required_keys:
                      if profile_data.get(key) is None:
                          log.error(
                              'both storage_snapshot_count and '
                              'storage_snapshot_frequency required for profile '
      Severity: Minor
      Found in salt/cloud/clouds/packet.py and 1 other location - About 35 mins to fix
      salt/cloud/clouds/packet.py on lines 284..291

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

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

      def __virtual__():
          '''
          Check for Packet configs.
          '''
          if HAS_PACKET is False:
      Severity: Minor
      Found in salt/cloud/clouds/packet.py and 1 other location - About 35 mins to fix
      salt/cloud/clouds/joyent.py on lines 127..136

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

      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