Skip to content

Commit 45ae266

Browse files
Merge pull request #68 from bradmwilliams/oc-process-bug
Adding a template processing example
2 parents 0024aa3 + 43feff9 commit 45ae266

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

examples/templates.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/python
2+
3+
import openshift as oc
4+
5+
'''
6+
This example will scan all the templates, on the cluster, and look specifically for the openshift/nginx-example
7+
template. If the template is located, it clears the namespace (to prevent an error when calling 'oc process'),
8+
updates any template parameter(s), processes the template, and then creates the objects in the current namespace.
9+
'''
10+
if __name__ == '__main__':
11+
with oc.client_host():
12+
templates = oc.selector('templates', all_namespaces=True)
13+
14+
for template in templates.objects():
15+
if template.model.metadata.namespace == 'openshift' and template.model.metadata.name == 'nginx-example':
16+
template.model.metadata.namespace = ''
17+
18+
obj = oc.APIObject(dict_to_model=template.as_dict())
19+
20+
parameters = {
21+
'NAME': 'my-nginx',
22+
}
23+
24+
processed_template = obj.process(parameters=parameters)
25+
obj_sel = oc.create(processed_template)
26+
27+
for obj in obj_sel.objects():
28+
print('Created: {}/{}'.format(obj.model.kind, obj.model.metadata.name))
29+
print(obj.as_json(indent=4))

0 commit comments

Comments
 (0)