os-resource-classes
raw JSON → 1.1.0 verified Fri May 01 auth: no python
Provides resource class constants and utilities for OpenStack placement service. Version 1.1.0. Low release cadence.
pip install os-resource-classes Common errors
error ModuleNotFoundError: No module named 'os_resource_classes.resource_classes' ↓
cause Importing from an internal submodule that is not a public API.
fix
Change import to: from os_resource_classes import ResourceClass
error ValueError: 'my_custom_res' is not a valid resource class name ↓
cause Custom resource class names must start with 'CUSTOM_' and be uppercase without spaces.
fix
Use the CUSTOM_NAMESPACE prefix and convert to uppercase: name = 'CUSTOM_MY_CUSTOM_RES'
error AttributeError: module 'os_resource_classes' has no attribute 'resource_classes' ↓
cause Trying to access a constant that does not exist or using old naming.
fix
Use the correct symbols: ResourceClass, CUSTOM_NAMESPACE, normalize_name, etc.
Warnings
gotcha ResourceClass name must be uppercase letters, digits, underscores, and optionally start with 'CUSTOM_' for custom names. Avoid lowercase or hyphens. ↓
fix Use normalize_name() to standardize names before creating ResourceClass.
gotcha Do not import from os_resource_classes.resource_classes submodule directly; it may change in future versions. ↓
fix Import from the top-level package: from os_resource_classes import ResourceClass
deprecated The function 'resource_classes_from_flags' is deprecated and may be removed in a future release. ↓
fix Use resource_classes_from_names() instead.
Imports
- ResourceClass wrong
from os_resource_classes.resource_classes import ResourceClasscorrectfrom os_resource_classes import ResourceClass - CUSTOM_NAMESPACE
from os_resource_classes import CUSTOM_NAMESPACE - UUID_V4_PATTERN
from os_resource_classes import UUID_V4_PATTERN - resource_classes_from_names
from os_resource_classes import resource_classes_from_names - resource_classes_from_flags
from os_resource_classes import resource_classes_from_flags - normalize_name
from os_resource_classes import normalize_name
Quickstart
from os_resource_classes import ResourceClass
rc = ResourceClass('VCPU')
print(rc.name)
print(rc.id)
# Check if a name is standard
from os_resource_classes import CUSTOM_NAMESPACE
print(CUSTOM_NAMESPACE) # 'CUSTOM_'
# Convert names list to ResourceClass objects
from os_resource_classes import resource_classes_from_names
names = ['VCPU', 'MEMORY_MB', 'DISK_GB']
rcs = resource_classes_from_names(names)
print([rc.name for rc in rcs])