Wrapper around https://github.com/kubernetes-client/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:
- Export GitHub token
export GITHUB_TOKEN=<your_github_token>
sudo npm install --global release-it
npm install --save-dev @release-it/bumper
usage:
- Create a release, run from the relevant branch.
To create a 4.8 release, run:
git checkout v4.8
git pull
release-it # Follow the instructions
docs
Hosted on readthedocs.io openshift-python-wrapper
PR dependency
For PR dependency we use dpulls
To make PR depends on other PR add depends on #<PR NUMBER>
in the PR description.
Logging configuration
To change log level export OPENSHIFT_PYTHON_WRAPPER_LOG_LEVEL:
export OPENSHIFT_PYTHON_WRAPPER_LOG_LEVEL=<LOG_LEVEL> # can be: "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"
Examples
Client
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
.
NNCP Capture Syntax
Using capture syntax to switch ipv4 config between interfaces
with NodeNetworkConfigurationPolicy(
name="capture_nncp",
capture={'first-nic': 'interfaces.name=="ens8"',
'second-nic': 'interfaces.name=="ens9"'},
teardown=False, # Capture doesn't support reverting config on teardown
...
) as nncp:
nncp.add_interface(name="{{ capture.first-nic.interfaces.0.name }}", set_ipv4="{{ capture.second-nic.interfaces.0.ipv4 }}")
nncp.add_interface(name="{{ capture.second-nic.interfaces.0.name }}", set_ipv4="{{ capture.first-nic.interfaces.0.ipv4 }}")
yield nncp
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
Built Distribution
Hashes for openshift_python_wrapper-4.8.21.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d699d429286a4eb5db7c8a6dca2af7cd4216904613e0d69178d996897e4e5249 |
|
MD5 | b23fda31ca5ad02d44eb877200c09708 |
|
BLAKE2b-256 | 1208374bae6ff91c73d10d5dba7d281d3ece8830c750a689c2b5000aa6aa5eda |
Hashes for openshift_python_wrapper-4.8.21-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 295deb1f3429e57e7682810e912f131b7be299ad4680c38f258abd64592d627f |
|
MD5 | 3979832b60eec1a95b2301126767dbb7 |
|
BLAKE2b-256 | a77853971e948188da006c5ad0bbdf28e572c6a10209c583100a324333446c0d |