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   
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 return self.vm.install_file(path, VMBuilder.util.render_template(self.__module__.split('.')[2], self.vm, tmplname, context), mode=mode)
71