Skip to content

Commit 178dc1e

Browse files
Merge pull request #907 from allmightyspiff/issues906
Issues906 - Fixes pylint errors - Adds @Retry to list and details functions for HW and VS managers
2 parents ea3edff + 8594fa0 commit 178dc1e

File tree

11 files changed

+41
-34
lines changed

11 files changed

+41
-34
lines changed

SoftLayer/API.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
66
:license: MIT, see LICENSE for more details.
77
"""
8+
# pylint: disable=invalid-name
89
import warnings
910

1011
from SoftLayer import auth as slauth
1112
from SoftLayer import config
1213
from SoftLayer import consts
1314
from SoftLayer import transports
1415

15-
# pylint: disable=invalid-name
16-
17-
1816
API_PUBLIC_ENDPOINT = consts.API_PUBLIC_ENDPOINT
1917
API_PRIVATE_ENDPOINT = consts.API_PRIVATE_ENDPOINT
2018
__all__ = [

SoftLayer/CLI/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
66
:license: MIT, see LICENSE for more details.
77
"""
8-
# pylint: disable=w0401
8+
# pylint: disable=w0401, invalid-name
99

1010
from SoftLayer.CLI.helpers import * # NOQA

SoftLayer/CLI/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99

10+
# pylint: disable=keyword-arg-before-vararg
1011
class CLIHalt(SystemExit):
1112
"""Smoothly halt the execution of the command. No error."""
1213
def __init__(self, code=0, *args):

SoftLayer/CLI/firewall/edit.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ def open_editor(rules=None, content=None):
104104
data = tfile.read()
105105
return data
106106

107-
return
108-
109107

110108
def get_formatted_rule(rule=None):
111109
"""Helper to format the rule into a user friendly format.

SoftLayer/CLI/formatting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
:license: MIT, see LICENSE for more details.
88
"""
9-
# pylint: disable=E0202, consider-merging-isinstance, arguments-differ
9+
# pylint: disable=E0202, consider-merging-isinstance, arguments-differ, keyword-arg-before-vararg
1010
import collections
1111
import json
1212
import os

SoftLayer/CLI/virt/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ class MemoryType(click.ParamType):
1212
"""Memory type."""
1313
name = 'integer'
1414

15-
def convert(self, value, param, ctx):
15+
def convert(self, value, param, ctx): # pylint: disable=inconsistent-return-statements
1616
"""Validate memory argument. Returns the memory value in megabytes."""
1717
matches = MEMORY_RE.match(value.lower())
1818
if matches is None:
19-
self.fail('%s is not a valid value for memory amount'
20-
% value, param, ctx)
19+
self.fail('%s is not a valid value for memory amount' % value, param, ctx)
2120
amount_str, unit = matches.groups()
2221
amount = int(amount_str)
2322
if unit in [None, 'm', 'mb']:
@@ -26,8 +25,7 @@ def convert(self, value, param, ctx):
2625
return amount * 1024
2726
else:
2827
if amount % 1024 != 0:
29-
self.fail('%s is not an integer that is divisable by 1024'
30-
% value, param, ctx)
28+
self.fail('%s is not an integer that is divisable by 1024' % value, param, ctx)
3129
return amount
3230
elif unit in ['g', 'gb']:
3331
return amount * 1024

SoftLayer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
:license: MIT, see LICENSE for more details.
1616
"""
17-
# pylint: disable=w0401
17+
# pylint: disable=w0401,invalid-name
1818
from SoftLayer import consts
1919

2020
from SoftLayer.API import * # NOQA

SoftLayer/config.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_client_settings_env(**_):
4242
}
4343

4444

45-
def get_client_settings_config_file(**kwargs):
45+
def get_client_settings_config_file(**kwargs): # pylint: disable=inconsistent-return-statements
4646
"""Retrieve client settings from the possible config file locations.
4747
4848
:param \\*\\*kwargs: Arguments that are passed into the client instance
@@ -60,16 +60,14 @@ def get_client_settings_config_file(**kwargs):
6060
})
6161
config.read(config_files)
6262

63-
if not config.has_section('softlayer'):
64-
return
65-
66-
return {
67-
'endpoint_url': config.get('softlayer', 'endpoint_url'),
68-
'timeout': config.getfloat('softlayer', 'timeout'),
69-
'proxy': config.get('softlayer', 'proxy'),
70-
'username': config.get('softlayer', 'username'),
71-
'api_key': config.get('softlayer', 'api_key'),
72-
}
63+
if config.has_section('softlayer'):
64+
return {
65+
'endpoint_url': config.get('softlayer', 'endpoint_url'),
66+
'timeout': config.getfloat('softlayer', 'timeout'),
67+
'proxy': config.get('softlayer', 'proxy'),
68+
'username': config.get('softlayer', 'username'),
69+
'api_key': config.get('softlayer', 'api_key'),
70+
}
7371

7472

7573
SETTING_RESOLVERS = [get_client_settings_args,

SoftLayer/managers/hardware.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
66
:license: MIT, see LICENSE for more details.
77
"""
8+
import logging
89
import socket
910

1011
import SoftLayer
12+
from SoftLayer.decoration import retry
13+
from SoftLayer import exceptions
1114
from SoftLayer.managers import ordering
1215
from SoftLayer import utils
16+
17+
LOGGER = logging.getLogger(__name__)
18+
1319
# Invalid names are ignored due to long method names and short argument names
1420
# pylint: disable=invalid-name, no-self-use
1521

@@ -82,6 +88,7 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment='',
8288
immediate, False, cancel_reason, comment,
8389
id=billing_id)
8490

91+
@retry(exceptions.SoftLayerAPIError, logger=LOGGER)
8592
def list_hardware(self, tags=None, cpus=None, memory=None, hostname=None,
8693
domain=None, datacenter=None, nic_speed=None,
8794
public_ip=None, private_ip=None, **kwargs):
@@ -169,6 +176,7 @@ def list_hardware(self, tags=None, cpus=None, memory=None, hostname=None,
169176
kwargs['filter'] = _filter.to_dict()
170177
return self.account.getHardware(**kwargs)
171178

179+
@retry(exceptions.SoftLayerAPIError, logger=LOGGER)
172180
def get_hardware(self, hardware_id, **kwargs):
173181
"""Get details about a hardware device.
174182
@@ -335,6 +343,7 @@ def get_cancellation_reasons(self):
335343
'moving': 'Moving to competitor',
336344
}
337345

346+
@retry(exceptions.SoftLayerAPIError, logger=LOGGER)
338347
def get_create_options(self):
339348
"""Returns valid options for ordering hardware."""
340349

@@ -395,6 +404,7 @@ def get_create_options(self):
395404
'extras': extras,
396405
}
397406

407+
@retry(exceptions.SoftLayerAPIError, logger=LOGGER)
398408
def _get_package(self):
399409
"""Get the package related to simple hardware ordering."""
400410
mask = '''
@@ -490,7 +500,7 @@ def _get_ids_from_hostname(self, hostname):
490500
results = self.list_hardware(hostname=hostname, mask="id")
491501
return [result['id'] for result in results]
492502

493-
def _get_ids_from_ip(self, ip):
503+
def _get_ids_from_ip(self, ip): # pylint: disable=inconsistent-return-statements
494504
"""Returns list of matching hardware IDs for a given ip address."""
495505
try:
496506
# Does it look like an ip address?

SoftLayer/managers/vs.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(self, client, ordering_manager=None):
5858
else:
5959
self.ordering_manager = ordering_manager
6060

61+
@retry(exceptions.SoftLayerAPIError, logger=LOGGER)
6162
def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
6263
memory=None, hostname=None, domain=None,
6364
local_disk=None, datacenter=None, nic_speed=None,
@@ -161,6 +162,7 @@ def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
161162
func = getattr(self.account, call)
162163
return func(**kwargs)
163164

165+
@retry(exceptions.SoftLayerAPIError, logger=LOGGER)
164166
def get_instance(self, instance_id, **kwargs):
165167
"""Get details about a virtual server instance.
166168
@@ -235,6 +237,7 @@ def get_instance(self, instance_id, **kwargs):
235237

236238
return self.guest.getObject(id=instance_id, **kwargs)
237239

240+
@retry(exceptions.SoftLayerAPIError, logger=LOGGER)
238241
def get_create_options(self):
239242
"""Retrieves the available options for creating a VS.
240243
@@ -411,6 +414,7 @@ def _generate_create_dict(
411414

412415
return data
413416

417+
@retry(exceptions.SoftLayerAPIError, logger=LOGGER)
414418
def wait_for_transaction(self, instance_id, limit, delay=10):
415419
"""Waits on a VS transaction for the specified amount of time.
416420
@@ -482,6 +486,7 @@ def wait_for_ready(self, instance_id, limit, delay=10, pending=False):
482486
return False
483487
LOGGER.info('Auto retry in %s seconds', str(min(delay, until - now)))
484488
time.sleep(min(delay, until - now))
489+
return False
485490

486491
def verify_create_instance(self, **kwargs):
487492
"""Verifies an instance creation command.
@@ -670,7 +675,7 @@ def _get_ids_from_hostname(self, hostname):
670675
results = self.list_instances(hostname=hostname, mask="id")
671676
return [result['id'] for result in results]
672677

673-
def _get_ids_from_ip(self, ip_address):
678+
def _get_ids_from_ip(self, ip_address): # pylint: disable=inconsistent-return-statements
674679
"""List VS ids which match the given ip address."""
675680
try:
676681
# Does it look like an ip address?
@@ -893,8 +898,8 @@ def _get_upgrade_prices(self, instance_id, include_downgrade_options=True):
893898
mask = "mask[%s]" % ','.join(mask)
894899
return self.guest.getUpgradeItemPrices(include_downgrade_options, id=instance_id, mask=mask)
895900

896-
def _get_price_id_for_upgrade_option(self, upgrade_prices, option, value,
897-
public=True):
901+
# pylint: disable=inconsistent-return-statements
902+
def _get_price_id_for_upgrade_option(self, upgrade_prices, option, value, public=True):
898903
"""Find the price id for the option and value to upgrade. This
899904
900905
:param list upgrade_prices: Contains all the prices related to a VS upgrade
@@ -934,8 +939,8 @@ def _get_price_id_for_upgrade_option(self, upgrade_prices, option, value,
934939
else:
935940
return price.get('id')
936941

937-
def _get_price_id_for_upgrade(self, package_items, option, value,
938-
public=True):
942+
# pylint: disable=inconsistent-return-statements
943+
def _get_price_id_for_upgrade(self, package_items, option, value, public=True):
939944
"""Find the price id for the option and value to upgrade.
940945
941946
Deprecated in favor of _get_price_id_for_upgrade_option()

0 commit comments

Comments
 (0)