1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
31 distros = {}
32 hypervisors = {}
33 _distro_plugins = []
34 _hypervisor_plugins = []
35
36
37
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
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
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
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
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
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
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
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