# openshift-python-scale-utilities
Pypi: [openshift-python-scale-utilities](https://pypi.org/project/openshift-python-scale-utilities/)
Utilities to assist in scaling [openshift-python-wrapper](https://github.com/RedHatQE/openshift-python-wrapper) resources
## ocp_scale_utilities.threaded
Utilizes [ThreadPoolExecutor](https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor)
to operate on many resources in parallel across multiple threads.
### Usage
```
from ocp_resources.virtual_machine import VirtualMachine
from ocp_scale_utilities.threaded.utils import (
threaded_deploy_resources,
threaded_delete_resources,
threaded_wait_deleted_resources,
)
from ocp_scale_utilities.threaded.scale import ThreadedScaleResources
# Create iterable of VirtualMachine python objects to deploy
# Be sure to use deepcopy() when passing dicts to objects to avoid collisions
vms = [VirtualMachine(..., body=deepcopy(body))]
# Option A:
def funcA():
threaded_deploy_resources(resources=vms)
yield vms
threaded_delete_resources(resources=vms)
threaded_wait_deleted_resources(resources=vms)
# Option B:
def funcB():
with ThreadedScaleResources(resources=vms, wait_for_status=VirtualMachine.Status.RUNNING):
yield vms
```
## ocp_scale_utilities.monitoring
`MonitorResourceAPIServerRequests` provides a way to monitor a specific resource to determine if it is being actively used.
This allows the ability to wait for resources to settle after a major scale action,
improving reliability, and increasing readability in prometheus data.
### Usage
```
from ocp_resources.virtual_machine import VirtualMachine
from ocp_scale_utilities.monitoring import MonitorResourceAPIServerRequests
from ocp_scale_utilities.threaded.scale import ThreadedScaleResources
from ocp_utilities.monitoring import Prometheus
monitor_api_requests = MonitorResourceAPIServerRequests(
prometheus=Prometheus(...),
resource_class=VirtualMachine,
idle_requests_value=float(...), # Based on apiserver_request_total metric
)
monitor_api_requests.wait_for_idle()
with ThreadedScaleResources(resources=vms):
monitor_api_requests.wait_for_idle()
yield vms
monitor_api_requests.wait_for_idle()
```
## ocp_scale_utilities.logger
Logging at scale requires utilizing logging.QueueHandlers to avoid logging to closed streams.
```
root QueueHandler ┐ ┌> StreamHandler
├> Queue -> QueueListener ┤
basic QueueHandler ┘ └> FileHandler
```
### Usage
`main.py`
```
import logging
from ocp_scale_utilities.logger import setup_logging
from module import func
LOGGER = None
def main():
LOGGER.warning("main logged warning message")
func()
if __name__ == "__main__":
log_listener = setup_logging(log_level=logging.WARNING, log_file="/tmp/example.log")
LOGGER = logging.getLogger(__name__)
main()
log_listener.stop()
```
`module.py`
```
import logging
LOGGER = logging.getLogger(__name__)
def func():
LOGGER.warning("func logged warning message")
```
## Contributing
Please use pre-commit to check the code before commiting
```
pre-commit install
```
Raw data
{
"_id": null,
"home_page": null,
"name": "openshift-python-scale-utilities",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12.0",
"maintainer_email": "Sarah Bennert <sarahbx@redhat.com>",
"keywords": "Kubevirt, Openshift, Openshift Virtualization",
"author": null,
"author_email": "Sarah Bennert <sarahbx@redhat.com>",
"download_url": null,
"platform": null,
"description": "# openshift-python-scale-utilities\n\nPypi: [openshift-python-scale-utilities](https://pypi.org/project/openshift-python-scale-utilities/)\n\nUtilities to assist in scaling [openshift-python-wrapper](https://github.com/RedHatQE/openshift-python-wrapper) resources\n\n## ocp_scale_utilities.threaded\n\nUtilizes [ThreadPoolExecutor](https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor)\nto operate on many resources in parallel across multiple threads.\n\n\n### Usage\n```\nfrom ocp_resources.virtual_machine import VirtualMachine\nfrom ocp_scale_utilities.threaded.utils import (\n threaded_deploy_resources,\n threaded_delete_resources,\n threaded_wait_deleted_resources,\n)\nfrom ocp_scale_utilities.threaded.scale import ThreadedScaleResources\n\n# Create iterable of VirtualMachine python objects to deploy\n# Be sure to use deepcopy() when passing dicts to objects to avoid collisions\nvms = [VirtualMachine(..., body=deepcopy(body))]\n\n# Option A:\n\ndef funcA():\n threaded_deploy_resources(resources=vms)\n yield vms\n threaded_delete_resources(resources=vms)\n threaded_wait_deleted_resources(resources=vms)\n\n# Option B:\n\ndef funcB():\n with ThreadedScaleResources(resources=vms, wait_for_status=VirtualMachine.Status.RUNNING):\n yield vms\n```\n\n## ocp_scale_utilities.monitoring\n\n`MonitorResourceAPIServerRequests` provides a way to monitor a specific resource to determine if it is being actively used. \nThis allows the ability to wait for resources to settle after a major scale action,\nimproving reliability, and increasing readability in prometheus data.\n\n### Usage\n\n```\nfrom ocp_resources.virtual_machine import VirtualMachine\nfrom ocp_scale_utilities.monitoring import MonitorResourceAPIServerRequests\nfrom ocp_scale_utilities.threaded.scale import ThreadedScaleResources\nfrom ocp_utilities.monitoring import Prometheus\n\nmonitor_api_requests = MonitorResourceAPIServerRequests(\n prometheus=Prometheus(...),\n resource_class=VirtualMachine,\n idle_requests_value=float(...), # Based on apiserver_request_total metric\n)\n\nmonitor_api_requests.wait_for_idle()\nwith ThreadedScaleResources(resources=vms):\n monitor_api_requests.wait_for_idle()\n yield vms\nmonitor_api_requests.wait_for_idle()\n\n```\n## ocp_scale_utilities.logger\n\nLogging at scale requires utilizing logging.QueueHandlers to avoid logging to closed streams.\n\n```\n root QueueHandler \u2510 \u250c> StreamHandler\n \u251c> Queue -> QueueListener \u2524\nbasic QueueHandler \u2518 \u2514> FileHandler\n```\n\n### Usage\n`main.py`\n```\nimport logging\nfrom ocp_scale_utilities.logger import setup_logging\n\nfrom module import func\n\nLOGGER = None\n\ndef main():\n LOGGER.warning(\"main logged warning message\")\n func()\n\nif __name__ == \"__main__\":\n log_listener = setup_logging(log_level=logging.WARNING, log_file=\"/tmp/example.log\")\n LOGGER = logging.getLogger(__name__)\n main()\n log_listener.stop()\n```\n`module.py`\n```\nimport logging\nLOGGER = logging.getLogger(__name__)\n\ndef func():\n LOGGER.warning(\"func logged warning message\")\n```\n\n## Contributing\n\nPlease use pre-commit to check the code before commiting\n```\npre-commit install\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "OpenShift Python Scale Utilities",
"version": "0.1.1.4",
"project_urls": {
"Bug Tracker": "https://github.com/RedHatQE/openshift-python-scale-utilities/issues",
"Download": "https://pypi.org/project/openshift-python-scale-utilities/",
"homepage": "https://github.com/RedHatQE/openshift-python-scale-utilities"
},
"split_keywords": [
"kubevirt",
" openshift",
" openshift virtualization"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "fd23eee48286ffafcc88e0891a3f104fd26ee4d363fed6bad46536306356a8c3",
"md5": "0340e4d20986deeda927a8e3cf7e5a7f",
"sha256": "b1c8cb418ac631962347228eaceea3df5c0b57e0651e8a3e086ce27fffedbc2c"
},
"downloads": -1,
"filename": "openshift_python_scale_utilities-0.1.1.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0340e4d20986deeda927a8e3cf7e5a7f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12.0",
"size": 11605,
"upload_time": "2025-08-16T15:13:03",
"upload_time_iso_8601": "2025-08-16T15:13:03.832498Z",
"url": "https://files.pythonhosted.org/packages/fd/23/eee48286ffafcc88e0891a3f104fd26ee4d363fed6bad46536306356a8c3/openshift_python_scale_utilities-0.1.1.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-16 15:13:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "RedHatQE",
"github_project": "openshift-python-scale-utilities",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "openshift-python-scale-utilities"
}