Package VMBuilder
[frames] | no frames]

Source Code for Package VMBuilder

 1  #!/usr/bin/python 
 2  # 
 3  #    Uncomplicated VM Builder 
 4  #    Copyright (C) 2007-2009 Canonical Ltd. 
 5  #     
 6  #    See AUTHORS for list of contributors 
 7  # 
 8  #    This program is free software: you can redistribute it and/or modify 
 9  #    it under the terms of the GNU General Public License version 3, as 
10  #    published by the Free Software Foundation. 
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  #    The publically exposed bits of VMBuilder 
21  # 
22  import logging 
23  import VMBuilder.plugins 
24  from   VMBuilder.distro     import Distro 
25  from   VMBuilder.hypervisor import Hypervisor 
26  from   VMBuilder.plugins    import Plugin 
27  from   VMBuilder.frontend   import Frontend 
28  from   VMBuilder.vm         import VM 
29  from   VMBuilder.exception  import VMBuilderException, VMBuilderUserError 
30   
31  # Internal bookkeeping 
32  distros = {} 
33  hypervisors = {} 
34  _plugins = [] 
35  frontends = {} 
36  frontend = None 
37   
38  # This is meant to be populated by plugins. It should contain a list of the files that we give back to the user. 
39   
40 -def register_hypervisor(cls):
41 """Register a hypervisor plugin with VMBuilder""" 42 hypervisors[cls.arg] = cls
43
44 -def register_distro(cls):
45 """Register a distro plugin with VMBuilder""" 46 distros[cls.arg] = cls
47
48 -def register_frontend(cls):
49 """Register a frontend plugin with VMBuilder""" 50 frontends[cls.arg] = cls
51
52 -def register_plugin(cls):
53 """Register a plugin with VMBuilder""" 54 _plugins.append(cls)
55
56 -def set_frontend(arg):
57 global frontend 58 if arg in frontends.keys(): 59 frontend = frontends[arg]() 60 else: 61 raise VMBuilderException("Unknown frontend")
62
63 -def run():
64 """This is sort of weird, but a handy shortcut, if you want to use one of the frontends""" 65 frontend.run()
66 67 logging.debug('Loading plugins') 68 VMBuilder.plugins.load_plugins() 69