Source code for zhmcclient._tape_link

# Copyright 2026 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.

"""
Starting with SE version 2.15.0, tape link management capabilities have been
introduced for DPM mode.

A :term:`tape link` object represents a single tape link associated with a
DPM-enabled :term:`CPC`. Tape links define pathways to tape library storage
that can be attached to partitions. When a tape link is attached to a
partition, its fulfilled resources are virtualized and the partition view of
them is represented by a set of
:term:`virtual tape resources <Virtual Tape Resource>`.

Tape links are top-level resources whose conceptual parent is the
:term:`Console`. In the zhmcclient, the :class:`~zhmcclient.TapeLink` objects
are accessible via the :attr:`~zhmcclient.Console.tape_links` property of a
:class:`~zhmcclient.Console` object.

Tape links can be listed, created, deleted, and updated. They also support
querying and updating selected properties of their virtual tape resources.

Tape link resources have a lifecycle that is reflected in their
``fulfillment-state`` property. Creating or modifying a tape link can require
subsequent SAN configuration changes by a storage administrator before the tape
link resources become usable by a partition. Fulfillment is auto-detected by
the HMC and can transition through states such as ``pending``, ``complete``,
``pending-with-mismatches``, and ``incomplete``.

The canonical URI of a tape link is ``/api/tape-links/{tape-link-id}``, and
its ``parent`` property identifies the owning Console. The ``cpc-uri``
property identifies the CPC associated with the tape link, and the
``tape-library-uri`` property identifies the linked tape library once it is
specified or discovered.

Tape links can only be managed on CPCs that support the tape library
management feature (SE version >= 2.15.0).
"""


import copy
import re

from ._manager import BaseManager
from ._resource import BaseResource
from ._virtual_tape_resource import VirtualTapeResourceManager
from ._logging import logged_api_call
from ._utils import RC_TAPE_LINK, append_query_parms

__all__ = ['TapeLinkManager', 'TapeLink']


[docs] class TapeLinkManager(BaseManager): """ Manager providing access to the :term:`tape links <tape link>` of the :term:`Console`. Derived from :class:`~zhmcclient.BaseManager`; see there for common methods and attributes. Objects of this class are not directly created by the user; they are accessible via the following instance variable: * :attr:`~zhmcclient.Console.tape_links` of a :class:`~zhmcclient.Console` object. The tape links managed by this class are associated with DPM-enabled CPCs and can be filtered by properties such as ``cpc-uri``, ``name``, and ``fulfillment-state``. HMC/SE version requirements: * SE version >= 2.15.0 """ def __init__(self, console): # This function should not go into the docs. # Parameters: # console (:class:`~zhmcclient.Console`): # Console defining the scope for this manager. # Resource properties that are supported as filter query parameters. # If the support for a resource property changes within the set of HMC # versions that support this type of resource, this list must be set up # for the version of the HMC this session is connected to. query_props = [ 'cpc-uri', 'name', 'fulfillment-state', 'tape-library-uri', ] super().__init__( resource_class=TapeLink, class_name=RC_TAPE_LINK, session=console.manager.session, parent=console, base_uri='/api/tape-links', oid_prop='object-id', uri_prop='object-uri', name_prop='name', query_props=query_props) @property def console(self): """ :class:`~zhmcclient.Console`: The Console object representing the HMC. """ return self._parent
[docs] @logged_api_call def list(self, full_properties=False, filter_args=None, additional_properties=None): """ List the tape links defined on this Console. Tape links for which the authenticated user does not have object-access permission are not included. The properties in the returned resource objects are by default those returned by the "List Tape Links" HMC operation defined in the :term:`HMC API` book and can be expanded with the "full_properties" and "additional_properties" parameters of this method. Any resource property may be specified in a filter argument. For details about filter arguments, see :ref:`Filtering`. When using filters to get a single resource object of this type, the ``name`` property alone is not sufficient, because the name of tape link objects is unique within the associated CPC and can thus be used for a tape link object associated to a different CPC. In that case, specify the ``cpc-uri`` property in addition to the ``name`` property in the filter. The listing of resources is handled by performing an HMC list operation in context of the parent resource, in an optimized way. For details, see :ref:`Listing resources`. HMC/SE version requirements: * SE version >= 2.15.0 Authorization requirements: * Object-access permission to the Console. * Object-access permission to any tape links to be included in the result. Parameters: full_properties (bool): If `True`, the set of properties in the returned resource objects will be expanded to the full set of readable properties defined in the data model for Tape Library objects in the :term:`HMC API` book. filter_args (dict): Filter arguments that narrow the list of returned resources to those that match the specified filter arguments. For details, see :ref:`Filtering`. `None` causes no filtering to happen. additional_properties (list of string): A list of property names. If specified, the set of properties in the returned resource objects will be expanded with the specified properties. `None` is treated the same as an empty list. Returns: : A list of :class:`~zhmcclient.TapeLink` objects. Raises: :exc:`~zhmcclient.HTTPError` :exc:`~zhmcclient.ParseError` :exc:`~zhmcclient.AuthError` :exc:`~zhmcclient.ConnectionError` :exc:`~zhmcclient.FilterConversionError` """ result_prop = 'tape-links' list_uri = self._base_uri return self._list_with_operation( list_uri, result_prop, full_properties, filter_args, additional_properties)
[docs] @logged_api_call def create(self, properties): """ Create a tape link on this Console. The new tape link establishes a pathway to tape library storage for a partition on a DPM-enabled CPC. Depending on the requested properties and the SAN environment, the new tape link may initially enter the ``pending`` fulfillment state until its requested resources are fulfilled. HMC/SE version requirements: * SE version >= 2.15.0 Authorization requirements: * Object-access permission to the Console. * Object-access permission to the CPC and any explicitly referenced resources such as the tape library or adapter ports. * Task permission to the "Configure Storage - System Programmer" task. Parameters: properties (dict): Initial property values. Allowable properties are defined in section 'Request body contents' in section 'Create Tape Link' in the :term:`HMC API` book. Typical input properties include ``name``, ``description``, ``cpc-uri``, ``connectivity``, ``max-partitions``, ``tape-library-uri``, and ``adapter-port-uris``. If ``tape-library-uri`` or enough adapter ports are not specified, the remaining assignment may be deferred to the storage administrator. Returns: :class:`~zhmcclient.TapeLink`: The resource object for the new tape link. The object will have its ``object-uri`` property set as returned by the HMC, and will also have the input properties set. Raises: :exc:`~zhmcclient.HTTPError` :exc:`~zhmcclient.ParseError` :exc:`~zhmcclient.AuthError` :exc:`~zhmcclient.ConnectionError` """ result = self.session.post(self._base_uri, body=properties) # There should not be overlaps, but just in case there are, the # returned props should overwrite the input props: props = copy.deepcopy(properties) props.update(result) name = props.get(self._name_prop, None) uri = props[self._uri_prop] tape_link = TapeLink(self, uri, name, props) self._name_uri_cache.update(name, uri) return tape_link