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

Check in partition/lpar list that specified CPC exists #520

Merged
merged 1 commit into from
Feb 12, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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