openshift-client 2.0.4__tar.gz → 2.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openshift-client-2.0.4 → openshift_client-2.0.6}/PKG-INFO +145 -108
- {openshift-client-2.0.4 → openshift_client-2.0.6}/README.md +139 -102
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/__init__.py +1 -1
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/action.py +1 -1
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/apiobject.py +10 -8
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/base_verbs.py +24 -11
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client.egg-info/PKG-INFO +145 -108
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client.egg-info/requires.txt +2 -1
- {openshift-client-2.0.4 → openshift_client-2.0.6}/pyproject.toml +3 -4
- {openshift-client-2.0.4 → openshift_client-2.0.6}/LICENSE +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/ansible.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/config.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/context.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/decorators.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/model.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/naming.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/result.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/selector.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/status.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/test_apiobject.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/test_model.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/test_selector.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/test_util.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client/util.py +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client.egg-info/SOURCES.txt +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client.egg-info/dependency_links.txt +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/packages/openshift_client.egg-info/top_level.txt +0 -0
- {openshift-client-2.0.4 → openshift_client-2.0.6}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: openshift-client
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.6
|
|
4
4
|
Summary: OpenShift python client
|
|
5
5
|
Author-email: Justin Pierce <jupierce@redhat.com>
|
|
6
6
|
Maintainer-email: Brad Williams <brawilli@redhat.com>
|
|
@@ -205,20 +205,21 @@ Classifier: Intended Audience :: Information Technology
|
|
|
205
205
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
206
206
|
Classifier: Operating System :: OS Independent
|
|
207
207
|
Classifier: Programming Language :: Python
|
|
208
|
-
Classifier: Programming Language :: Python :: 2
|
|
209
|
-
Classifier: Programming Language :: Python :: 2.7
|
|
210
208
|
Classifier: Programming Language :: Python :: 3
|
|
211
209
|
Classifier: Programming Language :: Python :: 3.12
|
|
212
210
|
Classifier: Topic :: Utilities
|
|
213
|
-
Requires-Python: >=
|
|
211
|
+
Requires-Python: >=3.0
|
|
214
212
|
Description-Content-Type: text/markdown
|
|
215
213
|
License-File: LICENSE
|
|
216
|
-
Requires-Dist:
|
|
214
|
+
Requires-Dist: build
|
|
217
215
|
Requires-Dist: six
|
|
216
|
+
Requires-Dist: pyyaml
|
|
218
217
|
Provides-Extra: ssh
|
|
219
218
|
Requires-Dist: paramiko; extra == "ssh"
|
|
219
|
+
Dynamic: license-file
|
|
220
220
|
|
|
221
221
|
# Openshift Python Client
|
|
222
|
+
|
|
222
223
|
<!-- Install doctoc with `npm install -g doctoc` then `doctoc README.md --github` -->
|
|
223
224
|
|
|
224
225
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
@@ -228,73 +229,82 @@ Requires-Dist: paramiko; extra == "ssh"
|
|
|
228
229
|
- [Overview](#overview)
|
|
229
230
|
- [Reader Prerequisites](#reader-prerequisites)
|
|
230
231
|
- [Setup](#setup)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
- [Prerequisites](#prerequisites)
|
|
233
|
+
- [Installation Instructions](#installation-instructions)
|
|
234
|
+
- [Using PIP](#using-pip)
|
|
235
|
+
- [For development](#for-development)
|
|
235
236
|
- [Usage](#usage)
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
237
|
+
- [Quickstart](#quickstart)
|
|
238
|
+
- [Selectors](#selectors)
|
|
239
|
+
- [APIObjects](#apiobjects)
|
|
240
|
+
- [Making changes to APIObjects](#making-changes-to-apiobjects)
|
|
241
|
+
- [Running within a Pod](#running-within-a-pod)
|
|
242
|
+
- [Tracking oc invocations](#tracking-oc-invocations)
|
|
243
|
+
- [Time limits](#time-limits)
|
|
244
|
+
- [Advanced contexts](#advanced-contexts)
|
|
245
|
+
- [Something missing?](#something-missing)
|
|
246
|
+
- [Running oc on a bastion host](#running-oc-on-a-bastion-host)
|
|
247
|
+
- [Gathering reports and logs with selectors](#gathering-reports-and-logs-with-selectors)
|
|
248
|
+
- [Advanced verbs:](#advanced-verbs)
|
|
248
249
|
- [Examples](#examples)
|
|
249
250
|
- [Environment Variables](#environment-variables)
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
251
|
+
- [Defaults when invoking `oc`](#defaults-when-invoking-oc)
|
|
252
|
+
- [Master timeout](#master-timeout)
|
|
253
|
+
- [SSH Client Host](#ssh-client-host)
|
|
253
254
|
|
|
254
255
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
255
256
|
|
|
256
257
|
## Overview
|
|
258
|
+
|
|
257
259
|
The [openshift-client-python](https://www.github.com/openshift/openshift-client-python) library aims to provide a readable, concise, comprehensive, and fluent
|
|
258
260
|
API for rich interactions with an [OpenShift](https://www.openshift.com) cluster. Unlike other clients, this library exclusively uses the command
|
|
259
261
|
line tool (oc) to achieve the interactions. This approach comes with important benefits and disadvantages when compared
|
|
260
262
|
to other client libraries.
|
|
261
263
|
|
|
262
264
|
Pros:
|
|
265
|
+
|
|
263
266
|
- No additional software needs to be installed on the cluster. If a system with python support can (1) invoke `oc`
|
|
264
|
-
locally OR (2) ssh to a host and invoke `oc`, you can use the library.
|
|
267
|
+
locally OR (2) ssh to a host and invoke `oc`, you can use the library.
|
|
265
268
|
- Portable. If you have python and `oc` working, you don't need to worry about OpenShift versions or machine architectures.
|
|
266
269
|
- Custom resources are supported and treated just like any other resource. There is no need to generate code to support them.
|
|
267
270
|
- Quick to learn. If you understand the `oc` command line interface, you can use this library.
|
|
268
271
|
|
|
269
272
|
Cons:
|
|
273
|
+
|
|
270
274
|
- This API is not intended to implement something as complex as a controller. For example, it does not implement
|
|
271
|
-
watch functionality. If you can't imagine accomplishing your use case through CLI interactions, this API is probably
|
|
272
|
-
not the right starting point for it.
|
|
275
|
+
watch functionality. If you can't imagine accomplishing your use case through CLI interactions, this API is probably
|
|
276
|
+
not the right starting point for it.
|
|
273
277
|
- If you care about whether a REST API returns a particular error code, this API is probably not for you. Since it
|
|
274
|
-
is based on the CLI, high level return codes are used to determine success or failure.
|
|
278
|
+
is based on the CLI, high level return codes are used to determine success or failure.
|
|
275
279
|
|
|
276
280
|
## Reader Prerequisites
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
281
|
+
|
|
282
|
+
* Familiarity with OpenShift [command line interface](https://docs.okd.io/latest/cli_reference/index.html)
|
|
283
|
+
is highly encouraged before exploring the API's features. The API leverages
|
|
284
|
+
the [oc](https://docs.okd.io/latest/cli_reference/openshift_cli/getting-started-cli.html#cli-getting-started)
|
|
285
|
+
binary and, in many cases, passes method arguments directly on to the command line. This document cannot, therefore,
|
|
286
|
+
provide a complete description of all possible OpenShift interactions -- the user may need to reference
|
|
287
|
+
the CLI documentation to find the pass-through arguments a given interaction requires.
|
|
282
288
|
|
|
283
289
|
* A familiarity with Python is assumed.
|
|
284
290
|
|
|
285
291
|
## Setup
|
|
292
|
+
|
|
286
293
|
### Prerequisites
|
|
294
|
+
|
|
287
295
|
1. Download and install the OpenShift [command-line Tools](https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/) needed to access your OpenShift cluster.
|
|
288
296
|
|
|
289
297
|
### Installation Instructions
|
|
290
298
|
|
|
291
299
|
#### Using PIP
|
|
300
|
+
|
|
292
301
|
1. Install the `openshift-client` module from PyPI.
|
|
293
302
|
```bash
|
|
294
303
|
sudo pip install openshift-client
|
|
295
304
|
```
|
|
296
305
|
|
|
297
306
|
#### For development
|
|
307
|
+
|
|
298
308
|
1. Git clone https://github.com/openshift/openshift-client-python.git (or your fork).
|
|
299
309
|
2. Add required libraries
|
|
300
310
|
```bash
|
|
@@ -306,6 +316,7 @@ the CLI documentation to find the pass-through arguments a given interaction req
|
|
|
306
316
|
## Usage
|
|
307
317
|
|
|
308
318
|
### Quickstart
|
|
319
|
+
|
|
309
320
|
Any standard Python application should be able to use the API if it imports the openshift package. The simplest
|
|
310
321
|
possible way to begin using the API is login to your target cluster before running your first application.
|
|
311
322
|
|
|
@@ -319,20 +330,20 @@ print('OpenShift client version: {}'.format(oc.get_client_version()))
|
|
|
319
330
|
print('OpenShift server version: {}'.format(oc.get_server_version()))
|
|
320
331
|
|
|
321
332
|
# Set a project context for all inner `oc` invocations and limit execution to 10 minutes
|
|
322
|
-
with oc.project('openshift-infra'), oc.timeout(10*60):
|
|
333
|
+
with oc.project('openshift-infra'), oc.timeout(10 * 60):
|
|
323
334
|
# Print the list of qualified pod names (e.g. ['pod/xyz', 'pod/abc', ...] in the current project
|
|
324
335
|
print('Found the following pods in {}: {}'.format(oc.get_project_name(), oc.selector('pods').qnames()))
|
|
325
|
-
|
|
336
|
+
|
|
326
337
|
# Read in the current state of the pod resources and represent them as python objects
|
|
327
338
|
for pod_obj in oc.selector('pods').objects():
|
|
328
|
-
|
|
339
|
+
|
|
329
340
|
# The APIObject class exposes several convenience methods for interacting with objects
|
|
330
341
|
print('Analyzing pod: {}'.format(pod_obj.name()))
|
|
331
342
|
pod_obj.print_logs(timestamps=True, tail=15)
|
|
332
|
-
|
|
343
|
+
|
|
333
344
|
# If you need access to the underlying resource definition, get a Model instance for the resource
|
|
334
345
|
pod_model = pod_obj.model
|
|
335
|
-
|
|
346
|
+
|
|
336
347
|
# Model objects enable dot notation and allow you to navigate through resources
|
|
337
348
|
# to an arbitrary depth without checking if any ancestor elements exist.
|
|
338
349
|
# In the following example, there is no need for boilerplate like:
|
|
@@ -347,6 +358,7 @@ with oc.project('openshift-infra'), oc.timeout(10*60):
|
|
|
347
358
|
```
|
|
348
359
|
|
|
349
360
|
### Selectors
|
|
361
|
+
|
|
350
362
|
Selectors are a central concept used by the API to interact with collections
|
|
351
363
|
of OpenShift resources. As the name implies, a "selector" selects zero or
|
|
352
364
|
more resources on a server which satisfy user specified criteria. An apt
|
|
@@ -368,10 +380,10 @@ sa_selector = oc.selector(["serviceaccount/deployer", "serviceaccount/builder"])
|
|
|
368
380
|
|
|
369
381
|
# Performing an operation will act on all selected resources. In this case,
|
|
370
382
|
# both serviceaccounts are labeled.
|
|
371
|
-
sa_selector.label({"mylabel"
|
|
383
|
+
sa_selector.label({"mylabel": "myvalue"})
|
|
372
384
|
|
|
373
385
|
# Selectors can also select based on kind and labels.
|
|
374
|
-
sa_label_selector = oc.selector("sa", labels={"mylabel":"myvalue"})
|
|
386
|
+
sa_label_selector = oc.selector("sa", labels={"mylabel": "myvalue"})
|
|
375
387
|
|
|
376
388
|
# We should find the service accounts we just labeled.
|
|
377
389
|
print("Found labeled serviceaccounts: " + sa_label_selector.names())
|
|
@@ -407,7 +419,7 @@ project = projects[0]
|
|
|
407
419
|
|
|
408
420
|
# The APIObject exposes methods providing simple access to metadata and common operations.
|
|
409
421
|
print('The project is: {}/{}'.format(project.kind(), project.name()))
|
|
410
|
-
project.label({
|
|
422
|
+
project.label({'mylabel': 'myvalue'})
|
|
411
423
|
|
|
412
424
|
# And the APIObject allow you to interact with an object's data via the 'model' attribute.
|
|
413
425
|
# The Model is similar to a standard dict, but also allows dot notation to access elements
|
|
@@ -444,6 +456,7 @@ oc.selector('node/alpha').object().model.status.conditions.can_match(
|
|
|
444
456
|
}
|
|
445
457
|
)
|
|
446
458
|
|
|
459
|
+
|
|
447
460
|
# can_match can also ensure nest objects and list are present within a resource. Several
|
|
448
461
|
# of these types of checks are already implemented in the openshift.status module.
|
|
449
462
|
def is_route_admitted(apiobj):
|
|
@@ -461,8 +474,8 @@ def is_route_admitted(apiobj):
|
|
|
461
474
|
})
|
|
462
475
|
```
|
|
463
476
|
|
|
464
|
-
|
|
465
477
|
### Making changes to APIObjects
|
|
478
|
+
|
|
466
479
|
```python
|
|
467
480
|
# APIObject exposes simple interfaces to delete and patch the resource it represents.
|
|
468
481
|
# But, more interestingly, you can make detailed changes to the model and apply those
|
|
@@ -471,6 +484,7 @@ def is_route_admitted(apiobj):
|
|
|
471
484
|
project.model.metadata.labels['my_label'] = 'myvalue'
|
|
472
485
|
project.apply()
|
|
473
486
|
|
|
487
|
+
|
|
474
488
|
# If modifying the underlying API resources could be contentious, use the more robust
|
|
475
489
|
# modify_and_apply method which can retry the operation multiple times -- refreshing
|
|
476
490
|
# with the current object state between failures.
|
|
@@ -480,6 +494,7 @@ def make_model_change(apiobj):
|
|
|
480
494
|
apiobj.model.data['somefile.yaml'] = 'wyxz'
|
|
481
495
|
return True
|
|
482
496
|
|
|
497
|
+
|
|
483
498
|
# modify_and_apply will call the function and attempt to apply its changes to the model
|
|
484
499
|
# if it returns True. If the apply is rejected by the API, the function will pull
|
|
485
500
|
# the latest object content, call make_model_change again, and try the apply again
|
|
@@ -508,18 +523,20 @@ def set_unmanaged_in_cvo(apiobj):
|
|
|
508
523
|
apiobj.model.spec.overrides.append(desired_entry)
|
|
509
524
|
return True
|
|
510
525
|
|
|
526
|
+
|
|
511
527
|
result, changed = oc.selector('clusterversion.config.openshift.io/version').object().modify_and_apply(set_unmanaged_in_cvo)
|
|
512
528
|
if changed:
|
|
513
529
|
context.report_change('Instructed CVO to ignore openshift-samples operator')
|
|
514
530
|
|
|
515
531
|
```
|
|
516
532
|
|
|
517
|
-
|
|
518
533
|
### Running within a Pod
|
|
534
|
+
|
|
519
535
|
It is simple to use the API within a Pod. The `oc` binary automatically
|
|
520
536
|
detects it is running within a container and automatically uses the Pod's serviceaccount token/cacert.
|
|
521
537
|
|
|
522
538
|
### Tracking oc invocations
|
|
539
|
+
|
|
523
540
|
It is good practice to setup at least one tracking context within your application so that
|
|
524
541
|
you will be able to easily analyze what `oc` invocations were made on your behalf and the result
|
|
525
542
|
of those operations. *Note that details about all `oc` invocations performed within the context will
|
|
@@ -535,61 +552,63 @@ with oc.tracking() as tracker:
|
|
|
535
552
|
print('Current user: {}'.format(oc.whoami()))
|
|
536
553
|
except:
|
|
537
554
|
print('Error acquiring current username')
|
|
538
|
-
|
|
555
|
+
|
|
539
556
|
# Print out details about the invocations made within this context.
|
|
540
557
|
print(tracker.get_result())
|
|
541
558
|
```
|
|
542
559
|
|
|
543
560
|
In this case, the tracking output would look something like:
|
|
561
|
+
|
|
544
562
|
```json
|
|
545
563
|
{
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
564
|
+
"status": 0,
|
|
565
|
+
"operation": "tracking",
|
|
566
|
+
"actions": [
|
|
567
|
+
{
|
|
568
|
+
"status": 0,
|
|
569
|
+
"verb": "project",
|
|
570
|
+
"references": {},
|
|
571
|
+
"in": null,
|
|
572
|
+
"out": "aos-cd\n",
|
|
573
|
+
"err": "",
|
|
574
|
+
"cmd": [
|
|
575
|
+
"oc",
|
|
576
|
+
"project",
|
|
577
|
+
"-q"
|
|
578
|
+
],
|
|
579
|
+
"elapsed_time": 0.15344810485839844,
|
|
580
|
+
"internal": false,
|
|
581
|
+
"timeout": false,
|
|
582
|
+
"last_attempt": true
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
"status": 0,
|
|
586
|
+
"verb": "whoami",
|
|
587
|
+
"references": {},
|
|
588
|
+
"in": null,
|
|
589
|
+
"out": "aos-ci-jenkins\n",
|
|
590
|
+
"err": "",
|
|
591
|
+
"cmd": [
|
|
592
|
+
"oc",
|
|
593
|
+
"whoami"
|
|
594
|
+
],
|
|
595
|
+
"elapsed_time": 0.6328380107879639,
|
|
596
|
+
"internal": false,
|
|
597
|
+
"timeout": false,
|
|
598
|
+
"last_attempt": true
|
|
599
|
+
}
|
|
600
|
+
]
|
|
583
601
|
}
|
|
584
602
|
```
|
|
585
603
|
|
|
586
|
-
Alternatively, you can record actions yourself by passing an action_handler to the tracking
|
|
604
|
+
Alternatively, you can record actions yourself by passing an action_handler to the tracking
|
|
587
605
|
contextmanager. Your action handler will be invoked each time an `oc` invocation completes.
|
|
588
606
|
|
|
589
607
|
```python
|
|
590
608
|
def print_action(action):
|
|
591
609
|
print('Performed: {} - status={}'.format(action.cmd, action.status))
|
|
592
610
|
|
|
611
|
+
|
|
593
612
|
with oc.tracking(action_handler=print_action):
|
|
594
613
|
try:
|
|
595
614
|
print('Current project: {}'.format(oc.get_project_name()))
|
|
@@ -600,14 +619,16 @@ with oc.tracking(action_handler=print_action):
|
|
|
600
619
|
```
|
|
601
620
|
|
|
602
621
|
### Time limits
|
|
622
|
+
|
|
603
623
|
Have a script you want to ensure succeeds or fails within a specific period of time? Use
|
|
604
|
-
a `timeout` context. Timeout contexts can be nested - if any timeout context expires,
|
|
605
|
-
the current oc invocation will be killed.
|
|
624
|
+
a `timeout` context. Timeout contexts can be nested - if any timeout context expires,
|
|
625
|
+
the current oc invocation will be killed.
|
|
606
626
|
|
|
607
627
|
```python
|
|
608
628
|
#!/usr/bin/python
|
|
609
629
|
import openshift_client as oc
|
|
610
630
|
|
|
631
|
+
|
|
611
632
|
def node_is_ready(node):
|
|
612
633
|
ready = node.model.status.conditions.can_match({
|
|
613
634
|
'type': 'Ready',
|
|
@@ -626,38 +647,42 @@ You will be able to see in `tracking` context results that a timeout occurred fo
|
|
|
626
647
|
invocation. The `timeout` field will be set to `True`.
|
|
627
648
|
|
|
628
649
|
### Advanced contexts
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
650
|
+
|
|
651
|
+
If you are unable to use a KUBECONFIG environment variable or need fine grained control over the
|
|
652
|
+
server/credentials you communicate with for each invocation, use openshift-client-python contexts.
|
|
653
|
+
Contexts can be nested and cause oc invocations within them to use the most recently established
|
|
632
654
|
context information.
|
|
633
655
|
|
|
634
656
|
```python
|
|
635
657
|
with oc.api_server('https:///....'): # use the specified api server for nested oc invocations.
|
|
636
|
-
|
|
658
|
+
|
|
637
659
|
with oc.token('abc..'): # --server=... --token=abc... will be included in inner oc invocations.
|
|
638
660
|
print("Current project: " + oc.get_project_name())
|
|
639
|
-
|
|
661
|
+
|
|
640
662
|
with oc.token('def..'): # --server=... --token=def... will be included in inner oc invocations.
|
|
641
663
|
print("Current project: " + oc.get_project_name())
|
|
642
664
|
```
|
|
643
665
|
|
|
644
|
-
You can control the loglevel specified
|
|
666
|
+
You can control the loglevel specified for `oc` invocations.
|
|
667
|
+
|
|
645
668
|
```python
|
|
646
669
|
with oc.loglevel(6):
|
|
647
|
-
|
|
670
|
+
# all oc invocations within this context will be invoked with --loglevel=6
|
|
648
671
|
oc...
|
|
649
672
|
```
|
|
650
673
|
|
|
651
674
|
You ask `oc` to skip TLS verification if necessary.
|
|
675
|
+
|
|
652
676
|
```python
|
|
653
677
|
with oc.tls_verify(enable=False):
|
|
654
|
-
|
|
678
|
+
# all oc invocations within this context will be invoked with --insecure-skip-tls-verify
|
|
655
679
|
oc...
|
|
656
680
|
```
|
|
657
681
|
|
|
658
682
|
### Something missing?
|
|
659
|
-
|
|
660
|
-
|
|
683
|
+
|
|
684
|
+
Most common API iterations have abstractions, but if there is no openshift-client-python API
|
|
685
|
+
exposing the `oc` function you want to run, you can always use `oc.invoke` to directly pass arguments to
|
|
661
686
|
an `oc` invocation on your host.
|
|
662
687
|
|
|
663
688
|
```python
|
|
@@ -683,6 +708,7 @@ occur on the remote host.
|
|
|
683
708
|
### Gathering reports and logs with selectors
|
|
684
709
|
|
|
685
710
|
Various objects within OpenShift have logs associated with them:
|
|
711
|
+
|
|
686
712
|
- pods
|
|
687
713
|
- deployments
|
|
688
714
|
- daemonsets
|
|
@@ -701,6 +727,7 @@ with oc.project('openshift-monitoring'):
|
|
|
701
727
|
```
|
|
702
728
|
|
|
703
729
|
The above example would output something like:
|
|
730
|
+
|
|
704
731
|
```
|
|
705
732
|
Container: openshift-monitoring:pod/node-exporter-hw5r5(node-exporter)
|
|
706
733
|
time="2018-10-22T21:07:36Z" level=info msg="Starting node_exporter (version=0.16.0, branch=, revision=)" source="node_exporter.go:82"
|
|
@@ -709,19 +736,21 @@ time="2018-10-22T21:07:36Z" level=info msg=" - arp" source="node_exporter.go:97"
|
|
|
709
736
|
...
|
|
710
737
|
```
|
|
711
738
|
|
|
712
|
-
Note that these logs are held in memory. Use tail or other available method parameters to ensure
|
|
739
|
+
Note that these logs are held in memory. Use tail or other available method parameters to ensure
|
|
713
740
|
predictable and efficient results.
|
|
714
741
|
|
|
715
742
|
To simplify even further, you can ask the library to pretty-print the logs for you:
|
|
743
|
+
|
|
716
744
|
```python
|
|
717
745
|
oc.selector(['daemonset', 'deployment']).print_logs()
|
|
718
746
|
```
|
|
719
747
|
|
|
720
|
-
And to quickly pull together significant diagnostic data on selected objects, use `report()` or `print_report()`.
|
|
748
|
+
And to quickly pull together significant diagnostic data on selected objects, use `report()` or `print_report()`.
|
|
721
749
|
A report includes the following information for each selected object, if available:
|
|
750
|
+
|
|
722
751
|
- `object` - The current state of the object.
|
|
723
752
|
- `describe` - The output of describe on the object.
|
|
724
|
-
- `logs` - If applicable, a map of logs -- one of each container associated with the object.
|
|
753
|
+
- `logs` - If applicable, a map of logs -- one of each container associated with the object.
|
|
725
754
|
|
|
726
755
|
```python
|
|
727
756
|
# Pretty-print a detail set of data about all deploymentconfigs, builds, and configmaps in the
|
|
@@ -732,23 +761,26 @@ oc.selector(['dc', 'build', 'configmap']).print_report()
|
|
|
732
761
|
### Advanced verbs:
|
|
733
762
|
|
|
734
763
|
Running oc exec on a pod.
|
|
764
|
+
|
|
735
765
|
```python
|
|
736
766
|
result = oc.selector('pod/alertmanager-main-0').object().execute(['cat'],
|
|
737
767
|
container_name='alertmanager',
|
|
738
768
|
stdin='stdin for cat')
|
|
739
|
-
|
|
769
|
+
print(result.out())
|
|
740
770
|
```
|
|
741
771
|
|
|
742
772
|
Finding all pods running on a node:
|
|
773
|
+
|
|
743
774
|
```python
|
|
744
775
|
with oc.client_host():
|
|
745
776
|
for node_name in oc.selector('nodes').qnames():
|
|
746
777
|
print('Pods running on node: {}'.format(node_name))
|
|
747
|
-
|
|
748
|
-
|
|
778
|
+
for pod_obj in oc.get_pods_by_node(node_name):
|
|
779
|
+
print(' {}'.format(pod_obj.fqname()))
|
|
749
780
|
```
|
|
750
781
|
|
|
751
782
|
Example output:
|
|
783
|
+
|
|
752
784
|
```
|
|
753
785
|
...
|
|
754
786
|
Pods running on node: node/ip-172-31-18-183.ca-central-1.compute.internal
|
|
@@ -764,34 +796,39 @@ Pods running on node: node/ip-172-31-18-183.ca-central-1.compute.internal
|
|
|
764
796
|
- [Some unit tests](examples/cluster_tests.py)
|
|
765
797
|
|
|
766
798
|
## Environment Variables
|
|
767
|
-
|
|
768
|
-
|
|
799
|
+
|
|
800
|
+
To allow openshift-client-python applications to be portable between environments without needing to be modified,
|
|
801
|
+
you can specify many default contexts in the environment.
|
|
769
802
|
|
|
770
803
|
### Defaults when invoking `oc`
|
|
804
|
+
|
|
771
805
|
Establishing explicit contexts within an application will override these environment defaults.
|
|
806
|
+
|
|
772
807
|
- `OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_PATH` - default path to use when invoking `oc`
|
|
773
808
|
- `OPENSHIFT_CLIENT_PYTHON_DEFAULT_CONFIG_PATH` - default `--kubeconfig` argument
|
|
774
809
|
- `OPENSHIFT_CLIENT_PYTHON_DEFAULT_API_SERVER` - default `--server` argument
|
|
775
|
-
- `OPENSHIFT_CLIENT_PYTHON_DEFAULT_CA_CERT_PATH` - default `--
|
|
810
|
+
- `OPENSHIFT_CLIENT_PYTHON_DEFAULT_CA_CERT_PATH` - default `--certificate-authority` argument
|
|
776
811
|
- `OPENSHIFT_CLIENT_PYTHON_DEFAULT_PROJECT` - default `--namespace` argument
|
|
777
812
|
- `OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_LOGLEVEL` - default `--loglevel` argument
|
|
778
813
|
- `OPENSHIFT_CLIENT_PYTHON_DEFAULT_SKIP_TLS_VERIFY` - default `--insecure-skip-tls-verify`
|
|
779
814
|
|
|
780
815
|
### Master timeout
|
|
816
|
+
|
|
781
817
|
Defines an implicit outer timeout(..) context for the entire application. This allows you to ensure
|
|
782
818
|
that an application terminates within a reasonable time, even if the author of the application has
|
|
783
819
|
not included explicit timeout contexts. Like any `timeout` context, this value is not overridden
|
|
784
820
|
by subsequent `timeout` contexts within the application. It provides an upper bound for the entire
|
|
785
821
|
application's oc interactions.
|
|
786
822
|
|
|
787
|
-
- `OPENSHIFT_CLIENT_PYTHON_MASTER_TIMEOUT`
|
|
823
|
+
- `OPENSHIFT_CLIENT_PYTHON_MASTER_TIMEOUT`
|
|
788
824
|
|
|
789
825
|
### SSH Client Host
|
|
790
|
-
|
|
826
|
+
|
|
827
|
+
In some cases, it is desirable to run an openshift-client-python application using a local `oc` binary and
|
|
791
828
|
in other cases, the `oc` binary resides on a remote client. Encoding this decision in the application
|
|
792
829
|
itself is unnecessary.
|
|
793
830
|
|
|
794
|
-
Simply wrap you application in a `client_host` context without arguments. This will try to pull
|
|
831
|
+
Simply wrap you application in a `client_host` context without arguments. This will try to pull
|
|
795
832
|
client host information from environment variables if they are present. If they are not present,
|
|
796
833
|
the application will execute on the local host.
|
|
797
834
|
|
|
@@ -800,7 +837,7 @@ in the environment. Otherwise, `oc` interactions will be executed on the host ru
|
|
|
800
837
|
|
|
801
838
|
```python
|
|
802
839
|
with oc.client_host(): # if OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_HOSTNAME if not defined in the environment, this is a no-op
|
|
803
|
-
print(
|
|
840
|
+
print('Found nodes: {}'.format(oc.selector('nodes').qnames()))
|
|
804
841
|
```
|
|
805
842
|
|
|
806
843
|
- `OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_HOSTNAME` - The hostname on which the `oc` binary resides
|