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

Source Code for Package VMBuilder.plugins

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