Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F-String Updates - account/bandwidthblock #1975

Merged
merged 14 commits into from Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion SoftLayer/CLI/account/billing_items.py
Expand Up @@ -42,7 +42,7 @@ def item_table(items, ordered=None):
table.align['Category Code'] = 'l'
for item in items:
description = item.get('description')
fqdn = "{}.{}".format(item.get('hostName', ''), item.get('domainName', ''))
fqdn = f"{item.get('hostName', '')}.{item.get('domainName', '')}"
if fqdn != ".":
description = fqdn
user = utils.lookup(item, 'orderItem', 'order', 'userRecord')
Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/CLI/account/cancel_item.py
Expand Up @@ -17,4 +17,4 @@ def cli(env, identifier):
item = manager.cancel_item(identifier)

if item:
env.fout("Item: {} was cancelled.".format(identifier))
env.fout(f"Item: {identifier} was cancelled.")
6 changes: 3 additions & 3 deletions SoftLayer/CLI/account/item_detail.py
Expand Up @@ -23,13 +23,13 @@ def item_table(item):
"""Formats a table for billing items"""

date_format = '%Y-%m-%d'
table = formatting.Table(["Key", "Value"], title="{}".format(item.get('description', 'Billing Item')))
table = formatting.Table(["Key", "Value"], title=f"{item.get('description', 'Billing Item')}")
table.add_row(['createDate', utils.clean_time(item.get('createDate'), date_format, date_format)])
table.add_row(['cycleStartDate', utils.clean_time(item.get('cycleStartDate'), date_format, date_format)])
table.add_row(['cancellationDate', utils.clean_time(item.get('cancellationDate'), date_format, date_format)])
table.add_row(['description', item.get('description')])
table.align = 'l'
fqdn = "{}.{}".format(item.get('hostName', ''), item.get('domainName', ''))
fqdn = f"{item.get('hostName', '')}.{item.get('domainName', '')}"
if fqdn != ".":
table.add_row(['FQDN', fqdn])

Expand All @@ -43,7 +43,7 @@ def item_table(item):
ordered_by = "IBM"
user = utils.lookup(item, 'orderItem', 'order', 'userRecord')
if user:
ordered_by = "{} ({})".format(user.get('displayName'), utils.lookup(user, 'userStatus', 'name'))
ordered_by = f"{user.get('displayName')} ({utils.lookup(user, 'userStatus', 'name')})"
table.add_row(['Ordered By', ordered_by])
table.add_row(['Notes', item.get('notes')])
table.add_row(['Location', utils.lookup(item, 'location', 'name')])
Expand Down
8 changes: 4 additions & 4 deletions SoftLayer/CLI/bandwidth/pools.py
Expand Up @@ -39,19 +39,19 @@ def cli(env):
name = item.get('name')
region = utils.lookup(item, 'locationGroup', 'name')
servers = manager.get_bandwidth_pool_counts(identifier=item.get('id'))
allocation = "{} GB".format(item.get('totalBandwidthAllocated', 0))
allocation = f"{item.get('totalBandwidthAllocated', 0)} GB"

current = utils.lookup(item, 'billingCyclePublicBandwidthUsage', 'amountOut')
if current is not None:
current = "{} GB".format(current)
current = f"{current} GB"
else:
current = "0 GB"

projected = "{} GB".format(item.get('projectedPublicBandwidthUsage', 0))
projected = f"{item.get('projectedPublicBandwidthUsage', 0)} GB"

cost = utils.lookup(item, 'billingItem', 'nextInvoiceTotalRecurringAmount')
if cost is not None:
cost = "${}".format(cost)
cost = f"${cost}"
else:
cost = "$0.0"

Expand Down
14 changes: 7 additions & 7 deletions SoftLayer/CLI/bandwidth/pools_detail.py
Expand Up @@ -24,15 +24,15 @@ def cli(env, identifier):
table.add_row(['Id', bandwidths['id']])
table.add_row(['Name', bandwidths['name']])
table.add_row(['Create Date', utils.clean_time(bandwidths.get('createDate'), '%Y-%m-%d')])
current = "{} GB".format(utils.lookup(bandwidths, 'billingCyclePublicBandwidthUsage', 'amountOut'))
current = f"{utils.lookup(bandwidths, 'billingCyclePublicBandwidthUsage', 'amountOut')} GB"
if current is None:
current = '-'
table.add_row(['Current Usage', current])
projected = "{} GB".format(bandwidths.get('projectedPublicBandwidthUsage', 0))
projected = f"{bandwidths.get('projectedPublicBandwidthUsage', 0)} GB"
if projected is None:
projected = '-'
table.add_row(['Projected Usage', projected])
inbound = "{} GB".format(bandwidths.get('inboundPublicBandwidthUsage', 0))
inbound = f"{bandwidths.get('inboundPublicBandwidthUsage', 0)} GB"
if inbound is None:
inbound = '-'
table.add_row(['Inbound Usage', inbound])
Expand All @@ -58,8 +58,8 @@ def _bw_table(bw_data):
"""Generates a bandwidth useage table"""
table_data = formatting.Table(['Id', 'HostName', "IP Address", 'Amount', "Current Usage"])
for bw_point in bw_data:
amount = "{} GB".format(utils.lookup(bw_point, 'bandwidthAllotmentDetail', 'allocation', 'amount'))
current = "{} GB".format(bw_point.get('outboundBandwidthUsage', 0))
amount = f"{utils.lookup(bw_point, 'bandwidthAllotmentDetail', 'allocation', 'amount')} GB"
current = f"{bw_point.get('outboundBandwidthUsage', 0)} GB"
ip_address = bw_point.get('primaryIpAddress')
if ip_address is None:
ip_address = '-'
Expand All @@ -71,8 +71,8 @@ def _virtual_table(bw_data):
"""Generates a virtual bandwidth usage table"""
table_data = formatting.Table(['Id', 'HostName', "IP Address", 'Amount', "Current Usage"])
for bw_point in bw_data:
amount = "{} GB".format(utils.lookup(bw_point, 'bandwidthAllotmentDetail', 'allocation', 'amount'))
current = "{} GB".format(bw_point.get('outboundBandwidthUsage', 0))
amount = f"{utils.lookup(bw_point, 'bandwidthAllotmentDetail', 'allocation', 'amount')} GB"
current = f"{bw_point.get('outboundBandwidthUsage', 0)} GB"
ip_address = bw_point.get('primaryIpAddress')
if ip_address is None:
ip_address = '-'
Expand Down
6 changes: 2 additions & 4 deletions SoftLayer/CLI/block/access/list.py
Expand Up @@ -14,12 +14,10 @@
@click.argument('volume_id')
@click.option('--columns',
callback=column_helper.get_formatter(storage_utils.COLUMNS),
help='Columns to display. Options are: {0}.'.format(
', '.join(column.name for column in storage_utils.COLUMNS)),
help=f"Columns to display. Options are: { ', '.join(column.name for column in storage_utils.COLUMNS)}.",
default=','.join(storage_utils.DEFAULT_COLUMNS))
@click.option('--sortby',
help='Column to sort by. Options are: {0}.'.format(
', '.join(column.name for column in storage_utils.COLUMNS)),
help=f"Column to sort by. Options are: { ', '.join(column.name for column in storage_utils.COLUMNS)}.",
default='name')
@environment.pass_env
def cli(env, columns, sortby, volume_id):
Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/CLI/block/detail.py
Expand Up @@ -112,7 +112,7 @@ def cli(env, volume_id):
original_volume_info.add_row(['Original Snapshot Name', block_volume['originalSnapshotName']])
table.add_row(['Original Volume Properties', original_volume_info])

notes = '{}'.format(block_volume.get('notes', ''))
notes = f"{block_volume.get('notes', '')}"
table.add_row(['Notes', notes])

env.fout(table)
3 changes: 1 addition & 2 deletions SoftLayer/CLI/block/duplicate.py
Expand Up @@ -89,8 +89,7 @@ def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
raise exceptions.ArgumentError(str(ex))

if 'placedOrder' in order.keys():
click.echo("Order #{0} placed successfully!".format(
order['placedOrder']['id']))
click.echo(f"Order #{order['placedOrder']['id']} placed successfully!")
for item in order['placedOrder']['items']:
click.echo(" > %s" % item['description'])
else:
Expand Down
3 changes: 1 addition & 2 deletions SoftLayer/CLI/block/list.py
Expand Up @@ -60,8 +60,7 @@
@click.option('--sortby', help='Column to sort by', default='username')
@click.option('--columns',
callback=column_helper.get_formatter(COLUMNS),
help='Columns to display. Options: {0}'.format(
', '.join(column.name for column in COLUMNS)),
help=f"Columns to display. Options: { ', '.join(column.name for column in COLUMNS)}",
default=','.join(DEFAULT_COLUMNS))
@environment.pass_env
def cli(env, sortby, columns, datacenter, username, storage_type, order):
Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/CLI/block/modify.py
Expand Up @@ -50,7 +50,7 @@ def cli(env, volume_id, new_size, new_iops, new_tier):
raise exceptions.ArgumentError(str(ex))

if 'placedOrder' in order.keys():
click.echo("Order #{0} placed successfully!".format(order['placedOrder']['id']))
click.echo(f"Order #{order['placedOrder']['id']} placed successfully!")
for item in order['placedOrder']['items']:
click.echo(" > %s" % item['description'])
else:
Expand Down
10 changes: 4 additions & 6 deletions SoftLayer/CLI/block/order.py
Expand Up @@ -72,7 +72,7 @@ def cli(env, storage_type, size, iops, tier, os_type,
hourly_billing_flag = True

if service_offering != 'storage_as_a_service':
click.secho('{} is a legacy storage offering'.format(service_offering), fg='red')
click.secho(f"{service_offering} is a legacy storage offering", fg='red')
if hourly_billing_flag:
raise exceptions.CLIAbort(
'Hourly billing is only available for the storage_as_a_service service offering'
Expand Down Expand Up @@ -123,12 +123,10 @@ def cli(env, storage_type, size, iops, tier, os_type,
raise exceptions.ArgumentError(str(ex))

if 'placedOrder' in order.keys():
click.echo("Order #{0} placed successfully!".format(
order['placedOrder']['id']))
click.echo(f"Order #{order['placedOrder']['id']} placed successfully!")
for item in order['placedOrder']['items']:
click.echo(" > %s" % item['description'])
click.echo(
'\nYou may run "slcli block volume-list --order {0}" to find this block volume after it '
'is ready.'.format(order['placedOrder']['id']))
click.echo(f"\nYou may run 'slcli block volume-list --order {order['placedOrder']['id']}' "
"to find this block volume after it is ready.")
else:
click.echo("Order could not be placed! Please verify your options and try again.")
3 changes: 1 addition & 2 deletions SoftLayer/CLI/block/replication/locations.py
Expand Up @@ -24,8 +24,7 @@
@click.argument('volume-id')
@click.option('--columns',
callback=column_helper.get_formatter(COLUMNS),
help='Columns to display. Options: {0}'.format(
', '.join(column.name for column in COLUMNS)),
help=f"Columns to display. Options: { ', '.join(column.name for column in COLUMNS)}",
default=','.join(DEFAULT_COLUMNS))
@click.option('--sortby', help='Column to sort by', default='Long Name')
@environment.pass_env
Expand Down
3 changes: 1 addition & 2 deletions SoftLayer/CLI/block/replication/order.py
Expand Up @@ -70,8 +70,7 @@ def cli(env, volume_id, snapshot_schedule, datacenter, tier, os_type, iops):
raise exceptions.ArgumentError(str(ex))

if 'placedOrder' in order.keys():
click.echo("Order #{0} placed successfully!".format(
utils.lookup(order, 'placedOrder', 'id')))
click.echo(f"Order #{utils.lookup(order, 'placedOrder', 'id')} placed successfully!")
for item in utils.lookup(order, 'placedOrder', 'items'):
click.echo(" > %s" % item.get('description'))
else:
Expand Down
3 changes: 1 addition & 2 deletions SoftLayer/CLI/block/replication/partners.py
Expand Up @@ -16,8 +16,7 @@
@click.argument('volume-id')
@click.option('--columns',
callback=column_helper.get_formatter(COLUMNS),
help='Columns to display. Options: {0}'.format(
', '.join(column.name for column in COLUMNS)),
help=f"Columns to display. Options: { ', '.join(column.name for column in COLUMNS)}",
default=','.join(DEFAULT_COLUMNS))
@click.option('--sortby', help='Column to sort by', default='Username')
@environment.pass_env
Expand Down
4 changes: 2 additions & 2 deletions SoftLayer/CLI/block/snapshot/get_notify_status.py
Expand Up @@ -15,6 +15,6 @@ def cli(env, volume_id):
enabled = block_manager.get_volume_snapshot_notification_status(volume_id)

if enabled == 0:
click.echo("Disabled: Snapshots space usage threshold is disabled for volume {}".format(volume_id))
click.echo(f"Disabled: Snapshots space usage threshold is disabled for volume {volume_id}")
else:
click.echo("Enabled: Snapshots space usage threshold is enabled for volume {}".format(volume_id))
click.echo(f"Enabled: Snapshots space usage threshold is enabled for volume {volume_id}")
3 changes: 1 addition & 2 deletions SoftLayer/CLI/block/snapshot/list.py
Expand Up @@ -32,8 +32,7 @@
default='created')
@click.option('--columns',
callback=column_helper.get_formatter(COLUMNS),
help='Columns to display. Options: {0}'.format(
', '.join(column.name for column in COLUMNS)),
help=f"Columns to display. Options: { ', '.join(column.name for column in COLUMNS)}",
default=','.join(DEFAULT_COLUMNS))
@environment.pass_env
def cli(env, volume_id, sortby, columns):
Expand Down
3 changes: 1 addition & 2 deletions SoftLayer/CLI/block/snapshot/order.py
Expand Up @@ -53,8 +53,7 @@ def cli(env, volume_id, size, tier, upgrade, iops):
raise exceptions.ArgumentError(str(ex))

if 'placedOrder' in order.keys():
click.echo("Order #{0} placed successfully!".format(
order['placedOrder']['id']))
click.echo(f"Order #{order['placedOrder']['id']} placed successfully!")
for item in order['placedOrder']['items']:
click.echo(" > %s" % item['description'])
if 'status' in order['placedOrder'].keys():
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/block/subnets/assign.py
Expand Up @@ -24,14 +24,14 @@ def cli(env, access_id, subnet_id):
assigned_subnets = block_manager.assign_subnets_to_acl(access_id, subnet_ids)

for subnet in assigned_subnets:
message = "Successfully assigned subnet id: {} to allowed host id: {}".format(subnet, access_id)
message = f"Successfully assigned subnet id: {subnet} to allowed host id: {access_id}"
click.echo(message)

failed_to_assign_subnets = list(set(subnet_ids) - set(assigned_subnets))
for subnet in failed_to_assign_subnets:
message = "Failed to assign subnet id: {} to allowed host id: {}".format(subnet, access_id)
message = f"Failed to assign subnet id: {subnet} to allowed host id: {access_id}"
click.echo(message)

except SoftLayer.SoftLayerAPIError as ex:
message = "Unable to assign subnets.\nReason: {}".format(ex.faultString)
message = f"Unable to assign subnets.\nReason: {ex.faultString}"
click.echo(message)
6 changes: 3 additions & 3 deletions SoftLayer/CLI/block/subnets/list.py
Expand Up @@ -31,9 +31,9 @@ def cli(env, access_id):

table = formatting.Table(COLUMNS)
for subnet in subnets:
row = ["{0}".format(subnet['id']),
"{0}".format(subnet['networkIdentifier']),
"{0}".format(subnet['cidr'])]
row = [f"{subnet['id']}",
f"{subnet['networkIdentifier']}",
f"{subnet['cidr']}"]
table.add_row(row)

env.fout(table)
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/block/subnets/remove.py
Expand Up @@ -24,14 +24,14 @@ def cli(env, access_id, subnet_id):
removed_subnets = block_manager.remove_subnets_from_acl(access_id, subnet_ids)

for subnet in removed_subnets:
message = "Successfully removed subnet id: {} for allowed host id: {}".format(subnet, access_id)
message = f"Successfully removed subnet id: {subnet} for allowed host id: {access_id}"
click.echo(message)

failed_to_remove_subnets = list(set(subnet_ids) - set(removed_subnets))
for subnet in failed_to_remove_subnets:
message = "Failed to remove subnet id: {} for allowed host id: {}".format(subnet, access_id)
message = f"Failed to remove subnet id: {subnet} for allowed host id: {access_id}"
click.echo(message)

except SoftLayer.SoftLayerAPIError as ex:
message = "Unable to remove subnets.\nReason: {}".format(ex.faultString)
message = f"Unable to remove subnets.\nReason: {ex.faultString}"
click.echo(message)
6 changes: 3 additions & 3 deletions tests/CLI/modules/block_tests.py
Expand Up @@ -231,7 +231,7 @@ def test_volume_order_performance(self, order_mock):
' > Performance Storage\n > Block Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n'
'\nYou may run "slcli block volume-list --order 478" to find this block volume '
'\nYou may run \'slcli block volume-list --order 478\' to find this block volume '
'after it is ready.\n')

def test_volume_order_endurance_tier_not_given(self):
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_volume_order_endurance(self, order_mock):
' > Endurance Storage\n > Block Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n'
'\nYou may run "slcli block volume-list --order 478" to find this block volume '
'\nYou may run \'slcli block volume-list --order 478\' to find this block volume '
'after it is ready.\n')

@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_volume_order_hourly_billing(self, order_mock):
' > Block Storage\n'
' > 20 GB Storage Space\n'
' > 200 IOPS\n'
'\nYou may run "slcli block volume-list --order 10983647" to find this block volume '
'\nYou may run \'slcli block volume-list --order 10983647\' to find this block volume '
'after it is ready.\n')

@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
Expand Down