Skip to main content

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.9 release, run:
git checkout v4.9
git pull
release-it # Follow the instructions

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

openshift_python_wrapper-4.9.13.tar.gz (53.3 kB view details)

Uploaded Source

Built Distribution

openshift_python_wrapper-4.9.13-py3-none-any.whl (89.9 kB view details)

Uploaded Python 3

File details

Details for the file openshift_python_wrapper-4.9.13.tar.gz.

File metadata

  • Download URL: openshift_python_wrapper-4.9.13.tar.gz
  • Upload date:
  • Size: 53.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/6.3.12-200.fc38.x86_64

File hashes

Hashes for openshift_python_wrapper-4.9.13.tar.gz
Algorithm Hash digest
SHA256 9214640d17b0d368e334e919444403ef2155df258357da317596e537a18f42a2
MD5 3c2424b2214e555c53069e5340c93cc8
BLAKE2b-256 cbd04c706475723055b89332fe3670df8e748c111a712d0a09d91affcd5cb027

See more details on using hashes here.

File details

Details for the file openshift_python_wrapper-4.9.13-py3-none-any.whl.

File metadata

File hashes

Hashes for openshift_python_wrapper-4.9.13-py3-none-any.whl
Algorithm Hash digest
SHA256 b808cb31f63a9cdfd05320a17668a318a8222d12fa817629d431ae3f022ee6e2
MD5 22286ead862dbefe79c20bbbaf78b2a5
BLAKE2b-256 f1bf9048933a232fcae85d0de3a637a05f3b2bd39adf4665523ae143f83a4293

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page