Skip to content

Commit 5509391

Browse files
Merge pull request #1988 from JayasilanJibm/issue_1987
F-string changes for managers, transports, test module and few other files
2 parents 6aa4717 + 3a5c756 commit 5509391

26 files changed

+57
-62
lines changed

SoftLayer/CLI/user/detail.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def basic_info(user, keys):
7474
else:
7575
table.add_row(['APIKEY', 'No'])
7676
table.add_row(['Name', f"{user.get('firstName', '-')} {user.get('lastName', '-')}"])
77-
table.add_row(['Name', f"{user.get('firstName', '-')} {user.get('lastName', '-')}"])
7877
table.add_row(['Email', user.get('email')])
7978
table.add_row(['OpenID', user.get('openIdConnectUserName')])
8079
address = f"{user.get('address1')} \

SoftLayer/auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ def __init__(self, username, token, r_token=None):
131131

132132
def get_request(self, request):
133133
"""Sets token-based auth headers."""
134-
request.transport_headers['Authorization'] = 'Bearer {}'.format(self.api_key)
134+
request.transport_headers['Authorization'] = f'Bearer {self.api_key}'
135135
request.transport_user = self.username
136136
return request
137137

138138
def __repr__(self):
139-
return "BearerAuthentication(username={}, token={})".format(self.username, self.api_key)
139+
return f"BearerAuthentication(username={self.username}, token={self.api_key})"

SoftLayer/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def __init__(self, fault_code, fault_string, url=None):
2626
self.url = url
2727

2828
def __repr__(self):
29-
return "{} ({}): {}".format(self.url, self.faultCode, self.faultString)
29+
return f"{self.url} ({self.faultCode}): {self.faultString}"
3030

3131
def __str__(self):
32-
return "{} ({}): {}".format(self.url, self.faultCode, self.faultString)
32+
return f"{self.url} ({self.faultCode}): {self.faultString}"
3333

3434

3535
class SoftLayerAPIError(SoftLayerError):

SoftLayer/managers/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def cancel_item(self, identifier, reason="No longer needed", note=None):
293293

294294
if note is None:
295295
user = self.client.call('Account', 'getCurrentUser', mask="mask[id,displayName,email,username]")
296-
note = "Cancelled by {} with the SLCLI".format(user.get('username'))
296+
note = f"Cancelled by {user.get('username')} with the SLCLI"
297297

298298
return self.client.call('Billing_Item', 'cancelItem', False, True, reason, note, id=identifier)
299299

SoftLayer/managers/hardware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def get_create_options(self, datacenter=None):
400400
_mask = "mask[priceGroups]"
401401
dc_details = self.client.call('SoftLayer_Location', 'getDatacenters', mask=_mask, filter=_filter, limit=1)
402402
if not dc_details:
403-
raise SoftLayerError("Unable to find a datacenter named {}".format(datacenter))
403+
raise SoftLayerError(f"Unable to find a datacenter named {datacenter}")
404404
# A DC will have several price groups, no good way to deal with this other than checking each.
405405
# An item should only belong to one type of price group.
406406
for group in dc_details[0].get('priceGroups', []):

SoftLayer/managers/ipsec.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ def get_tunnel_context(self, context_id, **kwargs):
120120
contexts = self.account.getNetworkTunnelContexts(**kwargs)
121121
if len(contexts) == 0:
122122
raise SoftLayerAPIError('SoftLayer_Exception_ObjectNotFound',
123-
'Unable to find object with id of \'{}\''
124-
.format(context_id))
123+
f'Unable to find object with id of \'{context_id}\'')
125124
return contexts[0]
126125

127126
def get_translation(self, context_id, translation_id):
@@ -137,8 +136,7 @@ def get_translation(self, context_id, translation_id):
137136
if x['id'] == translation_id), None)
138137
if translation is None:
139138
raise SoftLayerAPIError('SoftLayer_Exception_ObjectNotFound',
140-
'Unable to find object with id of \'{}\''
141-
.format(translation_id))
139+
f'Unable to find object with id of \'{translation_id}\'')
142140
return translation
143141

144142
def get_translations(self, context_id):

SoftLayer/managers/license.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def cancel_item(self, key, cancel_immediately=False):
4747

4848
if not vm_ware_find:
4949
raise exceptions.CLIAbort(
50-
"Unable to find license key: {}".format(key))
50+
f"Unable to find license key: {key}")
5151
return vm_ware_find
5252

5353
def create(self, datacenter, item_package):

SoftLayer/managers/load_balancer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def get_lbaas_by_name(self, name, mask=None):
121121
object_filter = {'name': {'operation': name}}
122122
this_lbs = self.lbaas.getAllObjects(filter=object_filter, mask=mask)
123123
if not this_lbs:
124-
raise exceptions.SoftLayerError("Unable to find LBaaS with name: {}".format(name))
124+
raise exceptions.SoftLayerError(f"Unable to find LBaaS with name: {name}")
125125

126126
return this_lbs[0]
127127

SoftLayer/managers/object_storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ def _get_id_from_username(self, username):
9797
if len(account) == 1:
9898
return [account[0]['id']]
9999
elif len(account) > 1:
100-
raise SoftLayerError("Multiple object storage accounts found with the name: {}".format(username))
100+
raise SoftLayerError(f"Multiple object storage accounts found with the name: {username}")
101101
else:
102-
raise SoftLayerError("Unable to find object storage account id for: {}".format(username))
102+
raise SoftLayerError(f"Unable to find object storage account id for: {username}")

SoftLayer/managers/ordering.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def get_package_by_key(self, package_keyname, mask=None):
266266

267267
packages = self.package_svc.getAllObjects(mask=mask, filter=_filter)
268268
if len(packages) == 0:
269-
raise exceptions.SoftLayerError("Package {} does not exist".format(package_keyname))
269+
raise exceptions.SoftLayerError(f"Package {package_keyname} does not exist")
270270

271271
return packages.pop()
272272

@@ -352,8 +352,7 @@ def get_preset_by_key(self, package_keyname, preset_keyname, mask=None):
352352

353353
if len(presets) == 0:
354354
raise exceptions.SoftLayerError(
355-
"Preset {} does not exist in package {}".format(preset_keyname,
356-
package_keyname))
355+
f"Preset {preset_keyname} does not exist in package {package_keyname}")
357356

358357
return presets[0]
359358

@@ -385,8 +384,7 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
385384
matching_item = [i for i in items
386385
if i['keyName'] == item_keyname][0]
387386
except IndexError as ex:
388-
message = "Item {} does not exist for package {}".format(item_keyname,
389-
package_keyname)
387+
message = f"Item {item_keyname} does not exist for package {package_keyname}"
390388
raise exceptions.SoftLayerError(message) from ex
391389

392390
# we want to get the price ID that has no location attached to it,
@@ -704,7 +702,7 @@ def resolve_location_name(self, location_key):
704702

705703
default_region_keyname = 'unknown'
706704
if not location_key or location_key == default_region_keyname:
707-
raise exceptions.SoftLayerError("Invalid location {}".format(location_key))
705+
raise exceptions.SoftLayerError(f"Invalid location {location_key}")
708706

709707
default_regions = [{'keyname': default_region_keyname}]
710708
index_first = 0
@@ -716,7 +714,7 @@ def resolve_location_name(self, location_key):
716714
return location_key
717715
if location.get('regions', default_regions)[index_first].get('keyname') == location_key:
718716
return location_name
719-
raise exceptions.SoftLayerError("Location {} does not exist".format(location_key))
717+
raise exceptions.SoftLayerError(f"Location {location_key} does not exist")
720718

721719
def get_items(self, package_id, storage_filter=None, mask=None):
722720
""""Returns the items .

0 commit comments

Comments
 (0)