rancher-client
Python Rancher Client with Async Support
This library is a fork from Rancher's official client-python to enable support of:
- Environment Variables for Service Usage
- Async [WIP] / Sync Client Support
- Replace
requestsin favor ofhttpx
Installing
Note: This package requires Python 3+
pip install rancher-client
pip install git+https://github.com/growthengineai/rancher-client.git@main
Environment Variables
Below are the currently supported Environment Variables
One of the following sets:
-
RANCHER_URL: str = "" -
RANCHER_ACCESS_KEY: str = "" -
RANCHER_SECRET_KEY: str = "" -
RANCHER_TOKEN: str = None -
CATTLE_URL: str = "" -
CATTLE_ACCESS_KEY: str = "" -
CATTLE_SECRET_KEY: str = "" -
CATTLE_TOKEN: str = None -
HTTPX_TIMEOUT: float = 15.0 -
HTTPX_KEEPALIVE: int = 50 -
HTTPX_MAXCONNECT: int = 200 -
SSL_VERIFY: bool = True -
RANCHER_LOG_LEVEL: str = "info" -
RANCHER_CACHE_DIR: str =~/rancher-client/rancher/.cache
Using API
import rancher
from rancher import RancherClient
client = RancherClient(url='https://localhost:8443/v3',
access_key='<some valid access key>',
secret_key='<some valid secret key>')
# curl -s https://localhost:8443/v3/users?me=true
client.list_user(me='true')
# curl -s -X POST https://localhost:8443/v3/users -H 'Content-Type: application/json' -d '{ "username" : "user1", "password": "Password1" }'
client.create_user(username='user1', password='Password1')
# curl -s -X PUT https://localhost:8443/v3/users/user-xyz123 -H 'Content-Type: application/json' -d '{ "description" : "A user" }'
user = client.by_id_user('user-xyz123')
client.update(user, description='A user')
# curl -s -X DELETE https://localhost:8443/v3/users/user-xyz123
user = client.by_id_user('user-xyz123')
client.delete(user)
# Links
# curl -s https://localhost:8443/v3/clusterRoleTemplateBindings?userId=user-xyz123
user = client.by_id_user('user-xyz123')
user.clusterRoleTemplateBindings()
Examples
Actions Rancher API spec
From the spec
"Actions perform an operation on a resource and (optionally) return a result."
To perform the setpodsecuritypolicytemplate action on a project object these are the steps.
This first method has built-in retry logic inside of client.action() when the error returned is 409
#creates a project and handles cleanup
project = admin_pc.project
# create an api_client from a management context
api_client = admin_mc.client
# perform the action via the client api
api_client.action(obj=project, action_name="setpodsecuritypolicytemplate",
podSecurityTemplateId=pspt.id)
Or alternatively, performing the action from the project context (which does not have built-in retry logic)
project = api_client.create_project(name="test-project", clusterId="local")
project.setpodsecuritypolicytemplate(podSecurityPolicyTemplateId="my-pspt")
Metadata
Release files for rancher-client 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rancher-client-0.0.1.tar.gz | 2.9 kB | Without provenance | Details for rancher-client-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rancher_client-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for rancher_client-0.0.1-py3-none-any.whl |
Total release size: 5.4 kB
Release files / rancher-client-0.0.1.tar.gz
| Download URL | rancher-client-0.0.1.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9472849dfe8decb8e3f9a0149f3f4e8d8d6aa3def4868f3726039160b0121f8a
|
|
BLAKE2b-256 checksum How to use checksums |
0724fa9f9d0de5a02d3fd6b88f97d56354032aa4f52e65da5c8f27f117625e35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.8.10
|
Release files / rancher_client-0.0.1-py3-none-any.whl
| Download URL | rancher_client-0.0.1-py3-none-any.whl |
|---|---|
| Size | 2.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bf6eb164ef95460b450341b979b482783ce2c83d23a1ca5e75ba61fd9d69405e
|
|
BLAKE2b-256 checksum How to use checksums |
0ac38c7f7ebf402778b4aaab367ff81fa6fc4de4a0527985871f17ff2dba7fae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.8.10
|
Security for rancher-client 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.