Skip to content

Commit

Permalink
Defined HMC resource class names centrally
Browse files Browse the repository at this point in the history
Details:

* Moved the resource class names into the utils module.

* Added a set VALID_RESOURCE_CLASSES that contains all valid resource class
  names.

Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Nov 10, 2021
1 parent 49666a5 commit 7b43fc5
Show file tree
Hide file tree
Showing 26 changed files with 148 additions and 48 deletions.
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Released: not yet

**Cleanup:**

* Defined HMC resource class names centrally.

**Known issues:**

* See `list of open issues`_.
Expand Down
19 changes: 17 additions & 2 deletions zhmcclient/_activation_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,19 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, \
RC_RESET_ACTIVATION_PROFILE, RC_IMAGE_ACTIVATION_PROFILE, \
RC_LOAD_ACTIVATION_PROFILE

__all__ = ['ActivationProfileManager', 'ActivationProfile']

# Resource class names, by profile type:
ACTIVATION_PROFILE_CLASSES = {
'reset': RC_RESET_ACTIVATION_PROFILE,
'image': RC_IMAGE_ACTIVATION_PROFILE,
'load': RC_LOAD_ACTIVATION_PROFILE,
}


class ActivationProfileManager(BaseManager):
"""
Expand Down Expand Up @@ -99,9 +108,15 @@ def __init__(self, cpc, profile_type):
'name',
]

try:
activation_profile_class = ACTIVATION_PROFILE_CLASSES[profile_type]
except KeyError:
raise ValueError("Unknown activation profile type: {}".
format(profile_type))

super(ActivationProfileManager, self).__init__(
resource_class=ActivationProfile,
class_name='{}-activation-profile'.format(profile_type),
class_name=activation_profile_class,
session=cpc.manager.session,
parent=cpc,
base_uri='{}/{}-activation-profiles'.format(cpc.uri, profile_type),
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
from ._port import PortManager
from ._logging import logged_api_call
from ._utils import repr_dict, repr_manager, repr_timestamp, matches_filters, \
divide_filter_args
divide_filter_args, RC_ADAPTER

__all__ = ['AdapterManager', 'Adapter']

Expand Down Expand Up @@ -118,7 +118,7 @@ def __init__(self, cpc):

super(AdapterManager, self).__init__(
resource_class=Adapter,
class_name='adapter',
class_name=RC_ADAPTER,
session=cpc.manager.session,
parent=cpc,
base_uri='/api/adapters',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_capacity_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_CAPACITY_GROUP

__all__ = ['CapacityGroupManager', 'CapacityGroup']

Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(self, cpc):

super(CapacityGroupManager, self).__init__(
resource_class=CapacityGroup,
class_name='capacity-group',
class_name=RC_CAPACITY_GROUP,
session=cpc.manager.session,
parent=cpc,
base_uri='{}/capacity-groups'.format(cpc.uri),
Expand Down
5 changes: 3 additions & 2 deletions zhmcclient/_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import timestamp_from_datetime, divide_filter_args, matches_filters
from ._utils import timestamp_from_datetime, divide_filter_args, \
matches_filters, RC_CONSOLE
from ._storage_group import StorageGroupManager
from ._storage_group_template import StorageGroupTemplateManager
from ._user import UserManager
Expand Down Expand Up @@ -66,7 +67,7 @@ def __init__(self, client):

super(ConsoleManager, self).__init__(
resource_class=Console,
class_name='console',
class_name=RC_CONSOLE,
session=client.session,
parent=None,
base_uri='/api/console',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_cpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from ._capacity_group import CapacityGroupManager
from ._logging import logged_api_call
from ._exceptions import ParseError
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_CPC

__all__ = ['CpcManager', 'Cpc']

Expand Down Expand Up @@ -95,7 +95,7 @@ def __init__(self, client):

super(CpcManager, self).__init__(
resource_class=Cpc,
class_name='cpc',
class_name=RC_CPC,
session=client.session,
parent=None,
base_uri='/api/cpcs',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_hba.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters
from ._utils import matches_filters, RC_HBA

__all__ = ['HbaManager', 'Hba']

Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, partition):

super(HbaManager, self).__init__(
resource_class=Hba,
class_name='hba',
class_name=RC_HBA,
session=partition.manager.session,
parent=partition,
base_uri='{}/hbas'.format(partition.uri),
Expand Down
5 changes: 3 additions & 2 deletions zhmcclient/_ldap_server_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, \
RC_LDAP_SERVER_DEFINITION

__all__ = ['LdapServerDefinitionManager', 'LdapServerDefinition']

Expand Down Expand Up @@ -61,7 +62,7 @@ def __init__(self, console):

super(LdapServerDefinitionManager, self).__init__(
resource_class=LdapServerDefinition,
class_name='ldap-server-definition',
class_name=RC_LDAP_SERVER_DEFINITION,
session=console.manager.session,
parent=console,
base_uri='/api/console/ldap-server-definitions',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_lpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from ._resource import BaseResource
from ._exceptions import StatusTimeout
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_LOGICAL_PARTITION

__all__ = ['LparManager', 'Lpar']

Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self, cpc):

super(LparManager, self).__init__(
resource_class=Lpar,
class_name='logical-partition',
class_name=RC_LOGICAL_PARTITION,
session=cpc.manager.session,
parent=cpc,
base_uri='/api/logical-partitions',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_nic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters
from ._utils import matches_filters, RC_NIC

__all__ = ['NicManager', 'Nic']

Expand Down Expand Up @@ -59,7 +59,7 @@ def __init__(self, partition):

super(NicManager, self).__init__(
resource_class=Nic,
class_name='nic',
class_name=RC_NIC,
session=partition.manager.session,
parent=partition,
base_uri='{}/nics'.format(partition.uri),
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from ._hba import HbaManager
from ._virtual_function import VirtualFunctionManager
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_PARTITION

__all__ = ['PartitionManager', 'Partition']

Expand Down Expand Up @@ -79,7 +79,7 @@ def __init__(self, cpc):

super(PartitionManager, self).__init__(
resource_class=Partition,
class_name='partition',
class_name=RC_PARTITION,
session=cpc.manager.session,
parent=cpc,
base_uri='/api/partitions',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_password_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_PASSWORD_RULE

__all__ = ['PasswordRuleManager', 'PasswordRule']

Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(self, console):

super(PasswordRuleManager, self).__init__(
resource_class=PasswordRule,
class_name='password-rule',
class_name=RC_PASSWORD_RULE,
session=console.manager.session,
parent=console,
base_uri='/api/console/password-rules',
Expand Down
16 changes: 14 additions & 2 deletions zhmcclient/_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters
from ._utils import matches_filters, RC_NETWORK_PORT, RC_STORAGE_PORT

__all__ = ['PortManager', 'Port']

# Resource class names, by port type:
PORT_CLASSES = {
'network': RC_NETWORK_PORT,
'storage': RC_STORAGE_PORT,
None: '',
}


class PortManager(BaseManager):
"""
Expand All @@ -56,10 +63,15 @@ def __init__(self, adapter, port_type):
# * `storage`: Ports of a storage adapter
# * None: Adapter family without ports

try:
port_class = PORT_CLASSES[port_type]
except KeyError:
raise ValueError("Unknown port type: {}".format(port_type))

super(PortManager, self).__init__(
resource_class=Port,
session=adapter.manager.session,
class_name='{}-port'.format(port_type) if port_type else '',
class_name=port_class,
parent=adapter,
base_uri='',
# TODO: Re-enable the following when unit/test_hba.py has been
Expand Down
5 changes: 3 additions & 2 deletions zhmcclient/_storage_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
from ._storage_volume import StorageVolumeManager
from ._virtual_storage_resource import VirtualStorageResourceManager
from ._logging import logged_api_call
from ._utils import append_query_parms, matches_filters, divide_filter_args
from ._utils import append_query_parms, matches_filters, divide_filter_args, \
RC_STORAGE_GROUP

__all__ = ['StorageGroupManager', 'StorageGroup']

Expand Down Expand Up @@ -127,7 +128,7 @@ def __init__(self, console):

super(StorageGroupManager, self).__init__(
resource_class=StorageGroup,
class_name='storage-group',
class_name=RC_STORAGE_GROUP,
session=console.manager.session,
parent=console,
base_uri='/api/storage-groups',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_storage_group_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from ._resource import BaseResource
from ._storage_volume_template import StorageVolumeTemplateManager
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_STORAGE_TEMPLATE

__all__ = ['StorageGroupTemplateManager', 'StorageGroupTemplate']

Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, console):

super(StorageGroupTemplateManager, self).__init__(
resource_class=StorageGroupTemplate,
class_name='storage-template',
class_name=RC_STORAGE_TEMPLATE,
session=console.manager.session,
parent=console,
base_uri='/api/storage-templates',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_storage_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_STORAGE_VOLUME

__all__ = ['StorageVolumeManager', 'StorageVolume']

Expand Down Expand Up @@ -85,7 +85,7 @@ def __init__(self, storage_group):

super(StorageVolumeManager, self).__init__(
resource_class=StorageVolume,
class_name='storage_volume',
class_name=RC_STORAGE_VOLUME,
session=storage_group.manager.session,
parent=storage_group,
base_uri='{}/storage-volumes'.format(storage_group.uri),
Expand Down
5 changes: 3 additions & 2 deletions zhmcclient/_storage_volume_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, \
RC_STORAGE_TEMPLATE_VOLUME

__all__ = ['StorageVolumeTemplateManager', 'StorageVolumeTemplate']

Expand Down Expand Up @@ -80,7 +81,7 @@ def __init__(self, storage_group_template):

super(StorageVolumeTemplateManager, self).__init__(
resource_class=StorageVolumeTemplate,
class_name='storage-template-volume',
class_name=RC_STORAGE_TEMPLATE_VOLUME,
session=storage_group_template.manager.session,
parent=storage_group_template,
base_uri='{}/storage-template-volumes'.format(
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_TASK

__all__ = ['TaskManager', 'Task']

Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(self, console):

super(TaskManager, self).__init__(
resource_class=Task,
class_name='task',
class_name=RC_TASK,
session=console.manager.session,
parent=console,
base_uri='/api/console/tasks',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_unmanaged_cpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_CPC

__all__ = ['UnmanagedCpcManager', 'UnmanagedCpc']

Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, console):

super(UnmanagedCpcManager, self).__init__(
resource_class=UnmanagedCpc,
class_name='cpc',
class_name=RC_CPC,
session=console.manager.session,
parent=console,
base_uri='/api/console',
Expand Down
4 changes: 2 additions & 2 deletions zhmcclient/_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ._manager import BaseManager
from ._resource import BaseResource
from ._logging import logged_api_call
from ._utils import matches_filters, divide_filter_args
from ._utils import matches_filters, divide_filter_args, RC_USER

__all__ = ['UserManager', 'User']

Expand Down Expand Up @@ -59,7 +59,7 @@ def __init__(self, console):

super(UserManager, self).__init__(
resource_class=User,
class_name='user',
class_name=RC_USER,
session=console.manager.session,
parent=console,
base_uri='/api/users',
Expand Down
Loading

0 comments on commit 7b43fc5

Please sign in to comment.