Skip to content

Commit

Permalink
Check in partition/lpar list that specified CPC exists
Browse files Browse the repository at this point in the history
Details:

* Fail partition/lpar list commands if the specified CPC does not exist.
  (issue #514)

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Feb 12, 2024
1 parent 896514f commit a03e083
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ Released: not yet
* Added support for zeroizing crypto domains with a new
command 'zhmc partition zeroize-crypto'. (issue #502)

* Fail partition/lpar list commands if the specified CPC does not exist.
(issue #514)

**Cleanup:**

* Fixed copyright statements (issue #542)
Expand Down
33 changes: 12 additions & 21 deletions zhmccli/_cmd_lpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,30 +828,21 @@ def cmd_lpar_list(cmd_ctx, cpc_name, options):

client = zhmcclient.Client(cmd_ctx.session)

if client.version_info() >= API_VERSION_HMC_2_14_0:
# This approach is faster than going through the CPC.
# In addition, starting with HMC API version 3.6 (an update to
# HMC 2.15.0), this approach supports users that do not have object
# access permission to the CPC.
filter_args = {}
if cpc_name:
filter_args['cpc-name'] = cpc_name
lpars = client.consoles.console.list_permitted_lpars(
filter_args=filter_args)
if cpc_name:
# Make sure a non-existing CPC is raised as error
cpc = client.cpcs.find(name=cpc_name)
lpars = cpc.lpars.list()
elif client.version_info() >= API_VERSION_HMC_2_14_0:
# This approach is faster than looping through the CPCs.
# In addition, this approach supports users that do not have object
# access permission to the parent CPC of the returned LPARs.
lpars = client.consoles.console.list_permitted_lpars()
else:
filter_args = {}
if cpc_name:
filter_args['name'] = cpc_name
try:
cpcs = client.cpcs.list(filter_args=filter_args)
except zhmcclient.Error as exc:
raise click_exception(exc, cmd_ctx.error_format)
lpars = []
cpcs = client.cpcs.list()
for cpc in cpcs:
try:
lpars.extend(cpc.lpars.list())
except zhmcclient.Error as exc:
raise click_exception(exc, cmd_ctx.error_format)
lpars.extend(cpc.lpars.list())
# The default exception handling is sufficient for the above.

if options['type']:
click.echo("The --type option is deprecated and type information "
Expand Down
30 changes: 11 additions & 19 deletions zhmccli/_cmd_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,29 +1107,21 @@ def cmd_partition_list(cmd_ctx, cpc_name, options):

client = zhmcclient.Client(cmd_ctx.session)

if client.version_info() >= API_VERSION_HMC_2_14_0:
# This approach is faster than going through the CPC.
if cpc_name:
# Make sure a non-existing CPC is raised as error
cpc = client.cpcs.find(name=cpc_name)
partitions = cpc.partitions.list()
elif client.version_info() >= API_VERSION_HMC_2_14_0:
# This approach is faster than looping through the CPCs.
# In addition, this approach supports users that do not have object
# access permission to the parent CPC of the LPAR.
filter_args = {}
if cpc_name:
filter_args['cpc-name'] = cpc_name
partitions = client.consoles.console.list_permitted_partitions(
filter_args=filter_args)
# access permission to the parent CPC of the returned partitions.
partitions = client.consoles.console.list_permitted_partitions()
else:
filter_args = {}
if cpc_name:
filter_args['name'] = cpc_name
try:
cpcs = client.cpcs.list(filter_args=filter_args)
except zhmcclient.Error as exc:
raise click_exception(exc, cmd_ctx.error_format)
partitions = []
cpcs = client.cpcs.list()
for cpc in cpcs:
try:
partitions.extend(cpc.partitions.list())
except zhmcclient.Error as exc:
raise click_exception(exc, cmd_ctx.error_format)
partitions.extend(cpc.partitions.list())
# The default exception handling is sufficient for the above.

if options['type']:
click.echo("The --type option is deprecated and type information "
Expand Down

0 comments on commit a03e083

Please sign in to comment.