Skip to content

Instantly share code, notes, and snippets.

@henrysher
Last active December 23, 2015 05:49
Show Gist options
  • Save henrysher/6589465 to your computer and use it in GitHub Desktop.
Save henrysher/6589465 to your computer and use it in GitHub Desktop.
userdata_base64.py
#!/usr/bin/env python
import os
import sys
import base64
import simplejson
def usage():
print >> sys.stderr, 'Usage: %s {f_userdata} {f_spot_configuration}' % (
os.path.basename(sys.argv[0]))
exit(1)
def main():
if len(sys.argv) != 3:
usage()
spot_cfg = simplejson.load(open(sys.argv[2], "r"))
spot_cfg['UserData'] = base64.b64encode(open(sys.argv[1], "r").read())
simplejson.dump(spot_cfg, open(sys.argv[2],"w"), sort_keys=True, indent=4, separators=(',', ': '))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment