Giter Site home page Giter Site logo

duyanyan / openshift-python-wrapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redhatqe/openshift-python-wrapper

0.0 1.0 0.0 892 KB

A python wrapper for https://github.com/openshift/openshift-restclient-python. With support for RedHat Container Virtualization.

License: Apache License 2.0

Makefile 0.29% Shell 1.23% Python 98.48%

openshift-python-wrapper's Introduction

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 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 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

openshift-python-wrapper's People

Contributors

adizav avatar akalenyu avatar amastbau avatar anatw avatar dalia-frank avatar dbasunag avatar duyanyan avatar geetikakay avatar guy9050 avatar ibesso-rh avatar ibragins avatar inbarrose avatar jpeimer avatar kbidarkar avatar mguetta1 avatar mor120 avatar myakove avatar ngavrilo avatar obaireys avatar ofirnash1 avatar pkliczewski avatar qwang1 avatar rnetser avatar ronikishner avatar sarahbx avatar sbulage avatar vsibirsk avatar yossisegev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.