0
votes

I'm interested in saving a python object in an openshift env variable.It appears the first thing to do is serialize the object with pickle. Based on http://pythontips.com/2013/08/02/what-is-pickle-in-python/, I have:

import pickle
a = ['test value','test value 2','test value 3']
file_Name = "testfile"
fileObject = open(file_Name,'wb') 
pickle.dump(a,fileObject)   
fileObject.close().

My next question is how to save the fileObject to a custom openshift env variable. Based on https://developers.openshift.com/en/managing-environment-variables.html#custom-variables, it appears you set it at the command line. I'd like to set it programmatically using python. How can I do this?

1

1 Answers

1
votes

Seems like you could probably just spawn a subprocess and run the appropriate commandline command (untested), e.g.

import subprocess, shlex

def openshift_env_var(appname, var, value): 
    cmd = 'rhc env set %s=%s -a %s' % (var, value, appname)
    subprocess.call(shlex.split(cmd))

>>> openshift_env_var('myapp', 'test', 'value')