• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zhmcclient / python-zhmcclient / test-3323

11 Mar 2025 02:09PM UTC coverage: 81.296% (-0.06%) from 81.351%
test-3323

Pull #1773

github

web-flow
Merge 4fd6d26e5 into 96b5245ca
Pull Request #1773: Release 1.19.1

8906 of 10955 relevant lines covered (81.3%)

29.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.11
/zhmcclient/_virtual_storage_resource.py
1
# Copyright 2018,2021 IBM Corp. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#    http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
"""
36✔
16
A :term:`virtual storage resource` object represents a storage-related
17
z/Architecture device that is visible to a partition and that provides access
18
for that partition to a :term:`storage volume`.
19

20
The storage-related z/Architecture devices that are visible to a partition are
21
different for the two storage architectures: For FCP, the virtualized HBA is
22
visible as a device, and the storage volumes (LUNs) are not represented as
23
devices. For FICON, each ECKD volume is visible as a device, but the
24
virtualized FICON adapter port is not represented as a device.
25

26
What the virtual storage resource objects represent, therefore depends on
27
the storage architecture of the storage volume they are used for:
28

29
* For FCP, a virtual storage resource object represents the virtualized HBA
30
  in the partition that is used to access the LUN. However, each usage of
31
  the virtual HBA in context of a storage group has its own virtual storage
32
  resource object.
33
* For FICON, a virtual storage resource object represents the ECKD volume.
34

35
Virtual storage resource objects are instantiated automatically when a storage
36
group is attached to a partition, and are removed automatically upon
37
detachment.
38

39
The :term:`HBA` resource objects known from DPM mode before introduction of the
40
"dpm-storage-management" firmware feature are no longer exposed.
41

42
Virtual storage resource objects are contained in :term:`storage group`
43
objects.
44

45
Storage groups and storage volumes only can be defined in CPCs that are in
46
DPM mode and that have the "dpm-storage-management"
47
:ref:`firmware feature <firmware features>` enabled.
48
"""
49

50

51
import re
36✔
52
import copy
36✔
53
# from requests.utils import quote
54

55
from ._manager import BaseManager
36✔
56
from ._resource import BaseResource
36✔
57
from ._logging import logged_api_call
36✔
58
from ._utils import RC_VIRTUAL_STORAGE_RESOURCE
36✔
59

60
__all__ = ['VirtualStorageResourceManager', 'VirtualStorageResource']
36✔
61

62

63
class VirtualStorageResourceManager(BaseManager):
36✔
64
    """
65
    Manager providing access to the :term:`virtual storage resources
66
    <Virtual Storage Resource>` in a particular :term:`storage group`.
67

68
    Derived from :class:`~zhmcclient.BaseManager`; see there for common methods
69
    and attributes.
70

71
    Objects of this class are not directly created by the user; they are
72
    accessible via the following instance variable of a
73
    :class:`~zhmcclient.StorageGroup` object:
74

75
    * :attr:`~zhmcclient.StorageGroup.virtual_storage_resources`
76

77
    HMC/SE version requirements:
78

79
    * :ref:`firmware feature <firmware features>` "dpm-storage-management"
80
    """
81

82
    def __init__(self, storage_group):
36✔
83
        # This function should not go into the docs.
84
        # Parameters:
85
        #   storage_group (:class:`~zhmcclient.StorageGroup`):
86
        #     Storage group defining the scope for this manager.
87

88
        # Resource properties that are supported as filter query parameters.
89
        # If the support for a resource property changes within the set of HMC
90
        # versions that support this type of resource, this list must be set up
91
        # for the version of the HMC this session is connected to.
92
        query_props = [
36✔
93
            'name',
94
            'device-number',
95
            'adapter-port-uri',
96
            'partition-uri',
97
        ]
98

99
        super().__init__(
36✔
100
            resource_class=VirtualStorageResource,
101
            class_name=RC_VIRTUAL_STORAGE_RESOURCE,
102
            session=storage_group.manager.session,
103
            parent=storage_group,
104
            base_uri=f'{storage_group.uri}/virtual-storage-resources',
105
            oid_prop='element-id',
106
            uri_prop='element-uri',
107
            name_prop='name',
108
            query_props=query_props)
109

110
    @property
36✔
111
    def storage_group(self):
36✔
112
        """
113
        :class:`~zhmcclient.StorageGroup`: :term:`Storage group` defining the
114
        scope for this manager.
115
        """
116
        return self._parent
×
117

118
    @logged_api_call
36✔
119
    def list(self, full_properties=False, filter_args=None):
36✔
120
        """
121
        List the virtual storage resources in this storage group.
122

123
        Any resource property may be specified in a filter argument. For
124
        details about filter arguments, see :ref:`Filtering`.
125

126
        The listing of resources is handled in an optimized way:
127

128
        * If this manager is enabled for :ref:`auto-updating`, a locally
129
          maintained resource list is used (which is automatically updated via
130
          inventory notifications from the HMC) and the provided filter
131
          arguments are applied.
132

133
        * Otherwise, if the filter arguments specify the resource name as a
134
          single filter argument with a straight match string (i.e. without
135
          regular expressions), an optimized lookup is performed based on a
136
          locally maintained name-URI cache.
137

138
        * Otherwise, the HMC List operation is performed with the subset of the
139
          provided filter arguments that can be handled on the HMC side and the
140
          remaining filter arguments are applied on the client side on the list
141
          result.
142

143
        HMC/SE version requirements:
144

145
        * :ref:`firmware feature <firmware features>` "dpm-storage-management"
146

147
        Authorization requirements:
148

149
        * Object-access permission to this storage group.
150

151
        Parameters:
152

153
          full_properties (bool):
154
            Controls that the full set of resource properties for each returned
155
            storage volume is being retrieved, vs. only the following short
156
            set: "element-uri", "name", "device-number", "adapter-port-uri",
157
            and "partition-uri".
158

159
          filter_args (dict):
160
            Filter arguments that narrow the list of returned resources to
161
            those that match the specified filter arguments. For details, see
162
            :ref:`Filtering`.
163

164
            `None` causes no filtering to happen, i.e. all resources are
165
            returned.
166

167
        Returns:
168

169
          : A list of :class:`~zhmcclient.VirtualStorageResource` objects.
170

171
        Raises:
172

173
          :exc:`~zhmcclient.HTTPError`
174
          :exc:`~zhmcclient.ParseError`
175
          :exc:`~zhmcclient.AuthError`
176
          :exc:`~zhmcclient.ConnectionError`
177
        """
178
        result_prop = 'virtual-storage-resources'
×
179
        list_uri = f'{self.storage_group.uri}/virtual-storage-resources'
×
180
        return self._list_with_operation(
×
181
            list_uri, result_prop, full_properties, filter_args, None)
182

183

184
class VirtualStorageResource(BaseResource):
36✔
185
    """
186
    Representation of a :term:`virtual storage resource`.
187

188
    Derived from :class:`~zhmcclient.BaseResource`; see there for common
189
    methods and attributes.
190

191
    Objects of this class are not directly created by the user; they are
192
    returned from creation or list functions on their manager object
193
    (in this case, :class:`~zhmcclient.VirtualStorageResourceManager`).
194

195
    HMC/SE version requirements:
196

197
    * :ref:`firmware feature <firmware features>` "dpm-storage-management"
198
    """
199

200
    def __init__(self, manager, uri, name=None, properties=None):
36✔
201
        # This function should not go into the docs.
202
        #   manager (:class:`~zhmcclient.VirtualStorageResourceManager`):
203
        #     Manager object for this resource object.
204
        #   uri (string):
205
        #     Canonical URI path of the resource.
206
        #   name (string):
207
        #     Name of the resource.
208
        #   properties (dict):
209
        #     Properties to be set for this resource object. May be `None` or
210
        #     empty.
211
        assert isinstance(manager, VirtualStorageResourceManager), (
×
212
            "VirtualStorageResource init: Expected manager type "
213
            f"{VirtualStorageResourceManager}, got {type(manager)}")
214
        super().__init__(
×
215
            manager, uri, name, properties)
216
        self._attached_partition = None
×
217
        self._adapter_port = None
×
218
        self._storage_volume = None
×
219

220
    @property
36✔
221
    def attached_partition(self):
36✔
222
        """
223
        :class:`~zhmcclient.Partition`: The partition to which this virtual
224
        storage resource is attached.
225

226
        The returned partition object has only a minimal set of properties set
227
        ('object-id', 'object-uri', 'class', 'parent').
228

229
        Note that a virtual storage resource is always attached to a partition,
230
        as long as it exists.
231

232
        HMC/SE version requirements:
233

234
        * :ref:`firmware feature <firmware features>` "dpm-storage-management"
235

236
        Authorization requirements:
237

238
        * Object-access permission to the storage group owning this
239
          virtual storage resource.
240

241
        Raises:
242

243
          :exc:`~zhmcclient.HTTPError`
244
          :exc:`~zhmcclient.ParseError`
245
          :exc:`~zhmcclient.AuthError`
246
          :exc:`~zhmcclient.ConnectionError`
247
        """
248
        if self._attached_partition is None:
×
249
            part_mgr = self.manager.storage_group.manager.cpc.partitions
×
250
            part = part_mgr.resource_object(self.get_property('partition-uri'))
×
251
            self._attached_partition = part
×
252
        return self._attached_partition
×
253

254
    @property
36✔
255
    def adapter_port(self):
36✔
256
        """
257
        :class:`~zhmcclient.Port`: The storage adapter port associated with
258
        this virtual storage resource, once discovery has determined which
259
        port to use for this virtual storage resource.
260

261
        This applies to both, FCP and FICON/ECKD typed storage groups.
262

263
        The returned adapter port object has only a minimal set of properties
264
        set ('object-id', 'object-uri', 'class', 'parent').
265

266
        HMC/SE version requirements:
267

268
        * :ref:`firmware feature <firmware features>` "dpm-storage-management"
269

270
        Authorization requirements:
271

272
        * Object-access permission to the storage group owning this
273
          virtual storage resource.
274
        * Object-access permission to the CPC of the storage adapter.
275
        * Object-access permission to the storage adapter.
276

277
        Raises:
278

279
          :exc:`~zhmcclient.HTTPError`
280
          :exc:`~zhmcclient.ParseError`
281
          :exc:`~zhmcclient.AuthError`
282
          :exc:`~zhmcclient.ConnectionError`
283
        """
284
        if self._adapter_port is None:
×
285
            port_uri = self.get_property('adapter-port-uri')
×
286
            assert port_uri is not None
×
287
            m = re.match(r'^(/api/adapters/[^/]+)/.*', port_uri)
×
288
            adapter_uri = m.group(1)
×
289
            adapter_mgr = self.manager.storage_group.cpc.adapters
×
290
            filter_args = {'object-uri': adapter_uri}
×
291
            adapter = adapter_mgr.find(**filter_args)
×
292
            port_mgr = adapter.ports
×
293
            port = port_mgr.resource_object(port_uri)
×
294
            self._adapter_port = port
×
295
        return self._adapter_port
×
296

297
    @logged_api_call
36✔
298
    def update_properties(self, properties):
36✔
299
        """
300
        Update writeable properties of this virtual storage resource.
301

302
        This method serializes with other methods that access or change
303
        properties on the same Python object.
304

305
        HMC/SE version requirements:
306

307
        * :ref:`firmware feature <firmware features>` "dpm-storage-management"
308

309
        Authorization requirements:
310

311
        * Object-access permission to the storage group owning this
312
          virtual storage resource.
313
        * Task permission to the "Configure Storage - System Programmer" task.
314

315
        Parameters:
316

317
          properties (dict): New values for the properties to be updated.
318
            Properties not to be updated are omitted.
319
            Allowable properties are the properties with qualifier (w) in
320
            section 'Data model' in section 'Virtual Storage Resource object'
321
            in the :term:`HMC API` book.
322

323
        Raises:
324

325
          :exc:`~zhmcclient.HTTPError`
326
          :exc:`~zhmcclient.ParseError`
327
          :exc:`~zhmcclient.AuthError`
328
          :exc:`~zhmcclient.ConnectionError`
329
        """
330
        # pylint: disable=protected-access
331
        self.manager.session.post(self.uri, resource=self, body=properties)
×
332
        is_rename = self.manager._name_prop in properties
×
333
        if is_rename:
×
334
            # Delete the old name from the cache
335
            self.manager._name_uri_cache.delete(self.name)
×
336
        self.update_properties_local(copy.deepcopy(properties))
×
337
        if is_rename:
×
338
            # Add the new name to the cache
339
            self.manager._name_uri_cache.update(self.name, self.uri)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc