Skip to content

Commit

Permalink
Removed unused ability to have Cpc object in find_...() functions
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Nov 23, 2023
1 parent e863787 commit c7b6fbe
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 44 deletions.
8 changes: 3 additions & 5 deletions zhmccli/_cmd_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@
STORAGE_TYPE_OPTIONS = sorted(list(STORAGE_TYPE_PROPERTIES.keys()))


def find_adapter(cmd_ctx, client, cpc_or_name, adapter_name):
def find_adapter(cmd_ctx, client, cpc_name, adapter_name):
"""
Find an adapter by name and return its resource object.
"""
if isinstance(cpc_or_name, zhmcclient.Cpc):
cpc = cpc_or_name
else:
cpc = find_cpc(cmd_ctx, client, cpc_or_name)
cpc = find_cpc(cmd_ctx, client, cpc_name)

# The CPC must be in DPM mode. We don't check that because it would
# cause a GET to the CPC resource that we otherwise don't need.
try:
Expand Down
8 changes: 3 additions & 5 deletions zhmccli/_cmd_capacitygroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
MAX_CAP = 255.0


def find_capacitygroup(cmd_ctx, client, cpc_or_name, capacitygroup_name):
def find_capacitygroup(cmd_ctx, client, cpc_name, capacitygroup_name):
"""
Find a capacity group by name and return its resource object.
"""
if isinstance(cpc_or_name, zhmcclient.Cpc):
cpc = cpc_or_name
else:
cpc = find_cpc(cmd_ctx, client, cpc_or_name)
cpc = find_cpc(cmd_ctx, client, cpc_name)

# The CPC must be in DPM mode. We don't check that because it would
# cause a GET to the CPC resource that we otherwise don't need.
try:
Expand Down
4 changes: 2 additions & 2 deletions zhmccli/_cmd_hba.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
from ._cmd_partition import find_partition


def find_hba(cmd_ctx, client, cpc_or_name, partition_name, hba_name):
def find_hba(cmd_ctx, client, cpc_name, partition_name, hba_name):
"""
Find an HBA by name and return its resource object.
"""
partition = find_partition(cmd_ctx, client, cpc_or_name, partition_name)
partition = find_partition(cmd_ctx, client, cpc_name, partition_name)
try:
hba = partition.hbas.find(name=hba_name)
except zhmcclient.Error as exc:
Expand Down
14 changes: 4 additions & 10 deletions zhmccli/_cmd_lpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@
from ._cmd_certificates import find_certificate


def find_lpar(cmd_ctx, client, cpc_or_name, lpar_name):
def find_lpar(cmd_ctx, client, cpc_name, lpar_name):
"""
Find an LPAR by name and return its resource object.
"""
if isinstance(cpc_or_name, zhmcclient.Cpc):
cpc_name = cpc_or_name.name
else:
cpc_name = cpc_or_name

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 parent CPC of the LPAR.

lpars = client.consoles.console.list_permitted_lpars(
filter_args={'name': lpar_name, 'cpc-name': cpc_name})
if len(lpars) != 1:
Expand All @@ -55,10 +51,8 @@ def find_lpar(cmd_ctx, client, cpc_or_name, lpar_name):
cmd_ctx.error_format)
lpar = lpars[0]
else:
if isinstance(cpc_or_name, zhmcclient.Cpc):
cpc = cpc_or_name
else:
cpc = find_cpc(cmd_ctx, client, cpc_name)
cpc = find_cpc(cmd_ctx, client, cpc_name)

# The CPC must not be in DPM mode. We don't check that because it would
# cause a GET to the CPC resource that we otherwise don't need.
try:
Expand Down
4 changes: 2 additions & 2 deletions zhmccli/_cmd_nic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
VLAN_TYPES = ['enforced', 'none']


def find_nic(cmd_ctx, client, cpc_or_name, partition_name, nic_name):
def find_nic(cmd_ctx, client, cpc_name, partition_name, nic_name):
"""
Find a NIC by name and return its resource object.
"""
partition = find_partition(cmd_ctx, client, cpc_or_name, partition_name)
partition = find_partition(cmd_ctx, client, cpc_name, partition_name)
try:
nic = partition.nics.find(name=nic_name)
except zhmcclient.Error as exc:
Expand Down
14 changes: 4 additions & 10 deletions zhmccli/_cmd_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,15 @@
MAX_BOOT_TIMEOUT = 600


def find_partition(cmd_ctx, client, cpc_or_name, partition_name):
def find_partition(cmd_ctx, client, cpc_name, partition_name):
"""
Find a partition by name and return its resource object.
"""
if isinstance(cpc_or_name, zhmcclient.Cpc):
cpc_name = cpc_or_name.name
else:
cpc_name = cpc_or_name

if client.version_info() >= API_VERSION_HMC_2_14_0:
# This approach is faster than going through the CPC.
# In addition, this approach supports users that do not have object
# access permission to the parent CPC of the LPAR.

partitions = client.consoles.console.list_permitted_partitions(
filter_args={'name': partition_name, 'cpc-name': cpc_name})
if len(partitions) != 1:
Expand All @@ -77,10 +73,8 @@ def find_partition(cmd_ctx, client, cpc_or_name, partition_name):
cmd_ctx.error_format)
partition = partitions[0]
else:
if isinstance(cpc_or_name, zhmcclient.Cpc):
cpc = cpc_or_name
else:
cpc = find_cpc(cmd_ctx, client, cpc_or_name)
cpc = find_cpc(cmd_ctx, client, cpc_name)

# The CPC must be in DPM mode. We don't check that because it would
# cause a GET to the CPC resource that we otherwise don't need.
try:
Expand Down
4 changes: 2 additions & 2 deletions zhmccli/_cmd_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
from ._cmd_adapter import find_adapter


def find_port(cmd_ctx, client, cpc_or_name, adapter_name, port_name):
def find_port(cmd_ctx, client, cpc_name, adapter_name, port_name):
"""
Find a port by name and return its resource object.
"""
adapter = find_adapter(cmd_ctx, client, cpc_or_name, adapter_name)
adapter = find_adapter(cmd_ctx, client, cpc_name, adapter_name)
try:
port = adapter.ports.find(name=port_name)
except zhmcclient.Error as exc:
Expand Down
5 changes: 2 additions & 3 deletions zhmccli/_cmd_vfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
from ._cmd_partition import find_partition


def find_vfunction(
cmd_ctx, client, cpc_or_name, partition_name, vfunction_name):
def find_vfunction(cmd_ctx, client, cpc_name, partition_name, vfunction_name):
"""
Find a virtual function by name and return its resource object.
"""
partition = find_partition(cmd_ctx, client, cpc_or_name, partition_name)
partition = find_partition(cmd_ctx, client, cpc_name, partition_name)
try:
vfunction = partition.virtual_functions.find(name=vfunction_name)
except zhmcclient.Error as exc:
Expand Down
8 changes: 3 additions & 5 deletions zhmccli/_cmd_vswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
from ._cmd_cpc import find_cpc


def find_vswitch(cmd_ctx, client, cpc_or_name, vswitch_name):
def find_vswitch(cmd_ctx, client, cpc_name, vswitch_name):
"""
Find a virtual switch by name and return its resource object.
"""
if isinstance(cpc_or_name, zhmcclient.Cpc):
cpc = cpc_or_name
else:
cpc = find_cpc(cmd_ctx, client, cpc_or_name)
cpc = find_cpc(cmd_ctx, client, cpc_name)

# The CPC must be in DPM mode. We don't check that because it would
# cause a GET to the CPC resource that we otherwise don't need.
try:
Expand Down

0 comments on commit c7b6fbe

Please sign in to comment.