Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/appliance.py
blob: ccbf983895bfa2cc0916a78780780bb2a16ea2b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python

import logging
import os
import sys
from time import gmtime, strftime

import imgcreate
import appcreate
import shutil
import zipfile

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 = 'soas3-%s' % appliance_date
    if os.path.exists(os.path.join(appliances_dir, appliance_name + '.tar.gz')):
	print 'Appliance %s exists already' % appliance_name
	sys.exit(2)

    ks = imgcreate.read_kickstart(os.path.join(base_dir, 'soas-appliance.ks'))
    creator = appcreate.ApplianceImageCreator(ks, 'soas3-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')

    zip = zipfile.ZipFile('%s.zip' % appliance_name, 'w', zipfile.ZIP_DEFLATED)
    zip.write('soas3-appliance/soas3-appliance-sda.vmdk', '%s.vmdk' % appliance_name)
    zip.close()

    shutil.rmtree('soas3-appliance')

    return 0

if __name__ == "__main__":
    sys.exit(main())