Package VMBuilder :: Package plugins
[frames] | no frames]

Source Code for Package VMBuilder.plugins

 1  # 
 2  #    Uncomplicated VM Builder 
 3  #    Copyright (C) 2007-2009 Canonical Ltd. 
 4  #     
 5  #    See AUTHORS for list of contributors 
 6  # 
 7  #    This program is free software: you can redistribute it and/or modify 
 8  #    it under the terms of the GNU General Public License version 3, as 
 9  #    published by the Free Software Foundation. 
10  # 
11  #    This program is distributed in the hope that it will be useful, 
12  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  #    GNU General Public License for more details. 
15  # 
16  #    You should have received a copy of the GNU General Public License 
17  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
18  # 
19  import os 
20  import VMBuilder 
21  from VMBuilder.util import run_cmd 
22   
23 -def load_plugins():
24 for plugin in find_plugins(): 25 exec "import %s" % plugin
26
27 -def find_plugins():
28 retval = [] 29 for plugin_dir in __path__: 30 for p in os.listdir(plugin_dir): 31 path = '%s/%s' % (plugin_dir, p) 32 if os.path.isdir(path) and os.path.isfile('%s/__init__.py' % path): 33 retval.append("VMBuilder.plugins.%s" % p) 34 return retval
35
36 -class Plugin(object):
37 - def __init__(self, vm):
38 self.vm = vm 39 self.register_options()
40
41 - def register_options(self):
42 pass
43
44 - def set_defaults(self):
45 pass
46
47 - def preflight_check(self):
48 """ 49 Override this method with checks for anything that might cause the VM creation to fail 50 51 raise an exception if you can see already that this won't work 52 """ 53 pass
54
55 - def post_install(self):
56 """ 57 This is called just after the distro is installed, before it gets copied to the fs images. 58 """ 59 pass
60
61 - def deploy(self):
62 """ 63 Perform deployment of the VM. 64 65 If True is returned, no further deployment will be done. 66 """ 67 return False
68
69 - def install_from_template(self, path, tmplname, context=None, mode=None):
70 if not self.vm.fsmounted: 71 raise VMBuilderException('install_from_template called while file system is not mounted') 72 return self.vm.install_file(path, VMBuilder.util.render_template(self.__module__.split('.')[2], self.vm, tmplname, context), mode=mode)
73
74 - def run_in_target(self, *args, **kwargs):
75 if not self.vm.fsmounted: 76 raise VMBuilderException('install_from_template called while file system is not mounted') 77 return run_cmd('chroot', self.vm.installdir, *args, **kwargs)
78