Skip to main content

Wrapper around https://github.com/openshift/openshift-restclient-python

Project description

openshift-python-wrapper

A python wrapper for https://github.com/openshift/openshift-restclient-python.

With support for RedHat Container Virtualization. (Openshift Virtualization) https://www.openshift.com/learn/topics/virtualization/

Installation

From source:

git clone https://github.com/RedHatQE/openshift-python-wrapper.git
cd openshift-python-wrapper
python setup.py install --user

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.

Code check

We use pre-commit for code check.

pre-commit install

Project details


Release history Release notifications | RSS feed

This version

1.5

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-1.5.tar.gz (36.9 kB view details)

Uploaded Source

File details

Details for the file openshift-python-wrapper-1.5.tar.gz.

File metadata

  • Download URL: openshift-python-wrapper-1.5.tar.gz
  • Upload date:
  • Size: 36.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for openshift-python-wrapper-1.5.tar.gz
Algorithm Hash digest
SHA256 91fb4fad2263638b3cb363ea491e1919800f3beb1546fc0d742697c98c7f9ca5
MD5 d86eaa8993e56138bd45f19a73427f5f
BLAKE2b-256 52856069bfd137e197e36b5e75b83fe181d9204fffc2c3c1b09c0db5357ec46a

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