diff options
author | Sebastian Dziallas <sebastian@when.com> | 2009-03-20 22:55:28 (GMT) |
---|---|---|
committer | Sebastian Dziallas <sebastian@when.com> | 2009-03-20 22:55:28 (GMT) |
commit | 5c0babf7276d4826b084777a922f8c8298c433c6 (patch) | |
tree | 8644997610d4ececf28cfb28365b1e378b303cb8 /appliance.py | |
parent | 4a8e2a0eb551ce40a495a9aa0acdd61d0fe62ba2 (diff) |
remove old ks files and move to new build script (soas-2)
Diffstat (limited to 'appliance.py')
-rw-r--r-- | appliance.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/appliance.py b/appliance.py new file mode 100644 index 0000000..b28d89e --- /dev/null +++ b/appliance.py @@ -0,0 +1,55 @@ +#!/usr/bin/python + +import logging +import os +import sys +from time import gmtime, strftime + +import imgcreate +import appcreate +import shutil +import tarfile + +base_dir = os.path.dirname(__file__) +appliances_dir = os.path.join(base_dir, 'appliances') +cache_dir = os.path.join(base_dir, 'cache') +last_file = os.path.join(appliances_dir, 'last') + +def main(): + + if not os.path.exists(appliances_dir): + os.mkdir(appliances_dir) + + appliance_date = strftime("%Y%m%d", gmtime()) + appliance_name = 'soas2-%s' % appliance_date + if os.path.exists(os.path.join(appliances_dir, appliance_name + '.tar.gz')): + print 'Appliance %s exist already' % appliance_name + sys.exit(2) + + ks = imgcreate.read_kickstart(os.path.join(base_dir, 'appliance.ks')) + creator = appcreate.ApplianceImageCreator(ks, 'soas2-appliance', 'vmdk', 512, 1) + + try: + creator.mount(cachedir=cache_dir) + creator.install() + creator.configure() + creator.unmount() + creator.package(appliances_dir, "none", "") + except imgcreate.CreatorError, e: + logging.error("Unable to create appliance : %s" % e) + return 1 + finally: + creator.cleanup() + + os.chdir('./appliances') + + tar = tarfile.open('%s.tar.gz' % appliance_name, 'w:gz') + tar.add('soas2-appliance') + tar.close() + + shutil.rmtree('soas2-appliance') + + return 0 + +if __name__ == "__main__": + sys.exit(main()) |