Wrapper around https://github.com/openshift/openshift-restclient-python
Project description
openshift-python-wrapper
Pypi: openshift-python-wrapper
A python wrapper for openshift-restclient-python with support for RedHat Container Virtualization. (Openshift Virtualization)
Docs: openshift-python-wrapper docs
Installation
From source:
git clone https://github.com/RedHatQE/openshift-python-wrapper.git
cd openshift-python-wrapper
python setup.py install --user
From pypi:
pip install openshift-python-wrapper --user
Release new version
requirements:
- gh github cli
gh auth login # Follow login instructions
sudo npm install github-release-notes -g
- export GREN_GITHUB_TOKEN=< TOKEN >
- Run ./scripts/release.sh providing source branch and target version (must be executed from main branch)
usage:
./scripts/release.sh main v1.5.5
docs
Hosted on readthedocs.io
## PR dependency
For PR dependency we use [dpulls](https://www.dpulls.com/)
To make PR depends on other PR add `depends on #<PR NUMBER>` in the PR description.
## Examples
### Client
```python
client = DynamicClient(client=kubernetes.config.new_client_from_config())
The examples given below are relevant to all resources. For simplicity we will use the resource - Namespace.
Import
Import Namespace:
from resources.namespace import Namespace
Create
Create a Namespace:
ns = Namespace(name="namespace-example-1")
ns.create()
Will return True
if creation succeeded.
We can also use the with
statement which ensures automatic clean-up of the code executed:
with Namespace(name="namespace-example-2") as ns:
yield ns
teardown=False
- Disables clean-up after execution.
Wait
Wait for Namespace to be in status Active
:
ns.wait_for_status(status=Namespace.Status.ACTIVE, timeout=120)
Will raise a TimeoutExpiredError
if Namespace is not in the desired status.
Delete
Delete the Namespace
ns.delete()
Will return False
if not found.
Exists
Checks if Namespace exists on the server:
ns.exists
Will return None
if not found.
Get
Query to get Pods (resource) in the connected cluster with label of label_example=example
. Returns a generator
of the resource - pod
for pod in Pod.get(dyn_client=client, label_selector="label_example=example")):
pod.log()
We can also get the name of the Node that the pod
is running on:
pod.node.name
VM
Start:
with VirtualMachine(
name="vm-example",
namespace="namespace-example",
node_selector="worker-node-example",
) as vm:
vm.start()
Stop:
vm.stop()
Restart:
vm.restart()
Get VMI:
test_vmi = vm.vmi
After having a VMI, we can wait until VMI is in running state:
test_vmi.wait_until_running()
Will raise TimeoutExpiredError
if VMI failed to run.
Then, we can get the Pod that is in Running state and execute a command on it:
command_output = test_vmi.virt_launcher_pod.execute(command="command-example")
If no Pod was found, will raise ResourceNotFoundError
.
Code check
We use pre-commit for code check.
pre-commit install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for openshift-python-wrapper-2.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e75f324d812209a03c2d8437f95910761d9f87bd46d01e996bdba2c23d03aa8 |
|
MD5 | 9e8d0a2505c91ce7c2f0266187ff1bda |
|
BLAKE2b-256 | 3938033c2700f5202341947b8232ae0b80eb70c7077d360eb5e44daf2f77e7af |