Skip to content

Commit

Permalink
Support for Partition Links
Browse files Browse the repository at this point in the history
Details:

* Added support for Partition Links with a new 'zhmcclient.PartitionLink'
  resource class (and corresponding manager class). Added the following
  methods for partition links to the 'zhmcclient.Partition' class:
  'attach_network_link()', 'detach_network_link()',
  'attach_ctc_link()', 'detach_ctc_link()', 'list_attached_partition_links()'.

* Because the "Create Partition Link" HMC operation does not return the
  'object-uri' property of the created partition link, the handling of HTTP POST
  operations has been enhanced to add the URI returned in the "Location" header
  field as an artificial property 'location-uri' to the result data, if the
  "Location" header field is set and the result data does not contain
  'object-uri' or 'element-uri'.

* Added the following example scripts:

    examples/list_attached_partition_links.py
    examples/list_partition_links.py

* Added end2end testcases for 'zhmcclient.PartitionLink' and for the new
  methods addded to 'zhmcclient.Partition'.

* Added the following functions to the end2end utils.py:

    assert_properties(act_obj, exp_obj)
    skipif_no_partition_link_feature(cpc)
    pformat_as_dict(dict_)
    copy_dict(dict_)
    copy_list(list_)

* In the end2end utils.py function standard_partition_props(), improved
  the performance by retrieving the necessary CPC properties no longer
  by pulling all properties, but by pulling them selectively.

Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Jan 22, 2025
1 parent 07eb7e7 commit 8a92f8b
Show file tree
Hide file tree
Showing 16 changed files with 2,451 additions and 4 deletions.
6 changes: 6 additions & 0 deletions changes/1678.feature.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Because the "Create Partition Link" HMC operation does not return the
'object-uri' property of the created partition link, the handling of HTTP POST
operations has been enhanced to add the URI returned in the "Location" header
field as an artificial property 'location-uri' to the result data, if the
"Location" header field is set and the result data does not contain 'object-uri'
or 'element-uri'.
5 changes: 5 additions & 0 deletions changes/1678.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added support for Partition Links with a new 'zhmcclient.PartitionLink'
resource class (and corresponding manager class). Added the following
methods for partition links to the 'zhmcclient.Partition' class:
'attach_network_link()', 'detach_network_link()',
'attach_ctc_link()', 'detach_ctc_link()', 'list_attached_partition_links()'.
5 changes: 5 additions & 0 deletions docs/appendix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ Resources scoped to CPCs in DPM mode

For details, see section :ref:`Partitions`.

Partition Link
A resource that interconnects two or more :term:`Partitions <Partition>`,
using one of multiple interconnect technologies such as SMC-D,
Hipersockets, or CTC.

Port
The physical connector port (jack) of an :term:`Adapter`.

Expand Down
20 changes: 20 additions & 0 deletions docs/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,26 @@ Storage Volume Templates
:special-members: __str__


.. _`Partition Links`:

Partition Links
---------------

.. automodule:: zhmcclient._partition_link

.. autoclass:: zhmcclient.PartitionLinkManager
:members:
:autosummary:
:autosummary-inherited-members:
:special-members: __str__

.. autoclass:: zhmcclient.PartitionLink
:members:
:autosummary:
:autosummary-inherited-members:
:special-members: __str__


.. _`Capacity Groups`:

Capacity Groups
Expand Down
81 changes: 81 additions & 0 deletions examples/list_attached_partition_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python
# Copyright 2025 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Example that lists partition links attached to a partition.
"""

import sys
import requests.packages.urllib3

import zhmcclient
from zhmcclient.testutils import hmc_definitions

requests.packages.urllib3.disable_warnings()

# Get HMC info from HMC inventory and vault files
hmc_def = hmc_definitions()[0]
nickname = hmc_def.nickname
host = hmc_def.host
userid = hmc_def.userid
password = hmc_def.password
verify_cert = hmc_def.verify_cert

if len(sys.argv) != 3:
print(f"Usage: {sys.argv[0]} CPC PARTITION")
sys.exit(2)

cpc_name = sys.argv[1]
part_name = sys.argv[2]

print(__doc__)

print(f"Using HMC {nickname} at {host} with userid {userid} ...")

print("Creating a session with the HMC ...")
try:
session = zhmcclient.Session(
host, userid, password, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
client = zhmcclient.Client(session)
console = client.consoles.console

print(f"Finding partition {part_name} on CPC {cpc_name} ...")
cpc = client.cpcs.find(name=cpc_name)
part = cpc.partitions.find(name=part_name)

print(f"Listing partition links attached to partition {part_name} ...")
partition_links = part.list_attached_partition_links()

print()
print("Partition Link Type State Attached partitions")
print("---------------------------------------------------------------------------------------")
for pl in partition_links:
name = pl.get_property('name')
type = pl.get_property('type')
state = pl.get_property('state')
attached_parts = pl.list_attached_partitions()
attached_part_names = [p.name for p in attached_parts]
print(f"{name:20s} {type:12s} {state:10} {', '.join(attached_part_names)}")
print()

finally:
print("Logging off ...")
session.logoff()
74 changes: 74 additions & 0 deletions examples/list_partition_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python
# Copyright 2024 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Example that lists partition links.
"""

import sys
import requests.packages.urllib3
from pprint import pprint

import zhmcclient
from zhmcclient.testutils import hmc_definitions

requests.packages.urllib3.disable_warnings()

# Get HMC info from HMC inventory and vault files
hmc_def = hmc_definitions()[0]
nickname = hmc_def.nickname
host = hmc_def.host
userid = hmc_def.userid
password = hmc_def.password
verify_cert = hmc_def.verify_cert

# Whether to list partition links with full properties
full_properties = False

print(__doc__)

print(f"Using HMC {nickname} at {host} with userid {userid} ...")

print("Creating a session with the HMC ...")
try:
session = zhmcclient.Session(
host, userid, password, verify_cert=verify_cert)
except zhmcclient.Error as exc:
print(f"Error: Cannot establish session with HMC {host}: "
f"{exc.__class__.__name__}: {exc}")
sys.exit(1)

try:
client = zhmcclient.Client(session)
console = client.consoles.console

print(f"Listing all partition links ...")
partition_links = console.partition_links.list()

print()
print("Partition Link Type State Attached partitions")
print("---------------------------------------------------------------------------------------")
for pl in partition_links:
name = pl.get_property('name')
type = pl.get_property('type')
state = pl.get_property('state')
attached_parts = pl.list_attached_partitions()
attached_part_names = [p.name for p in attached_parts]
print(f"{name:20s} {type:12s} {state:10} {', '.join(attached_part_names)}")
print()

finally:
print("Logging off ...")
session.logoff()
Loading

0 comments on commit 8a92f8b

Please sign in to comment.