1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import logging
22 import os
23
24 from VMBuilder.util import run_cmd, call_hooks
25 import VMBuilder.plugins
26
27 -class Context(VMBuilder.plugins.Plugin):
29 self._config = {}
30 super(Context, self).__init__(self)
31 self.plugins = [plugin_class(self) for plugin_class in self.plugin_classes]
32 self.plugins.sort(key=lambda x:x.priority)
33 self._cleanup_cbs = []
34 self.hooks = {}
35 self.template_dirs = [os.path.expanduser('~/.vmbuilder/%s'),
36 os.path.dirname(__file__) + '/plugins/%s/templates',
37 '/etc/vmbuilder/%s']
38 self.overwrite = False
39
40
42 logging.info("Cleaning up")
43 while len(self._cleanup_cbs) > 0:
44 self._cleanup_cbs.pop(0)()
45
46 - def add_clean_cb(self, cb):
47 self._cleanup_cbs.insert(0, cb)
48
49 - def add_clean_cmd(self, *argv, **kwargs):
50 cb = lambda : run_cmd(*argv, **kwargs)
51 self.add_clean_cb(cb)
52 return cb
53
54 - def cancel_cleanup(self, cb):
55 try:
56 self._cleanup_cbs.remove(cb)
57 except ValueError:
58
59 pass
60
61
62 - def register_hook(self, hook_name, func):
63 self.hooks[hook_name] = self.hooks.get(hook_name, []) + [func]
64
65 - def call_hooks(self, *args, **kwargs):
66 try:
67 call_hooks(self, *args, **kwargs)
68 except Exception:
69 self.cleanup()
70 raise
71
76
78 self.chroot_dir = chroot_dir
79
86
88 """Install the distro into destdir"""
89 raise NotImplemented('Distro subclasses need to implement the has_xen_support method')
90
92 """Install the distro into destdir"""
93 raise NotImplemented('Distro subclasses need to implement the install method')
94
95 - def post_mount(self, fs):
96 """Called each time a filesystem is mounted to let the distro add things to the filesystem"""
97
99 """Let the distro copy the install logfile to the guest"""
100