Name: openshift-restclient-python
Owner: OpenShift
Description: Python client for the OpenShift API
Created: 2017-02-16 13:19:01.0
Updated: 2018-05-23 07:24:47.0
Pushed: 2018-05-23 21:03:48.0
Size: 3226
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Python client for the OpenShift API.
From source:
clone https://github.com/openshift/openshift-restclient-python.git
penshift-restclient-python
on setup.py install
From PyPi directly:
install openshift
Using Dockerfile:
er build -t openshift-restclient-python -f Dockerfile .
The OpenShift client depends on the Kubernetes Python client, and as part of the installation process, the Kubernetes (K8s) client is automatically installed.
In the case you are using Docker, you will likely need to share your .kube/config
with the openshift-restclient-python
container:
er run -it -v $HOME/.kube/config:/root/.kube/config:z openshift-restclient-python python
There are two ways this project interacts with the OpenShift API. The first, now deprecated, is to use models and functions generated with swagger from the API spec. The second, new approach, is to use a single model and client to generically interact with all resources on the server. The dynamic client also works with resources that are defined by aggregated API servers or Custom Resource Definitions.
To work with the dynamic client, you will need an instantiated kubernetes client object. For example, the following uses the dynamic client to create a new Service object:
rt yaml
kubernetes import client, config
openshift.dynamic import DynamicClient
client = config.new_client_from_config()
client = DynamicClient(k8s_client)
ervices = dyn_client.resources.get(api_version='v1', kind='Service')
ice = """
: Service
ersion: v1
data:
me: my-service
:
lector:
app: MyApp
s:
protocol: TCP
port: 8080
targetPort: 9376
ice_data = yaml.load(service)
= v1_services.create(body=service_data, namespace='default')
sp is a ResourceInstance object
t(resp.metadata)
Now in the following example, we use the dynamic client to create a Route object, and associate it with the new Service:
rt yaml
kubernetes import client, config
openshift.dynamic import DynamicClient
client = config.new_client_from_config()
client = DynamicClient(k8s_client)
outes = dyn_client.resources.get(api_version='route.openshift.io/v1', kind='Route')
e = """
ersion: route.openshift.io/v1
: Route
data:
me: frontend
:
st: www.example.com
:
kind: Service
name: my-service
e_data = yaml.load(route)
= v1_routes.create(body=route_data, namespace='default')
sp is a ResourceInstance object
t(resp.metadata)
And finally, the following uses the dynamic client to list Projects the user can access:
kubernetes import client, config
openshift.dynamic import DynamicClient
client = config.new_client_from_config()
client = DynamicClient(k8s_client)
rojects = dyn_client.resources.get(api_version='project.openshift.io/v1', kind='Project')
ect_list = v1_projects.get()
project in project_list.items:
print(project.metadata.name)
To work with a K8s object, use the K8s client, and to work with an OpenShift specific object, use the OpenShift client. For example, the following uses the K8s client to create a new Service object:
rt yaml
kubernetes import client, config
ig.load_kube_config()
= client.CoreV1Api()
ice = """
: Service
ersion: v1
data:
me: my-service
:
lector:
app: MyApp
s:
protocol: TCP
port: 8080
targetPort: 9376
ice_data = yaml.load(service)
= api.create_namespaced_service(body=service_data, namespace='default')
sp is a V1Service object
t resp.metadata.self_link
Now in the following example, we use the OpenShift client to create a Route object, and associate it with the new Service:
rt yaml
openshift import client, config
ig.load_kube_config()
= client.OapiApi()
e = """
ersion: v1
: Route
data:
me: frontend
:
st: www.example.com
:
kind: Service
name: my-service
e_data = yaml.load(route)
= api.create_namespaced_route(body=route_data, namespace='default')
sp is a V1Route object
t resp.metadata.self_link
And finally, the following uses the OpenShift client to list Projects the user can access:
openshift import client, config
ig.load_kube_config()
= client.OapiApi()
ect_list = oapi.list_project()
project in project_list.items:
print project.metadata.name
All OpenShift API and Model documentation can be found in the Generated client's README file
Updating the generated client requires the following tools:
To apply the updates:
1) Incorporate new changes to update scripts
- [scripts/constants.py](./scripts/constants.py), [scripts/pom.xml](./scripts/pom.xml), [scripts/preprocess_spec.py](./scripts/preprocess_spec.py), and [update-client.sh](./update-client.sh) are the most important
2) Run tox -e update_client
We are downstream of the kubernetes python client. We maintain compatibility for API version n-2
- so if you are connecting to a version 3.6 OpenShift cluster, the list of supported python client versions would be [0.3.x, 0.4.x, 0.5.x]
.
| openshift python | kubernetes python | Kubernetes 1.5 | Kubernetes 1.6 | Kubernetes 1.7 | Kubernetes 1.8 | Kubernetes 1.9 | |——————|——————-|—————-|—————-|—————-|—————-|—————-| | openshift 0.3 | kubernetes 3.0 | + | + | ? | - | - | | openshift 0.4 | kubernetes 4.0 | + | + | + | ? | - | | openshift 0.5 | kubernetes 5.0 | + | + | + | + | ? | | openshift HEAD | kubernetes HEAD | + | +* | + | + | ? |
Key:
?
Exactly the same features / API objects in both openshift-restclient-python and the OpenShift
version.+
openshift-restclient-python has features or api objects that may not be present in the
OpenShift cluster, but everything they have in common will work.-
The OpenShift cluster has features the openshift-restclient-python library can't use
(additional API objects, etc).*
This client/server combination may work, but is not officially supported.If you have any problem with the package or any suggestions, please file an issue.
Participation in the Kubernetes community is governed by the CNCF Code of Conduct.