0

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 Answer 1

1

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.