File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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 ))
You can’t perform that action at this time.
0 commit comments