|
2 | 2 |
|
3 | 3 | from __future__ import print_function
|
4 | 4 | from __future__ import absolute_import
|
5 |
| -from openshift import * |
| 5 | + |
| 6 | +import openshift as oc |
| 7 | +from openshift import null, Missing, OpenShiftPythonException |
6 | 8 |
|
7 | 9 | try:
|
8 | 10 |
|
9 |
| - print("Projects created by users:", \ |
10 |
| - oc.selector("projects").narrow( |
11 |
| - lambda project: project.metadata.annotations["openshift.io/requester"] is not Missing |
| 11 | + print("Projects created by users:", oc.selector("projects").narrow( |
| 12 | + lambda prj: prj.metadata.annotations["openshift.io/requester"] is not Missing |
12 | 13 | ).qnames())
|
13 | 14 |
|
14 | 15 | oc.selector("projects").narrow(
|
15 | 16 | # Eliminate any projects created by the system
|
16 |
| - lambda project: project.metadata.annotations["openshift.io/requester"] is not Missing |
| 17 | + lambda prj: prj.metadata.annotations["openshift.io/requester"] is not Missing |
17 | 18 | ).narrow(
|
18 | 19 | # Select from user projects any which violate privileged naming convention
|
19 |
| - lambda project: |
20 |
| - project.metadata.qname == "openshift" or |
21 |
| - project.metadata.qname.startswith("openshift-") or |
22 |
| - project.metadata.qname == "kubernetes" or |
23 |
| - project.metadata.qname.startswith("kube-") or |
24 |
| - project.metadata.qname.startswith("kubernetes-") |
| 20 | + lambda prj: |
| 21 | + prj.metadata.qname == "openshift" or |
| 22 | + prj.metadata.qname.startswith("openshift-") or |
| 23 | + prj.metadata.qname == "kubernetes" or |
| 24 | + prj.metadata.qname.startswith("kube-") or |
| 25 | + prj.metadata.qname.startswith("kubernetes-") |
25 | 26 | ).for_each(
|
26 |
| - lambda project: error("Invalid project: %s" % project.metadata.qname) |
| 27 | + lambda prj: oc.error("Invalid project: %s" % prj.metadata.qname) |
27 | 28 | )
|
28 | 29 |
|
29 |
| - with timeout(5): |
| 30 | + with oc.timeout(5): |
30 | 31 | success, obj = oc.selector("pods").until_any(lambda pod: pod.status.phase == "Succeeded")
|
31 | 32 | if success:
|
32 | 33 | print("Found one pod was successful: " + str(obj))
|
33 | 34 |
|
34 |
| - with timeout(5): |
| 35 | + with oc.timeout(5): |
35 | 36 | success, obj = oc.selector("pods").narrow("pod").until_any(
|
36 | 37 | lambda pod: pod.status.conditions.can_match({"type": "Ready", "status": False, "reason": "PodCompleted"}))
|
37 | 38 | if success:
|
38 | 39 | print("Found one pod was successful: " + str(obj))
|
39 | 40 |
|
| 41 | + with oc.project("myproject") as project: |
40 | 42 |
|
41 |
| - |
42 |
| - with project("myproject"): |
43 |
| - |
44 |
| - oc.create_if_absent( |
| 43 | + project.create_if_absent( |
45 | 44 | {
|
46 | 45 | "apiVersion": "v1",
|
47 | 46 | "kind": "User",
|
|
56 | 55 | }
|
57 | 56 | )
|
58 | 57 |
|
59 |
| - oc.create_if_absent( |
| 58 | + project.create_if_absent( |
60 | 59 | {
|
61 | 60 | "apiVersion": "v1",
|
62 | 61 | "kind": "User",
|
|
71 | 70 | }
|
72 | 71 | )
|
73 | 72 |
|
74 |
| - |
75 | 73 | pods = oc.selector("pod")
|
76 | 74 | print("Pods: " + str(pods.qnames()))
|
77 | 75 |
|
|
84 | 82 | print(str(user))
|
85 | 83 |
|
86 | 84 | john = oc.selector("user/john")
|
87 |
| - john.label({"mylabel": None}) # remove a label |
| 85 | + john.label({"mylabel": null}) # remove a label |
88 | 86 |
|
89 | 87 | label_selector = oc.selector("users", labels={"mylabel": "myvalue"})
|
90 | 88 |
|
|
98 | 96 |
|
99 | 97 | users.label({"another_label": "another_value"})
|
100 | 98 |
|
101 |
| - john.patch({ |
| 99 | + john.object().patch({ |
102 | 100 | "groups": null,
|
103 | 101 | "identities": [
|
104 | 102 | "github: 19783215"
|
|
117 | 115 | if user.notthere.dontcare.wontbreak is not Missing:
|
118 | 116 | print("Should see this, but also shouldn't see exception")
|
119 | 117 |
|
120 |
| - oc.delete_if_present("user/bark", "user/bite") |
| 118 | + project.delete_if_present("user/bark", "user/bite") |
121 | 119 |
|
122 | 120 | bark_obj = {
|
123 | 121 | "apiVersion": "v1",
|
|
157 | 155 |
|
158 | 156 | bark_bite_sel.until_any(lambda obj: obj.metadata.qname == "bite")
|
159 | 157 |
|
160 |
| - |
161 |
| - |
162 | 158 | except OpenShiftPythonException as e:
|
163 | 159 | print("An exception occurred: " + str(e))
|
0 commit comments