Package VMBuilder
[frames] | no frames]

Source Code for Package VMBuilder

 1  #!/usr/bin/python 
 2  # 
 3  #    Uncomplicated VM Builder 
 4  #    Copyright (C) 2007-2008 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 as published by 
10  #    the Free Software Foundation, either version 3 of the License, or 
11  #    (at your option) any later version. 
12  # 
13  #    This program is distributed in the hope that it will be useful, 
14  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  #    GNU General Public License for more details. 
17  # 
18  #    You should have received a copy of the GNU General Public License 
19  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
20  # 
21  #    The publically exposed bits of VMBuilder 
22  # 
23  import logging 
24  import VMBuilder.plugins 
25  from   VMBuilder.distro     import Distro 
26  from   VMBuilder.hypervisor import Hypervisor 
27  from   VMBuilder.plugins    import Plugin 
28  from   VMBuilder.frontend   import Frontend 
29  from   VMBuilder.vm         import VM 
30  from   VMBuilder.exception  import VMBuilderException, VMBuilderUserError 
31   
32  # Internal bookkeeping 
33  distros = {} 
34  hypervisors = {} 
35  _plugins = [] 
36  frontends = {} 
37  frontend = None 
38   
39  # This is meant to be populated by plugins. It should contain a list of the files that we give back to the user. 
40   
41 -def register_hypervisor(cls):
42 """Register a hypervisor plugin with VMBuilder""" 43 hypervisors[cls.arg] = cls
44
45 -def register_distro(cls):
46 """Register a distro plugin with VMBuilder""" 47 distros[cls.arg] = cls
48
49 -def register_frontend(cls):
50 """Register a frontend plugin with VMBuilder""" 51 frontends[cls.arg] = cls
52
53 -def register_plugin(cls):
54 """Register a plugin with VMBuilder""" 55 _plugins.append(cls)
56
57 -def set_frontend(arg):
58 global frontend 59 if arg in frontends.keys(): 60 frontend = frontends[arg]() 61 else: 62 raise VMBuilderException("Unknown frontend")
63
64 -def run():
65 """This is sort of weird, but a handy shortcut, if you want to use one of the frontends""" 66 frontend.run()
67 68 logging.debug('Loading plugins') 69 VMBuilder.plugins.load_plugins() 70