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) self._console = console @property def console(self): """ :class:`~zhmcclient.Console`: The Console object representing the HMC. """ return self._console
[docs] @logged_api_call def list(self, full_properties=False, filter_args=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. Any resource property may be specified in a filter argument. For details about filter arguments, see :ref:`Filtering`. The listing of resources is handled in an optimized way: * If this manager is enabled for :ref:`auto-updating`, a locally maintained resource list is used (which is automatically updated via inventory notifications from the HMC) and the provided filter arguments are applied. * Otherwise, if the filter arguments specify the resource name as a single filter argument with a straight match string (i.e. without regular expressions), an optimized lookup is performed based on a locally maintained name-URI cache. * Otherwise, the HMC List operation is performed with the subset of the provided filter arguments that can be handled on the HMC side and the remaining filter arguments are applied on the client side on the list result. 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): Controls that the full set of resource properties for each returned tape link is being retrieved, vs. only a short set of properties returned by the HMC for tape link list operations. 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. 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, None)
[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