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
39
41 logging.info("Cleaning up")
42 while len(self._cleanup_cbs) > 0:
43 self._cleanup_cbs.pop(0)()
44
45 - def add_clean_cb(self, cb):
46 self._cleanup_cbs.insert(0, cb)
47
48 - def add_clean_cmd(self, *argv, **kwargs):
49 cb = lambda : run_cmd(*argv, **kwargs)
50 self.add_clean_cb(cb)
51 return cb
52
53 - def cancel_cleanup(self, cb):
54 try:
55 self._cleanup_cbs.remove(cb)
56 except ValueError:
57
58 pass
59
60
61 - def register_hook(self, hook_name, func):
62 self.hooks[hook_name] = self.hooks.get(hook_name, []) + [func]
63
64 - def call_hooks(self, *args, **kwargs):
65 try:
66 call_hooks(self, *args, **kwargs)
67 except Exception:
68
69 raise
70
75
77 self.chroot_dir = chroot_dir
78
85
87 """Install the distro into destdir"""
88 raise NotImplemented('Distro subclasses need to implement the has_xen_support method')
89
91 """Install the distro into destdir"""
92 raise NotImplemented('Distro subclasses need to implement the install method')
93
94 - def post_mount(self, fs):
95 """Called each time a filesystem is mounted to let the distro add things to the filesystem"""
96
98 """Let the distro copy the install logfile to the guest"""
99