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.log 
 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.exception  import VMBuilderException, VMBuilderUserError 
 29   
 30  # Internal bookkeeping 
 31  distros = {} 
 32  hypervisors = {} 
 33  _distro_plugins = [] 
 34  _hypervisor_plugins = [] 
 35   
 36  # This is meant to be populated by plugins. It should contain a list of the files that we give back to the user. 
 37   
38 -def register_hypervisor(cls):
39 """ 40 Register a hypervisor class with VMBuilder 41 42 @type cls: Hypervisor 43 @param cls: The new Hypervisor subclass to be registered with VMBuilder 44 """ 45 hypervisors[cls.arg] = cls
46
47 -def get_hypervisor(name):
48 """ 49 Get Hypervisor subclass by name 50 51 @type name: string 52 @param name: Name of the Hypervisor subclass (defined by its .arg attribute) 53 """ 54 if name in hypervisors: 55 return hypervisors[name] 56 else: 57 raise VMBuilderUserError('No such hypervisor. Available hypervisors: %s' % (' '.join(hypervisors.keys())))
58
59 -def register_distro(cls):
60 """ 61 Register a distro class with VMBuilder 62 63 @type cls: Distro 64 @param cls: The new Distro subclass to be registered with VMBuilder 65 """ 66 distros[cls.arg] = cls
67
68 -def get_distro(name):
69 """ 70 Get Distro subclass by name 71 72 @type name: string 73 @param name: Name of the Distro subclass (defined by its .arg attribute) 74 """ 75 if name in distros: 76 return distros[name] 77 else: 78 raise VMBuilderUserError('No such distro. Available distros: %s' % (' '.join(distros.keys())))
79
80 -def register_distro_plugin(cls):
81 """ 82 Register a distro plugin with VMBuilder 83 84 B{Note}: A "distro plugin" is not a plugin that implements a new 85 Distro. It's a plugin that pertains to Distro's. If you want to 86 register a new Distro, use register_distro. 87 88 @type cls: Plugin 89 @param cls: The Plugin class to registered as a distro plugin 90 """ 91 _distro_plugins.append(cls) 92 _distro_plugins.sort(key=lambda x: x.priority)
93
94 -def register_hypervisor_plugin(cls):
95 """ 96 Register a hypervisor plugin with VMBuilder 97 98 B{Note}: A "hypervisor plugin" is not a plugin that implements a new 99 Hypervisor. It's a plugin that pertains to Hypervisor's. If you 100 want to register a new Hypervisor, use register_hypervisor. 101 102 @type cls: Plugin 103 @param cls: The Plugin class to registered as a hypervisor plugin 104 """ 105 _hypervisor_plugins.append(cls) 106 _hypervisor_plugins.sort(key=lambda x: x.priority)
107
108 -def set_console_loglevel(level):
109 """ 110 Adjust the loglevel that will be sent to the console. 111 112 @type level: number 113 @param level: See the standard logging module 114 """ 115 VMBuilder.log.console.setLevel(level)
116
117 -def get_version_info():
118 """ 119 Return a dict containing version information for VMBuilder. 120 121 @return: A dict with (at least) the following keys: 122 - major: Major version number. 123 - minor: Minor version number. 124 - micro: Micro version number. 125 - revno: The revision number of the current branch or the branch from which the tarball was created. 126 """ 127 import vcsversion 128 info = vcsversion.version_info 129 info['major'] = 0 130 info['minor'] = 12 131 info['micro'] = 4 132 return info
133 134 logging.debug('Loading plugins') 135 VMBuilder.plugins.load_plugins() 136