Skip to content

Commit

Permalink
Converted remaining uses of format() to f-strings
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Jun 22, 2024
1 parent 1ff5110 commit d81c341
Show file tree
Hide file tree
Showing 132 changed files with 2,051 additions and 2,405 deletions.
1 change: 1 addition & 0 deletions changes/1542.cleanup.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Converted most remaining uses of format() to f-strings.
4 changes: 2 additions & 2 deletions docs/notebooks/tututils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ def make_client(zhmc, userid=None, password=None):
session = zhmcclient.Session(zhmc, USERID, PASSWORD)
session.logon()
client = zhmcclient.Client(session)
print('Established logged-on session with HMC {} using userid {}'.
format(zhmc, USERID))
print(f'Established logged-on session with HMC {zhmc} using '
f'userid {USERID}')
return client
19 changes: 9 additions & 10 deletions examples/activation_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
session = zhmcclient.Session(
host, userid, password, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print("Error: Cannot establish session with HMC {}: {}: {}".
format(host, exc.__class__.__name__, exc))
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
Expand All @@ -53,8 +53,7 @@
print("Finding a CPC in classic mode ...")
cpcs = client.cpcs.list(filter_args={'dpm-enabled': False})
if not cpcs:
print("Error: HMC at {} does not manage any CPCs in classic mode".
format(host))
print(f"Error: HMC at {host} does not manage any CPCs in classic mode")
sys.exit(1)
cpc = cpcs[0]
print(f"Using CPC {cpc.name}")
Expand All @@ -64,8 +63,8 @@
try:
profiles = cpc.reset_activation_profiles.list()
except zhmcclient.Error as exc:
print("Error: Cannot list reset activation profiles for CPC {}: {}: {}".
format(cpc.name, exc.__class__.__name__, exc))
print("Error: Cannot list reset activation profiles for CPC "
f"{cpc.name}: {exc.__class__.__name__}: {exc}")
sys.exit(1)
for profile in profiles:
print(profile.name, profile.get_property('element-uri'))
Expand All @@ -75,8 +74,8 @@
try:
profiles = cpc.image_activation_profiles.list()
except zhmcclient.Error as exc:
print("Error: Cannot list image activation profiles for CPC {}: {}: {}".
format(cpc.name, exc.__class__.__name__, exc))
print("Error: Cannot list image activation profiles for CPC "
f"{cpc.name}: {exc.__class__.__name__}: {exc}")
sys.exit(1)
for profile in profiles:
print(profile.name, profile.get_property('element-uri'))
Expand All @@ -86,8 +85,8 @@
try:
profiles = cpc.load_activation_profiles.list()
except zhmcclient.Error as exc:
print("Error: Cannot list load activation profiles for CPC {}: {}: {}".
format(cpc.name, exc.__class__.__name__, exc))
print("Error: Cannot list load activation profiles for CPC "
f"{cpc.name}: {exc.__class__.__name__}: {exc}")
sys.exit(1)
for profile in profiles:
print(profile.name, profile.get_property('element-uri'))
Expand Down
18 changes: 8 additions & 10 deletions examples/adapter_port_vswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
session = zhmcclient.Session(
host, userid, password, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print("Error: Cannot establish session with HMC {}: {}: {}".
format(host, exc.__class__.__name__, exc))
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
Expand All @@ -53,29 +53,27 @@
print("Finding a CPC in DPM mode ...")
cpcs = client.cpcs.list(filter_args={'dpm-enabled': True})
if not cpcs:
print("Error: HMC at {} does not manage any CPCs in DPM mode".
format(host))
print(f"Error: HMC at {host} does not manage any CPCs in DPM mode")
sys.exit(1)
cpc = cpcs[0]
print(f"Using CPC {cpc.name}")

print(f"Listing adapters on CPC {cpc.name} ...")
adapters = cpc.adapters.list()
for adapter in adapters:
print("{} ({})".format(
adapter.name, adapter.get_property('detected-card-type')))
card_type = adapter.get_property('detected-card-type')
print(f"{adapter.name} ({card_type})")
ports = adapter.ports.list(full_properties=False)
for port in ports:
print(f"\t{port.name}")

print("Listing virtual switches and backing adapters on CPC {} ...".
format(cpc.name))
print("Listing virtual switches and backing adapters on CPC "
f"{cpc.name} ...")
vswitches = cpc.vswitches.list()
for vswitch in vswitches:
backing_adapter_uri = vswitch.get_property('backing-adapter-uri')
backing_adapter = vswitch.manager.resource_object(backing_adapter_uri)
print("{} (adapter: {})".
format(vswitch.name, backing_adapter.name))
print(f"{vswitch.name} (adapter: {backing_adapter.name})")

finally:
print("Logging off ...")
Expand Down
4 changes: 2 additions & 2 deletions examples/api_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
try:
session = zhmcclient.Session(host, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print("Error: Cannot establish session with HMC {}: {}: {}".
format(host, exc.__class__.__name__, exc))
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

client = zhmcclient.Client(session)
Expand Down
31 changes: 15 additions & 16 deletions examples/async_operation_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
session = zhmcclient.Session(
host, userid, password, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print("Error: Cannot establish session with HMC {}: {}: {}".
format(host, exc.__class__.__name__, exc))
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
Expand All @@ -69,8 +69,7 @@
print("Finding a CPC in DPM mode ...")
cpcs = client.cpcs.list(filter_args={'dpm-enabled': True})
if not cpcs:
print("Error: HMC at {} does not manage any CPCs in DPM mode".
format(host))
print(f"Error: HMC at {host} does not manage any CPCs in DPM mode")
sys.exit(1)
cpc = cpcs[0]
print(f"Using CPC {cpc.name}")
Expand All @@ -87,16 +86,16 @@
'maximum-memory': 4096,
})
except zhmcclient.Error as exc:
print("Error: Cannot create partition {} on CPC {}: {}: {}".
format(part_name, cpc.name, exc.__class__.__name__, exc))
print(f"Error: Cannot create partition {part_name} on CPC {cpc.name}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
print(f"Starting partition {part.name} asynchronously ...")
job = part.start(wait_for_completion=False)

print("Creating a notification receiver for topic {} ...".
format(job_topic_name))
print("Creating a notification receiver for topic "
f"{job_topic_name} ...")
try:
receiver = zhmcclient.NotificationReceiver(
job_topic_name, host, userid, password)
Expand All @@ -114,7 +113,7 @@
break
else:
print("Received completion notification for another job: "
"{} - continue to wait".format(headers['job-uri']))
f"{headers['job-uri']} - continue to wait")
except zhmcclient.NotificationError as exc:
print(f"Notification Error: {exc} - reconnecting")
continue
Expand All @@ -132,8 +131,8 @@
try:
job_status, op_result = job.check_for_completion()
except zhmcclient.Error as exc:
print("Error: Start operation failed with {}: {}".
format(exc.__class__.__name__, exc))
print("Error: Start operation failed with "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)
assert job_status == 'complete'
print("Start operation succeeded")
Expand All @@ -144,17 +143,17 @@
try:
part.stop(wait_for_completion=True)
except zhmcclient.Error as exc:
print("Error: Stop operation failed with {}: {}".
format(exc.__class__.__name__, exc))
print("Error: Stop operation failed with "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

print(f"Deleting partition {part.name} ...")
try:
part.delete()
except zhmcclient.Error as exc:
print("Error: Cannot delete partition {} on CPC {} for clean up - "
"Please delete it manually: {}: {}".
format(part.name, cpc.name, exc.__class__.__name__, exc))
print(f"Error: Cannot delete partition {part.name} on CPC "
f"{cpc.name} for clean up - "
f"Please delete it manually: {exc.__class__.__name_}: {exc}")
sys.exit(1)

finally:
Expand Down
26 changes: 12 additions & 14 deletions examples/async_operation_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
session = zhmcclient.Session(
host, userid, password, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print("Error: Cannot establish session with HMC {}: {}: {}".
format(host, exc.__class__.__name__, exc))
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
Expand All @@ -55,8 +55,7 @@
print("Finding a CPC in DPM mode ...")
cpcs = client.cpcs.list(filter_args={'dpm-enabled': True})
if not cpcs:
print("Error: HMC at {} does not manage any CPCs in DPM mode".
format(host))
print(f"Error: HMC at {host} does not manage any CPCs in DPM mode")
sys.exit(1)
cpc = cpcs[0]
print(f"Using CPC {cpc.name}")
Expand All @@ -73,23 +72,22 @@
'maximum-memory': 4096,
})
except zhmcclient.Error as exc:
print("Error: Cannot create partition {} on CPC {}: {}: {}".
format(part_name, cpc.name, exc.__class__.__name__, exc))
print(f"Error: Cannot create partition {part_name} on CPC {cpc.name}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
print(f"Starting partition {part.name} asynchronously ...")
job = part.start(wait_for_completion=False)

sleep_time = 1
print("Polling for job completion with sleep time {} sec ...".
format(sleep_time))
print(f"Polling for job completion with sleep time {sleep_time} sec ...")
while True:
try:
job_status, op_result = job.check_for_completion()
except zhmcclient.Error as exc:
print("Error: Job completed; Start operation failed with "
"{}: {}".format(exc.__class__.__name__, exc))
f"{exc.__class__.__name__}: {exc}")
break
print(f"Job status: {job_status}")
if job_status == 'complete':
Expand All @@ -103,17 +101,17 @@
try:
part.stop(wait_for_completion=True)
except zhmcclient.Error as exc:
print("Error: Stop operation failed with {}: {}".
format(exc.__class__.__name__, exc))
print("Error: Stop operation failed with "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

print(f"Deleting partition {part.name} ...")
try:
part.delete()
except zhmcclient.Error as exc:
print("Error: Cannot delete partition {} on CPC {} for clean up - "
"Please delete it manually: {}: {}".
format(part.name, cpc.name, exc.__class__.__name__, exc))
print(f"Error: Cannot delete partition {part.name} on CPC "
"{cpc.name} for clean up - "
f"Please delete it manually: {exc.__class__.__name__}: {exc}")
sys.exit(1)

finally:
Expand Down
7 changes: 3 additions & 4 deletions examples/cleanup_test_partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
session = zhmcclient.Session(
host, userid, password, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print("Error: Cannot establish session with HMC {}: {}: {}".
format(host, exc.__class__.__name__, exc))
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
Expand All @@ -57,8 +57,7 @@
for part in parts:
if re.match(r'^zhmc_test_[a-z0-9\-]{8,}$', part.name):
if part.get_property('status') != 'stopped':
print("Stopping test partition: {} ...".
format(part.name))
print(f"Stopping test partition: {part.name} ...")
part.stop()
print(f"Deleting test partition: {part.name} ...")
part.delete()
Expand Down
31 changes: 14 additions & 17 deletions examples/discover_storage_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
session = zhmcclient.Session(
host, userid, password, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print("Error: Cannot establish session with HMC {}: {}: {}".
format(host, exc.__class__.__name__, exc))
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
Expand All @@ -54,8 +54,7 @@
print("Finding CPCs in DPM mode ...")
cpcs = client.cpcs.list(filter_args={'dpm-enabled': True})
if not cpcs:
print("Error: HMC at {} does not manage any CPCs in DPM mode".
format(host))
print(f"Error: HMC at {host} does not manage any CPCs in DPM mode")
sys.exit(1)

print("Selecting a z14 or higher CPC ...")
Expand All @@ -67,34 +66,32 @@
cpc = _cpc
break
if not cpc:
print("Error: HMC at {} does not manage any z14 or higher CPC in DPM "
"mode".format(host))
print(f"Error: HMC at {host} does not manage any z14 or higher CPC "
"in DPM mode")
sys.exit(1)
print("Using CPC {} (SE version: {})".
format(cpc.name, cpc.get_property('se-version')))
se_version = cpc.get_property('se-version')
print(f"Using CPC {cpc.name} (SE version: {se_version})")

print("Listing storage groups of CPC {} and selecting the first FCP "
"storage group ...".format(cpc.name))
print(f"Listing storage groups of CPC {cpc.name} and selecting the "
"first FCP storage group ...")
storage_groups = cpc.list_associated_storage_groups()
sg = None
for _sg in storage_groups:
if _sg.get_property('type') == 'fcp':
sg = _sg
break
if not sg:
print("Could not find any FCP storage group for CPC {}".
format(cpc.name))
print(f"Could not find any FCP storage group for CPC {cpc.name}")
sys.exit(1)
print("Using FCP storage group: {} (type: {}, shared: {}, fulfillment: {})".
format(sg.name, sg.get_property('type'), sg.get_property('shared'),
sg.get_property('fulfillment-state')))
print(f"Using FCP storage group: {sg.name} (type: {sg.get_property('type')}, "
f"shared: {sg.get_property('shared')}, "
f"fulfillment: {sg.get_property('fulfillment-state')})")

print(f"Listing partitions attached to storage group {sg.name} ...")
parts = sg.list_attached_partitions()
part_names = [p.name for p in parts]
part_names_str = ', '.join(part_names) if part_names else "<none>"
print("Partitions attached to storage group {}: {}".
format(sg.name, part_names_str))
print(f"Partitions attached to storage group {sg.name}: {part_names_str}")

print(f"Getting connection report for storage group {sg.name} ...")
report = sg.get_connection_report()
Expand Down
4 changes: 2 additions & 2 deletions examples/dump_hmc_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
session = zhmcclient.Session(
host, userid, password, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print("Error: Cannot establish session with HMC {}: {}: {}".
format(host, exc.__class__.__name__, exc))
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
Expand Down
Loading

0 comments on commit d81c341

Please sign in to comment.